1129 Commits

Author SHA1 Message Date
Péter Gál 27da5a538c Update API version number (#3000)
JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-08-01 13:24:41 +02:00
Péter Gál 8ebd3230a1 Make sure that snapshot API return values are the same as in the docs (#2997)
The snapshot API docs describe that those functions returns error if
the related features are not enabled. Updated the return values to follow
the API documentation.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-31 19:23:55 +02:00
Péter Gál 1409a68dcb Generate jerryscript-config.h before build (#2934)
Previously after the library was build there was no easy way
to get back the information of how it was build.

This change adds a bit of CMake code to generate the
jerryscript-config.h file containing the default options
and adding the modified build options/features.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-31 19:21:24 +02:00
Péter Gál c90306449e Correctly handle call arguments when using 'super' calls (#2996)
There are two interconnected changes here:
* Added missing argument number handling for `super.propname(..)` calls.
* The `super.propname.call(...)` is does not need extra 'this' binding helper.

Fixes #2990.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-31 15:13:06 +02:00
Dániel Bátyai dfafb1aa6b Fix unhandled exceptions with unicode error messages (#2994)
Fixes #2993

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-30 19:48:56 +02:00
Dániel Bátyai a2d242eab9 Use python3 for mbedOS build on Travis (#2995)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-30 16:46:16 +02:00
Péter Gál 99b061ad10 Fix incorrect feature guard for class support (#2992)
In `ecma-helpers.c` there was an incorrect macro guard which
tested the `JERRY_ES2015` feature but the `JERRY_ES2015_CLASS`
feature should be tested instead.

Profile options for testing:
* JERRY_ES2015=0
* JERRY_ES2015_CLASS=1
* JERRY_ES2015_OBJECT_INITIALIZER=1

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-29 14:29:21 +02:00
Péter Gál c64ee882da Introduce new jerry-ext methods to ease property registration (#2715)
New methods
* jerryx_set_properties: Allows multiple property registration for via a single call
* jerryx_set_property_str: Allows property registration without the need to
    create the property name JS value. The property name can be directly passed
    as a `const char*` value and must be zero terminated.
* jerryx_get_property_str: Allows getting a property value on a given object.
    The property name can be directly passed as a `const char*` value.
* jerryx_has_property_str: Allows checking if a property exists on a given object.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-25 20:37:44 +02:00
Péter Gál 3e12738037 Improve single-source generation (#2989)
Detected and fixed minor issues with the single-source generation:
* On Windows the line info generation now correctly escapes the path separators.
* Fixed an incorrect C file include order. Now the global object C file is
  force included to get all common headers at the start in the generated source
  file.
* Added a missing colon which fixed the correct removal of the config.h include.
* Fix the command line help.
* Small typo fix.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-25 20:34:12 +02:00
Dániel Bátyai 6744376bbe Add Configuration doc to the README (#2988)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-25 20:33:20 +02:00
Istvan Miklos 7575fa454a Migration Guide (#2419)
* Migration Guide

Migration guide from JerryScript 1.0 to 2.0.

Co-authored-by: László Langó llango.u-szeged@partner.samsung.com
Co-authored-by: Peter Gal pgal.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu

* Add version information for API methods

For each API method/type the documentation now includes
the version it was introduced or a change occured.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-25 20:33:03 +02:00
Dániel Bátyai d3c78d8c6a Improve lastIndex calculation in RegExp match (#2982)
Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-25 18:20:51 +02:00
Péter Gál 50be3a5384 Document and improve the single-source generation (#2986)
Changes done:
* Added usage/configuration info for this mode.
* Created `tools/srcgenerator.py` to allow source/header generation
  without using CMake.
* Adapted CMake to use the `srcgenerator.py` script.
* Added jerry-libm single-source build.
* Improved the `srcmerger.py` script to correctly handle the line numbering.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-25 12:46:00 +02:00
Csaba Osztrogonác 7685afddf9 Fix Math.pow (#2985)
The Math.pow implementation calls libm's pow. The ISO C and ES5.1
standards differ on some special cases of pow. jerry-libm is already
ES5.1 conform, but system libm libraries on Linux and Windows aren't.

Math.pow(NaN, +/-0.0) is NaN on Windows and Linux with system libm,
but should be 1.0 according to ES5.1 / 15.8.2.13.

This patch handles this special case in Math.pow instead of calling pow of libm.

JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu
2019-07-24 19:41:03 +02:00
Szilagyi Adam ea577d6ed0 Add keys, values, entires functions for typedArray (#2925)
Extended the typedArray functionality based on ES2015

Co-authored-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
2019-07-24 15:48:28 +02:00
Péter Gál 434994eb67 Add extra details for the api example page (#2956)
Add simple examples and details on how to execute them.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-24 15:47:55 +02:00
Csaba Osztrogonác 81c3763a30 Update README.md after renaming 01.GETTING-STARTED.md (#2983)
JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu
2019-07-24 11:41:35 +02:00
Dániel Bátyai 5d6eebac4c Add documentation for configuration options (#2977)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-23 15:32:41 +02:00
Robert Fancsik 4a9e185840 Rework the engine's internal recursion limit (#2969)
This patch unifies the recursion limit checking for RegExp, function call and JSON as well.
Until now the limit was only a counter which was increased/decreased at certain points.
This counter has been substituted with a numeric limit which allows to restrict the stack usage.

This patch fixes #2963 and resolves the closed #2258 issue.

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-23 15:31:37 +02:00
Péter Gál f53dba1a3a Add dependency info for accessing memstats from API (#2979)
The documentation of `jerry_get_memory_stats` method was missing
the requirements on what build option or feature is required.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-22 11:15:19 +02:00
Dániel Bátyai ec11a7b4e9 Resolve module paths relative to the current module (#2976)
The current module implementation resolves module paths relative to the
current working directory, but paths should be resolved relative to the
currently evaluated module/source.

This requires a change in the jerry_port_normalize_path port API
function, so that it also takes the current module path as an argument.
On the engine side, we now also create a module object for the main
script, so that we can properly identify the base path for other
modules.

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-17 14:44:18 +02:00
Robert Fancsik 6c441091b4 Optional arguments should advance the iterator in jerryx_arg_transform_optional (#2962)
This patch fixes #2288

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-17 14:16:41 +02:00
Dániel Bátyai ff22634e27 Refactor memory management (#2954)
This PR is a general cleanup for garbage collection and memory
allocation code paths.

Changes:
  * Removed an unnecesary local variable from 'ecma_gc_mark'.
  * Refactored 'ecma_gc_run' to have an implicit list head during
    iteration, which results in one less condition in the loops,
    and changed the loops to use compressed pointers to reduce the
    overall amount of compression/decompression.
  * Renamed 'jmem_free_unused_memory_severity_t' to 'jmem_pressure_t',
    and added additional values.
  * Removed 'jmem_free_unused_memory_callback', instead
    'ecma_free_unused_memory' is now called directly.
  * Reworked 'ecma_free_unused_memory' to handle all code paths related
    to 'jmem_pressure_t', and moved all relevant code paths into this
    function. This simplifies the code paths in other places.
  * Reworked 'jmem_heap_gc_and_alloc_block' to be more streamlined.
  * Changed mem-stats to not report unused pool chunks as allocated
    memory.
  * Created an allocator internal API for allocating/freeing memory blocks
    that are not reported as used memory in mem-stats.
  * Removed iteration statistics for the jerry allocator from mem-stats,
    as they don't provide any actually useful information.

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-17 14:12:23 +02:00
Dániel Bátyai a44d584842 Fix 'eval' checking in import/export statements. (#2978)
Fixes #2975

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-17 14:11:13 +02:00
Robert Fancsik 329b1fd3f7 Use custom dispatcher for Number.prototype routines (#2968)
Binary size gain:
     - Intel: ~630B (gcc-7.3)
     - Arm: ~280B (arm-linux-gnueabi-gcc-7.3)

Futher improvements:
 - Separate toFixed, toExponential, toPrecision common part into a helper function

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-17 14:10:20 +02:00
Robert Fancsik 7aa3bfdc6d Use custom dispatcher for Function.prototype routines (#2967)
Binary size gain:
     - Intel: ~70B (gcc-7.3)
     - Arm: 50 B (arm-linux-gnueabi-gcc-7.3)

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-17 14:10:05 +02:00
Robert Fancsik c0b8845530 Use custom dispatcher for Object routines (#2966)
Binary size gain:
     - Intel: ~370B (gcc-7.3)
     - Arm: ~240B (arm-linux-gnueabi-gcc-7.3)

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-17 14:09:44 +02:00
Robert Fancsik f158dd4fb5 Use custom dispatcher for Object.prototype routines (#2965)
Binary size gain:
     - Intel: ~250B (gcc-7.3)
     - Arm: ~65B (arm-linux-gnueabi-gcc-7.3)

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-17 14:09:29 +02:00
Robert Fancsik 603cd88006 Use custom dispatcher for String.prototype routines (#2964)
Binary size gain:
     - Intel: ~1.3KB (gcc-7.3)
     - Arm: ~650B (arm-linux-gnueabi-gcc-7.3)

Co-authored-by: Marko Fabo mfabo@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-17 14:09:14 +02:00
Robert Fancsik a21a4191ca Improve RegExp.prototype.compile (#2971)
This patch fixes the return value of the routine also fixes several incorrect regression-tests
due to the previously incorrect [[RegExpMatcher]] internal slot check.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-17 08:14:38 +02:00
Robert Fancsik 2700e66c4b Improve class literal parsing (#2970)
Until now "get"/"set" were always parsed as special 'keywords' for accessor methods,
but they should be parsed as simple class method if no identifier is followed by them.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-16 13:52:05 +02:00
Robert Fancsik 6bd7d70a69 Fix Lcache and property hashmap related buildoption tests (#2973)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-16 13:04:40 +02:00
Dániel Bátyai 75728980a3 Fix mbedos5 build on Travis (#2974)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-15 20:21:00 +02:00
Virag Orkenyi 3c2088cf7b Math.sign and Math.trunc (#2943)
JerryScript-DCO-1.0-Signed-off-by: Örkényi Virág orkvi@inf.u-szeged.hu
2019-07-11 19:42:27 +02:00
Dániel Bátyai c304b9a38a Include file path in Syntax error messages (#2941)
When using ES6 modules it was not possible to identify which module
an error originates from.

This PR changes the error message to also include the file path using
the file:line:column format, and updates the source context printing for
unhandled exceptions to use the correct file.

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-11 12:33:02 +02:00
Robert Fancsik 3f47e1b0aa Container object's internal object must be allocated firstly (#2961)
This patch slightly reworks the container objects internal objects allocation.
This rework allows the same lifetime of the objects without the manual allocation/deallocation of the internal object.

This patch also fixes #2951.

Co-authored-by: Dániel Bátyai <dbatyai@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-11 12:32:17 +02:00
Robert Fancsik a3cd2d7ff6 This argument must be pseudo-array in {Map/Set}Iterator.prototype.next routine (#2960)
This patch fixes #2950.

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-11 11:33:17 +02:00
Robert Fancsik 06000b5161 Fix the repeat count checking in String.prototype.repeat (#2959)
This patch fixes #2948

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-11 11:32:11 +02:00
Robert Fancsik 788fdc6603 Add missing release value call to %TypedArray%.prototype.findIndex routine (#2958)
This patch fixes #2947

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-11 11:31:04 +02:00
Péter Gál 1374d5f562 Update and improve API documentation (#2952)
A few parts of the API documentation was not clear enough.
Added extra details and examples.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-10 22:43:33 +02:00
Daniella Barsony d4ce20d0fd Implement String startsWith/includes/endsWith (#2926)
Co-authored-by: Tamas Keri tkeri@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2019-07-10 14:41:38 +02:00
Dániel Bátyai 04d5d56a68 Fix URLs in the repository after organization switch (#2955)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-07-09 19:13:57 +02:00
Péter Gál ef5dd5c698 Rework CMake options to use the new macro config format (#2933)
Updated all feature related CMake option to use JERRY_ format.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-08 18:25:17 +02:00
Robert Fancsik 2b8c428694 Improve gen-unicode.py to support unicode ranges (#2944)
This patch fixes #2936

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-05 15:44:56 +02:00
Robert Fancsik e902b870aa Limit the call stack size for native/builtin functions as well (#2935)
VM_RECURSION_LIMIT only prevented the recursion of interpreted codeblocks but
native/builtin function calls can also create stack overflow due to the too deep recursion.

This patch fixes #2905.

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-05 12:21:48 +02:00
Robert Fancsik 8766bb3b37 CBC_PUSH_THIS_LITERAL must be converted back to CBC_PUSH_THIS during emitting unary lvalue opcode (#2939)
This patch fixes #2937.

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-04 18:26:46 +02:00
Akos Kiss d22f6b451b Add pull request template (#2942)
Provide contributors with a checklist to ensure quality PRs and to
avoid common pitfalls. The items in the checklist are mostly beyond
the capabilities of automated checker tools and more like reminders
of best practices. Still, they can save lot of valuable reviewer
time (hopefully).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-07-04 10:35:05 +02:00
Akos Kiss b137942ea7 Add issue template for bug reports (#2940)
Help both the community and ourselves by describing what
information is required in a bug report.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-07-02 16:12:40 +02:00
Robert Fancsik a72d14f575 Make API unavailable while processing native free callbacks (#2932)
This patch fixes #2889 and extends the API documentation of the native free callbacks.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-07-02 15:46:19 +02:00
Péter Gál eef1efa394 Rework usages/naming of configuration macros [part 3] (#2927)
Reworked the JERRY_DEBUGGER macro to be a 0/1 switch.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-07-01 13:12:19 +02:00
Szilagyi Adam 1ea77cc490 Fix buffer-overflow in ecma_op_typedarray_set_with_typedarray (#2922)
Wrong method were used to get the source buffer pointer
Fixes #2851

Co-authored-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
2019-07-01 13:09:39 +02:00
Akos Kiss dea73d87e8 Hide info about --libfuzzer in tools/build.py behind --devhelp (#2929)
This reduces the noise when a user asks for help via `--help`, as
libfuzzer support is very developer-only.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-06-28 11:03:49 +02:00
Robert Fancsik f6f52a2bf1 Update the internals documentation (#2923)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-06-27 12:56:06 +02:00
Akos Kiss de71fe4f71 Fix implicit integer conversion reported by Clang 8 (#2928)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-06-27 09:53:00 +02:00
Robert Fancsik 9d4c2315f3 Implement the Map/Set iterator operations (#2882)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-06-24 11:18:37 +02:00
Daniella Barsony 6f7dbbce7e Implement Array/TypedArray find index (#2893)
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2019-06-24 11:14:06 +02:00
Robert Fancsik 95650993a2 Container object's properties must be marked during GC. (#2913)
This patch fixes #2895 and fixes #2911.

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-06-24 11:13:11 +02:00
Robert Fancsik 44b21de7fc Ensure that the constructed object in [[Set]] operation with primitive base cannot be extensible (#2917)
Related part of the standard: https://www.ecma-international.org/ecma-262/5.1/#sec-8.7 1st note.

This patch fixes #2914.

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-06-24 11:12:23 +02:00
Dániel Bátyai cbd41df5eb Module sources should be parsed in strict mode (#2920)
Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-06-24 08:14:34 +02:00
Szilagyi Adam 03202995a0 Add missing release to ecma_op_container_foreach (#2912)
The result of the callback function was not freed
Fixes #2910

Co-authored-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
2019-06-21 19:02:06 +02:00
Robert Fancsik 8b459d9643 Resolve build error after #2888 (#2921)
This patch fixes the build error due to #2888 since this patch has been merged without rebasing to #2903.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-06-21 15:44:35 +02:00
Szilagyi Adam 7b65167e81 Fix allocation problems when using import and export (#2919)
Construct ecma_string only when there is no parser error using lit_object's index in parser_module_parse_export_caluse and parser_module_parse_import_clause
Fixes #2908

Co-authored-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
2019-06-21 14:21:08 +02:00
Robert Fancsik b707c3f8da Reduce the size of vm_frame_ctx_t. (#2886)
The reference to the previous context is only used by the debugger and the backtrace info,
so this element should not be part of the structure by default.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-06-21 14:04:24 +02:00
Akos Kiss 78657e667d Make libfuzzer driver properly handle ES2015 test inputs with Promises (#2918)
Not running enqueued jobs (resulting from promises) caused false
alarms (internal assertion failures) at cleanup.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-06-20 09:24:11 +02:00
Gabriel Schulhof 3275c062f8 Improve JS object native pointer unit test (#2915)
After setting a second native pointer, check that both the pointer that
was first set and the second pointer that was set are there.

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2019-06-20 09:09:04 +02:00
Szilagyi Adam 6e9cf4d459 Release operands properly in opfunc_addition (#2909)
Right and left value release wasn't complete
Fixes #2901
Fixes #2902

Co-authored-by: Tibor Dusnoki <tdusnoki@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
2019-06-19 12:29:58 +02:00
Péter Gál 01ecc7bb7b Rework usages/naming of configuration macros [part 2] (#2903)
There are quite a few configuration macros in the project.
As discussed in the #2520 issue there are a few awkward constructs.

Main changes:

* The following macros are now 0/1 switches:
** Renamed CONFIG_ECMA_LCACHE_DISABLE to JERRY_LCACHE.
** Renamed CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE to JERRY_PROPERTY_HASHMAP.
** Renamed CONFIG_DISABLE_UNICODE_CASE_CONVERSION to JERRY_UNICODE_CASE_CONVERSION.
** Renamed ENABLE_REGEXP_STRICT_MODE to JERRY_REGEXP_STRICT_MODE.
** Renamed JERRY_DISABLE_JS_PARSER to JERRY_PARSER.
** Renamed JERRY_ENABLE_ERROR_MESSAGES to JERRY_ERROR_MESSAGES.
** Renamed JERRY_ENABLE_EXTERNAL_CONTEXT to JERRY_EXTERNAL_CONTEXT.
** Renamed JERRY_ENABLE_LINE_INFO to JERRY_LINE_INFO.
** Renamed JERRY_ENABLE_LOGGING to JERRY_LOGGING.
** Renamed JERRY_ENABLE_SNAPSHOT_EXEC to JERRY_SNAPSHOT_EXEC.
** Renamed JERRY_ENABLE_SNAPSHOT_SAVE to JERRY_SNAPSHOT_SAVE.
** Renamed JERRY_SYSTEM_ALLOCATOR to JERRY_SYSTEM_ALLOCATOR.
** Renamed JERRY_VM_EXEC_STOP to JERRY_VM_EXEC_STOP.
** Renamed JMEM_GC_BEFORE_EACH_ALLOC to JERRY_MEM_GC_BEFORE_EACH_ALLOC.
** Renamed JMEM_STATS to JERRY_MEM_STATS.
** Renamed PARSER_DUMP_BYTE_CODE to JERRY_PARSER_DUMP_BYTE_CODE.
** Renamed REGEXP_DUMP_BYTE_CODE to JERRY_REGEXP_DUMP_BYTE_CODE.
* Recursion check changes:
** Renamed REGEXP_RECURSION_LIMIT to JERRY_REGEXP_RECURSION_LIMIT.
** Renamed VM_RECURSION_LIMIT to JERRY_VM_RECURSION_LIMIT.
* Attribute macro changes:
** Renamed JERRY_CONST_DATA to JERRY_ATTR_CONST_DATA.
** Renamed JERRY_HEAP_SECTION_ATTR to JERRY_ATTR_GLOBAL_HEAP.
  Now the macro can specify any attribute for the global heap object.
* Other macro changes:
** Renamed CONFIG_MEM_HEAP_AREA_SIZE to JERRY_GLOBAL_HEAP_SIZE.
   Then new macro now specify the global heap size in kilobytes.
* Updated documentations to reflect the new macro names.

For more deatils please see jerry-core/config.h.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-06-19 12:28:21 +02:00
Daniella Barsony 985de93d04 Implement String repeat (#2904)
Co-authored-by: Tamas Keri tkeri@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2019-06-19 12:19:21 +02:00
Akos Kiss 8ee8bc2767 Improve libfuzz integration (#2916)
- Allow command line tools to build together with libfuzzer driver.
  Compile everything with `-fsanitize=fuzzer-no-link` to prevent
  linking in libfuzzers's `main` symbol in all executables (causing
  duplicate symbol errors in command line tools), and add
  `-fsanitize=fuzzer` to the libfuzzer driver only.

- Make ASan optional when building with libfuzzer to allow the user
  to choose freely from available sanitizers (e.g., UBSan, MSan,
  HWASan).

- Stabilize libfuzzer by resetting PRNG seed at every invocation.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-06-19 11:34:06 +02:00
Dániel Bátyai 3953fee035 Correctly propagate errors when parsing modules (#2907)
Fixes #2896.

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-06-14 03:29:26 -04:00
szilagyiadam 351acdf545 Add missing release value call for opfunc_addition (#2899)
Right_value wasn't correctly freed in case of an error.
Fixes #2894
Fixes #2897

Co-authored-by: Tibor Dusnoki <tdusnoki@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
2019-06-11 17:42:14 +02:00
Renáta Hodován e2646f93cc Integrate LLVM's libfuzzer engine with JerryScript (#2898)
JerryScript-DCO-1.0-Signed-off-by: Renata Hodovan reni@inf.u-szeged.hu
2019-06-07 14:43:20 +02:00
Robert Fancsik 343e80053b Implement the for of statement (#2871)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-06-07 12:35:42 +02:00
Daniella Barsony b6fc4e13ae Fix rounding issue (#2890)
Fixes #2802

JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2019-05-31 08:31:36 +02:00
Robert Fancsik 076f515d61 Implement the string iterators (#2873)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-30 12:34:19 -04:00
Robert Fancsik 442e482afa Add missing error check for ecma_regexp_exec_helper (#2887)
This patch fixes #2885.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-28 14:22:57 +02:00
Robert Fancsik e1c552ba2e Cleanup unused macros/typedefs from ecma-globals.h (#2888)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-28 10:56:10 +02:00
László Langó 8e39fbc46f Fixed 'C4028' compiler warnings. (#2881)
The formal paramters of some function definitions were different
from the declarations.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-05-21 09:17:10 +02:00
Dániel Bátyai 0ba2d17faf Fix heap limit calculation when using the system allocator. (#2872)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-05-17 11:28:00 +02:00
Dániel Bátyai 9a512c8fcf Properly release property name collection in for-in opcode handler (#2875)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-05-16 15:34:41 +02:00
Dániel Bátyai fd3e982e69 Fix ecma collection header deallocation (#2874)
Collection headers are allocated using the pool allocator, so they
should be freed by it as well.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-05-14 14:10:39 +02:00
Robert Fancsik 76a1fc5674 Support external context in the snapshot tool (#2870)
This patch fixes #2869.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-13 16:07:39 +02:00
Robert Fancsik 4331e39b9a Implement the Set builtin object (#2841)
Also implement the missing iterator initializer part from the Map builtin object constructor.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-10 20:28:43 +02:00
Robert Fancsik 99c7a4040f Super parsing options should be set only in direct eval call (#2863)
This patch fixes #2846.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-10 12:23:29 +02:00
Robert Fancsik 063e7fde2b undefined byteLength should be treated 0 in DataView constructor (#2856)
This patch fixes #2854.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-10 10:47:25 +02:00
Dániel Bátyai 4bdc3a1c46 Implement path normalization in port-default (#2861)
Updated the default port so that it now provides path normalization for
common platforms.

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-05-09 18:31:58 +02:00
Dániel Bátyai 57f08ee70e Add NuttX specific port implementation. (#2864)
The NuttX target has been problematic for some time, due to the fact
that NuttX apps are built with NuttX's own libc implementation, while
the default-port in JerryScript was compiled with the host libc, which
caused a mismatch between the two.

In order to work around this issue, most of the port implementation is already
duplicated in the NuttX target's jerry_main.c.

This PR adds a NuttX specific port implementation by moving the already
implemented port functions from jerry_main into a separate file, adding
implementation for the missing functions, and disabling the default-port
in JerryScript.

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-05-09 16:33:25 +02:00
László Langó 0e41311989 Fixed build issues with ES2015 subset profile on Windows. (#2865)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-05-09 16:31:54 +02:00
Robert Fancsik 2d1ad149c1 Fix key iteration in ecma_op_map_foreach (#2855)
This patch fixes #2852 and fixes #2853 as well.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-08 15:21:43 +02:00
Robert Fancsik eb993d57ed DataView object underlying ArrayBuffer should be marked during GC. (#2849)
This patch fixes #2848 and fixes #2850 as well.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-05-08 15:14:21 +02:00
László Langó 372ebd8260 Fixed linker issues of handle scope in jerry-ext on Windows platform. (#2862)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-05-08 11:42:02 +02:00
Dániel Bátyai 3ec6b68063 Clear top module context after local variables have been imported (#2859)
This fixes an assertion failure which was caused by incorrectly importing
the same variables multiple times.

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-05-06 17:35:33 +02:00
Mate Dabis 3823d2fc81 Fixed typo in parser (#2860)
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis mdabis@inf.u-szeged.hu
2019-05-06 12:57:14 +02:00
Daniella Barsony a2e7816485 Update README (#2844)
Removed Artik053 and updated the links to the measurement site.

JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2019-04-30 15:20:38 +02:00
Dániel Bátyai 1cdb3c6c56 Fix identifier handling inside export statements (#2843)
Fixes #2842

Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2019-04-30 10:53:48 +02:00
legendecas 097e1862d2 Set constructor to prototype for ES2015 Classes (#2818)
JerryScript-DCO-1.0-Signed-off-by: legendecas legendecas@gmail.com
2019-04-29 13:36:23 +02:00
Robert Fancsik 56b6d3a45d Class this binding must be bound to non-heritage contexts as well (#2829)
This patch fixes #2822.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-26 13:34:02 +02:00
Daniel Vince 37b7645e6a Rework ES2015 module system and add missing features. (#2792)
Co-authored-by: Dániel Bátyai <dbatyai@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Daniel Vince vinced@inf.u-szeged.hu
2019-04-25 14:57:17 +02:00
Robert Sipka 938e9c7530 [Debugger] Fixes the processing methods of incoming part messages (#2840)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2019-04-25 13:43:33 +02:00
László Langó 806b9f05c0 Fixed build failure caused by conversion warning with GCC-5.4 (#2839)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-04-25 10:27:52 +02:00
László Langó a6a7d8c7b8 Make the underlying buffer of the ArrayBuffer accessible. (#2836)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-04-24 16:03:56 +02:00
Akos Kiss c4ac67d4af Bump Zephyr target to 1.14.0 (#2837)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-04-24 14:47:58 +02:00
Philippe Coval d3234c2b8c Add STM32F7 support (#2838)
Some flags are not defined because,
they can be deduced from CPU type.

It was tested on NucleoF767ZI running current NuttX master branch.

Change-Id: I68c9787fe3003338228f47fbaf3e7a9522bcd6d5
Forwarded: https://github.com/pando-project/jerryscript/pull/2838
Relate-to: https://github.com/pando-project/libtuv/pull/136
JerryScript-DCO-1.0-Signed-off-by: Philippe Coval p.coval@samsung.com
2019-04-24 14:46:14 +02:00
Robert Fancsik 10d820165d Enable 32bit cpointers by default if the given heap size is greater than 512KB (#2833)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-24 14:41:07 +02:00
Robert Fancsik 6801871161 Super parse options should be cleared before setting it's value (#2831)
This patch fixes #2825.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-24 14:40:09 +02:00
Robert Fancsik 962d549be6 Non-object values should give early false result for instanceof operator (#2830)
This patch fixes #2823.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-24 14:39:04 +02:00
Robert Fancsik 760fc4fb95 Remove incorrect assertions from class construction instructions (#2827)
A class expression can be part of any kind of expression since the asserts for the stack position calculation were incorrect.
This patch fixes #2819.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-24 14:36:19 +02:00
jerry-weng 9d7a0db0dd Add missing jerry_release_value by calling jerry_set_property and jerry_set_property_by_index (#2821)
JerryScript-DCO-1.0-Signed-off-by: jerry-weng jjweng2007@gmail.com
2019-04-18 11:24:27 +02:00
László Langó 5be93dc7f7 Minor fixes of the documentation (#2834)
* Fixed wrong file name indexes in the docs folder.
 * Added description of the logging options into the getting started guide
 * Added missing files to the 'update-webpage.sh' script

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-04-18 10:16:45 +02:00
Robert Fancsik d2931c6e40 Rework Map object (#2760)
This patch reworks the core of the builtin Map object.

Advantages:
 - Provide sublinear access time for the elements via Lcache and property hashmap
 - This implementation is suitable for the builtin Set object as well

Also add the missing 'forEach' routine for the builtin object as well.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-17 14:50:03 +02:00
László Langó bc9efb07a5 Updated the API reference (#2828)
Fixed style issues, fixed inaccurate descriptions and added missing information.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-04-17 11:45:33 +02:00
Robert Fancsik 5c72d995e4 Implement DataView builtin (#2804)
New API functions:
 - jerry_create_dataview
 - jerry_value_is_dataview
 - jerry_get_dataview_buffer

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-16 08:26:39 +02:00
Robert Fancsik b3f4aa6816 Allow the JS objects to have more than one native pointer data (#2814)
Currently JS objects can only have one native pointer data which could be a limitation in special cases.
This patch allows to register multiple native infos, which can be accessed/associated with the corresponding `jerry_object_native_info_t`.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-16 07:50:49 +02:00
Robert Fancsik c818930cdc Use custom dispatcher for Global object's routines (#2794)
Binary size gain:
     - Intel: ~780B (gcc-7.3)
     - Arm: ~450B (arm-linux-gnueabi-gcc-7.3)

The change also contains the renovation of each builtin routine to use early return in case of error to make the code less complicated.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-16 07:48:04 +02:00
lidija-b e944cdaa8b Add endian set for default toolchain (#2808)
When default toolchain is used and architecture not listed in
"#if" in jerry-libm-internal.h on little endian around 90
test-suite tests, 4 unittests and 30 jerry-tests fails depending
on setup tested.
This change checks endians in case no toolchain is found and
sets __LITTLE_ENDIAN macro if it is little endian. This way
it will be set for any future arhitectures using little endian
and architecture that can have both big and little endian not
listed in jerry-libm-internal.h check.

JerryScript-DCO-1.0-Signed-off-by: Lidija Besker lidija.besker@rt-rk.com
2019-04-12 16:32:58 +02:00
Mate Dabis 09d8793e30 Increase branch coverage: Array.prototype functions (#2796)
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 399 / 476
	-after:  472 / 476

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi repasics@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi repasics@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis mdabis@inf.u-szeged.hu
2019-04-12 14:00:44 +02:00
Robert Fancsik 48cec485e1 Identifiers should be stored in the lexical environment if argument object needs to be created (#2816)
This patch fixes #2699.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-12 13:48:02 +02:00
Péter Gál 40f7b1c27f Rework usages/naming of configuration macros [part 1] (#2793)
There are quite a few configuration macros in the project.
As discussed in the #2520 issue there are a few awkward constructs.

Main changes:

* Renamed all CONFIG_DISABLE_<name>_BUILTIN macro to JERRY_BUILTIN_<name> format.
* The special JERRY_BUILTINS macro specifies the basic config for all es5.1 builtins.
* Renamed all CONFIG_DISABLE_ES2015_<name> to JERRY_ES2015_<name> format.
* The special JERRY_ES2015 macro specifies the basic config for all es2015 builtins.
* Renamed UNICODE_CASE_CONVERSION to JERRY_UNICODE_CASE_CONVERSION.
* Renamed ENABLE_REGEXP_STRICT_MODE to JERRY_REGEXP_STRICT_MODE.
* All options (in this change) can have a value of 0 or 1.
* Renamed ENABLE_REGEXP_STRICT_MODE to JERRY_REGEXP_STRICT_MODE.
  JERRY_REGEXP_STRICT_MODE is set to 0 by default.
* Reworked CONFIG_ECMA_NUMBER_TYPE macro to JERRY_NUMBER_TYPE_FLOAT64 name and now
  it uses the value 1 for 64 bit floating point numbers and 0 for 32 bit floating point
  number.
  By default the 64-bit floating point number mode is enabled.
* All new JERRY_ defines can be used wit the `#if ENABLED (JERRY_...)` construct to
  test if the feature is enabled or not.
* Added/replaced a few config.h includes to correctly propagate the macro values.
* Added sanity checks for each macro to avoid incorrectly set values.
* Updated profile documentation.
* The CMake feature names are not updated at this point.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-04-09 10:14:46 +02:00
Daniella Barsony 722d092528 Add missing port functions for artik053 target (#2811)
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2019-04-03 11:20:57 +02:00
László Langó 89cf1a988c Run test262 test suite in both release and debug mode on Travis CI. (#2810)
The CI ran test262 test suite in release mode only to save time.
This patch enables the debug testing on the test suite, which means
the runtime of the "Conformance Tests" job will increase by a few
minutes.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-04-02 20:26:21 +02:00
Robert Fancsik 4b9fee1ba0 Fix typo in the API documentation (#2809)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-04-02 10:13:41 +02:00
Péter Gál 3f6599c358 Add a "single" source/header file generation and build mode (#2790)
Introduce a new way of building: before any file is compiled
all source files are combined into a single C file and all
header files into a single H file (per subdir).

This new approach makes it possible to quickly integrate JerryScript
into other projects:

```
$ gcc -o demo demo.c jerryscript.c jerryscript-port-default.c -lm
```

To use the source generator run:
```
$ cmake -Bbuild_dir -H. -DENABLE_ALL_IN_ONE_SOURCE=ON
$ make -C build_dir generate-single-source
```

This will create the following files in the `build_dir`:
* jerryscript.c
* jerryscript.h
* jerryscript-config.h
* jerryscript-port-default.c
* jerryscript-port-default.h

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-04-01 11:06:13 +02:00
Robert Fancsik e063b8af80 Fix bound functions with no arguments after #2801 (#2805)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-29 12:13:27 +01:00
László Langó 4a67f131bb Fixed typo in README.md of particle target. (#2806)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-03-29 12:09:25 +01:00
Robert Fancsik f23c746b45 Merge external direct magic strings into direct magic strings (#2766)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-29 09:38:54 +01:00
László Langó 6efdb283aa Fixed 'jerry_get_object_keys' API function. (#2807)
'jerry_get_object_keys' always gave back an empty array.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-03-28 19:02:44 +01:00
legendecas 5b29bf6288 Implement handle scope API in jerry-ext (#2753)
JerryScript-DCO-1.0-Signed-off-by: legendecas legendecas@gmail.com
2019-03-27 14:49:59 +01:00
legendecas 772ab277ea Fixes assertion on calling String builtin with symbol (#2803)
JerryScript-DCO-1.0-Signed-off-by: legendecas legendecas@gmail.com
2019-03-26 16:14:04 +01:00
Robert Sipka 3d656cdf57 [Debugger] Implementation of transport over serial connection (#2800)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2019-03-26 09:39:51 +01:00
Robert Fancsik 0981985134 Remove outer loop from ecma_op_function_call (#2801)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-25 15:11:06 +01:00
Akos Kiss 61a79af8c1 Bump RIOT OS target to 2019.01 (#2786)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-03-22 09:46:19 +01:00
Robert Fancsik 7b23ecc272 Merge base resolve + get/put operations for lexical environments to increase performance (#2798)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-21 09:45:56 +01:00
Daniel Vince 4123f35a3b Part I: Implement ES2015 module system. (#2599)
JerryScript-DCO-1.0-Signed-off-by: Daniel Vince vinced@inf.u-szeged.hu
2019-03-18 16:22:06 +01:00
Robert Sipka 3d3e6fdf58 [Debugger] Create a simplified transmission layer (#2781)
It supports the raw packet sending over a TCP/IP protocol

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2019-03-18 11:00:15 +01:00
Péter Gál fbd734ed28 Split the Travis checks into two test calls (#2797)
The cppcheck can run for quite a long time, sometimes even more than
10 minutes. This change splits the test execution into two part:
* First, do all checks excluding the cppcheck call with the default timeout.
* Second, do the cppcheck call with a 30 minutes maximum timeout.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-03-18 09:32:40 +01:00
wangzhikang123 f3c8eeecb5 Fix the vm stop checking bug (#2795)
when the vm executes VM_OC_LESS operation, the lookahead optimization will cause the by-passing of vm stop checking.
Thus we need to disable the optimization here if JERRY_VM_EXEC_STOP is defined.

JerryScript-DCO-1.0-Signed-off-by: Wang Zhikang wzk0406@mail.ustc.edu.cn
2019-03-13 15:18:35 +01:00
Robert Fancsik 7d48e011c9 Fix getting the iterated object's length property (#2784)
This patch fixes #2782.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-13 13:56:01 +01:00
Péter Gál 162ba8c116 Make jerryx_port_handler_print_char truly a port function (#2789)
In the previous approach `jerryx_port_handler_print_char` was implemented
in by the jerry-default-port. This implementation however required the
jerry-ext handler header file which created a requirement in the
jerry-default-port for the jerry-ext headers.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-03-13 10:19:30 +01:00
Robert Fancsik 90f37a5573 Optimize LCache entrys keys (#2767)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-08 18:46:12 +01:00
Robert Fancsik ea195cd131 Use [[DefineOwnProperty]] in the iterator next step in ecma_builtin_promise_do_all (#2773)
This patch fixes #2770.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-07 08:04:19 +01:00
Robert Fancsik 1fba8901d6 Ensure that Symbol.toStringTag property is copied to buffer as a cesu8 string (#2772)
This path fixes #2769.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-06 18:45:50 +01:00
Robert Fancsik 9c7b96878b Iterated object should be marked during GC (#2785)
This patch fixes #2783

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-06 18:23:57 +01:00
Robert Fancsik dfe7ff8ddb Add missing builtin object type checks from ecma_object_check_class_name_is_object (#2780)
This patch fixes #2779 and the same issue for the Symbol.prototype object, also fixes the check
for the Iterator/ArrayIterator object as well since these checks macro guards were misplaced.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-06 18:18:59 +01:00
Robert Fancsik 2f18b92e0f Fix the rest parameter behavior if the arguments object needs to be created (#2778)
This patch fixes #2777.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-06 18:16:10 +01:00
Robert Fancsik e4fee93b92 Fix the JSON stringify context abort in case of error (#2776)
This patch fixes #2774 and fixes #2775 as well.
Also add a shortcut to access the length of the array in `ecma_builtin_json_array`.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-06 18:11:00 +01:00
Robert Fancsik cedf8e460a Builtin Object constructor should handle symbol arguments (#2771)
This patch fixes #2768.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-03-06 17:12:03 +01:00
Akos Kiss 85e05094e9 Bump NuttX target to 7.28 (#2787)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-03-05 10:14:56 +01:00
Akos Kiss 6cc70d4adc Bump Mbed OS target to 5.11.5 (#2788)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-03-05 09:52:52 +01:00
Robert Sipka 6d490c7296 Separate the debugger-client to support the later usage of other communication protocols (#2764)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2019-02-26 10:56:44 +01:00
Robert Fancsik d4e27d3003 Target arraybuffer's buffer should be absolute addressed in ecma_op_typedarray_set_with_typedarray (#2758)
This patch fixes #2757, also adds a short path for the case when the source and the target typedarrays are the same.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-21 13:24:52 +01:00
wille.io a1fdcf06cb Compile with clang-7.0 (#2754)
jerry_debugger_scope_variable_type_t was not explicitly sized by the compiler as 8bit, accept uint8_t instead (you still can call the fn with a jerry_debugger_scope_variable_type_t)

JerryScript-DCO-1.0-Signed-off-by: wille-io mike@wille.io
2019-02-19 20:23:49 +01:00
Istvan Miklos 9c10d82e4a Fix JSON.stringify (#2759)
There was a wrong check on the property types, it did not check that the
property was name accessor. Also fixed a test case.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2019-02-19 11:29:13 +01:00
Robert Fancsik 60bbd731e5 Add new symbol related API functions. (#2741)
New functions:
 - ecma_create_symbol
 - ecma_value_is_symbol
 - jerry_get_symbol_descriptive_string

Also improve the jerryx_handler_print to be able to print symbol values via using the jerry_get_symbol_descriptive_string API function for symbol values.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-19 07:45:50 +01:00
Robert Fancsik cffb299f37 Ensure that symbol properties can be set via computed object literals (#2747)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-13 18:32:36 +01:00
Robert Fancsik 044b4ea827 Add missing error checks for ecma_regexp_exec_helper (#2756)
This patch fixes #2755.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-13 12:50:01 +01:00
László Langó 2d16705050 Added 'instanceof' binary operation to the API (#2751)
Added 'JERRY_BIN_OP_INSTANCEOF' to 'jerry_binary_operation_t' and
'jerry_binary_operation'. Added unit tests for this new operation
and updated the documentations.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-02-13 12:49:28 +01:00
Robert Fancsik ed0662612d Use custom dispatcher for Array.prototype routines (#2742)
Binary size gain:
 - Intel: ~2.5KB (gcc-7.3)
 - Arm: ~1.2KB (arm-linux-gnueabi-gcc-7.3)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-13 10:46:57 +01:00
Péter Gál f22eea5c6e Allow build artifacts on AppVeyor (#2752)
Enabled the creation of JerryScript Windows binary artifacts during builds.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-02-09 17:01:31 +01:00
Robert Fancsik 4f5ffb4f3a Implement Iterator interface and Array iterators (#2640)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-08 11:10:32 +01:00
Robert Fancsik 2dd854d28b Ensure that ecma_get_number throws error for symbol values. (#2744)
This patch fixes #2743.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-07 16:07:35 +01:00
Robert Fancsik 243e14ac21 Reduce the memory allocations while getting a string's length property (#2736)
This patch reduces the number of string to string object conversion during property managing operations,
via access the length property directly from the string instead of the newly created string object.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-07 16:07:13 +01:00
László Langó 81ccd6a743 Added new 'jerry_binary_operation' API function (#2746)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-02-06 15:40:54 +01:00
Robert Fancsik 5e846c9efa Fix instanceof operator for implicit class constructors (#2748)
Implicit class constructor functions should not be handled as bound functions during [[HasInstance]] check.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-06 15:06:43 +01:00
Robert Fancsik 6b9c924d08 Add recursion limit for VM (#2737)
This patch adds posibility to supervise the VM call stack to avoid aborts/crashes due to the recursion calls.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-01 15:32:26 +01:00
Robert Fancsik 5c1a4f18ea Implement @@toStringTag well-known symbol related features (#2739)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-02-01 14:59:22 +01:00
Robert Fancsik ca8442c523 Add duplicated argument check for function rest parameter (#2740)
Also add a missing word from `PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER` error message.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-31 14:15:42 +01:00
Robert Fancsik 1ff322b72f Ensure that symbol properties are not listed in ecma_builtin_list_lazy_property_names (#2734)
This patch fixes #2733.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-31 13:42:18 +01:00
Robert Fancsik 924f4bbd74 Fix the order of value finalizing in ecma_builtin_typedarray_prototype_join (#2726)
This patch fixes #2724.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-25 11:03:11 +01:00
Robert Fancsik 4c1ee94652 Add support for function rest parameter (#2647)
ECMAScript v6, 14.1.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-25 09:24:39 +01:00
Robert Fancsik a42f239abb Fix super keyword parsing for arrow functions. (#2664)
This patch fixes #2657.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-22 09:21:28 +01:00
László Langó 858c3e68a1 Fixed unreachable jump statements. (#2722)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-01-22 09:19:33 +01:00
Robert Fancsik 7ed7935084 Add missing ecma_deref_ecma_string call to ecma_builtin_json_object (#2720)
This patch fixes #2719.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-22 01:26:34 +01:00
Robert Fancsik 5becf43ede Fix %TypedArray% object instances symbol properties (#2704)
Add missing check for during property handling for %TypedArray% object since until now only string property names were possible.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-22 01:11:58 +01:00
Robert Fancsik 71608288e6 Substitute symbols with their descriptive string in ecma_raise_standard_error_with_format (#2708)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-22 01:10:42 +01:00
Akos Kiss 2365b4ec35 Fix out-of-bounds writes (buffer overflows) in unit tests (#2714)
Fixes #2711
Fixes #2712

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-21 12:40:27 +01:00
Akos Kiss 936766d241 Bump Tizen RT target to release 2.0 (#2709)
Current build test uses and documentation refers to release 1.1,
however, 2.0 has been out since Oct 2018. This commit bumps the
target to that latest release.

Co-authored-by: Roland Takacs <rtakacs.uszeged@partner.samsung.com>
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-21 12:28:39 +01:00
Akos Kiss 772a88050b Fix buffer overflow while printing unhandled exception (#2710)
Fixes #2675

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-21 12:22:27 +01:00
Akos Kiss 77767c2161 Add pkg-config metadata files for libraries (#2680)
Should core, ext, libm, and/or port libraries be properly installed
on some system, help compilation and linking against them by
providing standard `.pc` files, which can be picked up by
pkg-config.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-21 09:38:05 +01:00
Akos Kiss 67ef396354 Use union to convert between jerryx_arg_int_option_t and uintptr_t (#2718)
This fixes potential out-of-bounds reads in jerry-ext when dealing
with integer argument mappings.

Fixes #2713

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-21 09:29:34 +01:00
Istvan Miklos c23cf4176a Add RegExp recursion depth limit (#2543)
The regexp engine does not have any recursion depth check, thus it can cause problems with various regexps. Added a new build option `--regexp-recursion-limit N` whose
default value is 0, which is for unlimited recursion depth. Also added a build-option-test.

Fixes #2448
Fixes #2190

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2019-01-17 20:16:50 +01:00
Roland Takacs 162e2ddcb6 Use logical operators for bool converions. (#2707)
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2019-01-17 14:30:05 +01:00
Roland Takacs 0b3d5edc06 Fix some type conversions in ecma-builtins. (#2706)
Added missing parentheses and explicit type conversions.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2019-01-17 12:50:16 +01:00
Péter Gál 545c6c771b Update the debugger to work on Windows (#2684)
Changed the debugger-tcp.c file to include Windows specific
socket handling code and mode user all components are compilable
for Windows.

Added appveyor configuration to build with and without debugger.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2019-01-17 11:40:29 +01:00
Akos Kiss 7934117625 Bump Mbed target to Mbed OS 5.11.1 (#2695)
The git hash mbed-os.lib was pointing to marked Mbed OS 5.5.5 and
was more than a year old and more than 10.000 commits behind latest
mbed-os master.

This commit forwards the reference to the latest Mbed OS release
(5.11.1).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-17 10:38:02 +01:00
Daniel Vince 243f2ffcad Style fix in the lexer.h (#2705)
JerryScript-DCO-1.0-Signed-off-by: Daniel Vince vinced@inf.u-szeged.hu
2019-01-17 07:50:05 +01:00
Robert Fancsik 86e60ddf8d Fix inner classes in class heritage environment (#2686)
This patch is the proper fix for #2667, since #2269 did not fix the problem entirely.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-16 14:36:54 +01:00
t-harvey cfdb5eddb3 Added the _restore function to "unpop" the argument stack. (#2592)
Added a unit test for the jerryx_arg_js_iterator_restore function.
Added the specification to the documentation.

JerryScript-DCO-1.0-Signed-off-by: Timothy Harvey t-harvey@ti.com
2019-01-16 11:43:36 +01:00
Robert Fancsik 7e3d688e5b Implement the Symbol builtin object (#2601)
This patch contains the base functionalities that the new builtin object requires.

Currently unavailable:
 - print (Symbol('foo')) - this features requires the refactor of the print handler function
 - Several global symbol based builtin routines (follow up patch)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-16 10:09:23 +01:00
Akos Kiss 08c7183ef8 Update slug, org, and project key info for the SonarCloud service (#2690)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-16 16:24:12 +09:00
Kristof Kosztyo 325c426c1e Fix api example in the documentation (#2703)
JerryScript-DCO-1.0-Signed-off-by: Kristof Kosztyo kkristof@inf.u-szeged.hu
2019-01-15 20:21:58 +01:00
Robert Fancsik d716f900e1 Fix getting array length in ecma_builtin_promise_do_{race, all} (#2702)
This patch fixes #2700.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-15 17:31:59 +01:00
Robert Fancsik b4df594d3e Normalize routine's arguments before dispatch (#2687)
Binary size gain:
 - Intel: ~860B (gcc-7.3)
 - Arm: ~660B (arm-linux-gnueabi-gcc-7.3)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-15 16:45:16 +01:00
Akos Kiss a9c3ddff1f Bump NuttX RTOS target to 7.27 (#2696)
Both documentation and travis makefile were referring to NuttX 7.22,
which was released in Sep 2017. This commit bumps the version to the
latest release (7.27, from Nov 2018).

Additionally, it also sets the stlink tool to a fixed (and tagged)
version.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-15 14:02:55 +01:00
Robert Fancsik c305d70b11 Fix "arguments" and "eval" parsing (#2661)
This patch fixes #2656 and fixes #2659 as well.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-15 13:29:56 +01:00
Peter Marki 98aa08e33c Add subdir-level gitignore to the nuttx target directory (#2635)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2019-01-15 11:16:53 +01:00
Robert Fancsik ee267e8aa9 Add missing ecma_deref_ecma_string in ecma_builtin_typedarray_prototype_join (#2701)
This patch fixes #2698.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-15 09:01:33 +01:00
Akos Kiss 9ced3addaa Bump ESP8266 target to SDK v2.1.0 (#2697)
Until now, the ESP8266 target used a non-tagged git hash revision
of the RTOS SDK (from Oct 2017). Moreover, the compiler was also a
custom-built gcc.

This commit sets the RTOS SDK version to v2.1.0, released Oct 2018,
which is the latest old-style SDK for ESP. The commit also changes
the used gcc to an Espressif-provided pre-built toolchain, which is
tagged for the (latest) v3.0.1 SDK release.

(The SDK bump is not to the latest SDK version because the new
v3.x line of the SDK is "ESP-IDF style", which is incompatible with
the current target code base. On the other hand, the toolchain
comes from the latest SDK release because the v2.x line had no
pre-built toolchain suggestions -- but it builds v2.x sources
correctly.)

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-15 08:35:39 +01:00
Robert Fancsik f02de7a31f Add missing error check in ecma_builtin_promise_do_all (#2694)
This patch fixes #2693.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-14 23:46:01 +01:00
Robert Fancsik 2c031c1220 Implement Object.assign routine (#2678)
Related part of the standard: ECMA-262 v6, 19.1.2.1

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-14 15:04:00 +01:00
Akos Kiss 52fdf4ef3f Travis CI config maintenance (#2683)
- `sudo: false` has been deprecated.
- `install` step is skipped by default for C projects, so there is
  no need setting it explicitly.
- Homebrew addon can be used to install dependencies for OSX jobs
  (and, by experience, it is a lot faster than manually invoking
  brew).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-14 14:45:36 +01:00
Akos Kiss adb80c2045 Update links in docs (#2691)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-11 18:57:30 +09:00
Robert Fancsik 93ec226650 Extract binary lvalue operators (#2630)
This patch substitutes all binary lvalue operators with an assigment + the corresponding binary operator.
E.g. A += (expression) is pasred as A = A + (expression).

Due to this replacement, all the related binary lvalue CBC opcodes can be removed.
Also the arithmetic related VM instructions can put their result directly onto the stack, since no more checking is needed.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-10 08:47:45 +01:00
Robert Fancsik e8502fa8cc Fix class extends value (#2662)
This patch fixes #2658 and ensures that when a class extends value is null and the class has no explicit constructor
the proper error is raised during constructing a class instance.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-09 14:27:50 +01:00
Daniel Balla 3ee771655f Fix JerryScript build with clang-6.0 (#2610)
This patch fixes the following error with Clang-6.0

```
jerryscript/jerry-core/api/jerry.c:1527:71: error: implicit conversion loses integer precision:
      'jerry_regexp_flags_t' to 'uint16_t' (aka 'unsigned short') [-Werror,-Wconversion]
  jerry_value_t ret_val = ecma_op_create_regexp_object (ecma_pattern, flags);
```

Also change the `jerry_create_regexp` and `jerry_create_regexp_sz` functions' `flags` parameter to `uint16_t` since the values created with `bitwise inclusive OR` are not part of the enum.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2019-01-09 09:22:47 +01:00
Robert Fancsik 99b968de3c Reduce the memory footprint of 'ecma_instantiate_builtin' (#2646)
This patch introduces a new builtin descriptor table to substitute the generated switch-case structure in 'ecma_instantiate_builtin',
also removes the corresponding helpers functions to simplify the instantiation process.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-09 09:04:21 +01:00
Zsolt Borbély 0c20f8e701 Fix broken links in README (#2679)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2019-01-08 09:59:27 +01:00
Akos Kiss e5fc13f6db Build test disabled jerry-libm (#2681)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-08 09:57:51 +01:00
Robert Fancsik ef2c3b46d7 Fix super property reference parsing (#2672)
`PARSER_CLASS_SUPER_PROP_REFERENCE` flag should be applied for only binary lvalue tokens.
This patch fixed #2671.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-08 09:33:26 +01:00
László Langó 7b48be81c3 Fixed assertion in RegExp built-in. (#2663)
Fixes #2660

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-01-08 09:04:58 +01:00
László Langó 2f8c0a168f Removed ECMA_TRY_CATCH macros from RegExp built-in (#2642)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2019-01-04 15:12:03 +01:00
Akos Kiss f2404ac0e1 Simplify the collection of sources in cmake files (#2673)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-04 08:59:15 +01:00
Robert Fancsik af91072f44 Ensure that ecma_builtin_json_str_helper uses [[DefineOwnProperty]] internal method (#2665)
This patch fixes #2652 and fixes #2653 as well, also reverts #2521.
Related part of the standard ECMAScript v5.1 15.12.3.10.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-03 15:30:22 +01:00
Akos Kiss 1f204de150 Maintenance of fatal code enum (#2670)
- `ERR_SYSCALL` is a legacy that has not been used anymore since
  the removal of jerry-libc. This commit removes it from the port
  API.
- `ERR_DISABLED_BYTE_CODE` is a (relatively) recent addition to the
  fatal code enum. At the time it was added, the documentation has
  not been updated. This commit adds the missing documentation.
  (Plus, it removes a superfluous `JERRY_UNREACHABLE` from after a
  `jerry_fatal (ERR_DISABLED_BYTE_CODE)`.)

Note: As the port API is modified, this is an API-breaking change.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-03 15:27:09 +01:00
Robert Fancsik b80935ba92 Fix ecma_op_resolve_reference_base for super object bound lexical environments (#2668)
All ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND type lexical environments should return their outer reference during resolving syntactic reference.
This patch fixes #2666.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-03 13:37:01 +01:00
Robert Fancsik 1068b07cbe Ensure that inner classes do not inherit the parent's class HAS_SUPER flag. (#2669)
This patch fixes #2667.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-03 13:36:37 +01:00
Robert Fancsik b69f3fd0ff Add missing error check after vm_op_get_value (#2655)
This patch fixes #2654.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2019-01-02 12:56:02 +01:00
Akos Kiss aae50c9da0 Simplify version key in AppVeyor configuration (#2650)
The format `1.0.{build}` is artificial, the 1.0 prefix has no
meaning, `{build}` is enough.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2019-01-02 10:11:02 +01:00
Robert Fancsik ec142f5ff6 Fix the Map builtin name property (#2648)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-12-19 13:00:54 +01:00
Akos Kiss ae91800e4b Ensure fresh Python 2.7 on Trusty and compatible Intervaltree (#2645)
Recent failures of the Mbed OS target came from two independent
issues:
- some python packages started requiring Python>=2.7.10, and
- the latest Intervaltree 3.0.0 release was released broken.

This patch ensures a fresh python by 'lying' to the CI that this
is a Python project (Python images on the CI come with a recent
interpreter, not with the one shipped as default with the OS), and
locks Intervaltree to a stable version.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-12-17 16:15:14 +01:00
Daniel Balla a1595fa23a Fix possible failure in backtrace info (#2643)
Make sure to ignore static snapshots when sending backtrace information to the debugger.
The `JMEM_SET_NON_NULL_POINTER` macro requires the frame context's `bytecode_header_p` pointer to be a heap pointer, but due to the static snapshot it might not be, causing an assertion failure.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-12-17 00:17:11 +01:00
Akos Kiss 5779a5b8a8 Fix MbedOS build (#2644)
Since recently, the newly released mbed-host-tests 1.4.4 gets
installed during the python requirement installation step. That
package requires pyocd>=0.14.0, which cannot be satisfied for
whatever reason. This quick fix pins mbed-host-tests to version
1.4.2, which does not have unsatisfiable requirements.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-12-14 18:08:32 +01:00
Akos Kiss 8ed5078e96 Rewrite debugger test runner to use portable redirect-and-append notation (#2641)
The test runner used `&>>` to channel stderr to stdout and append
all that to a file. However, that's Bash 4 syntax, which is not
available everywhere, e.g., on MacOS. Bash pre-4 syntax requires
the classic `>>file 2>&1` notation.

This commit rewrites the test runner to use the portable syntax.
Moreover, it also rewrites `&>` to `>file 2>&1` for the sake of
consistency.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-12-14 12:54:46 +01:00
László Langó 9b24bde4c6 Fixed connection lost of debugging sessions. (#2636)
The peek of the socket does not work on other platforms,
beacause the errno is not set correctly. The code path
added by #2427 Linux specific, so it has been guarded
to solve connection lost issues during debugging sessions
when the client does not send data but still connected.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-12-12 15:41:42 +01:00
Robert Sipka 93e71150fe Update the storage locations of the status badges (#2639)
The name of the database has been changed to jsremote-testrunner from remote-testrunner

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2018-12-12 13:43:26 +01:00
Zoltan Herczeg 83ee9cfca3 Fix named function expression creation. (#2634)
Create a local lexical environment with the name of the function. While
this is not too memory efficient, some corner cases requires its existence.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-12-12 12:50:03 +01:00
Robert Fancsik 4f0b075f85 Implement ES2015 {Array, %TypedArray%}.prototype.find routine (#2631)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-12-12 10:13:05 +01:00
Daniel Balla c6a2fd5d3d Fix an issue while debugging with static snapshots (#2606)
The issue was found when debugging IoT.js with static snapshots turned on, if an error was thrown an assertion failure was caused. The reason is the frame context's bytecode_header_p pointer was not a heap pointer. The jerry_debugger_breakpoint_hit function tries to set a compressed pointer which points to bytecode_header_p with the JMEM_CP_SET_NON_NULL_POINTER macro, which has an assertion that requires the above mentioned bytecode_header_p to be a heap pointer, which is obviously not.


Co-authored-by: Robert Fancsik frobert@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-12-11 18:51:00 +01:00
Robert Fancsik 101f62ce9d Improve the vm_loop suspending for exec operations (#2589)
Exec operations{call, construct, super_call} related bytecode sequences no longer executed twice.
The execution continues with the next opcode or a specific bytecode sequence if an error occurs during the operation.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-12-06 15:36:26 +01:00
Robert Fancsik 79b2df124e Separate VM_OC_PROP_GET to a single operation in vm_loop (#2607)
VM_OC_PROP_GET is the general vm instruction for getting an object's property.
This opcode can be mutated into several other opcodes depending on the context (pre- post increment, ident reference).
Since these mutated opcodes perform additional checks and VM_OC_PROP_GET is a highly frequent instruction and it is worth to introduce a special case for it.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-12-06 14:31:30 +01:00
Roland Takacs 3f9dd0f1f9 Use Thumb instructions on TizenRT. (#2629)
In order to decrease the binary size of JerryScript, enabled the Thumb
instruction set that is supported on ARM Cortex-R series processors.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-12-02 09:56:27 +01:00
Zoltan Herczeg bc1b13dcb6 Fix floating number parsing. (#2628)
This patches fixes floating point number parsing when the number starts with dot.

Fixes #2614.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-12-01 17:22:39 +01:00
László Langó a08291eb12 Unify the usage of boolean value creations. (#2623)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-11-30 11:33:30 +01:00
Robert Fancsik 6dfa4efbfb Remove unnecessary check from VM_OC_NOT (#2622)
This patch removes the ECMA_IS_VALUE_ERROR check from VM_OC_NOT, since the general toBoolean operation cannot throw an exception.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-30 07:45:48 +01:00
Robert Fancsik 24817b27f9 Optimize property call opcodes (#2609)
In with contexts the object base value must be resolved before executing a call operation.
Since this happens rarely the base resolving code paths has been seperated to an other VM opcode
so these extra checks do not burden the general property call steps.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-29 09:00:22 +01:00
Robert Fancsik e11c499b4b Reduce ecma_{ref, deref}_object calls while using ecma_builtin_get (#2616)
The following stucture was highly frequented in the code base:

 - Get a builtin object // This operation increases the reference count of the object
 - Use it for create a new object
 - Deref the builtin object

After a builtin has been instantiated there is always at least one reference to "keep it alive",
so increase/decrease the reference count for getting the value only is unnecessary.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-28 20:23:21 +01:00
Tóth Béla 8410570dd9 Seperate tests from test-api.c - Property (#2596)
Seperate the property based test from the `test-api.c` file.

JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-11-28 13:13:24 +01:00
Roland Takacs 5151f9161f Use logical operators for bool converions. (#2620)
The explicit boolean type conversion (introduced by #2575) desn't work
with TizenRT if custom boolean representation is used. Of course,
TizenRT gives an opportunity to use the C99 standard boolean (that works
well if that is set).

I've replaced all the explicit boolean type conversions with double
negations that helps to work JerryScript well with custom boolean types.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-11-28 11:35:12 +01:00
Akos Kiss 17178ec185 Make CONFIG_ECMA_LCACHE_DISABLE and CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE build-tested (#2615)
Because these feature guards don't have their counterpart options in cmake, they
seem to be less tested. This commit makes them build-tested at least.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-11-28 09:40:54 +01:00
Csaba Repasi 5533b8ba9b Add new tests (#2578)
Added tests/jerry/unusual.js to test corner cases
Added tests/jerry-test-suite/11/11.08/11.08.06/11.08.06-008.js (a new test of instanceof)
Added new floatingpoint test case to tests/jerry/arithmetics-2.js
Added new test case to tests/jerry/arithmetics-bignums.js

JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi repasics@inf.u-szeged.hu
2018-11-22 10:10:37 +01:00
Zoltan Herczeg a0a6eaaee8 Support identifier references for object initializers. (#2597)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-11-22 10:07:11 +01:00
Daniel Balla 3d33d3258a Rename a regression test to match the issue number (#2613)
There was a typo in a regression test name, referencing to a different pull request rather than the issue it fixes.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-11-22 02:24:48 +01:00
Robert Fancsik 8e28316b1a Fix a typo in Object.getOwnPropertyNames test (#2612)
With the change the test file truly checks the corresponding part of the standard (ECMAScript v5, 15.2.3.4.1).

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-22 02:08:06 +01:00
Daniel Balla f9e21540d6 Typo fixes related to jerry_json_stringify (#2611)
JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-11-22 02:05:34 +01:00
Renáta Hodován c87aa83b0d Skip -m32 build-test on non-Linux non-x86 platforms (#2558)
The `-m32/64` compiler flags are x86/64-specific (mostly; at least in the
context of JerryScript-supported architectures) and macOS has deprecated 32-bit
support, so it's better to keep the build-testing of `-m32` to x86[-64]/Linux
only.

JerryScript-DCO-1.0-Signed-off-by: Renata Hodovan reni@inf.u-szeged.hu
2018-11-21 20:15:45 +01:00
Marko Fabo 22b08518c7 target: mbedos5: Modify generate_pins.py (#2524)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2018-11-20 14:53:19 +01:00
Robert Fancsik 49a0836daa Add missing ecma_free_value in ecma_builtin_promise_do_all (#2604)
This patch fixes #2602 and fixes #2603 as well.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-20 14:40:34 +01:00
Daniel Balla 704eb45cb8 [API] Add RegExp C API (#2542)
This patch supports creating a RegExp object through the C API.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-11-19 13:18:00 +01:00
Robert Sipka 47fa5904b1 Improve the evaluate requests (#2583)
Currently it evaluates the given expression in the context of the top most stack frame.
The expression should access to any variables and arguments that are in the scope chain.
Implement the eval_at request with the level of the scope chain as a further argument.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2018-11-15 15:53:10 +01:00
Robert Sipka 6c4b316609 [Debugger] Modify the object representation in case of variables request. (#2594)
Return with the object`s toString() method instead of create a json formated string from it.
It could have led to an error in previous cases (an object contains itself etc.)

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2018-11-15 14:13:49 +01:00
Robert Fancsik 9535a230ba Reduce the argument count of ecma_op_object_get_property_names (#2598)
Introduce ECMA_LIST_ARRAY_INDICES[_ENUMBERABLE[_PROTOTYPE]] flags instead of passing 3 boolean arguments.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-15 13:40:44 +01:00
Ádám Kallai ba8e144f7b docs: Fix jerry_get_property API example (#2590)
The first paramter of the function should be 'global_object' instead of obj_val
in this case.

JerryScript-DCO-1.0-Signed-off-by: Adam Kallai kadam@inf.u-szeged.hu
2018-11-13 13:30:59 +01:00
Ádám Kallai 8219595c2d targets: Speculative workaround for Zephry Travis CI (#2595)
The latest version of Pyocd does not install on Linux,
in Zephry master branch the version was locked to 0.12.0 in requirements.txt.
It's temporary workaround to fix Travis CI for Zephry v1.13.0.

JerryScript-DCO-1.0-Signed-off-by: Adam Kallai kadam@inf.u-szeged.hu
2018-11-13 13:15:05 +01:00
Robert Fancsik ecf385888f Disable class Array/%TypedArray%.prototype.{slice, map, concat, filter, splice} related tests (#2588)
This patch fixes #2587.
The reason of disabling these tests is that the current implementation slightly differs from the related part of the standard (ECMA-262 v6, 9.4.2.3.6.d.1).
This part requires the hidden Symbol.@@species property, hence this functionality has not been implemented yet in the project.
Also add the related test case to prevent further errors.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-09 09:42:16 +01:00
Robert Fancsik 1fc369e493 Use binary search for keyword checking (#2584)
This patch improves keyword searching during identifier parsing.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-08 10:24:53 +01:00
László Langó 7f17210d98 Added missing include for debugger build. (#2586)
In certain platforms the explicit include of 'sys/socket.h' is needed,
e.g.: TizenRT.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-11-06 18:15:27 +01:00
Robert Fancsik 3faec79071 Reduce ecma_builtin_helper_def_prop arguments (#2585)
This patch uses the ECMA_PROPERTY_CONFIGURABLE[_ENUMERABLE_[WRITABLE]] marco to pass the options instead of using 3 boolean arguments for it.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-11-06 18:13:38 +01:00
matedabis 74d474248d Enable the already fixed test cases (#2570)
Enable already fixed asserts

JerryScript-DCO-1.0-Signed-off-by: Mate Dabis mdabis@inf.u-szeged.hu
2018-10-31 09:53:21 +01:00
repasics 3c1d0e6100 Enable test cases (#2566)
Enable previously disabled test cases in math-pow.js. Everything works as expected.

JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi repasics@inf.u-szeged.hu
2018-10-30 15:25:54 +01:00
Tóth Béla 63e8287f2b Seperate tests from test-api.c - Strings (#2564)
`test-api.c` is contains testing for all API functions. This file is too big and hard to read. This patch moves the strings and string methods into a separate test file.

JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-10-30 11:42:54 +01:00
Zoltan Herczeg 83fc0aa04f Add support for function argument initializers. (#2571)
EcmaScript 2015 14.1.

Note: arrow functions with default arguments are not supported yet.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-10-30 10:48:35 +01:00
Akos Kiss aeddb1cd88 Get rid of ? true : false (#2575)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-10-29 14:51:59 +01:00
Robert Sipka 34c5e229ee List scope chain levels and their variables to the selected stack frame. (#2557)
It supports to list the scope chain of the current execution context and see
which variables are available.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2018-10-29 14:33:31 +01:00
Akos Kiss 7120b8ec02 Improve .travis.yml (#2577)
- Use builtin support of Travis CI for job names instead of using
  a custom environment variable for the same purpose.
- Use `skip` in `script` and `install` steps instead of `true`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-10-29 13:37:19 +01:00
Zoltan Herczeg 93567fbb8f Support methods for object initializers. (#2567)
MethodDefinition in ES-2015 12.2.6.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-10-26 23:47:08 +02:00
Roland Takacs ffbd6e6c5c Fix type conversion errors in case of TizenRT. (#2572)
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-10-26 14:21:00 +02:00
Robert Fancsik d1860d0e34 Implement ES2015 class feature (part II.) (#2439)
This patch is the second milestone of the implementation of this new language element.

Supported:
 - Single class inheritance
 - Functionality of 'super' keyword
 - Implicit constructor in class heritage
 - Specific behaviour while extending with the built-in 'Array' or '%TypedArray%' object
 - Abstract subclasses (Mix-ins)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-10-25 16:00:48 +02:00
Zoltan Herczeg e0e6363f85 Fix object initializer prescanning issues. (#2563)
This patch fixes incorrect syntax errors reported by the prescanner for
ES5.1 getter/setter property initializers and ES2015 computed properties.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-10-19 13:49:41 +02:00
Tóth Béla f8f691deb1 Move version numbers to public headers (#2556)
JERRY_SNAPSHOT_VERSION and JERRY_DEBUGGER_VERSION were moved into public headers, to grant access to them.

JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-10-19 11:49:53 +02:00
Zoltan Herczeg 5060579b90 Fix double literal free. (#2535)
Fixes #2531.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-10-18 01:17:53 +02:00
crazy2be 3afc4b0b85 Change jerry_port interface to allow for a correct implementation of timezones. (#2540)
The previous jerry_port interface did not allow timezones to be handled correctly,
even if the host system was up to the task. This PR changes the jerry_port interface
to allow a completely correct implementation to exist, and provides one (for Linux/BSD
systems) in default-date.c.

Fixes #1661

JerryScript-DCO-1.0-Signed-off-by: crazy2be crazy1be@gmail.com
2018-10-18 00:58:18 +02:00
crazy2be 9ab33e86d3 Add some progress printing to the test262 tests (#2559)
Previously, these would run for several minutes without printing
any progress. Now, at least print the number of tests executed.

JerryScript-DCO-1.0-Signed-off-by: crazy2be crazy1be@gmail.com
2018-10-15 08:22:29 +02:00
Akos Kiss afe2a80431 Ensure that tests are always executed in a proper time zone (#2551)
The America/Los_Angeles time zone is already enforced for test262
Travis CI jobs but that doesn't guarantee the correctness of
locally executed tests. So, this patch moves the setting of the
`TZ` environment variable from `.travis.yml` to `run-tests.py`.

The date-related tests in the jerry test suite also rely on a time
zone (UTC). Thus, `TZ` is forced for those tests, too.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-10-09 11:43:07 +02:00
Akos Kiss 1393e9c3da Remove the support for "N*.js"-named disabled tests (#2553)
The only such test was a legacy of the long removed compact
profile, which is also removed.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-10-08 13:48:39 +02:00
Akos Kiss a9c6364bce Fix mismatch in context getter/setter names of default port (#2554)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-10-08 13:48:23 +02:00
Akos Kiss 4a0dd587fc Fix documentation of jerryx_handler_assert (#2555)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-10-08 13:48:09 +02:00
Roland Takacs 1302887498 Remove the JERRY_SNAPSHOT_FOUR_BYTE_CPOINTER snapshot flag. (#2550)
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-10-05 09:55:37 +02:00
Zoltan Herczeg d5a635a54a Fix use after free during creation of Promise reactions. (#2532)
The ecma_enqueue_promise_reaction_job() function allocates memory,
which might trigger a GC run. During this GC the objects in the
reactions collection are not marked.

Fixes #2486.
Fixes #2506.
Fixes #2541.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-10-05 08:08:41 +02:00
Zsolt Borbély 48810a9d88 Add missing doc to webpage generator script (#2548)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2018-10-04 10:59:30 +02:00
Zoltan Herczeg a8399f4416 Rework op_construct. (#2547)
The new form should be more suitable for classes.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-10-03 11:52:01 +02:00
Robert Fancsik abf22597e5 Add missing error check in ecma_builtin_promise_do_race (#2546)
Fixes #2544.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-10-03 11:39:43 +02:00
Daniel Vince e12d015bd2 Fix typo in the byte code documentation. (#2545)
JerryScript-DCO-1.0-Signed-off-by: Daniel Vince vinced@inf.u-szeged.hu
2018-10-01 12:19:42 +02:00
Daniel Balla 7717d2ee27 Change Promise properties to internal properties (#2526)
There was an issue in the Promise implementation where properties were accessible from JavaScript.
ie. `Object.defineProperty(Object.prototype, 0, {})` could modify properties which should've been inaccessible.
The reason behind that is somewhat interesting as 0-7 were the same values as the enum values in the property list of the Promise object.
Changing these properties to internal, makes them inaccessible from JS side.

Also some tests have been changed, namely 2490 and 2465.
The 2490 one got renamed, and all of the testcases from the issue have been added.
2465 got changed as well, since currently our Promise implementation can't display Promise errors, so we should check if an error is correctly returned.

Fixes #2490

Co-authored-by: Robert Fancsik <frobert@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-09-24 13:49:41 +02:00
László Langó d08b46d15a Fix '--skip-list' argument of the test runner script. (#2536)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-09-24 13:17:04 +02:00
Daniel Balla 0523278a98 Fix not checking errno after calling recv() (#2538)
There was an issue not checking if recv() set the error value to EWOULDBLOCK or EAGAIN (both equals 11).
If recv() returns 0 that means the connection was gracefully closed from the other side. However, if you are using non-blocking sockets, and recv() returns 0, but sets the errno to EWOULDBLOCK or EAGAIN it means the socket operation would block.
This patch fixes #2537

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-09-24 09:21:35 +02:00
Zoltan Herczeg 35fbcd1ffd Increase the debugger version field size from 1 byte to 4 byte (#2513)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-09-20 09:33:56 +02:00
László Langó df69e1e08b Add more consts to external magic strings to get data moved from .data to .rodata. (#2534)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-09-20 09:17:58 +02:00
László Langó 81810d58f8 Fix memory leak in the snapshot creation. (#2533)
Bytecode must be freed when the source is parsed succesfully,
but the snapshot generating fails for some other reason.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-09-19 20:47:16 +02:00
Akos Kiss cfa7cfc08c Add soft assert handler to jerry-ext (#2516)
Allow developers to choose whether they want a hard or a soft
implementation behind `assert`, i.e., whether they want to kill
the whole engine in case of an assertion failure in the executed
script or just throw a JS error.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-18 14:42:28 +02:00
Robert Fancsik 685d8b3675 Fix JERRY_CONTEXT (error_value) handling during ecma_builtin_promise_reject_abrupt (#2519)
Fixes #2489.

Co-authored-by: Daniel Balla <dballa@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-09-17 18:27:00 +02:00
Akos Kiss b97f5ffca0 Send print output to debugger client from the port implementation (#2515)
... not from the print handler extension. The sending of logs is
already in the port implementation.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-17 18:17:16 +02:00
Zoltan Herczeg 3031a11f86 Fix LCache invalidation issue for native properties during GC. (#2530)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-09-17 17:31:50 +02:00
Robert Fancsik 6c21c08b0e Fix ecma_op_function_list_lazy_property_names in case of arrow function (#2529)
Fixes #2528.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-09-17 13:31:17 +02:00
Akos Kiss 3d3a8008a8 Don't use strlen for string literals (#2517)
Their length (size) is known at compile time. Therefore `sizeof`
is more efficient for them.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-17 10:07:24 +02:00
Tóth Béla 2d83d8ed17 Fix check-magic-strings.sh to return with non-zero if error happens (#2525)
Running `tools/run_tests.py --check-magic-strings` causes an IndexError,
but the script exits with 0, indicating error-less run.
Added error checking to the file, to indicate errors in the future.

Fixes #2522

JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-09-14 13:37:48 +02:00
Peter Marki 0d05dfcd68 Remove bad assertion in ecma_builtin_json_str_helper (#2521)
Fixes #2494

JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2018-09-14 12:04:47 +02:00
Tóth Béla 08e4a95394 Update regular expressions in gen-magic-strings.py (#2527)
In their past form, they could not recognize preprocessor directives,
if they didn't start on column 0. Updated them to fix this problem.

JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-09-14 08:22:35 +02:00
Akos Kiss f114f83720 Remove the JERRY_GET_CURRENT_CONTEXT macro (#2512)
It was an unused and undocumented macro that enabled diverting the
`jerry_port_get_current_context` calls, an approach that was not
used anywhere else in the Port API.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-13 14:18:47 +02:00
Akos Kiss 4ec607a58b Remove leading space from before #ifs (#2523)
It both is against coding style and confuses the
`gen-magic-strings.py` build tool.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-12 15:00:05 +02:00
Paul Sokolovsky 5472aff0dc targets: zephyr: Update for Zephyr 1.13 and SDK 0.9.3 (#2497)
Zephyr 1.13 made some refactorings to its CMake infrastructure which must
be propagated to applications.

Also, some config options were removed/refactored, so cleanup prj.conf.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2018-09-11 15:13:07 +02:00
Akos Kiss 7825e4756a Properly guard off LCache-related functionality (#2511)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-10 13:27:39 +02:00
Daniel Balla 8f64339e5f Fix ecma_op_object_put return value not being handled (#2514)
Fixes #2487
Fixes #2488

Co-authored-by: Robert Fancsik frobert@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-09-06 21:05:37 +02:00
László Langó 99c9a22b78 Improve API of literal save and the snapshot (command line) tool (#2507)
Removed 'jerry_parse_and_save_literals' and introduced
'jerry_get_literals_from_snapshot' instead which works
on snapshot buffers rather than source code. Added literal
saving feature to snapshot merge in the snapshot command
line tool. Also added missing 'jerry_cleanup()' calls to the
snapshot tool. Improved the console messages of the snapshot
tool.

Based on previous work of Tamas Zakor <ztamas@inf.u-szeged.hu>

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-09-06 13:45:15 +02:00
Akos Kiss 054717fd29 Promote dynamic memory management from debugger transport to core API (#2503)
Under the cover of the debugger transport layer, allocation on the
engine's heap has been made available to the public. As there are
actually no restrictions on what the allocated memory can be used
for, the memory management functions better fit in the core part
of the API.

Closes #1805

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-04 16:31:26 +02:00
Zoltan Herczeg 0a40f55e5f Introducing internal properties. (#2485)
Native handle and pointer are moved to internal properties.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-09-04 15:43:35 +02:00
Akos Kiss 30b7a72344 Merge instance into context (#2501)
There was quite some confusion about terminology around instances
and contexts. All the docs mentioned external contexts but
functions and types were referring to instances, and the relation
between these two concepts were not clear. This commit keeps
(external) context as the only surviving concept.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-04 13:56:49 +02:00
Zoltan Herczeg d3d42f7685 Implement the core of the map object. (#2447)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-09-04 13:30:00 +02:00
Daniel Balla 65e81f3262 Fix UTF8 string length calculation (#2508)
Fixes #2451
Fixes #2452
Fixes #2453

Co-authored-by: Robert Fancsik <frobert@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-09-04 10:47:28 +02:00
Akos Kiss b934dd8308 Fixup JMEM_HEAP_STAT_xxx definitions (#2509)
- Get the macro definition indentations right.
- Define some of the macros only if system allocator is not in use.
- Ensure that macros with arguments don't cause unused variable
  warnings even if memory statistics is disabled.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-04 10:24:24 +02:00
Daniella Barsony 9ea9061aa2 Fix run-test-suite (#2505)
You could not interrupt the test with Ctrl+C

JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2018-09-04 10:23:59 +02:00
László Langó 8547380d46 Fix constantness of 'jerry_merge_snapshots' function. (#2504)
'jerry_merge_snapshots' should not modify the input snapshots. Updated the
related unit test. Also fixed some minor style issues.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-09-03 14:00:07 +02:00
Zoltan Herczeg 2ad883ea48 Fix logging issues in the debugger. (#2483)
- Properly handle logging during transport close
 - Properly display data during parse

Furthermore hide global functions of the debugger.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-09-03 11:14:57 +02:00
Akos Kiss d270f82ecb Clean up memory statistics printing functions (#2502)
- Remove leftover declaration of `jmem_pools_stats_print`.
- Remove unnecessary trampoline function `jmem_stats_print`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-09-03 09:21:21 +02:00
Daniel Balla f5757e4c91 Fix ecma_builtin_promise_race_or_all function (#2491)
If a new Capability was created no check was issued if it happened to be an error.
Fixes #2465
Fixes #2468
Also fixes the second variant of #2490.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-08-31 16:45:32 +02:00
Akos Kiss c3b6bfe8b6 Reorganize heap context related elements (#2500)
- Moved global context's `JMEM_HEAP_SIZE` to jcontext.h as external
  context's heap size is declared there, too.
- Moved the assert on `jmem_heap_t` vs `JMEM_HEAP_SIZE` to jcontext.c,
  as both entities are declared in the corresponding header.
- Removed superfluous checks on `JMEM_HEAP_SIZE` as it is not a
  publicly configurable macro (opposed to `CONFIG_MEM_HEAP_AREA_SIZE`).
- Ensured that all definitions of and references to `jmem_heap_t`,
  `JERRY_HEAP_CONTEXT`, `JERRY_HEAP_SIZE`, and `JERRY_HEAP_AREA_SIZE`
  are guarded by `#ifndef JERRY_SYSTEM_ALLOCATOR`, as they are
  meaningless if the system allocator is used.

The commit also contains some stylistic changes in jcontext.h

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-31 14:58:11 +02:00
Akos Kiss 6049c0378d Merge lcache into context (#2498)
It is superfluous to maintain multiple globals when the whole
reason of context is to keep them in a single place. It also
simplifies initialization and external context creation a bit.

Also removed unused lcache header includes.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-31 13:10:37 +02:00
Akos Kiss a2645601ae Remove character pointer typedefs (#2492)
The `[jerry|ecma]_char_ptr_t` types are some old legacy that are
used quite inconsistently. Their `[jerry|ecma]_char_t *` variants
are used a lot more often, so it's better to stick to one form
throughout the code base.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-30 09:33:05 +02:00
László Langó df1893042d Added missing documentation of JerryScript instances to the API reference. (#2482)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-08-30 09:25:11 +02:00
Zoltan Herczeg 7d41d38e3c Remove deprecated native handle support. (#2496)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-08-29 12:51:37 +02:00
Akos Kiss b4dc6b0cbe Change jerry_debugger_send_{output,log} to take const jerry_char_t * (#2495)
... instead of `jerry_char_t []`, which is not used anywhere else
in the API.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-29 15:53:11 +09:00
Akos Kiss fa5c361774 Move the 'init/fini arrays' build option to jerry-ext (#2493)
Since the removal of jerry-libc, only jerry-ext uses the
`FEATURE_INIT_FINI` optional feature. Thus, it's better to move it
from the global cmakelists to that of jerry-ext.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-29 08:39:59 +02:00
Zoltan Herczeg 25f1718d84 Move some internal functions into JerryDebugger. (#2484)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-08-28 23:56:57 +02:00
Zoltan Herczeg bd42403600 Implement computed properties for object literals. (#2481)
Also disable ES5.1 property name dumplication checks
when ES2015 object literals are enabled.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-08-28 15:28:16 +02:00
Zoltan Herczeg 300e40ba9d Improve python debugger client. (#2441)
Replace DisplayData to DebuggerAction. The new class has only four type
options. Furthermore several functions returning with DisplayData is
changed to return with string.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-08-22 17:34:32 +02:00
Anthony Calandra b2cf7eb659 Add %TypedArray%.prototype.sort([ compareFunction ]) support. (#2437)
JerryScript-DCO-1.0-Signed-off-by: Anthony Calandra anthony@anthony-calandra.com
2018-08-22 08:49:12 +02:00
Akos Kiss 6e94414f9c Align the RIOT target with the clang build of RIOT OS (#2477)
This means cross building with clang and using short enums. Also
bump RIOT OS version to latest 2018.07.

Note: On Travis CI, clang-3.9 is used for testing. That version is
widely available, from Ubuntu 14.04 to 18.04.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-21 10:46:45 +02:00
Akos Kiss f6ccdbdddd Doctest debugger examples and fix revealed issues (#2475)
This will help to keep the debugger documentation up to date.
(Note: only compilation & linking is possible as execution would
require a connecting debugger client, which is not supported for
unit/doctests.)

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-21 09:42:56 +02:00
Akos Kiss 7639e613a4 Remove jerry-libc (#2332)
Rationale:
- There is no port under targets/ that would use it. All of them
  turn it off when building.
- That's no surprise, as jerry-libc supports no barebone MCUs but
  posix targets with syscalls only. Actually, that's Linux only,
  because macOS builds have turned off the use of jerry-libc a
  while ago.
- And there is no point in maintaining a highly restricted set of
  libc functions: as soon as someone wants to use JerryScript in a
  scenario that needs more functions than jerry-main, they have to
  choose a different libc (most problably the compiler's default
  one).

I think that we should not keep supporting an otherwise unused
library for the purposes of jerry-main on arm/x86/x64-linux  only.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-21 09:26:53 +02:00
Martine Lenders 851f4f0b89 Fix LLVM/clang conversion errors (#2473)
This fixes some conversion errors one gets when compiling with
LLVM/clang. Most of them are caused when a bit-specific type (i.e.
`uint16_t`) is implicitly cast to an `enum` of smaller value range.

The fix is just an explicit casting of those types to the desired target
type.

JerryScript-DCO-1.0-Signed-off-by: Martine Lenders m.lenders@fu-berlin.de
2018-08-21 08:22:57 +02:00
Robert Fancsik 505dace719 Add a validation before evaluating the source code (#2480)
This patch checks whether the source code is a valid UTF-8 string before evaluating it in prompt mode.
Also fixes #2476.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-08-21 13:53:56 +09:00
Marc Jessome cffeaba2a6 Fix syntax error when closing a block after a return statement (#2479)
This adds a right brace to the list of tokens that will end a return
statement.

JerryScript-DCO-1.0-Signed-off-by: Marc Jessome marc.jessome@fitbit.com
2018-08-21 13:51:40 +09:00
Zoltan Herczeg 767dd68ce1 Change literal status flags to enum. (#2474)
Also fix a white space typo.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-08-18 08:06:37 +02:00
Akos Kiss 4e58ccf680 Update debugger documentation (#2471)
The documentation has not been updated when the HTML client got
removed nor when the new transport layer replaced the previous
debug server initialization process.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-16 07:59:12 +09:00
Akos Kiss b52fff1f9d Distinguish between public and private headers in jerry-core (#2472)
The patch also ensures that all components access only the public
headers of other components (except for unit tests, which are
allowed to use private headers, too).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-16 07:55:38 +09:00
Akos Kiss a3112ab901 Split string-sending debugger API into output- and log-sending functions (#2461)
This helps to avoid the use of non-public headers and
protocol-internal constants in external code (e.g., in jerry-port
and jerry-ext).

The patch also cleans up the necessary includes in jerry-core public
headers, and the include order in jerry-port/default public headers.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-14 16:29:06 +09:00
Akos Kiss b9aa0da402 Fix unpacking mismatch in run-tests.py (#2466)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-14 08:25:13 +02:00
Akos Kiss 990b5d24dd Fix include directories of jerry-ext (#2464)
The distinction between public and private include directories was
not maintained and the install paths got confusing.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-13 13:02:10 +09:00
Akos Kiss b31e43075a Add explicit casts to enum-to-integer conversions (#2467)
Clang 6 is more picky about implicit conversions and complains
about loss of presicion and/or change of signedness.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-13 13:01:37 +09:00
Akos Kiss d7cb48d4cc Rename debugger-ws.h to debugger-sha1.h in debugger extension (#2463)
The renamed header doesn't contain any declarations related to
debugger-ws.c but contains the declaration of a function from
debugger-sha1.c.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-13 12:43:36 +09:00
Akos Kiss 79d1a3cc7e Fix FILE_PATTERNS of Doxyfile and some of the issues it was hiding (#2446)
`FILE_PATTERNS` is a space-separated list, in contrary to what is
suggested by its documentation. The pattern `*.h, *.c` does not
match header files but files with `.h,` extension only. Rewriting
the current comma-separated pattern makes Doxygen actually process
header files. However, it also reveals several hitherto hidden
issues (mostly missing documentation) in the code. This patch fixes
some of these documentation problems (and lists the files with
outstanding issues in a 'backlog').

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-13 12:42:19 +09:00
Akos Kiss 29e7330b9b Move all (nano|u)sleep-related decisions to default port implementation (#2462)
... where they belong.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-11 00:06:25 +02:00
Akos Kiss fb35e34801 Make string constants const char * const (#2458)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-10 21:08:49 +02:00
yangfasheng 81f37cf134 Modify header file contains. (#2460)
JerryScript-DCO-1.0-Signed-off-by: yangfasheng yangfasheng@rt-thread.com
2018-08-10 08:45:59 +02:00
Akos Kiss 17eb78aa63 Don't use a shell variable to store error output of doxygen (#2455)
Storing the error output of doxygen into a shell variable first and
echoing it later is error prone. In case of a long error output,
the whole shell will crash before being able to print the doxygen
diagnostics at all. This patch rewrites the check script to tee the
diagnostics (pipe them to console and store them to a file at the
same time) and check the output file size at the end.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-09 10:26:09 +02:00
Akos Kiss 3fd7e98d53 Make cppcheck print diagnostics only (#2456)
The progress messages of cppcheck produce a lengthy and verbose
log, making errors and warnings hard to find. This patch adds
`--quiet` to the invocation of `cppcheck`

Additionally, the patch relayouts the script to use a consistent
two-spaces indentation everywhere.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-09 10:12:18 +02:00
Akos Kiss f6b99b60d2 Reduce the scope of variable str_buf in jerry-main (#2457)
Also reduce the number of magic constants used in the code.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-09 10:11:25 +02:00
Akos Kiss 29f6ffc35b Make logging an optional feature and disable it by default (#2449)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-08 23:35:03 +09:00
Akos Kiss 58c568a68f Revisit unused global functions in jerry-core (#2450)
There are some leftover global functions in the code that are not
referenced at all anymore. These functions are removed by this
patch.

There are also some global functions that are only used in their
own modules. These functions are made static by this patch.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-08 23:34:13 +09:00
Peter Marki 47087dec56 Improve the output format of the testrunner (#2438)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2018-08-08 23:33:02 +09:00
Zoltan Herczeg 1ac2903d3c Fix a few parser style issues. (#2442)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-08-06 18:08:53 +02:00
Akos Kiss 2534d32339 Use #include<> for system headers and #include"" for own headers (#2445)
They are no big differences between the two forms as "" falls back
to <>. There are some inconsistencies in the code, though, which
are fixed by this patch.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-06 18:00:49 +02:00
Akos Kiss c93bea32c4 Simplify redundant condition in jerry-snapshot.c (#2444)
Redundant condition: is_c_format. '!A || (A && B)' is equivalent to
'!A || B'.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-08-05 15:41:58 +02:00
Daniella Barsony 64051b5bd8 Add total frame counter to backtrace in debugger (#2428)
This was needed for the VScode extension so we know in total howmany frames we have in the backtrace.

JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2018-08-03 11:30:13 +02:00
Daniel Balla 87897849f6 Fix for null pointer dereference in jmem_heap_free_block (#2440)
Fixes #2435.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-08-01 23:09:30 +09:00
Robert Fancsik 1f20bb3fe5 Remove unnecessary cbc_code_flag (#2443)
The removed flag can be substituted with the combination of two existing ones.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-07-31 20:15:27 +02:00
Daniel Balla ba76b506f5 Fix broken pipe error in Jerry Debugger (#2427)
This patch fixes an error caused by trying to send data to a closed socket.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-07-31 17:36:37 +09:00
Robert Fancsik a6ace5efdf Improve lexer_expect_object_literal_id option handling (#2436)
This patch allows to add further options flags to `lexer_expect_object_literal_id` to handle unique behaviors more easily
also substitutes `PARSER_IS_CLASS` flag hence it is removed.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-07-30 15:12:35 +02:00
Tamas Zakor 8482fef41a Splitting the debugger and console part of the python debugger (#2406)
Move DebuggerPrompt to jerry_client.py
Implement JerryDebugger functions in the jerry_client_ws.py file
Server response is displayed by jerry_client.py

JerryScript-DCO-1.0-Signed-off-by: Tamas Zakor ztamas@inf.u-szeged.hu
2018-07-23 13:10:39 +02:00
Robert Fancsik 77d9314b1d Simplify source evaluation options. (#2431)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-07-20 08:50:39 +02:00
Zoltan Herczeg 76ff084dc7 Move low-level debugger connection handling into jerry-ext. (#2426)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-07-19 10:14:43 +09:00
Zoltan Herczeg 88589902e2 Remove jerry_get_arg_value function. (#2425)
Remove automatic conversion of errors. Errors are
primary values, just like numbers or strings.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-07-19 10:13:40 +09:00
Tóth Béla 66dddadfd2 Change ../../libapps paths in TizenRT configuration Makefile (#2429)
This change helps the symlink method to work also with TizenRT/jerryscript configuration, while maintaining the old cp method usability.

JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-07-18 15:52:50 +02:00
Zoltan Herczeg 9513f3792d Reduce with stack consumption by 1. (#2430)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-07-18 15:52:00 +02:00
László Langó 5f4a220a65 Added literal list loading feature to the snapshot tool. (#2422)
It is needed to load literals and register them as magic strings
to be able to generate static snapshots. Also modified the list
format saving feature to save all of the literals not only the
identifiers.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-07-16 15:13:18 +09:00
Zoltan Herczeg f86d7459d1 Fixes for ES2015 classes. (#2424)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-07-13 14:59:53 +02:00
Robert Fancsik 0ca04376a5 Fix typos in the API documentation. (#2423)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-07-13 09:36:21 +02:00
Zoltan Herczeg 857ba99694 Rework JerryScript transport layer. (#2421)
Introducing jerryscript-debugger-transport.h interface, which allows
chaining multiple protocols (e.g. tcp and websocket).

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-07-13 01:21:08 +09:00
Robert Fancsik 43aae199ce Implement ES2015 class feature (part I.) (#2404)
This patch is the first milestone of the implementation of this new language element.

Currently supported:
 - Class statement
 - Class expression
 - Static methods

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-07-13 01:20:08 +09:00
Daniella Barsony 62cdb3965f Add start to backtrace for debugger (#2407)
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2018-07-12 12:44:54 +02:00
Zoltan Herczeg 04dcefe087 Rework function call. (#2414)
Furthermore add a construct flag, which disallows calling certain
functions without new. Constructing bound arrow functions correctly
throws error now.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-07-11 09:35:44 +09:00
Anthony Calandra 50daa39ee8 Optimize JSON Quote operation. (#2420)
JerryScript-DCO-1.0-Signed-off-by: Anthony Calandra anthony@anthony-calandra.com
2018-07-10 15:00:19 +02:00
Istvan Miklos 0c6b5eae65 Fix incorrect output from JSON.stringify (#2416)
This patch fixes the #2383 issue

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-07-03 19:21:45 +09:00
Anthony Calandra a456c90c1d Add %TypedArray%.prototype.fill(value, [ begin [, end ] ]) support. (#2415)
JerryScript-DCO-1.0-Signed-off-by: Anthony Calandra anthony@anthony-calandra.com
2018-07-03 19:21:14 +09:00
Anthony Calandra d5cd32b0c0 Support for %TypedArray%.prototype.set(typedArray [, offset]). (#2405)
This patch allows developers to set a typedarray given a source typedarray. This patch
attempts to follow section 22.2.3.22.2 in the ECMAScript spec as closely as possible.

JerryScript-DCO-1.0-Signed-off-by: AnthonyCalandra anthony@anthony-calandra.com
2018-07-03 15:19:53 +09:00
Anthony Calandra a74bf7dc91 Add %TypedArray%.prototype.subarray([ begin [, end ] ]) support. (#2410)
JerryScript-DCO-1.0-Signed-off-by: Anthony Calandra anthony@anthony-calandra.com
2018-06-28 09:41:07 +02:00
Istvan Miklos b9f2b1cf25 Replace jerry_value_set_abort_flag with jerry_create_abort_from_value (#2411)
Replaced the function, added some tests for it. Also changed the functions order to
alphabetical.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-06-28 08:09:03 +02:00
Zoltan Herczeg 34c081095a Fix escape sequence parsing in lexer_compare_identifier_to_current. (#2409)
Furthermore do not allow escape sequences in object initializer
get/set functions.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-23 10:02:14 +09:00
Istvan Miklos dfc0757242 Fix jerry_create_error_from_value (#2403)
Fixed the release issue, added some test cases for the function

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-06-22 12:19:13 +09:00
Imre Kiss e3265883fd Add restart command to the debugger (#2401)
With this feature the use can restart the actual debug session
(similar to the multiple source context reset) within a client.

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2018-06-22 12:18:18 +09:00
Zoltan Herczeg 35ac0e0445 Fix parse_print_final_cbc dump when arguments is used (#2400)
Currently the byte code start is incorrectly set when
a non-strict arguments object is present, and a random
memory area is dumped as byte code.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-21 08:38:17 +09:00
Zoltan Herczeg 03274c112a Remove ECMA_LEXICAL_ENVIRONMENT_OBJECT_BOUND. (#2408)
Only the global object bound to the root node of the lexical environment
tree does not have a provideThis flag, and ecma_op_implicit_this_value()
falls back to the global object. Hence we get the same effect regardless
of provideThis.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-20 15:27:45 +02:00
Zoltan Herczeg acdbbf2261 Add literal property to the byte code list. (#2397)
Initializing a property with a constant is frequent in object initializers.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-20 09:06:59 +02:00
László Langó 7f56756e11 Improve sonarqube analysis to cover more code path. (#2381)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-06-20 10:34:49 +09:00
Zoltan Herczeg 86ecc81130 Fix literal free when show opcodes is enabled. (#2398)
A literal might be not freed if it is stored in a register,
and PARSER_DUMP_BYTE_CODE is enabled, but opcodes are not shown.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-18 09:31:13 +02:00
Zoltan Herczeg 1044523af7 Add operational mode for jerry_gc API call. (#2385)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-15 16:31:48 +09:00
Mátyás Mustoha bc827cb497 Reduce code duplication between String.charAt and charCodeAt (#2331)
JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-06-14 17:48:25 +09:00
Paul Sokolovsky 49c79e4774 targets: zephyr: Remove old option from prj.conf (#2396)
CONFIG_CONSOLE_HANDLER_SHELL is an old option which was removed quite
some time ago from Zephyr. (And newer versions will warn/error on
usage on such options.)

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2018-06-13 21:47:56 +09:00
Zoltan Herczeg 9625fb842e Improve instanceof operator. (#2395)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-13 19:33:27 +09:00
Akos Kiss 5398e07f99 Rework 128 bit arithmetics of ecma_utf8_string_to_number (#2392)
* Rewritten 128-bit integer "type" to use two 64-bit ints (they are
  enough), and made it a proper struct instead of an array.
* Rewritten all single-bit shift loops to multi-bit shifts with the
  help of CLZ, and used `__builtin_clzll` where available.
* Simplified (and documented) 128-bit DIV10 operation.
* Renamed 128-bit integer handling macros to use simpler names.
  (And removed unused macros that were laying around.)

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-12 16:04:47 +02:00
Istvan Miklos 62dee2dd71 Fix jerry_get_value_from_error (#2394)
Fix the function to take into account the second argument even if it is called with not
an error value.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-06-12 12:54:17 +02:00
Péter Gál efa8850783 Use binary mode when opening via fopen in the tools (#2371)
In the snapshot tool the files were opened
in text mode. However the snapshot files
are binary files thus it is advised to use the
binary mode when opening the files.

Specifying the binary mode is a must on Windows
platform otherwise the read/write operations
are inserting extra '\r' characters.

To make the tools consitent across OSes all
fopen are now opening files in binary mode.

Also update jerry-libc to accept the 'b'
modifier and add a test case where the JS
file uses CR-LF line endings.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-06-12 04:38:35 +09:00
Péter Gál 9ae60a4910 Improve license checker line ending validation (#2391)
The license checker previously assumed that the
lines of the license will always end with \n
characters. However when checking a file
it could happen that other line endings are
returned (should only happen for test files) thus
the checker can incorrectly report invalid license
as the line endings are incorrect.

Additional note #1: in Python when reading a file
in text mode it can happen that the line endings are
converted to the host system's line ending.
However on Travis the conversion did not happen when
using the open built-in method. By switching to the
io.open call the conversion is enforced and
all line endings are converted to '\n' regardless of
the host system's line ending.

Additional note #2: it is possible that there
are input test files which are not utf-8 conformant
(eg.: to test the parser). These files can't be read
as utf-8 strings and an exception would occur.
By ignoring these errors the tool can check
the file's license. In the license text there is no
invalid utf-8 character so the check will work
correctly.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-06-11 19:37:28 +09:00
László Langó f32c183137 Fixed assertion in 're_insert_into_group'. (#2388)
Assertion 'qmin <= qmax' failed in 're_insert_into_group', but
it should throw a SyntaxError. Fixes #2384.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-06-11 16:25:53 +09:00
Zoltan Herczeg bd0ea4f474 Fix wrong code order in opfunc_in (#2390)
Also no conversion if the left value is a string.

Fixes #2386.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-06-11 10:20:57 +09:00
Péter Gál d637e31933 On simple strings the utf8 substring copy api call created an assert (#2389)
When the `jerry_substring_to_utf8_char_buffer` was called
with direct strings the assert incorrectly assumed that the
string is a ref counted string and tried to access the
refcount value resulting in a failed assert.

Added direct string check for the underlying implementation
and created a test case for such simple string.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-06-11 10:19:39 +09:00
Istvan Miklos 2d0e37ff74 Replace the jerry_value_set_error_flag function with jerry_create_error_from_value (#2367)
JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-06-11 10:16:58 +09:00
László Langó be59d0a224 Remove the indentation of preprocessor directives. (#2379)
Indenting preprocessor directives reduces the code readability, because it make preprocessor directives harder to spot.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-06-08 15:35:23 +09:00
Robert Sipka 64c5be812c [targets/tizenrt-artik053] Fix typo in Make.defs (#2387)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2018-06-07 18:21:28 +09:00
László Langó b4b0b7d572 Merged conditions of if statements where possible. (#2380)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-06-06 15:08:17 +09:00
Akos Kiss b61d0ed856 Rework command line handling of build tool (#2373)
In `tools/build.py`:
- For the sake of readability, group CLI arguments as general build
  options, options to control the building of components, and
  component-specific options.
- To prevent duplications, remove the defaults from those CLI
  arguments that correspond to CMake options and have defaults in
  any of the CMakeLists. Should any of the defaults change, they
  will have to be changed at a single place only. (Those options
  that are not set on the command line of `tools/build.py` are not
  passed as options to `cmake` either.)
- Convert `--unittests` and `--doctests` to ON/OFF options like the
  rest of the component switches.
- Touch on some of the help messages of the CLI arguments.

Other changes:
- The change in `--unittests` and `--doctests` is a slightly CLI-
  breaking change of `tools/build.py`. Thus, follow up on this in
  `tools/run-tests.py`.
- Move `ENABLE_ALL_IN_ONE` into `jerry-core` as it is not a general
  option but specific to that component.
- Remove the forcing of `ENABLE_ALL_IN_ONE` for some compilers/
  platforms as it is still an option, not a hard requirement.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-06 15:07:06 +09:00
willeio 8b8bced67f Buildable as shared libraries (#2351)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: wille-io mike@wille.io
2018-06-05 08:39:30 +09:00
Akos Kiss e1af56586c Declare parser_error_to_string conditionally (#2376)
Its implementation is only available if `JERRY_ENABLE_ERROR_MESSAGES`
is defined.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-04 10:55:51 +09:00
Akos Kiss 71471a0416 Add better support for proper installation after build (#2370)
- Add `--install` option to `tools/build.py`.
- Make use of `--install` in `tools/run-tests.py` by testing the
  installed the executables instead of those in the build tree.

Related changes:
- Collect unit test binaries in the `tests` subdir of the build
  tree instead of `bin`.
- The `ls`-based collection of the unit test binaries had some
  shortcomings hitherto unrevealed (it didn't filter for files so
  it could potentially "collect" dictionaries, too), which has now
  been replaced with a more stable `find`-based solution.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-04 10:55:29 +09:00
Akos Kiss 2cabb6f8ea Remove the leftover declaration of ecma_op_create_global_environment (#2375)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-04 10:50:02 +09:00
Akos Kiss 9da010ae6e Remove legacy public headers (#2372)
Recent changes to master have already introduced API-breaking
changes. So, if someone is still including the legacy headers,
following up on the header file name changes will be the least of
their problems.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-04 10:49:38 +09:00
Akos Kiss 1b2c565850 Direct alloc/dealloc implementations for ecma_number_t (#2377)
As a result of earlier developments, there remained no other
instatiations of the `ALLOC`, `DEALLOC`, and `DECLARE_ROUTINES_FOR`
templates. So, it's simpler to write the alloc/dealloc routines
directly for `ecma_number_t` as well.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-03 15:29:28 +02:00
Paul Sokolovsky eec2623cd9 targets: zephyr: Separate CMake definitions from options. (#2378)
Add a space between definition and options substitution groups, otherwise
they make expand to something like -DFOO-DBAR.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2018-06-03 14:38:37 +02:00
Akos Kiss 3e934723a3 Make sure that API function jerry_debugger_send_output is always implemented (#2374)
Also add some missing comments to `#else` directives.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-06-03 14:28:18 +02:00
László Langó 117ea1f899 Removed unused macro definitions. (#2369)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-06-01 10:00:10 +02:00
Akos Kiss 2291467c99 Remove duplications from test runner (#2364)
- Code contains syntactic duplications (e.g., build options copy-
  pasted repeatedly).
- Build options for test suites contain semantic duplications
  (ES5.1 profile builds happen multiple times, once by not
  specifying a profile and once by specifying es5.1 profile
  explicitly).
- External build options are not taken into account when detecting
  duplicated builds.

This patch provides improvement for these issues.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-30 19:57:38 +09:00
Zoltan Herczeg 7be9f91d22 Reverse the generation of line info. (#2363)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-05-30 19:57:12 +09:00
Akos Kiss d5593c12b4 Maintenance and merging of Valgrind and Valgrind-Freya code paths (#2362)
None of the code paths have been tested for long and especially the
Freya code paths have been long abandoned. This patch:
- Merges Valgrind-Freya into Valgrind code path (there should be no
  need to choose between them, Valgrind should work just fine).
- Removes leftover code (`VALGRIND_FREYA_CHECK_MEMPOOL_REQUEST` and
  `valgrind_freya_mempool_request`).
- Adds `JMEM_` prefix to Valgrind-related macros (to correctly
  leave the `VALGRIND_` prefix to Valgrind).
- Moves the definition of the Valgrind-related macros to a common
  header to avoid duplication.

Note: Adding a CI job to perform Valgrind Memchecks is left for
follow-up as it turns out to be excessively slow (>50 mins for a
`--jerry-tests --jerry-test-suite` run, and even a simple
`--jerry-tests` may get terminated prematurely because of timeout
issues).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-29 16:33:14 +09:00
Akos Kiss 3560c60c73 Make test runners support execution runtimes (#2360)
If the result of a build is not directly executable on the host
system or needs an execution runtime for any other reason (e.g.,
cross-compiled ARM binaries on Intel, emscripten-generated JS
files, binaries built with Valgrind support) then the current test
runners cannot work with them. This patch makes test runners
execute binaries via a runtime given in the `$RUNTIME` environment
variable (if it is specified).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-29 15:22:57 +09:00
Akos Kiss a509570c1d Simplify the AppVeyor configuration file (#2361)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-28 18:59:46 +09:00
Robert Fancsik e6664f6364 Fix heap buffer overflow in re_parse_char_class (#2352)
This patch fixes #2230 and fixes #2237.
Test cases are added for both issues and also adds new cases which caused the same error.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-05-28 10:13:17 +02:00
Istvan Miklos ac9fce1d8d Merge jerry_get_value_without_error and jerry_value_clear_error_flag functions (#2350)
JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-05-25 11:40:35 +02:00
Akos Kiss 4779451284 Cleanup code around JERRY_UNREACHABLEs (#2342)
`JERRY_UNREACHABLE`s often signal code structure that could be
improved: they can usually either be rewritten to `JERRY_ASSERT`s
or eliminated by restructuring loops, `if`s or `#if`s. Roughly,
the only valid occurences are in default cases of `switch`es. And
even they can often be merged into non-default cases.

Moreover, it is dangerous to write meaningful code after
`JERRY_UNREACHABLE` because it pretends as if there was a way to
recover from an impossible situation.

This patch rewrites/eliminates `JERRY_UNREACHABLE`s where possible
and removes misleading code from after them.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-25 07:27:30 +02:00
Zoltan Herczeg acb3e71436 Add JERRY_VLA calls to the snapshot tool. (#2357)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-05-25 10:34:55 +09:00
Akos Kiss 06910b456e Fix issues revealed by cppcheck 1.83 (#2355)
A more recent cppcheck has revealed some extra issues not detected
by the old one running on CI.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-24 15:48:34 +09:00
Robert Fancsik 9eb9fbf5f1 Fix heap buffer overflow in lit_utf_incr (#2345)
This patch fixes #2344.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-05-22 10:32:40 +02:00
Akos Kiss 43075a2ce6 Consolidate compiler-specific parts of CMakeLists (#2349)
The cmakelists contained various compiler-specific parts scattered
across the file. This patch moves them to as few conditional blocks
as possible.

Additional changes:
- `-Werror` does not depend on whether jerry-libc is enabled.
- Some stylistic fixes.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-22 17:15:40 +09:00
Akos Kiss cc473425d3 Fix cmakelists of doctests to run generation only once (#2347)
Custom commands with outputs used in multiple targets are prone to
being executed multiple times in parallel builds (and the repeated
overwrites of the outputs may lead to various hard-to-debug
errors). The fix is to add a custom target that depends on the
custom command and make the existing targets using the outputs
depend on the new custom target.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-22 09:14:18 +02:00
Akos Kiss 299643400d Don't let doctests pollute the source tree (#2346)
The patch changes the cmakelists of the doctests to extract the
test sources from the markdown docs into the binary tree.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-20 14:37:38 +09:00
Akos Kiss 5ddbfa5953 Add AppVeyor badge to readme (#2341)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-20 14:32:52 +09:00
Akos Kiss 7424d299d8 Define JERRY_UNREACHABLE for MSVC (#2340)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-20 14:32:07 +09:00
Akos Kiss 22339e0b54 Retire the Mbed OS 3 target (#2343)
Mbed OS 3 is discontinued, long live Mbed OS 5.

resolves #2338

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-20 14:31:25 +09:00
Akos Kiss 145ab1ed79 Simplify run-time feature checks in unit tests (#2339)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-19 07:07:21 +09:00
Yonggang Luo 872825fb57 Add Windows support. (#2306)
JerryScript-DCO-1.0-Signed-off-by: PKarics karicska@gmail.com
JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
2018-05-18 19:42:14 +09:00
Akos Kiss 13bd30ff54 Remove legacy jerry_get_memory_limits API function and unused configuration macros (#2329)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-18 10:43:52 +02:00
Zoltan Herczeg 5560c76b41 Convert certain push number opcodes to literals (#2328)
Binary operations are much faster with literal arguments.
The byte immediates are still kept for other cases, e.g. array declarations.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-05-18 17:22:53 +09:00
László Langó 64b16bf190 Update Doxygen config file and fix Doxygen warnings (#2324)
A lot of warnings remained hibben because 'EXTRACT_ALL' was previously set to YES.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-05-18 15:43:17 +09:00
Akos Kiss fb6259b2ec Fix parameter constness differences in function declarations and definitions (#2337)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-18 09:39:42 +09:00
Mátyás Mustoha 0415d74a74 Reduce code duplication in the TypedArray implementations (#2319)
This patch was done in cooperation with Tamás Kéri.

JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-05-18 09:38:41 +09:00
Peter Gal 27dcfa51e1 Build fix after landing #2249
The old `jerry_value_has_error_flag` function was used
when the #2249 PR was merged.

Replaced with the correct `jerry_value_is_error` call.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-05-17 13:56:37 +02:00
Istvan Miklos ea1133b210 Add tests for TypedArrays by using indexing api. (#2249)
JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-05-17 10:29:52 +02:00
Akos Kiss 36f6435eb8 Revert the Mbed Travis CI job to sudo-based VM to avoid sporadic OOMs
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-16 16:34:19 +02:00
Akos Kiss 53bd845d9f Move (almost all) Travis CI jobs to container-based infrastructure (#2333)
Container-based VMs promise significantly faster boot times.

More or less related changes:
- Added a JOBNAME to all jobs.
- Added `install-noapt` target to several Makefile.travis files to
  avoid `sudo apt-get install ...` steps. Those installations are
  now handled by the apt addon of Travis. The `install` targets are
  kept anyway to keep the makefiles self-contained.
- Removed a legacy workaround from the Coverity Scan job as it
  isn't necessary anymore to fiddle with the cerificates of
  scan.coverity.com.
- Fixed the Mbed and the Zephyr jobs.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-16 19:15:15 +09:00
Akos Kiss 19451fa2d1 Use ecma_number_t instead of double where possible (#2330)
Some code paths explicitly used double instead of ecma_number_t
even though the values assigned from or compared to were of type
ecma_value_t.

Related to #2251

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-16 09:17:34 +09:00
Péter Gál 38f0dbf065 Remove 'useless' variable from function.bind (#2327)
The `args_length` variable in the `ecma_builtin_function_prototype_object_bind`
method is not needed, the `arguments_number` variable can be
directly used.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-05-15 09:03:40 +09:00
Peter Gal 86111acbc4 Remove usage of comma operator in array prototype
There was a typo in the `ecma_builtin_array_prototype_helper_set_length`
method as the comma operator was used to close the statement, incorrectly

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-05-15 00:52:30 +02:00
Akos Kiss 65ae949dc3 Add jerryscript-compiler.h public header to cover compiler incompatibilities (#2313)
In general, public headers should not have compiler-specific
constructs but both the core and the port headers have attributes,
which are non-standard. It's better to factor out such constructs
to a common place (a new header) and hide them behind macros, which
can then be defined on a per-compiler basis.

This patch moves the existing definitions of function attributes and
likely/unlikely builtins to the new header. At the same time, it
unifies the names of these attribute defines and where they are
used. Moreover, it touches on jerry-main and removes the uses of
`__attribute__((unused))` entirely and replaces them with the
elsewhere used `(void) ...` pattern.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-14 09:41:26 +09:00
László Langó 0e131da4f7 Add SonarQube badge to 'README.md' and update '.travis.yml' to fix a warning. (#2325)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-05-12 14:20:51 +09:00
László Langó c829b307e5 Followup fix for SonarQube setup (#2322)
Fix the condition whether Travis should run the SonarQube analysis

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-05-11 09:11:20 +02:00
Akos Kiss 134845e099 Simplify code paths within PARSER_DUMP_BYTE_CODE (#2316)
Also fix an uncovered issue in the reporting of switching to strict
mode.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-10 19:37:19 +09:00
László Langó b0120423da Setup SonarQube analysis in Travis CI (#2321)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-05-10 10:42:40 +02:00
Mátyás Mustoha 1261cf3a54 Fix some incorrect documentation (#2320)
JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-05-09 17:37:27 +02:00
Akos Kiss d6cf634239 Refactor/fix/document the default port implementation (#2317)
- Various constructs could be expressed with simpler and/or more
  readable code.
- The jerry_port_log implementation for the debugger case was prone
  to buffer overflow error.
- Some documentation was still missing (even from
  jerryscript-port.h).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-09 11:15:45 +02:00
László Langó a1f71f8937 Update the 'README.md' of the JerryScript profiles. (#2309)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-05-08 17:14:41 +09:00
Akos Kiss fbb9bf31b2 Fix documentation of port API (#2312)
The patch fixes both the doc comments in the port header and the
corresponding markdown documentation.

The patch also removes an internal configuration macro guard
exposed by the public port header.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-08 15:07:05 +09:00
Akos Kiss 7981820dfb Use logging macros in jerry-core/debugger (#2315)
...instead of directly calling the logging port API function.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-08 11:41:51 +09:00
Istvan Miklos 7e4e551dd5 Fix sign-conversion warning on gcc when compiling to raspberry pi 2 (#2308)
JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-05-08 11:41:05 +09:00
Akos Kiss 5f60208d1e Tabulation/indentation fixes (#2314)
- Status messages in CMakeLists.txt files got misaligned, fixing.
- An extra space sneaked in before an `#ifdef`, fixing.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2018-05-07 15:51:55 +02:00
Gabriel "_|Nix|_" Schulhof 6dc2764a94 modules: add ability to clear cache (#2300)
This adds the ability to remove a single module from the cache, or to
clear the entire module cache.

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2018-05-04 10:12:17 +09:00
Istvan Miklos 369447aa09 Rename the jerry_value_has_abort_flag function. (#2291)
Rename the function to represent it's real functionality.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-05-03 16:50:16 +02:00
Peter Marki 51e193de57 Remove the html based debugger tools and add a readme with information about available debug tools (#2299)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2018-05-03 09:36:00 +02:00
Robert Sipka b750a9e0b2 Update links and add a new one to the latest memory usage and binary footprint results for Artik053 (#2304)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2018-05-03 08:32:16 +02:00
Istvan Miklos ba2e49caaa Rename the jerry_value_has_error_flag function. (#2290)
Rename the function to represent it's real functionality.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-05-03 08:24:05 +02:00
Mátyás Mustoha d672d1e71c Reduce code duplication between Object.isFrozen and isSealed (#2296)
JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-04-26 13:51:27 +02:00
Peter Marki 06ada9e6b4 Remove unused tool scripts (#2298)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2018-04-24 17:24:00 +09:00
Mátyás Mustoha 63ce292173 Reduce code duplication between RegExp.construct and [[Call]] (#2287)
JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-04-20 15:27:33 +02:00
Mátyás Mustoha a76926623a Reduce code duplication between String.match and search (#2277)
Moved the common preparation code for 'search' and 'match'
to a separate function.

JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-04-20 14:04:59 +02:00
Achie72 3df6ef30c0 Implement toString and join for TypedArrays. (#2255)
JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-04-19 10:14:34 +02:00
Mátyás Mustoha c288cdad48 Reduce code duplication between Array.reduce and reduceRight (#2280)
Their code differs only in handling the array index.

JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-04-19 09:13:20 +09:00
Zoltan Herczeg 5e097dc354 Add line info support. (#2286)
Add line info data to byte, which allows getting a backtrace info directly
from the engine. Snapshots are not supported.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-04-19 09:12:54 +09:00
Zoltan Herczeg 095b730f9d Improve stopping at errors. (#2278)
In some cases the debugger catches (reports) the same
exception multiple times. This is confusing since these
not new errors. This patch fixes this behaviour.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-04-18 19:31:17 +09:00
Zoltan Herczeg 96b528a486 Rework jerry_parse function. (#2282)
Remove jerry_parse_named_resource, merge its arguments to jerry_parse
and change is_strict argument to an option list for possible future extensions.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-04-17 09:51:52 +02:00
Mátyás Mustoha 3f3d4a64f1 Reduce code duplication between Array.forEach, some, and every (#2275)
Their implementation only differs in the stop condition and the
final return value.

JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
2018-04-13 13:32:46 +02:00
László Langó 2bfd3b75b7 Put 'Zephyr/Arduino 101 Build Test' to allowed failures temporarily. (#2279)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-04-13 14:28:46 +09:00
Peter Marki d86a507fdf Eliminate dead code in ecma_builtin_object_object_get_prototype_of (#2276)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2018-04-11 21:03:35 +09:00
Zoltan Herczeg e91471727f Support abort in the debugger. (#2273)
Aborts are not caught by catch/finally blocks,
so it is possible to stop a script using the debugger.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-04-11 13:59:13 +02:00
Zoltan Herczeg 5c0c21b26a Rework snapshot execution api. (#2270)
The _at functions replaces the original functions.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-04-11 10:39:58 +09:00
Tibor Dusnoki 46309b1502 Fixes return value of 'Date.now' (#2274)
'Date.now()' should return an integer value. Fixes #2272
JerryScript-DCO-1.0-Signed-off-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu
2018-04-09 13:27:16 +02:00
tdusnoki cb40106693 Use jerry_is_feature_enabled function instead of macros where possible (#2271)
JerryScript-DCO-1.0-Signed-off-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu
2018-04-09 08:26:36 +02:00
Peter Marki 8392eef8ad Implement the ES2015 version of Object.getPrototypeOf and add a test file for it (#2256)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2018-04-05 14:28:28 +02:00
Zoltan Herczeg 7b226f53e0 Rework snapshot generation API. (#2259)
Also remove eval context support. It provides no practical advantage.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-04-05 13:43:55 +02:00
Martijn Thé 35926f3f85 Add finalize_cb to jerry_context_data_manager_t (#2269)
This patch adds a new finalize_cb callback to jerry_context_data_manager_t.
The callback is run as the very last thing in jerry_cleanup, after the VM has been torn down entirely.
There was already the deinit_cb, which is run while the VM is still in the process of being torn down.
The reason the deinit_cb is not always sufficient is that there may still be objects alive (because they still being referenced) that have native pointers associated with the context manager that is being deinit'ed.
As a result, the free_cb's for those objects can get called *after* the associated context manager's deinit_cb is run. This makes cleanup of manager state that is depended on by the live objects impossible to do in the deinit_cb. That type of cleanup can only be done when all values have been torn down completely.

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2018-04-05 12:57:51 +02:00
Zoltan Herczeg 27939f0884 Simplify debugger-ws.h (#2266)
Remove several macros and types from it. This change simplifies
the external debugger interface.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-04-05 11:22:44 +02:00
ZsoltRaduska 78bd11e732 Add json parse and stringify function to jerryscript c api (#2243)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Raduska rzsolt@inf.u-szeged.hu
2018-04-05 09:58:07 +02:00
ZsoltRaduska 0476523f1a Improve jerry_is_feature_enabled with object availability information (#2250)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Raduska rzsolt@inf.u-szeged.hu
2018-04-05 09:54:07 +02:00
Daniel Balla f06d637238 Add ecma_free_all_enqueued_jobs function (#2265)
This function releases any remaining promise job that wasn't completed.
Also added this function to `jerry_cleanup ()`, therefore it will be automatically run.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-04-05 09:49:25 +02:00
Geoff Gustafson 634d9d38da Fix bug in stringToCesu8 conversion for 0x7ff (#2267)
JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson geoff@linux.intel.com
2018-04-04 10:17:16 +02:00
Istvan Miklos ff37959195 Remove TARGET_HOST macros (#2264)
Remove TARGET_HOST defines from the jerry-libc module and replace with compiler provided macros.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-04-03 14:58:47 +02:00
Jimmy Huang a0e315719b Remove websocket message macros in debugger (#2262)
JERRY_DEBUGGER_INIT_SEND_MESSAGE
JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE
JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE

JerryScript-DCO-1.0-Signed-off-by: Jimmy Huang jimmy.huang@intel.com
2018-04-03 09:06:20 +02:00
Péter Gál 708f66ad91 Fix accessing the contents of a direct string (#2261)
In the `ecma_string_get_chars` method
the contents of a direct string is accessed incorrectly.
It tries to extract the magic string id from the
string pointer but the direct string does not need
this step.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-03-29 20:20:59 +02:00
Daniel Vince ba22072db8 Fix typo and redundant text in the documentation. (#2260)
JerryScript-DCO-1.0-Signed-off-by: Daniel Vince vinced@inf.u-szeged.hu
2018-03-29 10:52:20 +09:00
Daniel Balla 8af89d951e Add the ability to throw an error to python debugger (#2188)
This patch makes it possible to throw an error from the python debugger client using the `throw` command.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-03-28 16:46:24 +02:00
Tamas Zakor 79289714dc Remove unused functions which caused build error on clang (#2257)
JerryScript-DCO-1.0-Signed-off-by: Tamas Zakor ztamas@inf.u-szeged.hu
2018-03-27 16:10:49 +02:00
Peter Marki e54dde55fe Add tests for the es5.1 profile to tools/run-tests.py (#2217)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
2018-03-24 10:48:08 +09:00
imiklos 15f6ca9f70 Move the sleep function to jerry-port (#2245)
Now the jerry-debugger uses the jerry-port's sleep, therefore if there are systems that don't support
usleep or nanosleep can now define their own function.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-03-22 10:36:40 +09:00
haesik d701a7bfb1 Remove ineffective codes (#2248)
Results of assert statements are always true,
I think we don't need these assert statements anymore

JerryScript-DCO-1.0-Signed-off-by: Haesik Jun haesik.jun@samsung.com
2018-03-21 18:37:46 +09:00
imiklos 6e9a94bf1a Remove new line from output log in python client. (#2244)
There was an unnecessary new line character in the python debugger client.

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
2018-03-21 18:37:13 +09:00
Péter Gál 66d0f53bbb Remove a few ECMA_TRY_CATCH macro usages (#2246)
By removing the ECMA_TRY_CATCH macros at these
places  ~200 bytes of .text is saved on rpi2.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-03-21 18:36:38 +09:00
Gabriel "_|Nix|_" Schulhof 3664d9ddd1 Add an API to traverse objects by their associated native data (#2236)
JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2018-03-21 08:48:27 +01:00
Zoltan Herczeg bb84466fcf Support static snapshots. (#2239)
Unlike normal snapshots, no part of a static snapshot is loaded into
the RAM when executed from ROM. Static snapshots rely heavily on
external magic strings.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-03-20 07:46:52 +09:00
Achie72 dde09cc4b6 Fix JSON.stringify, to allow TypedArray printing (#2242)
JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
2018-03-19 14:12:33 +01:00
Yuyupo 0b76ea6c82 Create snapshot test (#2241)
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2018-03-14 14:01:03 +01:00
Imre Kiss a79c217aa0 Add finish debugger command. (#2240)
With this command the engine continue running just after the function
in the current stack frame returns.

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2018-03-12 14:42:48 +01:00
Daniel Balla 685af74a10 Multiple nexts with one command (#2207)
Make a next command more gdb like.
If an argument is given `next 10`, it does 10 nexts.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-03-08 10:46:03 +01:00
Roland Takacs 29b337d159 Eliminate early memory deallocations in case of NuttX and TizenRT (#2235)
The error value is released in the print_unhandled_exception function, however
that value is used and released later. This patch fixes this bug.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-03-06 08:22:22 +01:00
Yuyupo 63e3eaf087 Remove ecma_get_length_string (#2234)
Fixes #2231

JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
2018-03-05 15:17:29 +01:00
Zoltan Herczeg 7b0e1672ae Improve property search. (#2232)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-03-05 14:54:33 +01:00
Zoltan Herczeg b9f96a64d9 Support large string constants in 32 bit cpointer mode. (#2233)
After this patch, all sunspider tests run when cpointer 32 is enabled.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-03-05 11:41:52 +01:00
László Langó 94760b1213 Improve builtin instantiation (#2226)
* Resolve linker errors with -O0 in some compilers
 * Reduce the stack usage

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-03-02 14:37:03 +01:00
Péter Gál 55058cf151 Add quiet mode for test runner(s) (#2228)
In one of the previous PR we have encountered a problem,
where the Travis cuts off the test execution
as the generated log file is too big.

By adding a quiet mode for the test runners, we will
only report the failing tests.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-03-02 10:18:17 +09:00
Péter Gál 575ec7e10a Check _XOPEN_SOURCE macro before defining (#2220)
In jrt.h the _XOPEN_SOURCE macro is defined.
However if the compiler already specifies this as
a default define, it can lead to compiler warnings
or errors.

By adding a macro check the warnings/errors can be
avoided.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-03-02 10:17:25 +09:00
Zoltan Herczeg d60d4dbba9 Improve magic string handling. (#2221)
Remove unnecessary ref / deref calls when magic strings are used.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-03-01 13:31:15 +01:00
Martijn Thé 26ee8f7137 Bugfix: check context manager deinit callback for NULL before calling it (#2222)
The deinit_cb should be allowed to be NULL.

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2018-03-01 09:31:39 +01:00
siposb94 ccc283289c Added several negative tests (#2215)
JerryScript-DCO-1.0-Signed-off-by: Balint Sipos siposb@inf.u-szeged.hu
2018-02-28 05:47:56 +01:00
László Langó e10f6d6adf Modified ecma string to utf8 string conversion to reduce binary size. (#2214)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-02-27 14:52:30 +01:00
László Langó 72b51accc8 Reduce the memory footprint of 'ecma_instantiate_builtin' (#2218)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-02-27 10:16:23 +01:00
László Langó fbc53f78b7 Eliminate the pylint warnings and update the pylint configuration (#2210)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-02-27 10:14:48 +01:00
László Langó 88f7baa192 Fix build failure of NuttX tools (#2225)
The CI is broken after 'https://bitbucket.org/nuttx/tools/commits/164450f982b404fdc2b3233db51dc3eaa1f08b7f',
because it cannot find 'aclocal-1.15'.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-02-27 10:12:05 +01:00
Geoff Gustafson d990832569 fix typos in debugger code (#2219)
JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson geoff@linux.intel.com
2018-02-23 08:22:16 +09:00
Zoltan Herczeg 51e3c4455a Implement direct strings. (#2196)
Direct strings are a new type of direct ecma-values (no memory allocation
is needed for encoding them) in JerryScript. Currently magic strings,
external magic strings and uint values are encoded as direct strings.

The constant pool of JerryScript byte-code is changed to hold ecma-values
rather than cpointers to support direct strings.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-02-23 08:21:46 +09:00
László Langó fbf5c32747 Removed 'is_static' parameter from 'BUILTIN' macro, because was never used. (#2216)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-02-22 09:14:56 +09:00
Zoltan Herczeg d841270747 Exclude hashmaps from GC marks. (#2212)
Fixes #2146.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-02-22 09:13:49 +09:00
Martijn Thé b8656877e2 Fix misc. compiler warnings (#2202)
JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2018-02-20 16:13:04 +01:00
László Langó 6fce323fa5 Fix assertion in 're_insert_simple_iterator' (#2209)
It is a followup fix after #2169. It also fixes a memory leak.
This fixes #2198 and fixes #2204

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-02-19 16:57:45 +09:00
László Langó c4b61db57a Fix '--cmake-param' option of the build script. (#2208)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2018-02-19 11:29:58 +09:00
Martijn Thé 3c57698ed8 Fix buffer overrun while parsing malformed JSON hex escape sequence (#2201)
Fixes https://github.com/jerryscript-project/jerryscript/issues/2200

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2018-02-16 09:02:03 +01:00
Péter Gál d7991ae54c Add C API to query the type of a JS value (#2195)
New API function:
 * jerry_value_get_type

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-02-13 13:48:07 +01:00
Péter Gál 4652c3caaf Add OpenWrt build guide (#2199)
There was an OpenWrt toolchain file however it's a bit outdated and
we did not have any guide on how to build for this target at all.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-02-12 17:21:57 +09:00
Daniel Balla e8608707b6 Make source scrolling command in python debugger (#2187)
Source is now scrollable after writing `scroll`.
Keys are `q` to quit, `w` to scroll up `s` to scroll down.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-02-07 09:38:54 +01:00
Zoltan Herczeg 67cee1f478 Remove arguments of ecma_new_values_collection. (#2197)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-02-07 13:05:04 +09:00
Péter Gál 6f339eb05c Introduce C API to query the type of an Error object (#2177)
New api function:
* jerry_get_error_type

Additionally update a few places where this new function
can be used.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-02-06 09:41:54 +01:00
Péter Gál 8041953a7a Add TypedArray C API (#2165)
New API functions added:
 - jerry_value_is_typedarray
 - jerry_create_typedarray
 - jerry_create_typedarray_for_arraybuffer_sz
 - jerry_create_typedarray_for_arraybuffer
 - jerry_get_typedarray_type
 - jerry_get_typedarray_length
 - jerry_get_typedarray_buffer

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-02-06 08:01:32 +01:00
mofosyne 0cc98340c3 Update documentation for jerry string to buffer function with suggestions to use substring. (#2174) (#2174)
In some use cases, you want to reliably copy jerry strings to buffer, even if it doesn't fit target buffer, but is acceptable to lose some bytes. In those cases, the documentation will now suggest using the substring function as an alternative instead.

JerryScript-DCO-1.0-Signed-off-by: Brian Khuu mofosyne@gmail.com
2018-02-02 12:09:57 +09:00
Daniel Balla c429530d02 Fix multiple JSON.parse issues (#2191)
Fixes #2180, #2192

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2018-02-01 22:34:21 +01:00
Zoltan Herczeg 36051ec92b Limit maximum number of arguments for apply(). (#2183)
The length*sizeof(ecma_value_t) may overflow on 32 bit systems which
cause a memory corruption when the values are filled.

Fixes #2182.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-02-01 15:09:53 +01:00
Zoltan Herczeg 06ebfc52ed Simplify ECMA_OP_TO_NUMBER_TRY_CATCH macro. (#2185)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-02-01 19:31:17 +09:00
Zoltan Herczeg c935e4b7e2 Return early if number conversion is failed in arraybuffer slice. (#2184)
Fixes #2181.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-02-01 19:30:03 +09:00
Szilard Ledan 607e605844 Fix regex brackets matching bug (#2179)
Fixes #2178.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan@inf.u-szeged.hu
2018-01-31 09:27:32 +01:00
Zoltan Herczeg 918eb22a01 Add support for aborts. (#2176)
Aborts are similar to exceptions except they are not caught by catch
and finally blocks. Callbacks should honor aborts as well and return
them without processing them. Aborts are never thrown by JavaScript
code.

In the future certain events such as out-of-memory condition may
also throw aborts.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-01-30 09:13:44 +09:00
Zoltan Herczeg b548eae4ad Improve get characters of a string function.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-01-29 10:35:56 +09:00
Martijn Thé 0d04c805ac Zero out unused bytes in snapshots (#1980)
Compiled code blocks are sized in multiples of JMEM_ALIGNMENT,
but it's possible that some bytes at the end remain unused and get filled
with junk. This causes snapshot output to become nondeterministic.
To fix this, zero out the compiled code buffer before using it.

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2018-01-26 08:26:09 +01:00
Peter Gal 4b699e997a Add ArrayBuffer with user specified buffer
New API functions:
 - jerry_create_arraybuffer_external
 - jerry_get_arraybuffer_pointer

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-01-25 10:14:53 +09:00
Roland Takacs 7acd688513 Print the return value of the engine in case of TizenRT.
Since TizenRT doesn't have any commands to get the return value of a process,
added a debug print line that shows the return value.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-01-25 09:28:18 +09:00
Szilard Ledan a4afde2663 Change '{' regex parsing to work similarly to other engines (#2134) (#2169)
Changed regex parsing to be able to handle opening braces
as other engines do, and also added a compile flag which
can disable this behaviour.

JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan@inf.u-szeged.hu
2018-01-24 12:18:44 +01:00
Zoltan Herczeg 1c64c1aeb7 Fix inserting pending breakpoints. (#2163)
Before this patch the JS execution is started right after the parsing
is completed. The problem is that some parts of the JS code is executed
before the debugger had any chance to insert pending breakpoints due
to network latency. This patch adds a delay after parsing when at least
one pendding breakpoint is available.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-01-23 10:47:47 +01:00
Peter Gal 40d05cdca2 Add version fields for debugger configuration
By adding version information to the debugger protocol
it is possible to report if the debugger client and server
have different expectations on debugger workings (opcodes, types, etc.).

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-01-23 10:17:33 +09:00
Robert Fancsik 52a14fa08f Fix the endianness of EPS8266 system
Also fix the order of js sources by evaluate the main.js for the last time.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-01-22 18:13:07 +09:00
Roland Takacs 680bafdc8c Modify the build method of TizenRT target
Introduced a cmake/toolchain_mcu_artik053.cmake file that defines
all the target specific compiler options.

Modified the Makefile.tizenrt to do not copy the created static
libraries to the TizenRT folder. Instead, the application builder
Makefile (tizenrt-artik053/apps/jerryscript/Makefile) copies the
required static libraries to TizenRT.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-01-16 10:57:37 +09:00
Péter Gál ded0d5a846 Introduce the Array Buffer C API (#2161)
Add C API to work with Array Buffers.
The following methods are added:
- jerry_value_is_arraybuffer
- jerry_create_arraybuffer
- jerry_arraybuffer_write
- jerry_arraybuffer_read
- jerry_get_arraybuffer_byte_length

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2018-01-11 20:36:08 +01:00
Zoltan Herczeg b9560b7c70 Rework ecma collection. (#2153)
Greatly simplify the iterator part and make it compatible with 32 bit cpointers.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2018-01-10 15:55:56 +01:00
Roland Takacs f833da2c13 Modify the build method of NuttX target. (#2154)
Modified the Makefile of the NuttX target to build only the application
file (targets/nuttx-stm32f4/jerry-main.c) and not the whole project.
It helps to build JerryScript separately and use the static libs when
building NuttX.
Also modified the README.md to describe the new build process.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
2018-01-09 09:34:01 +01:00
Zidong Jiang 4e7a9d2d53 [jerryx/arg]add jerryx_arg_utf8_string (#2133)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2018-01-08 10:17:40 +01:00
Paul Sokolovsky 290bc22f0c targets: zephyr: Update for Zephyr 1.10 which uses CMake-based build. (#2155)
In 1.10, Zephyr RTOS switched to CMake as means to generate application
makefiles. Consequently, drop Makefile, and introduce CMakeLists.txt,
and update master Makefile.zephyr accordingly.

With these changes, take a chance to make following "cosmetic" changes:

1. Make "qemu_x86" board target the default instead of "arduino_101".
Arduino 101 is just one of the boards of many supported by Zephyr
(and thus JerryScript port), while qemu_x86 is something everyone has.

2. Zephyr make target to run QEMU switched from "qemu" to "run".

3. Don't rely that there's zephyr.strip, it's presence is now
board-dependent. The most we can rely on is zephyr.elf.

targets: zephyr: Remove deprecated prj.mdef file.

MDEF files have been deprecated and ignored for few Zephyr releases.

targets: zephyr: Increase main (i.e. interpreter) thread stack size.

qemu_x86 target now has stack guard enabled by default and it trips with
the default stack size. Set it to 2K for now.

targets: zephyr: Makefile.travis: Update for Zephyr 1.10.

Zephyr 1.10 requires SDK 0.9.2 and CMake 3.8.2.

Also, don't hardcode CC path, it depends on a board and choosed
automatically by Zephyr build system.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2018-01-08 09:49:07 +01:00
tkeri e0e6aa0319 Add new snapshot execution test cases (#2160)
Add new function to avoid code duplication.

Add two new test cases to jerry_exec_snapshot function:
* test enable copy byte-code with global mode
* test enable copy byte-code with eval mode

JerryScript-DCO-1.0-Signed-off-by: Tamas Keri tkeri@inf.u-szeged.hu
2018-01-08 09:44:50 +01:00
Robert Sipka d6df000fe5 Update tests results badge links in the README
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2018-01-06 12:33:06 +09:00
Robert Fancsik 543f75a6c3 Fix random number generation on ESP8266
This patch uses the onboard RTC for generating random seed. It also improves the print handler to support float values.
The rom segment is slightly increased to fit to the latest master.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2018-01-04 19:22:08 +09:00
Zidong Jiang c3c0bb8ddc [Bugfix]free error in typearray set value routine (#2147)
Issue: #2143

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-12-20 12:52:29 +01:00
tkeri be9e88784a Fix unit-test inconsistency for promises (#2152)
Use a helper function to check the availability of promise.

JerryScript-DCO-1.0-Signed-off-by: Tamas Keri tkeri@inf.u-szeged.hu
2017-12-20 12:50:12 +01:00
Zoltan Herczeg a2d3ea61eb Optimize string concatenation. (#2141)
This patch adds two new string concatenation functions:
ecma_append_chars_to_string and ecma_append_magic_string_to_string

The former appends a cesu8 byte array and the latter appends a magic string
to the end of an ecma-string. These two free (dereference) their ecma-string
argument, and this change is also applied to the original ecma_concat_ecma_strings
function which simplifies string handling in most cases.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-12-19 13:45:48 +01:00
Robert Sipka bd574956e3 Fix conversion warnings (#2126)
NuttX and artik053 build - compiling with strict Werror=conversion - fail when jerry-debugger option is enabled.
This patch based on #2007, because most of them are fixed earlier within that PR, but it was closed before the land.

Credit: Piotr Marcinkiewicz p.marcinkiew@samsung.com

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-12-19 10:37:24 +01:00
Greg Miell 10f777689f Add extern "C" to module.h (#2150)
JerryScript-DCO-1.0-Signed-off-by: Greg Miell greg@gothack.ninja
2017-12-18 21:08:45 +01:00
László Langó 623fabd6e6 Put 'Mbed/K64F Build Test' to allowed failures temporarily. (#2151)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-12-18 12:14:02 +01:00
Daniel Balla 96df210cc5 Add object type checking to instantiation
It wasn't properly checked if the given object was an arrow function, therefore it always got wrongly casted into `ecma_arrow_function_t`.
Fixes issue #2110
*plus fixing a typo in the comments

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-12-13 18:14:34 +09:00
Zidong Jiang 11e0c13094 Add api: jerry_get_value_without_error_flag (#2096)
It is used to get the reference value from a error value

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-12-13 12:46:20 +08:00
Robert Fancsik 458dc58b59 Improve multiplication in vm
This patch improves the ecma_integers_values multiplication by checking if the multiplier or multiplicand is power of 2.
If it is it uses right shift instead of multiplication.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-12-11 17:47:39 +09:00
Robert Fancsik 90f2473f08 Remove trivial ecma_number arithmetic functions (#2123)
The affected function calls have been replaced with the appropriate arithmetic operands.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-12-07 13:41:02 +01:00
Péter Gál 8b109510fd Move _XOPEN_SOURCE macro to a more generic place (#2136)
Building with all-in-one and enabled debugger caused
errors as the sleep functions were not defined.

By moving the _XOPEN_SOURCE macro to a generic place
we make sure that the required sleep functions are
present in every case.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-12-07 11:54:37 +01:00
Akos Kiss 75ac090dd9 Refactor CLI argument handling and test runner logic of run-tests.py (#2091)
On argument handling:
- Merged all signoff check options into one, option value chooses
  between strict/tolerant check variants.
- Added sensible metavars to options with arguments (consistent
  with metavars of build.py).
- Reordered options to match the order the checks are executed in.
- Added `--all` alias to `--precommit` check option.
- Beautified code (always placed `help` on separate line, removed
  unnecessary arguments of `add_argument` that just repeated their
  defaults).

On test runner logic:
There was too many code duplication on how checks were executed, it
got refactored. No change in semantics.

The only change was in Travis CI-related invocations,
`--check-signed-off-travis` had to be rewritten to
`--check-signed-off=travis`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-12-07 11:54:14 +01:00
Robert Fancsik e83de3accd Remove ecma_simple_value_t and refactor ecma_make_simple_value (#2135)
This patch removes all ecma_make_simple_value calls to make the code more easy to understand.
Also removes the type ecma_simple_value_t which improves the performance in related code paths by calculating the value of new ecma_value_t is no longer needed.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-12-06 18:06:07 +01:00
László Langó 1007b63024 Fix clearing of error reference (#2131)
'ecma_clear_error_reference' must increase the reference of the returned
ecma value referenced by the error if there are more than one reference.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-12-06 14:47:40 +01:00
Peter Gal a8a6122a93 Force python2 when running test262
The test262 python script is not python 3 compatible
so we force it to be executed with python2.

Additionally print out the reason if the execution
failed.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-12-06 13:16:25 +09:00
Zoltan Herczeg e964393abe Add fast path to ecma_op_object_get with magic string. (#2078)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-12-05 17:17:56 +01:00
Peter Gal a8dffe023e Fix the mbed Travis build
On Travis the Python (by default) is a bit old
and causes problems when the yotta is being used.

Switching to Python 2.7.13 solves half of the problem.

The other problem is the pyOpenSSL 17.5 and Linux
library incompatibilities. Thus we force the pyOpenSSL
to a pre-17.5 version.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-12-05 20:16:25 +09:00
Marko Fabo 0fe8f6abac Improve bitwise operations in VM. (#2117)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-11-30 10:13:04 +01:00
Sanggyu Lee bf78065bc6 Update build guide for TizenRT 1.1
Previous guide is out of date.
Updated guide works with TizenRT 1.1.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-11-30 09:04:47 +09:00
Daniel Balla a1df9c1420 Fix undefined behaviour of global object freezing
Freezing the global object and later trying to add properties to it caused an assertion error (issue #2105).
This patch fixes the issue.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-11-28 11:30:10 +09:00
Imre Kiss 1ed886b872 Fix function parsing for debugger. (#2119)
Since the JerryScript can able to parse functions directly the
PARSER_LEXICAL_ENV_NEEDED and the PARSER_NO_REG_STORE flags
should be in the context's status flags for executing eval operations
by the debugger.

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2017-11-22 15:29:07 +01:00
Zidong Jiang 29056f9ab9 Fix error-free issue in promise
Fix issue: #2107

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-11-21 19:49:44 +09:00
Zidong Jiang 9a9dcf3332 Fix bug in promise resolve handler
Should get the error_value if `then` prop is an error.

Fix issue: #2111

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-11-21 14:25:51 +09:00
tkeri e15020be96 Fix api inconsistency for promises (#2113)
The change makes the jerry_value_is_promise api method
available in all cases, just like other promise api methods

JerryScript-DCO-1.0-Signed-off-by: Tamas Keri tkeri@inf.u-szeged.hu
2017-11-20 15:41:11 +01:00
Robert Fancsik fe6c7b9b61 Fixed TypedArray error handling
This patch fixes #2106. The problem was that the function always tried to transform the array-like object to TypedArray object even if there was an error during TypedArray creation.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-11-20 16:55:22 +09:00
rerobika 1dedc1b630 Fixed toFixed method string conversion (#2112)
This patch fixes #2108. The problem was if the convertible number had less significant fractions digits than the requested, the result was filled with memory junk instead of zeros.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-11-17 20:00:45 +01:00
rerobika 6c06a309c1 Fixed dynamic-stack-buffer-overflow in jerry_value_is_syntax_error (#2095)
Fixes issue #2094, which introduced an error caused by jerry_value_is_syntax_error.
The problem was that the function used strcmp instead of strncmp while checking if err_str_buf contains syntax error and it caused buffer overflow.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-11-17 11:39:11 +01:00
Marko Fabo b4a1825a83 Avoid code duplication in vm.
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-11-17 18:25:00 +09:00
Akos Kiss b43057c90b Add grouping macro guards for disabling engine features (#2084)
Until now, the engine's feature set was configurable either via
`CONFIG_*` macro guards defined individually on compiler command
line or via profiles (which are text files listing macro guards,
picked up by the cmake build system and turning them into compiler
command line options). And the features under profile control are
all enabled by default (i.e., all macros are `CONFIG_DISABLE_*`).

This causes a maintenance issue when new features are added to the
engine, because the disabling macros have to be added to all
profiles that don't include the new features. This can even cause
"compatibility break" for applications that embed JerryScript but
don't use the cmake or the python build system, because then
profiles are unavailable and all feature disabling guards have to
be explicitly passed to the compiler. (I.e., if such an application
wants to use the ES5.1 feature set, it must define all the ES2015
disable macros; if the engine is developed further and a new ES2015
feature gets implemented, then the new feature will sneak into the
application's binary unless its own build system is changed to add
the new feature guard.) Even the in-repo example Curie BSP target
seems to have suffered from this maintenance problem.

This patch introduces two new grouping macro guards that enable the
disabling of all ES5.1 builtins and all ES2015 features. As the
grouping logic is in config.h, the maintenance of non-cmake-based
build systems becomes easier (and there is no change for the python
and cmake-based build systems).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-11-16 16:31:30 +01:00
Akos Kiss 36479ddc1a Remove the 'external' toolchain file (#2089)
The 'external' toolchain file does nothing but transitively sets
some cmake system variables from values received on the command
line, and forcibly sets the C compiler. However, the same cmake
system variables can be directly set via the command line, together
with the C compiler, and specifying a toolchain is not a must.
Thus, this patch drops the superfluous 'external' toolchain file
and updates cmake-based targets to invoke cmake in a simpler form.

Related changes in this commit:
- While updating the cmake invocations, all the command line
  arguments have been reviewed and simplified (removed those, which
  did not change the defaults).
- Removed unnecessary forced C compiler settings from some
  toolchain files (and/or changed them to setting the "compiler
  works" flag to true, thus keeping cmake's compiler identification
  logic but disabling some of its overzealous compiler sanity
  checks).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-11-16 16:19:00 +01:00
Akos Kiss da24727824 Add Travis CI jobs for build testing several targets (#2102)
Hitherto, code under the `targets` directory was not tested and so
its maintenance was sometimes speculative. This commit adds build
testing for several targets to prevent them from bit rotting.
Targets covered by this commit are: ESP8266, Mbed, Mbed OS 5,
NuttX, RIOT, Tizen RT, and Zephyr.

Some issues were revealed and fixed:
- ESP8266: added missing include for `uint32_t` typedef.
- Tizen RT: replaced missing `str_to_uint` with `strtol`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-11-16 13:29:23 +01:00
Akos Kiss a0db3ee5b3 Ensure that the test version of the command line tool is stable for benchmarking (#2076)
Some benchmark suites contain test cases that have nonreproducible
behaviour. This is mostly caused by relying on "now" when dealing
with dates or timestamps, instead of using a fixed moment. (A
notorious example is the crypto-aes.js test case of the sunspider
bechmark suite, where the heap memory consumption can vary between
34K-41K heap because of using `(new Date()).getTime()`.)

This commit renames the jerry-minimal command line tool to
jerry-test (to better reflect its purpose) and adds extra code,
which intercepts some calls to libc (`gettimeofday`, `rand`) and
pins their results to some fixed values. This makes the tool
useless in a general case but ensures stable results when
benchmarking -- for which it is mostly used.

As a side effect, the commit also changes jerry-libc by making all
libc functions weak symbols to allow their override from
application code.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-11-16 12:36:58 +01:00
Péter Gál 7692aa9d66 Improve the heap limit measure tool (#2092)
Changes:
 * Added support for Python3
 * Suppressed the build output text
 * Code cleanup
 * Fixed pylint warnings

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-11-15 17:02:32 +01:00
Gabor Loki 1059fb1b30 Fix a small typo in the port API documentation (#2099)
JerryScript-DCO-1.0-Signed-off-by: Gabor Loki loki@inf.u-szeged.hu
2017-11-15 17:01:32 +01:00
Daniel Balla 7ad3edde08 Fix typo in byte-code.h (#2100)
Fixing a typo in byte-code.h, plus removing unnecessary guarding around it.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-11-15 17:01:01 +01:00
Akos Kiss 6b1ed6e021 Refactor/simplify .travis.yml (#2090)
Over time, `.travis.yml` grew somewhat organically and became quite
complex. With some rewrites, it can set up the Travis CI stages
better, and become simpler, more logical, and more maintainable.

The refactoring keeps all existing functionality.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-11-13 15:36:40 +01:00
Akos Kiss 52ecafc888 run-tests.py test options maintenance (#2087)
Pythonification of the `Options` class and unification of the
instance names.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-11-13 13:52:56 +01:00
rerobika 5d2000c954 Fix for issue #1993 (#1994)
This patch fixes this bug which caused corrupted stack by preventing unnecessary double to ascii conversion even if
the convertible number of digits is higher than allowed.
In addition, improved ecma_double_to_binary_floating_point function by removing a needless buffer.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-11-10 15:13:08 +01:00
Akos Kiss 1d2a686532 Whitespace gardening in jerry-libc (#2082)
Also includes the addition and styling of some doc comments (but
those are whitespace too).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-11-10 13:12:44 +01:00
Zidong Jiang 2865826fc4 [jerryx-module]Fix a bug in module name comparison (#2079)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-11-10 13:11:26 +01:00
Marko Fabo 9c013310ab Include missing header file in mbed/mbedos5. (#2083)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-11-10 12:58:53 +01:00
Daniel Balla 7e51423ca7 Fix Date.parse() in ecma-builtin-date.c (#2081)
Fixes issue #2073, which introduced an error caused by Date.parse()
The problem was that the function didn't properly check if there was a ':' after the hours.
If any UTF8 character was inserted there which got decoded into multiple characters, it caused the pointer to point at a wrong character.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-11-09 21:12:29 +01:00
Robert Fancsik 519ba8eb6c Fixed template literal parsing
Fixed an unhandled corner case while parsing slashes and template literals.
This patch fixes #2039 and adds a test case for it.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-11-09 14:12:34 +09:00
Robert Fancsik c3a9821171 Revive target: ESP8266
This patch updates ESP8266 build system and code base as well.
 - Removed unnecessary files.
 - Decreased code size.
 - Refactored jerry_{port, extapi, run}.c to make it more easy to handle.
 - Readme.md is updated as well which contains detailed step by step description about how to set up environment and use JerryScript.

Finally, it solves the related issue #1375.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-11-08 19:13:34 +09:00
Marko Fabo bdcd2d8179 Free JERRY_CONTEXT (error_value) (#2071)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-11-06 15:48:05 +01:00
Daniel Balla 3de6c7ec7a Fix jerry-libc's srand function (#2068)
The previous implementation of srand was wrong in jerry-libc.
It set all 4 values to the seed, not modifying anything in them, causing random values to be repeated pretty often.
This approach fixes the mentioned issue.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-11-06 11:31:22 +01:00
Péter Gál 8ae659227e Move snapshot generation function to the snapshot tool (#2057)
Now there is a snapshot tool which can merge snapshots
but was unable to generate snapshots by itself.

This change moves the snapshot generation utilities
to the snapshot tool.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-11-05 18:37:27 +01:00
Zsolt Borbély ee24965bcf Add missing headers for srand() to jerry-minimal and riot-stm32f4
A buildoption test is also added to test jerry-cmdline-minimal.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-11-04 12:17:59 +09:00
Daniel Balla 4690d128b3 Add info to documentation about random numbers, initialize srand (#2056)
Issue #2053 has highlighted the fact that random numbers are always generated with the same seed.
An example of generating different random numbers, other than the original seed, has been added to the documentation.
Furthermore srand initialization has been added to jerry-main, and targets.
Update test-common.h with srand call.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-11-03 15:31:57 +01:00
Marko Fabo 678fcb20ed Free the error_value of the global context before raise an error. (#2067)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-10-31 15:47:20 +01:00
Zidong Jiang 5bd72047cc jerryx: add jerryx_arg_array (#2052)
Related issue: #2046

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-10-30 20:39:14 +01:00
Akos Kiss 60bf613c07 Add regression test from issue #2008 (#2066)
The issue was reported against v1.0 and isn't reproducible anymore.
Still, adding the then-faulty input to the regression test suite to
prevent it occuring again.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-10-30 14:53:22 +01:00
Péter Gál 0ee7509030 Install pylint for user on Travis (#2064)
On Travis the pylint package can't be installed
due to insufficient permissions.

To fix this we'll try to install the package for the user
and not for the system.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-10-30 14:46:29 +01:00
Marko Fabo d9cc3fd4b7 Improve runtime by concatenation of opcodes. (#2059)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-10-29 08:19:18 +01:00
rerobika 6dae81565c Improve ecma_utf8_string_to_number function (#2006)
This patch extends the infinity and zero parsing of the convertible number by checking the normalized number exponent part.
This improvement prevents the engine's hanging while converting extreme big numbers.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-10-27 12:32:29 +02:00
Zidong Jiang 0bc4bb056d Fix promise thenable bug
Related Issue: #2060

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-10-27 18:37:58 +09:00
Marko Fabo d7c710d3d4 Delete unnecessary ?: statement.
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-10-25 09:45:49 +09:00
Zoltan Herczeg 53cd324179 Rework error to use a global slot to store the error value.
This change frees up the error bit in ecma_value_t, which allows
to define 4 more value types (e.g. symbols). To keep API
compatibility we introduce a box for values with error flag.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-10-24 17:33:04 +09:00
Akos Kiss 742654a3f1 Fix #endif comment at end of header files (#2049)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-10-21 14:47:37 +02:00
Daniel Balla 2f6c105522 Fix pending breakpoints in python debugger client (#2028)
There was an issue where pending breakpoints were incorrectly tried to be assigned to files, since they missed the sourcename check. It's also worth mentioning that pending breakpoints were not "moved" correctly to active status, just copied there instead, making them appear in the pending list still.
This patch fixes both of these issues.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-10-19 11:49:33 +02:00
Peter Gal 4913a42086 Fix API docs
The #2043 introduced a bit of error in the API
docs as there was missing backticks.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-10-19 16:26:59 +09:00
Péter Gál 6d988afbf4 Introduce a way to directly save snapshot functions and load them back (#2043)
Added two new api functions:
* jerry_parse_and_save_function_snapshot
* jerry_load_function_snapshot_at

The jerry_parse_and_save_function_snapshot function allows
creating snapshots from snapshot arguments and body source.

The jerry_load_function_snapshot_at function enables loading
back functions from a given snapshot as a JS function object.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-10-18 15:03:54 +02:00
Akos Kiss d0143adc82 Replace JERRY_JS_PARSER feature guard with JERRY_DISABLE_JS_PARSER (#2036)
* Replace JERRY_JS_PARSER feature guard with JERRY_DISABLE_JS_PARSER

All feature guards of jerry-core are deciding about the inclusion
or exclusion of a feature based on the state (defined or undefined)
of a macro -- except for the JS parser guard, which requires
`JERRY_JS_PARSER` to be defined with a value of either 0 or 1. This
has some issues:
- The engine cannot be built with a "clean" compiler invocation,
  i.e., without any `-D` command line macro definitions. This is
  painful for targets that must use a different build system from
  the project's own python/cmake-based one.
- Some build systems in targets and even some code in jerry-code
  are already confused about the different semantics of
  `JERRY_JS_PARSER`, and simply define it without a value and make
  decisions based on the macro being simply defined or not.

This patch renames the guard to `JERRY_DISABLE_JS_PARSER` and makes
use of it in jerry-core based on its state, not based on its value.
As obvious from the guard name, the default for the JS parser is
that it is included in the build.

The patch also touches those targets in the repository that
explicitly defined the original macro (correctly or incorrectly).

* Make cppcheck verbose

Cppcheck can be quite slow sometimes, especially on Travis CI,
which has a "10 mins without output means failure" rule. As the
code base of the project grows, we start to undeterministically
fall over that limit. Thus, this PR makes cppcheck verbose to
ensure that it keeps Travis CI continuously fed with output.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-10-17 17:11:54 +02:00
Zoltan Herczeg fe26674752 Support multiple primary functions in a single snapshot. (#1797)
This patch adds an extension to snapshots which allows storing
multiple position independent primary functions in a single
snapshot data. A new application called jerry-snapshot is
added to the project to manage snapshots. Currently the only
option is merging snapshots.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-10-12 14:43:32 +02:00
Zoltan Herczeg 9f0cf9ef1c Implement this binding for arrow functions.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-10-06 09:07:13 +09:00
Zsolt Borbély 1cc7cb58ce Enable promise builtin for nuttx-stm32f4 target (#2033)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-10-04 15:46:18 +02:00
Gabriel "_|Nix|_" Schulhof eb92b22b19 Fix possible uninitialized value (#2035)
JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-10-03 10:24:39 +02:00
László Langó 1027eb0c32 Updated the Doxyfile input directories. (#2024)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-10-02 11:57:28 +02:00
Zoltan Herczeg 29ea702fa4 Free the GC mark bit to increase the number of object types. (#2032)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-09-29 16:15:13 +02:00
Gabriel "_|Nix|_" Schulhof 6d53931055 module extension: add support for canonical name resolution (#2013)
Before attempting to load a module, each provided resolver must be given an
opportunity to examine the name of the requested module without actually
loading it so as to canonicalize it, in case a module can be referred to by
multiple names.

Then, modules are loaded and cached by their canonical name.

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-09-29 12:02:34 +02:00
Daniel Balla e527e41bac Fix typo in the debugger documentation (#2027)
The old function name was used in one occurrence.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-09-28 06:20:18 +02:00
Zoltan Herczeg 8a5bfd2279 Implement template literals. (#2025)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-09-27 11:24:51 +02:00
Gabriel "_|Nix|_" Schulhof fe864bcf53 Add job that tests with FEATURE_INIT_FINI turned ON (#2026)
Since modules behave differently depending on whether this feature is on or off
we should have a job that runs with the feature turned on.

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-09-27 10:51:42 +02:00
Zoltan Herczeg c6a33dd407 Implement arrow function parsing. (#2022)
Note: the special this behaviour of arrow functions is not implemented.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-09-26 10:40:45 +02:00
Gabriel "_|Nix|_" Schulhof 81952f3cd0 module: Re-implement using library constructors/destructors (#2018)
By using constructors/destructors we unify the case of static linking with
that of dynamic linking, and we reuse the build flag FEATURE_INIT_FINI. Using
constructors/destructors also allows us to cover the case where library
constructor/destructor functionality is unavailable, because we can expose the
module registration/unregistration functions as global symbols, to be called
explicitly from within the application.

Fixes https://github.com/jerryscript-project/jerryscript/issues/1952

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-09-22 12:35:38 +02:00
Zoltan Herczeg 8d916a44f1 Parse functions directly (#2015)
This patch adds direct function source code parsing, which
is useful to avoid source code duplications. The patch
also improves the Function constructor.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-09-21 11:03:23 +02:00
Zoltan Herczeg 7713d30702 Rework jerry_debugger_wait_for_client_source to use a callback.
The jerry_debugger_wait_and_run_client_source function is renamed to
jerry_debugger_wait_for_client_source and a callback is added which
is called when the source is received. Inside the callback the
application is free to do anything with the received source code.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-09-21 17:49:49 +09:00
Marko Fabo 9c3f814357 Fix #1931
The mentioned patch uses `this_obj` argument to get `setInterval` and
`setTimeout` properties from the global object, but `this_obj` is
undefined
in these scopes.

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-09-21 17:44:57 +09:00
Zsolt Borbély 9900fd930f Allow mem-stats when system allocator is enabled
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-09-21 09:58:43 +09:00
Robert Fancsik 15ee7bc036 Fixes pattern parsing in ecma_builtin_global_object_unescape ()
Issue #1990 revealed an unhandled corner case while parsing pattern. This patch fixes it and also adds a test case.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-09-21 09:58:15 +09:00
Robert Fancsik 30867e27e0 Fixes uint16_t overflow in ecma_new_ecma_string_from_utf8_converted_to_cesu8 ()
This unreported test issue revealed an assertion in jmem_heap_finalize ().
During the conversion the lot of additional information what a cesu8 represented string needs caused overflow while setting the new ecma_string_t variable's length. This patch fixes this issue and the mentioned test case is available here:
https://gist.github.com/rerobika/3bd590fdcf664a3fcfcc98f11b14c74e

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-09-20 15:09:15 +09:00
Imre Kiss 77ccdcc585 Add context reset to the debugger.
- The context reset request message can be sent anytime from a client.
- After the message received the engine will call the cleanup and init
  when in the source waiting mode (which means the currently processed file will be executed).
- After the reinitialization is done, the engine will wait
  for a new client connection(rest of the work is the client's responsibility).

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2017-09-13 18:12:44 +09:00
Zoltan Herczeg 04bccea6a6 Last line of the source code should be printed by the python debugger client.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-09-13 09:38:35 +09:00
Daniel Balla c8b99d05e1 Send every kind of output to the debugger client
Now correctly sending jerry_port_log output to the debugger client as well.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-09-07 19:02:24 +09:00
Zidong Jiang c21c21f9f9 [ecma-collection] Check whether the header's first chunk is NULL
Fix Issue: #1997

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-09-07 17:42:51 +09:00
László Langó a54427e255 Followup changes in JerryScript debugger after #1910.
* Remove 'jerry_debugger_cleaup'. Do it automatically in 'jerry_cleanup'.
* Updated the documentations.
* Updated the NuttX and Artik053 targets.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-09-07 17:26:03 +09:00
Daniel Balla a51def40e7 Fix #1947
If a literal was assigned the unused flag it wasn't freed, however it could have been not empty, therefore should've been freed.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-09-07 09:42:08 +09:00
Daniel Balla 7ccbe97b79 Move jerry_debugger_send_output to public API
The function jerry_debugger_send_output wasn't placed correctly in the public API.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-09-07 09:36:02 +09:00
Dániel Bátyai 01dd2f0b2a Clean up radix conversion in Number toString method (#2002)
The radix conversion code path was very messy which made it hard to understand
what was happening inside of it. The code got cleaned up, and a lot of comments
were added that explain what is happening and why.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2017-09-06 10:56:29 +02:00
Zidong Jiang 74045f2964 [Promise] check the argc of builtin resolve/reject handler
Fix issue: #1996

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-09-05 18:42:46 +09:00
Zidong Jiang 78e3d88bd9 [unix-main] call jerry_run_all_enqueued_jobs before cleanup
Related Issue: #1995

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-09-05 17:43:37 +09:00
Tamas Keri 39275c5dd2 Add minimal heapsize finder tool
Added a python tool which finds the smallest possible size of
JerryHeap without failing to run the given js file.

JerryScript-DCO-1.0-Signed-off-by: Tamas Keri tkeri@inf.u-szeged.hu
2017-09-05 17:42:42 +09:00
Yanhui Shen b32e5444d8 Allow "<NUL>" character within string literals in strict mode
JerryScript-DCO-1.0-Signed-off-by: Yanhui Shen shen.elf@gmail.com
2017-09-05 09:13:01 +09:00
Zoltan Herczeg 522c7d3f87 Correctly enumerate function property members.
Functions has several built-in non-enumerable properties, and
they are correctly ignored during enumeration after this patch.

External function prototype is also lazy enumerated.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-09-05 09:11:35 +09:00
Daniel Balla 7905422b19 Merge send_string functions in python debugger client (#1989)
Merging the messages to one check, therefore multiple duplicated lines are removed.
I didn't find a good solution though in the HTML client, since it would be nested switch cases / ifs, which wouldn't look okay IMO, the other solution would only save like 2 lines of code overall.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-09-04 12:33:28 +02:00
Jan Jongboom 5cdb98c75e target: mbedos5: Use math.h from stdlib, not from jerry-libm (#1988)
The math.h header file in JerryScript is lacking a number of functions which are required to build for certain mbed OS 5 targets. NUCLEO_F207ZG target fails to build as sqrtf() is not defined in this header file. Exclude this file from the build process, so the math.h from stdlib is included instead.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2017-09-04 12:11:02 +02:00
rerobika ce187049e9 GC should ignore not fully initialized objects (#1983)
Fixes #1970 which caused segmentation fault.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-09-04 10:25:19 +02:00
Robert Fancsik 0ef2418e5e Fix ecma_op_array_object_set_length method
So far a freed variable was tested during error flag inspection.
This patch fixes it and #1972 as well.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-08-31 08:55:51 +09:00
Daniel Balla 733f0ceea0 Send output to debugger client (#1955)
Sending the output to the debugger client, at the moment only the JS side prints are sent over.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-08-30 16:01:06 +02:00
Zoltan Herczeg e897858c64 Reduce the memory consumption of function objects. (#1954)
Several properties of strict and bound functions are moved to
lazy property instantiation. The memory consumption of bound
functions are also reduced when only a this is present.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-08-30 14:17:35 +02:00
Jan Jongboom 82a94d0f88 target: mbedos5: Update to mbed OS 5.5.5 (#1982)
Switches fatal implementation to JerryScript default, updates to latest stable version of mbed OS. Tested on K64F.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2017-08-30 13:08:01 +02:00
Robert Fancsik e62b5b601b Fix for issue #1974
The buffer size was previously badly computed since scale == 0 case was not checked, therefore the buffer size was smaller than intended.
This patch fixes this issue.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-08-30 09:07:26 +09:00
Tamas Keri 5d18ac8f0c Remove unnecessary if statement
JerryScript-DCO-1.0-Signed-off-by: Tamas Keri tkeri@inf.u-szeged.hu
2017-08-28 18:02:55 +09:00
fbmrk 1a18766488 target: mbedos5: Improve setInterval and setTimeout (#1931)
In setInterval and setTimeout there must be a reference increase to the given function.
If you use `jerry_acquire` and you want to cleanup the engine,
you get an assertion, because this value is released nowhere in the code.
In my opinion it is better to set the function as a property, so it is released automatically.

In launcher.cpp there is bad error handle. If `returned_value` has error flag, `parsed_code` is not released.

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-08-25 15:01:53 +02:00
fbmrk fe32b5c5d1 target: mbedos5: change all get/set_object_native_handle to get/set_object_native_pointer (#1898)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-08-25 11:24:04 +02:00
Hosung Kim 5de69b4ede target: tizenrt-artik053: Update porting
- rename artik05x to artik053
- fix to add library for jerryscript
- add rom patch for artik053
- enable jerry cmd in tizenrt
- change to absolute file path when loading file with jerry cmd
- update README.md and config file

JerryScript-DCO-1.0-Signed-off-by: Hosung Kim hs852.kim@samsung.com
2017-08-22 17:26:54 +09:00
Imre Kiss 3b1d578050 Multiple client source sending feature. (#1957)
Whit this enhancement the debugger can able handle more than one source file across the new source wait mode.
This feature can be used by the python client with the --client-source [paths] switch.
The client will store every source path, when the debugger send a signal about the waiting status, then the client will send one file from the list.

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2017-08-21 09:19:36 +02:00
Zidong Jiang 2888a6f488 [jerryx-arg]Check NaN in jerryx_arg_int
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-08-17 09:15:35 +09:00
Sanggyu Lee c1cff3f961 Fix new ArrayBuffer(length) for variaous input (#1959)
Currently new ArrayBuffer(length) does not conform to ES2017.
Major JS implementations follow ES2017 for ArrayBuffer(length).

For example, new ArrayBuffer(length) should not throw RangeError
for length = NaN, undefined, negative number, floating point, and so on.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-08-16 18:20:41 +08:00
Sanggyu Lee af16a3ae1a Implement typedarary.set(array, offset)
JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-08-11 14:38:37 +09:00
Daniel Balla a48f24f8da Reworking jerry_debugger_send_string method
From now on, jerry_debugger_send_string can send a subtype of the string, making it more simple to send over strings with special parameters, therefore seperating different types of messages are simpler.
Enumerations for various subtypes can be made, while there's only need to have 2 entries for the header type.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-08-10 08:28:58 +09:00
Robert Fancsik ad608e30dc Improve toFixed function
Fixes #1367.
From now numbers are represented as binary floating-point which guarantees the expected operation of toFixed function.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-08-10 08:27:27 +09:00
Imre Kiss 148f91c90d Fix internal jmem_heap_finalize assertion in debugger.
In case of received client source the client_source_data_p was not freed.

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2017-08-08 10:24:19 +09:00
Zidong Jiang c242248b47 Add API for get the memory stats (#1923)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-08-04 09:44:37 +02:00
Daniel Balla 8b5fe254d9 Implement source rework to HTML client (#1866)
Implementing the source command rework - along with display - to the html client too.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-08-04 09:44:05 +02:00
Imre Kiss 3e3d6373b8 Add source sending feature to the debugger. (#1932)
With this feature the debugger webIDE and the python client can able to send a source code to the debugger while that is running in wait mode.
This feature can be activated with the --debugger-wait-source switch and the debugger will wait for the source messages.
If every message part are received the debugger will continue the exectuion with the initalized options.

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2017-08-03 14:29:47 +02:00
rerobika a3885be6ce ecma_delete_property must recreate the hashmap even if one of the properties is still valid. (#1938)
Fixes #1934.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-08-02 08:19:48 +02:00
Martijn Thé 66b072d5ae Fix: make jerryx_module_resolve resolvers argument const (#1942)
The resolvers argument that is passed to jerryx_module_resolve() is
not mutated by the function. Therefore the argument should be const.
In the docs, a static const array is passed, but this currently does not
work w/o a cast. This patch fixes this.

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2017-08-01 15:39:21 +02:00
Zsolt Borbély 2a2a15f364 Make the webpage-generator script able to transform relative links
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-07-30 18:30:06 +09:00
Zidong Jiang 5b22e5e0ff Bugfix: the value in test cases should be invariable (#1939)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-07-27 13:37:20 +02:00
Zidong Jiang a4bc229592 Bugfix: should return error immediately in ecma_op_create_typedarray
Related issue: #1936

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-07-27 17:08:24 +09:00
Marko Fabo af2868ddb7 Add delete_property_by_index to the API
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-07-24 09:13:36 +09:00
fbmrk 1526bcc8c3 target: mbedos5: fix requirements.txt (#1933)
tools/generate_pins.py does not work with 2.18 version of pycparser

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-07-21 11:54:07 +02:00
rerobika d75710cf27 replace_str_curr_p must be inspected before dereferencing (#1926)
Fixes #1917.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-07-20 10:26:51 +02:00
László Langó ce1d555288 Fix regression after #1927
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-07-20 16:58:08 +09:00
fbmrk 44833cf7be Fix code inserting in API-REFERENCE.md (#1928)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-07-19 11:25:33 +02:00
László Langó 0ef9b8e027 Fix RegExp character class compilation on unicode ranges.
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-07-19 10:26:23 +09:00
Sanggyu Lee 5fd98fa2be Change tizenrt-artik05x port reference board to artik053
Artik053 board is publicly announced about one month ago.
So I updated tizenrt-artik05x reference board from sidk_s5jt200 to artik053.
Now, tizenrt-artik05x port works with latest TizenRT repo on artik053 board.

Also, I replaced str_to_uint to strtol since #1891 is landed.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-07-19 10:15:52 +09:00
Marko Fabo 270dbb00b2 error_name must be freed before return
Fixes #1918

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-07-19 07:19:02 +09:00
Gabriel "_|Nix|_" Schulhof 66b2a7670f New extension: module (#1863)
This extension provides the following facilities:
  - registering modules,
  - module resolvers, and
  - an API for retrieving a module instance given its name.

A module is defined as a global static structure containing a pointer
to a string which is the name of the module, and a pointer to a function
which will be called when an instance of the module is needed.

A module resolver is a function that accepts a string holding the name
of the module and returns a `jerry_value_t` in an out-parameter and
`true` if the module was found, or `false` if it was not. If it returns
`true` and the out-parameter has the error flag set then the API will
pass it through without caching.

This extension provides a built-in module resolver which attempts to
load modules that follow the above module definition.

The API provided by this extension invokes all module resolvers it
receives in sequence to attempt to resolve the name of a single module.
After one resolver returns `true` and a `jerry_value_t` that represents
the module the API stops iterating over the remaining resolvers and
caches the value if its error flag is not set. It then returns the
`jerry_value_t`. The API will return a `jerry_value_t` containing an
error indicating that the module was not found if it reaches the end of
the list of resolvers. The error it returns has an extra property
`"moduleName"` the value of which is a string containing the name of the
module that the API was asked to resolve.

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-07-18 15:54:24 +02:00
yichoi 5f2c72c472 Add test result information to the README.md (#1911)
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2017-07-17 13:40:56 +02:00
Osamu-Nakamura bb8ac29cce Revise the mistake in the example function described in "Step 5. Description of JerryScript value descriptors in docs/03.API-EXAMPLE.md (#1919)
JerryScript-DCO-1.0-Signed-off-by: Osamu Nakamura osamu.nakamura.xt@renesas.com
2017-07-16 10:32:01 +02:00
Akos Kiss 1f7606fc05 Improve pylint runner script (#1915)
- On OSX, `find` is more picky about its arguments than on Linux
  and requires the start directory(-ies) to be explicitly mentioned
  before the expressions (a.k.a. "primaries"). However, until now,
  the `pylint` runner script called `find` without a start dir,
  which caused an error on OSX.

- Until now, `find` looked for python scripts in all subdirectories
  of the project, causing `pylint` to check scripts under `targets/`
  and `tests/test262` (if `test262` was checked out). However, the
  files under `targets/` are less strictly controlled while
  `test262` is completely beyond the control of the project. This
  caused a lot of superfluous lint warnings.

This patch makes the `pylint` runner script call `find` in the
cross-platform way, and also limits the scope of the lint checks to
the `tools/` and `jerry-debugger/` directories.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-07-14 19:53:59 +02:00
yichoi 0844499cec Add IRC badge for convenience (#1920)
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2017-07-14 17:52:36 +02:00
Zidong Jiang 8c9b0d4086 Fix empty string issue in ext/args (#1921)
Now the js string "" can be converted to C array by jerryx_arg_string

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-07-14 17:41:02 +02:00
Akos Kiss 00f93bc287 Add support for doctests (#1909)
Markdown files in the docs/ directory can now be annotated to turn
fenced C code blocks into unit tests. The recognized syntax is:

    [doctest]: # (name="test.c", test="run")

    ```c
    // unit test code
    ```

The commit also fixes the issues revealed during the initial
annotation.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-07-14 16:18:20 +02:00
Robert Fancsik 3d744c958f Shifting array element down in the tree must be finished even if an error occurs
Fixes #1671

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-07-13 17:54:14 +09:00
Daniel Balla dbfb0170c1 JerryDebugger breakpoint system rework (#1908)
Reworking the python JerryDebugger breakpoint system.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-07-13 10:26:14 +02:00
Robert Sipka 89015a6119 Improve split method to gain memory (#1893)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-07-10 10:49:16 +02:00
Martijn Thé 91912689ad Fix hash calculation for strings created using jerry_create_string_from_utf8 (#1912)
The hash was being calculated over the bytes *after* the actual string bytes.

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2017-07-10 08:53:58 +02:00
Akos Kiss 18283d22c0 Make debugger port runtime configurable
Convert debug server port from a compile-time constant to a context
variable. This enables each engine instance (either running in the
same process or in different processes) to listen for connections
at different ports, i.e., multiple engines can be debugged at the
same time on the same machine.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-07-06 07:08:00 +09:00
fbmrk cfa4fdd1ef target: mbedos5: unnecessary acquire and argument check bug (#1892)
When you cleanup the engine you got an `ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p)` error.
There is an unnecessary call of jerry_acquire_value which causes the problem.

Also in the InterruptIn-js.cpp file there is a wrong check of an argument.

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-07-05 23:09:10 +02:00
fbmrk d3cf335dad target: mbedos5: fix mbedignore (#1894)
Ignoring the entire jerry-port/default library causes a link error, because of the need for the defaultx-handler.c source file.

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-07-04 11:54:36 +02:00
Sanggyu Lee 0b08322a21 Fix build warning in jerry-ext/arg on tizenrt-artik05x
tizenrt-arttik05x treats warning as error for uninitialized use.
This patch fixes the error in jerry-ext/arg by initializing to zero.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-07-04 16:20:44 +09:00
Youngil Choi a823169bde Add daily measurement information to READ.md
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2017-07-04 15:09:25 +09:00
Zoltan Herczeg e6832f5f27 Rework argument parsing.
Heavily simplify the interface of CLI.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-07-04 08:56:55 +09:00
Sanggyu Lee 6b0d9e1b6a Throw SyntaxError for identifier with supplementary character
Fix assertion failure issue #1871 on github.
Don't allow supplementary character as identifier start or part.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-07-03 08:31:20 +09:00
rerobika f359eb2d1b Stack data should be freed for while statements after the expression is parsed (#1897)
Fixes #1873.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-06-30 10:29:19 +02:00
rerobika 3c992de2b8 Fix a build error (#1895)
Fixed an error when neither of libraries are found the build fails.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-06-29 12:11:18 +02:00
rerobika c31e8b8c17 Add timeout to jerry_debugger_receive (#1885)
Fixed when debug server uses a CPU core on 100%.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
2017-06-28 11:26:45 +02:00
Akos Kiss 2f140e3b7f Add strtol to jerry-libc and make use of it in jerry-main (#1891)
As a side effect, refactor the variable types in
`print_unhandled_exception` to reduce the overuse of sized integer
types (generic `unsigned int` is better than `uint32_t` if there is
no actual requirement on integer width).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-06-26 17:10:07 +02:00
Zidong Jiang b153475093 add transform functions for integer in jerryx/arg (#1883)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-06-21 19:32:13 -05:00
Zidong Jiang e4eecc2019 add transform_object_properties in jerryx/arg (#1879)
Add a function in jerryx/arg.
jerryx_arg_transform_object_properties, it will validate the properties of a JS object, and convert those properties into native type.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-06-19 19:51:08 -05:00
fbmrk 7cc9d65c09 target: mbedos5: use jerry-ext (#1889)
Update target mbedos5 to use external function handlers: `assert`, `gc` and `print` from jerry-ext.

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-06-16 20:25:00 +02:00
fbmrk 70b078faa4 Update target mbedos5 README. (#1880)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-06-16 09:57:56 +02:00
Martijn Thé b947f56fd0 Add jerryscript-ext/autorelease.h with JERRYX_AR_VALUE_T (#1874)
JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2017-06-16 00:09:19 -05:00
Zidong Jiang 940f1f89c9 Check if it is object in Promise.prototype.then
Fix issue #1881

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-06-08 17:08:20 +09:00
Péter Gál d56713b9af When compiling with gcc 7 the current fallthrough comments (#1878)
are not accepted. This is a bug in gcc 7.

For now disable the fallthrough comment detection.
Disabling the check does not introduce any risk
as previously it was not enabled by default and
vera++ already check these kind of comments.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-06-08 17:07:40 +09:00
Péter Gál add60865e0 Rename files under jerry-code/debugger to avoid build fails (#1877)
Without the file renaming there are two jerry-debugger.c files.
Thus when the jerry-core archive is created there are two objects
in it with the same name. Generally this does not create any problems.
However if the archive is extracted then the second object file
will overwrite the first one which results in undefined reference
linkage error.

The jerry- prefix was removed from the file names and
fixed the include oreders where it was needed.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-06-07 08:39:30 +09:00
Akos Kiss 905cd705ef CMakeLists maintenance (#1826)
Removed various superfluous declarations, and rewrote some parts to
be nicer or more consistent.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-06-06 09:08:14 +02:00
Zidong Jiang 11d5402c35 Allow out_native_pointer_p in jerry_get_object_native_pointer to be NULL (#1876)
Support those cases when the existence of the native property is checked.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-06-05 10:44:56 +02:00
Daniel Balla 13930a1cd4 Fix exception argument check (#1875)
The If case didn't work properly when 0 was given to the --exception option.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-06-02 12:25:29 +02:00
Daniel Balla 5eb00b7ae0 Add command line option to exception and display commands (#1872)
You can now set --display and --exception parameters in the command line.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-06-02 10:40:12 +02:00
Robert Sipka ddbe067dee Set log level to JERRY_LOG_LEVEL_DEBUG when using show-opcodes on nuttx-stm32f4 target (#1869)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-06-01 08:51:15 +09:00
Zoltan Herczeg a9e7dd7b91 Check breakpoint stop condition in VM. (#1868)
Check breakpoint stop condition even after a message is processed.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-31 12:53:25 +02:00
Zoltan Herczeg efdc06996b Improve instance management in JerryScript. (#1849)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-31 15:53:53 +09:00
Daniel Balla b17a628c19 Add --color option to python debugger (#1865)
Adding --color option, highligthing the number of lines, the pointer and the actual breakpoint.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-05-31 08:53:55 +09:00
Daniel Balla 712d5ca8b7 Python debugger source & display command (#1850)
Reworked source(src) command to display a given range of the code, defaults to 3.

Added display command which does the same as the source, except it displays the source code everytime a breakpoint is hit.

Made tests for display, extended tests for src.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-05-30 10:58:34 +02:00
Sanggyu Lee ae60ff0aa3 Handle negative zero in number multiplication (#1856)
Keep sign for zero.
For example, 1 / (0 * (-1)) should be -Infinity, not +Infinity.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-05-30 10:57:32 +02:00
László Langó 631e9f9f80 Update the API examples to use print from extensions (#1846)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-05-30 09:59:49 +02:00
yichoi 783dcec6df Add license report and scan status with FOSSA (#1862)
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2017-05-30 16:11:46 +09:00
Jan Jongboom 37ed82437b target: mbedos5: Update to mbed OS 5.4.5 (#1853)
Also ignore the default jerry-port - see also #1847. Re-implement the `print()` function, as it's no longer part of core Jerry, but our programs still depend on it.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2017-05-30 09:09:09 +02:00
fbmrk a8a25e7f3c Update mbedos5 make (#1847)
Fix make clean and ignore jerry-port-default

JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-05-30 08:58:03 +02:00
Gabriel "_|Nix|_" Schulhof 708b155f38 Clean up property existence check inconsistencies (#1860)
`jerry_has_property ()` and `jerry_has_own_property ()` are inconsistent
in that they squash their return value into a `bool` when in fact it is
a `jerry_value_t`, thereby giving the wrong impression that a property
is there when it isn't and encouraging the leaking of `jerry_value_t`s
by disguising them as `bool`s.

Fixes https://github.com/jerryscript-project/jerryscript/issues/1859

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-05-29 15:54:32 +02:00
Paul Sokolovsky b51b6824bb targets: zephyr: Reinstate "print" function and error printing. (#1851)
Re-add "print" function following resent refactors when it was moved
from jerry-core to jerry-ext. This is done in particular to keep
detailed messages on errors.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2017-05-25 09:08:34 +02:00
Robert Sipka 557fa5006c Set log level to JERRY_LOG_LEVEL_DEBUG when using mem-stats or show-opcodes (#1848)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-05-25 15:25:00 +09:00
Gabriel "_|Nix|_" Schulhof de53adbf88 Lazily create a linked list of context items (#1833)
This approach has the benefit that it does not require any *a priori*
initialization, and that each context pointer is identified by the way
in which it was created. Additionally, retrieving the context pointer
now requires that the entity responsible for creating/destroying it
(the manager) be given. Since managers are stored in global static
const structures, they should not normally be visible across source
files, and thus there should be no danger that a context item will be
retrieved by the wrong manager and thus cast into the wrong data type.

Since the items are stored in a linked list, their number will be
limited to exactly as many as are needed for a given context, with the
caveat that storing too many on a context will cause slow retrieval.

Thanks @mhdawson for the idea!

Fixes https://github.com/jerryscript-project/jerryscript/issues/1845

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-05-24 14:10:18 +02:00
Zoltan Herczeg 29f57ec58f Print exception hint in the debugger client when an exception is thrown. (#1841)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-23 16:06:25 +02:00
László Langó 7770b6237a Fix parsing of UTF-8 RegExp literals (#1840)
Fixes #1831

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-05-23 12:04:11 +02:00
Daniel Balla 8894077656 Implement memstats command in the debugger (#1838)
Implementation of memstats command in jerry-debugger, python and html client.
Shows the allocated bytes, byte code bytes, string bytes, object bytes, property bytes and heap size.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-05-23 11:19:15 +02:00
Zoltan Herczeg e58f2880df Do not allocate memory for zero length strings. (#1844)
Fixes #1821.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-22 13:17:08 +02:00
László Langó a504fd0333 Fix character escape in character class parsing of RegExp objects. (#1834)
Fixes #1830

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-05-22 13:01:22 +02:00
Robert Sipka 04f3bf62b0 Set log level to JERRY_LOG_LEVEL_DEBUG when using mem-stats. (#1843)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-05-22 12:58:40 +02:00
Zidong Jiang eb2af2d2a6 jerryx_arg: add '\0' when transforming string (#1827)
Related issue: #1824

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-05-22 08:32:20 +08:00
Zidong Jiang 5e28bfc28a Support external context, heap and lcache (#1778)
JerryScript should support external context, heap and lcache,
so that it can have multiple instances and runtime configurable heap
size.

Related issue: 1746

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-05-20 11:00:19 +08:00
Zoltan Herczeg c6d890ee13 Support functions with number identifiers in the pre-scanner. (#1837)
Fixes #1829.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-19 14:49:38 +02:00
Imre Kiss 833796a20f Fix the getBreakpoint() function in the HTML Debugger client. (#1839)
There was a problem around the offset, the function tried to use some invalid object reference.

JerryScript-DCO-1.0-Signed-off-by: Imre Kiss kissi.szeged@partner.samsung.com
2017-05-19 14:38:19 +02:00
Daniel Balla ffdf151387 Fix a typo in a variable name (#1835)
There was a typo in a variable name causing the build to fail when mem-stats was turned on.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-05-19 10:03:02 +02:00
Levente Orban d48c65d258 Add pending breakpoints feature to HTML (JavaScript) Debugger client (#1828)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-05-19 09:50:17 +02:00
Zsolt Borbély 7833270ca0 Initialize an array in test-ext-arg.c (#1824)
In case of some compilers (e.g. gcc-4.9, gcc-5.4) the `TEST_ASSERT (arg3[4] == '\0')`
fails in test_validator1_handler() due to uninitialized memory fields.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-05-18 15:20:44 +02:00
Akos Kiss 23068bdf99 Move the job queue from the ports into jerry-core (#1804)
* Move the job queue from the ports into jerry-core

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu

* Remove port notification and keep `jerry_run_all_enqueued_jobs` API only

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-18 18:30:50 +09:00
Levente Orban 0806c16902 Add pending breakpoints feature to python debugger client (#1810)
- Support to add pending breakpoints
 - Add fbreak command for the prompt
 - Manage this breakpoints
 - Add tests for it

JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-05-18 09:00:38 +02:00
Akos Kiss 31cd3b8020 Rename internal lit identifiers (#1801)
We should keep the `jerry_` prefix for public API which is either
declared in jerry-core/include or implemented in jerry-core/api.
Moreover, we should also keep the convention to use short
identifiers for componentization within jerry-core, and use these
identifiers as directory names, file name prefixes, and identifier
prefixes.

Therefore, the tools/gen-unicode.py-generated arrays in
jerry-core/lit are renamed to use `lit_` prefix instead of `jerry_`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-16 10:34:41 +02:00
Akos Kiss 7837440cbb Add lightweight command line processor to jerry-main (#1809)
Eases command line option and sub-command definition, usage summary
and detailed help message printing, and argv processing.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-16 10:29:27 +02:00
Sanggyu Lee 1501699f48 Add setjmp and longjmp functions for tizenrt-artik05x (#1825)
This patch is based on nuttx-stm32f4 implementation.
However, I removed vldm and vstm since artik05x has no FPU.
It fixes the following error on running some testcases under tests/jerry/fail:

System Information:
        Versionarm_dataabort:
        Data abort. PC: 0410d9d8 DFAR: 0a00001d DFSR: 00000008
        up_assert: Assertion failed at file:armv7-r/arm_dataabort.c
        line: 111 task: appmain

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-05-16 09:57:32 +02:00
Zoltan Herczeg f4fbf0b0b5 Rework memory statistics to provide useful user information. (#1812)
Obsolote statistics is also removed.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-16 09:52:12 +09:00
Zoltan Herczeg f5b385ca6c Tracking variables to reduce the memory consumption of scope chain. (#1819)
Currently we keep all local variables in the scope chain as long as
a nested function is alive. These variables consume memory although
several of them are never used. This patch focuses on removing those
unused ones whose can be detected at parsing time.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-15 09:00:57 +02:00
Sanggyu Lee 8143a0cc10 Use external handlers in tizenrt-artik05x target (#1822)
This patch includes followings:
- Use external handlers in jerry-ext.
- Make jerry_main similar to other ports. (including options)
- Merge jerry_port.c into jerry_main.c
  jerry_port is clearly out of jerry-core.

This patch not included following:
- Use jerry-libm, instead of system libm.
  It is already included.
  We choose to use jerry-libm since the result of cube-3d sunspider was inaccurate
  when using NuttX libm.
- Correct setjmp/longjmp implementation.
  I tried to bring the source from NuttX port.
  Unfortunately it does not work in tizenrt-artik05x as it is.
  I will take a closer look the code and make sure it works.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-05-15 15:41:06 +09:00
Zsolt Borbély ca6e7881e8 Add category property to each .md file for the webpage (#1818)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-05-12 15:34:46 +02:00
Sanggyu Lee 91b06726bb Include jerry-ext/handler only in nuttx-stm32f4 target (#1816)
I included jerry-ext/handler only, rather than including all in jerry-ext.
Currently only handler is used in nuttx-stm32f4 repl.
nuttx.bin binary size is reduced from 231576 to 230456 bytes.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-05-12 15:17:11 +02:00
Levente Orban 0066e526f7 Increase verbosity when breakpoints not found in HTML client (#1817)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-05-12 11:36:56 +02:00
Zsolt Borbély e76d44a2ee Add docs about extensions to webpage-generator script (#1811)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-05-12 09:51:00 +02:00
Robert Sipka 2b152f079a Use external print handler in riot-stm32f4 target (#1814)
Extend example code with registering the `print` function in the global object.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-05-11 20:46:14 +02:00
Zoltan Herczeg 838e74df0f Remove include jerryscript.h from jrt.h. (#1803)
Fixes #1791.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-05-11 12:42:47 +02:00
Robert Sipka 7d133e55e4 Use external print, gc and assert handlers in nuttx-stm32f4 target (#1813)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-05-11 07:26:10 +02:00
fbmrk 1a7b258772 Set JERRY_JS_PARSER to 1 in mbed_app.json (#1808)
JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu
2017-05-10 17:14:24 +09:00
Akos Kiss a8f2d31bca Implement common external function handlers in jerry-ext (#1787)
Added `handler` module to `jerry-ext` to contain implementation of
commonly used external function handlers: `assert`, `gc`, and
`print`.

Also adapted jerry-main to use jerry-ext/handler

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-09 10:16:56 +02:00
Akos Kiss 68f9585b96 Fix jobqueue's return value handling in jerry-main's repl mode (#1807)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-09 12:40:53 +09:00
Akos Kiss 7f32abf75c Remove limitation on number of command line arguments in jerry-main (#1806)
Since JerryScript has been a C99 project for a while now, we can
use variable-length arrays. This allows the removal of the
artificial limit on command line arguments in jerry-main.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-09 12:40:37 +09:00
Akos Kiss 59c7ffe363 Shouldn't use jerry_value_t in ecma-exceptions.c (#1800)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-07 21:46:15 +02:00
Akos Kiss 91e976f8c7 Move jerry-core API implementations and headers into dedicated subdirectories (#1793)
Moved all public API headers under the `jerry-core/include`
directory. This makes installing all the public headers easier.
Also, should we have new public headers in the future, their
installation will be automatic, there will be no need to update the
build files. Moreover, this aligns better with the structure of
other libraries in the project (in those cases, public headers
always reside in `<library>/include`).

Moved all public API implementations under the `jerry-core/api`
directory. This cleans up the root directory of `jerry-core`,
moving all implementation code under "modules", i.e.,
subdirectories. This also makes the future splitting of the big and
monolithic `jerry.c` along features easier, if needed. (Debugger
and snapshot-related functions are already in separate sources.)

Notes:
* `jerryscript.h` is split up to separate header files along
  feature boundaries. These new headers are included by
  `jerryscript.h`, so this is not a breaking change but header
  modularization only.
* `jerry-snapshot.h` is still under `jerry-core/api`, keeping it as
  a non-public header.
* This commit also adapts all targets to the include path change.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-04 15:28:24 +02:00
Zidong Jiang 90efdf9c8b A tool in jerry-ext: arg transformer for binding (#1740)
It provides some APIs for binding developers, so that
they can validate the type of the js argument and convert/assign them
to the native argument.

Related Issue: #1716

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-05-04 18:00:35 +08:00
Zidong Jiang ede13835b2 Add promise C API (#1796)
Add API: jerry_create_promise, jerry_value_is_promise and jerry_resolve_or_reject_promise.

related issue: 1794

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-05-04 16:13:26 +08:00
Akos Kiss 240411771a Remove the built-in print and the jerry_port_console port API functions (#1749)
The built-in `print` is removed from jerry-core, but an external
`print` implementation is added to jerry-main. From now on, all
embedders of the engine have to implement their own `print` if they
need such a functionality.

For printing results in REPL mode of jerry-main, the external
`print` handler is called directly instead of looking up the `print`
function registered into the global object. (The two are the same,
but the indirection is not needed anymore.)

Because jerry-core does not contain `print` anymore,
`jerry_port_console` is removed from the port API. The default port
is updated, i.e., the implementation of `jerry_port_console` is
removed. Additionally, all references to `jerry_port_console` in
jerry-main are replaced by `printf`.

Speculatively, `jerry_port_console` is also removed from all
non-default targets. Most targets implemented it for the sake of the
engine only; in those targets the removal was trivial. Where the
function was called from the embedder application as well, the
calls were replaced with equivalents (e.g., `printf`, `printk`).

NOTE 1: This is a breaking change!

NOTE 2: This patch still leaves several targets without a JS `print`
implementation.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-03 11:47:56 +02:00
Akos Kiss 3705bf19d0 config.h maintenance (#1792)
The config header was full of legacy, no-longer-in-use defines. It
was also included from multiple files where it was not necessary.
This patch removes the unused defines, and cleans up headers so
that only `ecma-globals.h` includes `config.h`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-05-02 08:44:57 +02:00
Zoltan Herczeg 894aa6d036 Support ECMAScript stopping in JerryScript. (#1753)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-04-28 14:19:23 +02:00
Robert Sipka 0e38356e5b Update riot-stm32f4 target to use jerry-port-default-minimal (#1790)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-28 10:49:39 +02:00
Robert Sipka 56802c22a1 Remove unnecessary subfolder in tests/jerry/fail/ (#1783)
There is no need to create error code named subfolders since
every failing tests return with the same code.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-28 09:17:23 +02:00
Zidong Jiang 14c455bcd8 [native pointer] Check if freecb is NULL before calling it (#1789)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-04-28 09:01:40 +09:00
Akos Kiss 6ecee7eef4 Ensure that jerry-port is license-checked (#1788)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-28 08:59:10 +09:00
Sanggyu Lee c9dac6a720 target: tizenrt-artik05x: Add missing jerry_port.c (#1786)
Add missing jerry_port.c in previous initial port.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-04-27 10:25:29 +09:00
Robert Sipka fb432a8bd7 Eliminate pylint warnings from generate_pins.py (#1731)
It also contains small refactoring steps:

* Added a main() function - instead of just writing all the code into the
  "if name" block - to avoids creating global variables that could affect
  other functions.

* Added a `write_pins_to_files` function - which writes the generated pins
  into the output JS and C++ files - to avoid too many local variables.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-26 15:18:20 +02:00
Zidong Jiang 078f6e101d Implement other routines of Promise (#1729)
Add Promise.resolve, Promise.reject, Promise.race, Promise.all and
Promise.prototype.catch

Also it fixes the issue 1763

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-04-26 19:47:51 +08:00
Levente Orban 9d4123c3c4 Fix the exception handler bug (#1780)
If the debugger evaluate a variable out of the scope in eval mode, its get an error.

JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-04-26 20:29:16 +09:00
Akos Kiss 8aca0acaa1 Aftermath of PRs #1505 and #1755 (#1771)
PR #1505 added support for TI compiler. It explicitly added a
message to notify the user that static linking is forced. PR #1755
added a more generic approach to signal such forced settings and
adapted the TI-specific static linking notification to this
approach. However, it turned out that TI forcibly changed another
setting, too: it disabled release binary stripping, but without
notification. This patch fixes this by moving the setting override
to a consistent place and adding a notification.

PR #1505 also added some source code changes, most importantly a
complex struct initialization for a variable in
`ecma-objects-general.c`. However, that initialization was coded
as a macro to trick the style checker. This patch gets rid of that
macro and uses proper C99 struct initializer with designators.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-26 12:53:41 +02:00
Sanggyu Lee e8be1984bb target: tizenrt-artik05x: Initial porting (#1775)
Initial porting to tizenrt-artik05x.

Tizen RT is a lightweight RTOS-based platform to support low-end IoT devices.
The project is under developing in github TizenRt repo.
Artik05x is an IoT SoC solution that will be released soon.

This PR contains the minimum porting that can print Hello
world from jerryscript and a document for building and running.

I used jerry_port.c and jerry_main.c in nuttx port and default port for
porting base code. Also I used Make.defs and Makefile in working
example in tizenrt for adding jerryscript configuration.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-04-26 11:19:14 +02:00
Akos Kiss d48db1d5bd Remove jerry-internal.h (#1782)
The internal header was a legacy, declared two functions only. One
of them was not used anymore at all, the other was used at a single
call site. Moreover, their documentation was outdated. This patch
removes the header and the related function implementations -- as
well as the temptation to use such internal functions from outside
the library.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-26 08:05:33 +09:00
Akos Kiss fdbbd0e8af Turn port implementations into proper libraries (#1777)
This commit changes the concept of JerryScript port implementations
from a simple directory of C source files (which get injected among
the sources of `jerry-core`) into a proper static library (which
may be linked to an application together with `jerry-core`). As a
consequence, this commit introduces a new library to the
JerryScript component architecture: the sources of the default port
implementation form `jerry-port-default`.

Changes in more detail:

- The sources in `targets/default` are moved to `jerry-port/default`
  and are turned into a proper static library.
  - Actually, the default port implementation has two library
    variants, one that implements the bare minimum only
    (`jerry-port-default-minimal`) and one that has some extra
    functionalities specific to this implementation (the "full"
    `jerry-port-default`).
  - The new libraries have an interface header in
    `jerry-port/default/include`, which extends the common
    `jerryscript-port.h` API with functions specific to these
    libraries.
  - All non-standard port functions have now the
    `jerry_port_default_` prefix (this affects `jobqueue_init` and
    `jobqueue_run`).
  - The jobqueue implementation functions became config macro
    independent: it is now the responsibility of the linker to pick
    the needed objects from the library, and omit those (e.g.,
    jobqueue-related code) that are not referenced.
  - Build of the libraries can be controlled with the new
    `JERRY_PORT_DEFAULT` cmake option.

- The cmake option `PORT_DIR` is dropped, and `PORT_DIR/*.c` is not
  appended to `jerry-core` sources.
  - Instead, the `jerry` tool of `jerry-main` links to
    `jerry-port-default`, while `jerry-minimal` links to
    `jerry-port-default-minimal`.
  - `tests/unit-core` tests are also linked to
    `jerry-port-default-minimal`.

- Tools adapted.
  - `build.py` has `--jerry-port-default` instead of `--port-dir`.
  - `check-*.sh` have paths updated (`jerry-port/default` instead
    of `targets/default`).

- Miscellaneous.
  - Dropped `#ifndef`s from `jerryscript-port.h`. It is a public
    header of the `jerry-core` library, which means that it must
    not contain configuration-dependent parts (once the library is
    built with some config macros and the archive and the headers
    are installed, there is no way for the header to tell what
    those config macrose were).
  - Added documentation comments to the JobQueue Port API (in
    `jerryscript-port.h`) and to several default port
    implementation functions (in `jerry-port/default`).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-25 19:33:10 +02:00
Akos Kiss 49ae946644 Merge lit-unicode-*.inc.h-related generator scripts (#1767)
The `conversions` and `ranges` files had separate generators, which
shared some functionality through a 3rd python module, and were
quite similar to each other -- but also had some differences.
Moreover, as they were separate scripts, nothing forced to keep the
outputs in sync (to re-generate them at the same time from the same
inputs).

To fix these maintainability issues, this patch
- merges the two python files and part of the 3rd utility module
  into a single script while keeping the existing functionality,
- names the new file `gen-unicode.py` to align better with other
  generator script in `tools`, and
- adds some extra documentation how to retrieve the input files
  (as they are not part of the repository).

The refactoring affected the utility module as well, so this patch
also
- renames `c_source_helper.py` to `gen_c_source.py` (again, for
  naming consistency),
- reorganizes some of its functions not to export module-local
  helper functions, and
- adapts `js2c.py`, as it also uses this utility module.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-25 07:22:05 +09:00
Martijn Thé 1f6b396ebb bugfix: jerry_get_object_native_pointer: accept NULL for out_native_info_p (#1770)
With the jerry_set_object_native_pointer() the native_info_p is optional, so I think it makes sense that it is optional for the getter as well.

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2017-04-24 13:52:00 +02:00
Zsolt Borbély 07c86ece54 Fix alignment in case of enabled 32bit compressed pointers (#1764)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-24 13:02:14 +02:00
Martijn Thé 849ea45cc2 Improve documentation for jerry_get_object_native_pointer API (#1769)
Based on feedback I got from people who tried using the new API, it was not immediately clear how to properly use it.
Hopefully these doc additions make it more clear how to use it and why it is designed the way it is.
Also fixed some mistakes in the example and provided more comments to explain the intent of the code.

JerryScript-DCO-1.0-Signed-off-by: Martijn The martijn.the@intel.com
2017-04-24 10:40:24 +02:00
Sanggyu Lee acf88d2fe8 Fix maybe-uninitialized warning in ecma-objects.c (#1773)
During building jerryscript with arm-gcc-noneeabi 4.9.3,
maybe-uninitialized warning occurred. This patch fixed the warning.

JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com
2017-04-24 10:08:13 +02:00
Akos Kiss 4f4f75e1a8 Update paths in check tools (#1772)
In #1761, not all unit test paths have been updated in check tools.
This triggers no errors as `check-vera` emits a warning only while
`check-cppcheck` signals nothing. Still, this means that some of
the code in the repository that has been quality-assured, is now
avoiding checks. This patch fixes this.

Moreover, `check-cppcheck` has had incorrect paths for a while: it
looked for source files in the root of the repository, but those
files have been in `jerry-main` for almost a year now. This patch
fixes this, too.

Fallout of the above: `main-unix-minimal.c` had to be improved to
make `check-cppcheck` pass.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-24 09:01:03 +09:00
Akos Kiss 0ab099b787 Add JERRY_FEATURE_DEBUGGER to API docs (#1768)
In #1738, `JERRY_FEATURE_DEBUGGER` was added to the sources, but
the docs were not updated.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-24 09:00:21 +09:00
Akos Kiss 6ca8319aea Split unit tests into separate directories (#1761)
The unit tests should follow the component structure, so this patch
moves all `jerry-core` unit tests under `tests/unit-core` and the
`jerry-libm` unit tests under `tests/unit-libm`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-22 10:57:45 +09:00
Akos Kiss 66ade0d81c Add Python wrapper for the HTML-based debugger (#1736)
The patch aims at easing the startup of the HTML-based JerryScript
debugger client by adding a python script that starts the default
browser with the HTML page implementing the debugger client.
Additionally, the pyton script encodes the host:port address
information of the debug server in the file url and the HTML client
is extended to retrieve this information. Thus, both the console
and the browser-based debugger client can be started similarly.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-22 10:55:39 +09:00
Akos Kiss 6c3a6e7be3 Rename jerry-port.h to jerryscript-port.h (#1762)
All public headers should follow the pattern `jerryscript[-*].h`.
The `jerry-api.h` to `jerryscript.h` renaming has already happened
a while ago, now it's time for the port API header to follow.

This patch
* renames the public header file,
* updates all includes to use the new file name (in `jerry-main`,
  in all the targets, and in the docs), and
* keeps `jerry-port.h` as a deprecated forwarding header to leave
  some time for external users to follow up with this change.

As a related change, the header of the default port implementation
is also changed to `jerryscript-port-default.h`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-22 10:53:12 +09:00
Zidong Jiang 63b6fd1bc9 Add the class name of promise.prototype (#1766)
Fix Issue: 1765

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-04-22 08:34:42 +08:00
Akos Kiss 67c641e567 Generate lit-magic-strings.inc.h (#1690)
Currently, `lit-magic-strings.inc.h` is manually maintained. This
has several drawbacks:

- keeping the list of magic strings sorted first by length then
  alphabetically is error prone,
- it is easy to leave unused magic strings in the list by accident
  (e.g., `LIT_MAGIC_STRING_JERRY_UL` is defined as a magic string
  but not used anywhere in the code) and,
- it is very hard to add `CONFIG_DISABLE_*_BUILTIN` guards to the
  list, even though there are several magic strings, which are used
  in some of the configurations only (e.g, "setPrototypeOf" is used
  in ES2015 only).

To ease the maintenance of magic strings, this commit moves the
definition of magic strings to a config file
(`lit-magic-strings.ini`), and adds `tools/gen-magic-strings.py` to
generate the `.inc.h` file from this config file and from the use
cases of the strings in the code.

- The magic strings in the config file can appear in any order, the
  generator will ensure that they are correctly sorted.
- The generator skips those definitions that are not used anywhere
  (and emits a warning to signal that such definitions can be
  removed).
- The generator applies the same guards to the definitions in the
  `.inc.h` file as found in the code around the use of the strings
  to optimize for size.

The commit also changes some builtin-related `.inc.h` files by
adding guards that don't affect functionality but improve the
results of the generator.

To ensure that the invocation of the generator does not get
forgotten, the commit also adds `tools/check-magic-strings.sh` and
binds it into the testing infrastructure.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-21 11:42:36 +02:00
Roland Takacs 5231829fc9 Enable dummy time zone in nuttx-stm32f4 target. (#1760)
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.u-szeged@partner.samsung.com
2017-04-21 18:09:11 +09:00
Akos Kiss d93bc3a849 Make string handling in debugger more pythonic (#1757)
* `to_string` is unpythonic, let's use `__str__` instead.
* `\"%s\"` for strings is also unpythonic, let's use `%r`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-21 09:52:06 +09:00
Akos Kiss 4cff7a3f2c Fix/rewrite/darwinize test runner of jerry-debugger (#1756)
First issue was that `diff -u0` was not supported on OSX, thus got
replaced by `-U0`. Then, it turned out that test outcome was
determined based on diff's stdout, which was empty even though the
exit code was non-0 - this got changed, too.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-21 09:51:31 +09:00
Akos Kiss 84f0279289 Allow platforms/compilers to signal that user-specified settings are overridden (#1755)
Currently, the Darwin platform and the TI compiler force some of
the settings to predefined values. This patch ensures that these
overrides are highlighted during build.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-21 09:49:46 +09:00
Robert Sipka 5271214623 Support error messages on nuttx-stm32f4 target (#1754)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-21 09:48:58 +09:00
Akos Kiss 2ebb8de3ab .gitignore maintenance (#1758)
* OSX Finder leaves `.DS_Store` files around; make them ignored.
* The mbedk64f target has been renamed to mbed a long time ago;
  follow that change in .gitignore, too.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-21 09:45:09 +09:00
Akos Kiss ea44b3b44c Refactor the command line option handling of the jerry tool (#1745)
The file `main-unix.c` contained a lot of recurring patterns in the
command line option handling parts. This patch removes these code
clones with the introduction of two helper functions. The goal of
the patch is to have a smaller and maintainable `jerry` tool (mostly
source-wise).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-20 15:12:10 +02:00
Akos Kiss 2424ba71f2 OSX-related CMakeLists maintenance (#1750)
Disable release binary stripping on OSX: The linker of OSX does not
support `-s` for link-time stripping. (The option does not cause an
error but clutters build output with warnings.)

No OSX-dependent LTO flags: LTO is disabled on OSX.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-20 19:42:13 +09:00
Zsolt Borbély fda5924b06 Rename the doc of coding standard and add it to the update-webpage.sh (#1748)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-20 12:23:53 +02:00
Zsolt Borbély 2fa9ae8d64 Fix link-generation in tools/update-webpage.sh (#1747)
This change is required to fix invalid links in 'See also' sections.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-19 13:48:42 +02:00
Zsolt Borbély befa7a88fe [nuttx-stm32f4] Use jerry-libm instead of the math library in NuttX (#1744)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-19 10:22:48 +02:00
Robert Sipka 8d99e73db3 Add setjmp and longjmp functions for nuttx-stm32f4 target. (#1743)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-19 07:10:05 +09:00
Robert Sipka 9cbd5e78ad Refactor js2c.py and eliminate related pylint warnings (#1728)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-19 07:08:32 +09:00
yichoi 67d5df2735 Update mailing list information (#1742)
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2017-04-18 20:58:09 +09:00
Zsolt Borbély 5449b0f40b Always define debugger-related opcodes (#1734)
This change makes the generated snapshot independent from buildconfig.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-18 18:20:20 +09:00
Akos Kiss 0f4edbe580 Ensure that const and pure function attributes are used properly (#1739)
Some functions were incorrectly marked as const but were pure only
(or not even pure). Some functions were marked as pure but
qualified as const. Some functions were not attributed at all but
qualified either as pure or const. Some functions had attributes
at definition but not at declaration. This commit fixes these
inconsistencies.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-18 17:15:34 +09:00
Akos Kiss dc1dc093d9 Add JERRY_FEATURE_DEBUGGER (#1738)
Until now, it was not possible to query the engine whether its
build configuration contained debugging support. This commit adds
the `JERRY_FEATURE_DEBUGGER` label to `jerry_feature_t` and extends
`jerry_is_feature_enabled` to support the new feature flag.
Additionally, the command line tool `jerry` was enhanced to report
a warning when invoked with `--start-debug-server` but linked to a
non-debuggable engine.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-18 17:15:13 +09:00
Tomasz Wozniak 42206d27c8 Janitorial: add missing integer cast to remove compiler warning. (#1720)
JerryScript-DCO-1.0-Signed-off-by: Tomasz Wozniak t.wozniak@samsung.com
2017-04-17 11:30:18 +09:00
Gabriel "_|Nix|_" Schulhof b4a3985560 Support a user context void * pointer in jerry_context_t (#1717) (#1727)
This modification makes it possible to initialize a context in such a
way that a `void *` pointer is stored inside the context and is made
available via a new `jerry_get_user_context()` API.

The pointer is initialized via a new `jerry_init_with_user_context()`
API, which calls the existing `jerry_init()`, after which it sets the
value of the new `user_context` element in the `jerry_context_t`
structure using the context allocation callback provided as the second
parameter to the new `jerry_init_with_user_context()` API. The location
of the cleanup function responsible for deallocating the pointer created
by the context allocation callback is provided as the third parameter.
This location is stored in the context along with the pointer itself.

When a context is discarded via `jerry_cleanup()`, the user context
cleanup function is called to dispose of the pointer stored within the
context.

The semantics behind the API are such that it is now possible to choose
for each context an agent which manages arbitrary user data keyed to the
given context. The agent must be chosen at context instantiation time
and cannot be changed afterwards, remaining in effect for the lifetime
of the context.

Fixes #1717

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
2017-04-14 08:25:29 +08:00
Akos Kiss 4b9e458f44 Add support for init/fini arrays to libc (#1725)
The arrays contain the addresses of functions annotated with
constructor or destructor attributes. The support is optional,
requires FEATURE_INIT_FINI cmake option to be set. As of now, the
option is _not_ available in tools/build.py directly, only via
`--cmake-param="-DFEATURE_INIT_FINI=ON"`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-04-13 17:18:17 +02:00
Zsolt Borbély 950a0f10cd Fix a few issues which can lead to undefined-behaviour (#1730)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-13 21:34:10 +09:00
Robert Sipka 605e9847d2 Add testing support for nuttx-stm32f4 target (#1733)
Provide the 'assert' and 'gc' implementation for the engine.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-13 14:09:31 +02:00
Robert Sipka 95809cd977 Buildfix for nuttx-stm32f4 target (#1732)
The `jerry_port_jobqueue_enqueue` function is undefined on this target.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-13 20:47:00 +09:00
Zoltan Herczeg 239ae4963c Add documentation about the Coding Guidelines (#1459)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-04-13 16:53:07 +09:00
Zidong Jiang eb8dd4602b Implement the basic Promise (#1695)
Implement the Promise Constructor and routine: 'then'

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-04-12 22:10:08 +08:00
Zoltan Herczeg 01fe5ab190 Small improvements for type property support. (#1724)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-04-12 15:05:29 +02:00
Levente Orban a83319cfa1 Fix the stlink binary path (#1726)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-04-12 14:45:58 +02:00
David Brown 5481fca060 Fix .gitignore syntax (#1721)
Change instances of **.ext in the .gitignore to just *.ext.  I think
the intent was to match these patterns in any directory, which is what
will happen with simple patterns.  The '**' construct is meant to
match zero or more full paths, but it must be the sole component of
the path.

Discovered by a warning from ripgrep.

JerryScript-DCO-1.0-Signed-off-by: David Brown david.brown@linaro.org
2017-04-11 13:28:05 +02:00
Zidong Jiang e522e740a7 Add 'type' argument to set/get native handle API (#1711)
Ecma-object have native handle type inside, and binding code could use
type info to validate native handle's type.

Related issue #1681

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-04-10 16:51:37 +08:00
Zsolt Borbély 574dff512e Remove duplicated profile-check from build.py (#1718)
This check is performed in cmake-side too.
The README.md about the profiles is also updated.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-07 18:47:22 +02:00
Zsolt Borbély 69f03475b2 Add the directory of test262 tests to .gitignore (#1719)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-07 17:03:38 +02:00
Zoltan Herczeg 13b305f716 Refactoring several array buffer and typed array functions. (#1715)
The ecma_typedarray_create_object_with_typedarray function is fully rewritten.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-04-07 11:20:03 +02:00
Robert Sipka 1886d54474 Update unicode ranges to the latest version of Unicode Standard (version 9.0.0) (#1714)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-06 10:07:17 +02:00
Zsolt Borbély 5d950ccb05 Remove unused functions (#1710)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-04 10:49:47 +02:00
Zsolt Borbély db22169293 Fix wrong condition in vm.c (#1708)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-04-03 15:21:34 +02:00
Zoltan Herczeg 1aec439869 Mark target_function of bound objects. (#1707)
Fixes #1621.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-04-03 13:05:29 +02:00
Levente Orban a5b90ed858 Add minor features to debugger html client (#1705)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-04-03 12:36:48 +02:00
Robert Sipka 5f24620c8a Fix helper function for rounding numbers (#1702)
Fixes #1701

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-03 08:44:46 +02:00
Robert Sipka f0a7e2456a Add coverity scan (#1700)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-04-03 08:44:30 +02:00
Levente Orban efa7975ce9 Fix pylint warning in debugger python client (#1704)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-31 10:48:40 +02:00
Levente Orban 5525f5241d Bug fix for the debugger python client 'quit' command (#1703)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-31 08:34:40 +02:00
Zoltan Herczeg 750e0ca9d5 Fix several style fixes for typed arrays and optimize filter a bit. (#1697)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-30 16:06:11 +02:00
Zidong Jiang 41c63e08b1 Combine ARRAYBUFFER and TYPEDARRAY macros together (#1699)
Change CONFIG_DISABLE_ES2015_ARRAYBUFFER_BUILTIN to
CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
Because typedarray depends on arraybuffer and it doesn't make sense to
enable arraybuffer only.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-03-30 21:22:22 +08:00
Robert Sipka 3ff9a7de8a Fix the number of copied bytes in memmove (#1698)
Fixes #1634

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-30 10:40:05 +02:00
Levente Orban 20466a7637 Add missing test for debugger (#1692)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-30 10:29:32 +02:00
Zoltan Herczeg 343bac56b2 Add C-API for the debugger. (#1688)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-29 12:46:07 +02:00
Akos Kiss 2d9484a968 Don't do duplicate builds during test runs (#1691)
The `run-tests.py` test execution harness validates the correctness
of JerryScript by building various configurations of jerry and
running various test suites and subsets against it. However, until
now, it always built jerry for each (build configuration, test suite)
pair. This commit improves `run-tests.py` by skipping duplicate
builds, sharing the same-built binaries across multiple test suite
runs.

The patch also improves on the style of how `Option`s are specified
and fixes the name of the `jerry_tests-debug-cpointer_32bit`
option.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-03-28 15:48:09 +02:00
Zidong Jiang 16d5d6f79d Add a simple Job queue in default port. (#1685)
Job queue (event loop) is the basis of Promise. Each port should implement their own job queue.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-03-28 21:15:01 +08:00
Levente Orban 21cec3eb16 Add Stop at exception feature to the debugger (#1693)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-28 12:51:10 +02:00
Akos Kiss da07252c45 Sort minimal profile (#1689)
Profiles used to be in alpha order. However, after the recent
`CONFIG_DISABLE_[ES2015_]*_BUILTIN` renamings, the minimal profile
became unsorted. This commit re-sorts the file.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-03-27 11:01:05 +02:00
Robert Sipka faa9655981 Add asserts to avoid the access of cbc_flags and cbc_ext_flags arrays outside of their bounds (#1686)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-24 11:30:41 +01:00
Levente Orban c09ba8cdb3 Rename 'CONFIG_DISABLE_ARRAYBUFFER_BUILTIN' to 'CONFIG_DISABLE_ES2015_ARRAYBUFFER_BUILTIN' (#1687)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-24 11:30:23 +01:00
Zidong Jiang 8571ebfae5 Implement %TypedArray%.from and fix the issue #1670 (#1679)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-03-24 10:37:22 +01:00
Levente Orban f50193111b Rename 'CONFIG_DISABLE_TYPEDARRAY_BUILTIN' to 'CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN' (#1683)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-24 08:06:03 +01:00
Robert Sipka 0807c97cbb Eliminate duplicated statements in re-parser.c (#1680)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-23 16:20:32 +01:00
Péter Gál 013430aafb Fix minor inconsistencies in the API documentation (#1663)
In the jerry_set_prototype part the method was described
as jerry_get_prototype. Minor typo fix.

The usage of jerry_set_property was incorrect. Each
call to the jerry_set_property returns a value which must be freed.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-03-23 15:50:24 +01:00
Akos Kiss 4a5df52aa1 Factor out common macro un/definitions used for built-in descriptions (#1678)
The default definitions and undefinitions of macros used for built-in
descriptions (SIMPLE_VALUE, NUMBER_VALUE, STRING_VALUE, OBJECT_VALUE,
ROUTINE, ACCESSOR_READ_WRITE, ACCESSOR_READ_ONLY) are heavily cloned
all over the builtin-objects directory. This commit factors them out
into two header files, which are then included in the place of the
clones. This way, maintenance becomes a lot easier: e.g., if a new
macro gets introduced, default definition and undefinition don't have
to be added to all description files (of which there are 56 right now,
and their number will most probably just grow).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-03-23 09:36:29 +01:00
Zsolt Borbély 852a6aef53 Minor fixes around the debugger (#1677)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-03-23 09:08:06 +09:00
László Langó fa5d5febcc Fix several pylint warnings. (#1659)
Fixed all of the remaining warnings in 'build.py', 'run-tests.py' and 'check-license.py'.

Related issue: #1600

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-03-22 15:37:55 +01:00
Robert Sipka 78e4dcf6c2 Build fix for 32-bit float ecma-number storage (#1669)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-22 14:18:43 +01:00
Akos Kiss 6ddf00a9fa Fix comments of ecma_lexical_environment_type_t (#1676)
The comments of `ecma_lexical_environment_type_t` document why the
values of the enum are as they are, while referring to
`ecma_object_type_t`. However, they became out of sync lately and
refer to nonexistent enum labels and/or incorrect values. This
commit gets the two enums in sync.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-03-22 11:36:44 +01:00
Akos Kiss 20a21a1faf Unify timeout mechanism in test runners and ensure that they work on OSX (#1672)
On OSX, the traditional GNU `timeout` command is available as
`gtimeout`. So, this commit adds some logic to the test runners to
try and find the right command name on the host.

Moreover, the commit also unifies the timeout mechanism across all
test runners by rewriting occurrences of `ulimit`-based timeouting
to use the `[g]timeout` command.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-03-22 10:51:37 +01:00
Robert Sipka 7e1ade3406 Remove logically dead code (#1674)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-22 10:17:12 +01:00
Levente Orban 4420401cf5 Style fix: return value comments (#1668)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-21 10:24:54 +01:00
Akos Kiss e66bb5591d Implement Object.setPrototypeOf from ES2015 specification (#1666)
`Object.prototype.__proto__` has been implemented by most JS
engines to give R/W access to prototype chains, well before it made
it into the standard. JerryScript has decided not to implement it,
exactly because it was not part of ES 5.1. The only fully
ES5.1-compatible way of accessing the prototype chain is
`Object.getPrototypeOf` for reading.

However, ES2015 defines `Object.setPrototypeOf` for rewriting the
prototype chain, and JerryScript has now an ES2015 subset profile.
So, this commit adds its implementation to JerryScript.

Note, this commit does _not_ add `Object.prototype.__proto__`,
since that is in the Annex B of ES2015 specification, which is
optional for non-web-browser hosts.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-03-21 10:11:07 +01:00
Levente Orban 868ba92e02 Add more tests for the remote debugger (#1667)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-20 12:38:04 +01:00
Gabor Loki dd7e20c85d The mbed ports used wrong time computations for the (#1642)
'jerry_port_get_current_time' function. Microseconds was used instead of
milliseconds.

A quick fix has been done in the Yotta-based mbed port, and an extended one
- with correction - works in the mbed OS 5 port now.

JerryScript-DCO-1.0-Signed-off-by: Gabor Loki loki@inf.u-szeged.hu
2017-03-17 08:35:14 +01:00
Robert Sipka 23ac60915f Modify the snapshot API functions to expect a 32-bit aligned buffer pointer (#1655)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-17 09:01:59 +09:00
Levente Orban 05bb5d7890 Improve the debugger python client messages (#1654)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-17 09:01:10 +09:00
Akos Kiss edadc53def Fix Date objects' YearFromTime helper for out-of-range time values (#1658)
For negative out-of-range time values, ecma_date_year_from_time
fell into an infinite loop. (Moreover, for positive out-of-range
time values, it returned an incorrect year.) This patch fixes the
helper to return NaN in these cases (and ensures that its call
sites are prepared for NaN values).

Fixes #1657.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-03-16 17:03:42 +01:00
Robert Sipka d77d4ae1c6 Refactor the generator scripts for unicode tables (#1623)
Extract the source code generator methods into a separated `unicode_c_source.py` script.
Fix the generator scripts to make them compatible with both Python2 and Python3.
Remove pylint warnings.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-16 09:32:18 +01:00
Robert Sipka 818c9cd0b0 Fix issue #742 (#1650)
It is a workaround fix. The problem comes from the inaccuracy of the double rounding.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-16 08:59:48 +01:00
László Langó 202a88bbeb Temporarily disable a few test262 tests in automatic testing. (#1662)
Those tests are related the actual daylight saving adjustment.
Related issue: #1661

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-03-14 15:26:56 +01:00
Zoltan Herczeg 1b4426fd2a Check whether match result has error flag. (#1653)
Fixes #1641.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-14 10:01:22 +01:00
Gabor Loki ed32ba148c Fix the example code of 'jerry_define_own_property' function (#1656)
JerryScript-DCO-1.0-Signed-off-by: Gabor Loki loki@inf.u-szeged.hu
2017-03-13 15:52:06 +01:00
Zoltan Herczeg 679500b327 Improve breakpoint generator of the debugger. (#1652)
Now the debugger generates a breakpoint for each function before
its first executable statement. This allows inspecting the function
arguments. Position (line and column) info is also added which
simplifies finding of anonymus functions. Several tests were
update to check more corner cases.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-13 11:36:34 +01:00
László Langó 57ea06782b Fix several pylint warnings. (#1644)
Fixed
 * 'unused-wildcard-import'
 * 'bad-whitespace'
 * 'bad-continuation'
 * 'wrong-import-order'
in 'build.py', 'run-tests.py' and 'check-license.py'.

Related issue: #1600

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-03-13 11:18:49 +01:00
Zoltan Herczeg b140158104 Fix various number parsing issues. (#1648)
For example Number(".") and Number("e5") should be NaN not
zero. Parsing Number("e") caused buffer overflow as well.
Infinity parsing is a bit faster now.

Fixes #1636.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-09 15:03:46 +01:00
Tilmann Scheller f8dd54abb6 Fix old-style function definitions and enable warning. (#1651)
Function definitions with no parameters should always use the void keyword to allow the compiler to catch invalid calls of those functions at compile time.

Enable -Wold-style-definition to catch this early in the future.

Fixes #1649.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2017-03-09 13:41:26 +01:00
Yanhui Shen a2a160d6f9 Improve error messages (#1577)
JerryScript-DCO-1.0-Signed-off-by: Yanhui Shen shen.elf@gmail.com
2017-03-08 10:58:25 +01:00
Zoltan Herczeg 319702cdd2 Support internal properties in GC mark. (#1646)
Some internal properties are incorrectly handled as objects and
marked as visited. This memory overwrite caused random crashes
in IoT.js.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-07 14:14:05 +01:00
Zoltan Herczeg a20b9dfa19 Introducing debugger modes (run, breakpoint). (#1645)
This makes the code more robust and error prone, since certain
messages cannot be received in certain situations, e.g. an eval
command during garbage collection.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-07 11:58:46 +01:00
Zidong Jiang c6f22a9683 Make sure the size arg of alloc will not overflow (#1618)
Also make sure the bytelength = arraylength << shift will not overflow

Fix issue #1616

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-03-07 08:37:19 +09:00
Zidong Jiang 71e1383d13 Check if propery is not found before delete it. (#1637)
Fix issue #1633

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-03-06 21:08:30 +08:00
Levente Orban 8a86c579e6 Refactor the debugger multiple command usages (#1643)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-06 20:41:22 +09:00
Zidong Jiang b13f78f19e Check options in ecma_op_object_get_own_property for typedarray. (#1627)
And add regression-case subfolder for es2015

Fix issue #1622

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-03-06 19:07:02 +08:00
Zoltan Herczeg b5a91069fd Fix multiple debugger issues. (#1640)
- Wait for free byte code pointers during garbage collection.
- Detect incorrect free requests in the debugger server.
- Ignore byte code blocks loaded from snapshot.
- Use memmove instead of memcpy to avoid receive buffer corruption.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-06 11:13:25 +01:00
Levente Orban b996841a65 Add feature commands for debugger python script (#1604)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-03-06 11:08:30 +01:00
Robert Sipka 6254748081 Require JERRY_JS_PARSER macro to be defined (#1639)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-03-06 09:53:09 +01:00
Zoltan Herczeg ca2b057356 Call property should handle ECMA_SIMPLE_VALUE_REGISTER_REF. (#1631)
Fixes #1624.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-03-03 12:23:18 +01:00
Zsolt Borbély f780f2b8dc Allow to skip certain JS-tests under tests/jerry/ and tests/jerry-test-suite/ (#1632)
Add `--skip-list` option to tools/run-tests.py.

Additional modifications:
 - The test `parser-oom.js` doesn't work when system-allocator is enabled,
   hence we skip it in these jobs.
 - The sanitizer-tasks become mandatory.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-03-02 15:58:23 +01:00
László Langó 92f74f3cf5 Fix pylint install on Travis CI (#1608)
Followup fix after #1602

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-03-02 10:36:21 +01:00
Renáta Hodován 918a50c66b Fix typos in parser error messages. (#1629)
JerryScript-DCO-1.0-Signed-off-by: Renata Hodovan reni@inf.u-szeged.hu
2017-03-02 08:47:54 +01:00
Levente Orban e993ee6cdc Add delete all breakpoints feature to debugger (javascript) (#1628)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-02-28 10:51:48 +01:00
Zoltan Herczeg b8ccdee4db Numbers found in the literal table also has LEXER_LITERAL_OBJECT_ANY type. (#1626)
Fixes #1615.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-28 10:41:41 +01:00
Zoltan Herczeg 6efe39c83c Add source code support to the debugger. (#1614)
Besides the breakpoint list the JavaScript source code is
also sent to the debugger. This feature allows debugging
eval() function calls.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-28 09:25:26 +01:00
Zsolt Borbély c6a7765690 Merge OSX-jobs on Travis (#1625)
The start of OSX-jobs takes a considerable time.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-02-27 16:29:57 +01:00
Zoltan Herczeg 3de72af712 NaN must not be passed to date getter functions. (#1620)
Fixes #1547

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-27 11:19:29 +01:00
Zidong Jiang df4064c18e Implement ecma_object_get_class_name for all ES2015 builtin object (#1617)
Fix issue #1613

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-02-27 09:12:31 +01:00
Zidong Jiang f1d43784f5 No other objects should be allocated before a typedarray is fully (#1619)
initialized.

All members of an object must be valid when the garbage collector runs,
so no allocations are allowed during typed array initialization.

Fix issue #1605
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-02-25 09:23:44 +08:00
Robert Sipka 21340e6b02 Rework address setup in WebSocket Debugger Client (#1612)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-24 13:45:33 +01:00
Zoltan Herczeg 62a581fbb8 Fix typo in vm_decode_branch_offset. (#1611)
Fixes #1597.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-22 14:38:52 +01:00
Zoltan Herczeg 8245cdef2f Stack data should be freed after the for statement is fully parsed. (#1609)
Fixes #1598.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-22 14:38:32 +01:00
Robert Sipka 2d93a24a14 Bugfix for JerryScript HTML (WebSocket) Debugger Client connection (#1610)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-22 12:36:44 +01:00
Robert Sipka 993f1ce896 Set available features from nuttx menuconfig (nuttx-stm32f4 target). (#1607)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-22 12:36:31 +01:00
Robert Sipka 39dc4a6273 Remove shadowed declarations, undefined identifiers, and specify argument types where it is required. (#1601)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-22 10:34:44 +01:00
László Langó 5ef305dfee Avoid using global statement (#1606)
Related issue: #1600

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-02-22 09:12:57 +01:00
Zoltan Herczeg 54544163a9 Completely remove internal property support. (#1603)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-22 10:39:48 +09:00
Levente Orban cc0f69613a Add debugger connection port setting to build script (#1599)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-02-21 15:39:22 +01:00
Robert Sipka 9043ec620d Add debugger support on nuttx-smt32f4 target (#1591)
Using jerry_parse_named_resource to parse script and construct an EcmaScript function.
The file name will also passed to this function which is used by the debugger to find
the source code.
Run the constructed EcmaScript function instead of using the simple jerry runner.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-21 15:22:48 +01:00
László Langó 92eaea2a8e Add pylint checker to the project (#1602)
* Added 'pylint' to dependencies
 * Added pylint config file
 * Added to travis CI as an allow failure job
   (until all of the warnings are fixed)
 * Added to 'run-test.py'

Related issue: #1600

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-02-21 12:40:33 +01:00
Zoltan Herczeg 00e3de230f Introduce debugger status flags to control the operation of the debugger. (#1596)
Two issues were fixed as well: inserting breakpoints before non-directive
prologue strings and the receive can process multiple messages.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-21 11:57:04 +01:00
Levente Orban 33138c09f5 Rework address setup (#1589)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-02-20 09:12:49 +01:00
Zoltan Herczeg b02ef67cd2 Add eval support for JerryScript debugger (#1588)
The server can accept a string, execute it with eval,
and returns with the result converted to string. In
case of exception it returns with the exception message.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-17 14:31:56 +01:00
Gabor Loki 6739463c1e Fix the missing inline specifier if compiling with -fPIC (#1590)
JerryScript-DCO-1.0-Signed-off-by: Gabor Loki loki@inf.u-szeged.hu
2017-02-17 12:41:01 +01:00
Zidong Jiang 4727202c8e Add typedarray routine:reverse (#1585)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-02-16 18:32:13 +01:00
Robert Sipka 188dc46fe0 Rewrite the generator script of unicode ranges. (#1583)
The script generates the source file instead of copy the tables and paste these manually.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-16 18:31:30 +01:00
László Langó 799726aa42 Add new input validator API functions (#1576)
Fixes #1549

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-02-16 18:31:04 +01:00
Zsolt Borbély 93eb35081f Add Debugger documentation to webpage-generator script (#1587)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-02-16 17:39:19 +01:00
Robert Sipka 68afd14f7c Add --start_debug_server cmdline argument to nuttx-stm32f4 target (#1586)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-16 14:19:51 +01:00
Robert Sipka fdd31f20b5 Add print_help function to nuttx-stm32f4 target (#1584)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-16 12:49:49 +01:00
Péter Gál 75d8226af3 Add jerryscript.h and mark jerry-api.h as deprecated (#1579)
Add a notification for JerryScript API users that the jerry-api.h
will be removed in the future and should use the jerryscript.h
header instead.

Also update the examples in the docs and the targets where
the jerry-api.h is used.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2017-02-16 08:46:08 +01:00
Zidong Jiang 64a340ffeb typedarray routine: filter (#1581)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-02-15 19:20:15 +01:00
Zsolt Borbély e09cdffc66 Add address- and undefined behavior sanitizer to Travis CI (#1580)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-02-15 19:19:42 +01:00
Robert Sipka 1b5f839db9 Improve toLowerCase and toUpperCase functions. (#1575)
Language-sensitive mappings are not processed now.

Fixes #323

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-02-15 15:57:55 +01:00
Levente Orban 025a99ccbb Initial version of JerryScript debugger (#1557)
The debugger supports setting breakpoints, execution control (step, next, continue)
and getting backtrace. The communication is WebSocket-based, so a browser can
communicate with JerryScript without any intermediate application.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2017-02-14 15:03:01 +01:00
Zoltan Herczeg 453066fcf1 Regexp exec should not use the empty magic string. (#1582)
This is a workaround for an ASAN issue and a small optimization as well.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-14 14:18:46 +01:00
Zoltan Herczeg 66683e5d4b The main-unix utility should free the return value to avoid leaks. (#1578)
Fixes #1545.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-14 10:09:51 +01:00
slaff 5101d932f7 Fix compilation errors when LCACHE is disabled. (#1570)
JerryScript-DCO-1.0-Signed-off-by: Slavey Karadzhov slaff@attachix.com
2017-02-13 13:14:50 +01:00
Zidong Jiang 24e6c3f062 Add typedarray routine: reduce and reduceRight (#1569)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-02-10 13:36:00 +01:00
László Langó 32674ff379 Documentation update (#1573)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-02-10 11:05:26 +01:00
Zoltan Herczeg bfc5bee394 Restore deleted lines. (#1574)
In a previous patch the original null count behaviour of the
property hashmap is just only partially restored. Now it is
restored fully Also another assertion was forgot to be fixed
in another patch, and we do so now.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-10 10:53:43 +01:00
Zoltan Herczeg be720b2238 Seperate NULL and unused values. (#1572)
Fixes #1552.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-10 08:10:20 +01:00
László Langó 638b753135 Fix CMakeLists.txt in jerry-main. (#1571)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-02-09 15:41:14 +01:00
Zidong Jiang 7b01b29ec8 Add typedarray routine: every, some, foreach, and map (#1566)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-02-09 08:49:00 +01:00
László Langó a976b0c061 Improve performance of GC sweep (#1568)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-02-08 14:58:54 +01:00
László Langó 348894e41f Enable 32bit compressed pointers on 64bit systems. (#1567)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-02-08 14:58:37 +01:00
Zsolt Borbély 510708ebd6 Function jmem_heap_get_region_end is unused when the system-allocator is enabled (#1565)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-02-07 11:43:31 +01:00
Zoltan Herczeg cba165f8e6 Fix invalid assertion in js-parser. (#1556) (#1563)
256 registers can be used so less equal must be used instead of less.

Fixes #1556.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-06 15:50:43 +01:00
Zoltan Herczeg caf9308288 Fix invalid assertion in vm_loop. (#1561)
Because of the fallthrough case the value of 3 is also allowed in the default case.

Fixes #1555.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-06 10:19:31 +01:00
Zoltan Herczeg 589f2dec92 String.match should return on error. (#1560)
Fixes #1546.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-03 15:16:49 +01:00
Zoltan Herczeg a43186db41 Stack data should be freed for do-while statements after the expression is parsed. (#1558)
Fixes #1550.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-03 11:43:36 +01:00
Paul Sokolovsky c9f3869a41 targets: zephyr: Follow Zephyr 1.7-pre on console refactors. (#1548)
JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2017-02-01 13:37:30 +01:00
Zsolt Borbély 77ab2c713e Append external libraries separately not as a string (#1553)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-02-01 08:47:58 +01:00
Zoltan Herczeg 32f130916f Test various spaces in JavaScript source code. (#1554)
Fixes #1551.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-02-01 08:47:26 +01:00
László Langó 107c058bb1 Add doxygen checker (#1540)
* Fixed Doxygen issues
 * Updated Doxygen config
 * Added new script to test whether doxygen generation was successful or not
 * Added to Travis CI

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-01-31 12:27:59 +01:00
László Langó 623975d19f Add testing of 'JERRY_CPOINTER_32BIT' option to Travis CI. (#1544)
Added a new 'buildoptions' option to tools/run-tests.py to add
a comma separated list of extra build options to each test.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-01-30 15:44:26 +01:00
László Langó 7b59c80e18 Use default system allocator on 32bit systems, if JERRY_SYSTEM_ALLOCATOR is defined. (#1541)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-01-30 11:04:25 +01:00
Zoltan Herczeg 0c3ef892c0 Rework property hashmap delete. (#1543)
Triggering hashmap recreate during property delete may damage the
property chain list, so recreate postponed after the delete is done.

Next attempt to fix #1533.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-01-27 15:31:27 +01:00
Zidong Jiang 0547b31c16 [ES2015][TypedArray] add other 8 types (#1532)
Add Uint8Array, Int16Array Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array and Uint8ClampedArray. Support the conversion between any pairs of those types.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-01-24 15:06:31 +01:00
Robert Sipka 124582793f Copy the characters of an UTF-8 encoded substring into a specified buffer (#1524)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-01-24 15:04:48 +01:00
László Langó 976c8aee80 Organize public and internal parts of memory management (#1539)
* Introduced new 'jmem.h' for public part.
 * Removed obsolete headers

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-01-24 12:36:53 +01:00
t-harvey f88d1a4863 These changes are designed to enable the TI compilers to compile (#1505)
Jerryscript.  The changes include:

CMakeLists.txt: we added conditionals around GCC-specific flags, added
support for TI flags, and removed the always-on debugging flag (-g)

/toolchain_mcu_tim4f.cmake: new toolchain file uses TI-specific parameters

jerry-api.h: the sys/types.h file was #include'd but never used, so we
removed it

jrt-types.h: ditto

jerry-port-default-date.c: the TI toolchain doesn't include
sys/time.h, so we guarded uses of the package

ecma-objects-general.c: added initialization that Travis (the
auto-checking tool) required

JerryScript-DCO-1.0-Signed-off-by: Timothy Harvey t-harvey@ti.com
2017-01-24 07:38:53 +01:00
t-harvey 94b6aae52c Added #if control around GCC built-in functions so that the code can be (#1483)
compiled using non-GCC compilers.

This included adding an initialization to a variable that looks(!)
like it can reach a use before being initialized (b/c we turned
JERRY_UNREACHABLE into a nop) -- an example:

int foo;
switch (value_can_only_be_one_or_two)
   case 1:
   case 2:
       foo = 5;
   default:
      JERRY_UNREACHABLE();
x = foo +1;

...the compiler assumes that the path can go through the default case,
which leaves the value of foo undefined.

JerryScript-DCO-1.0-Signed-off-by: Timothy Harvey t-harvey@ti.com
2017-01-23 12:19:35 +01:00
Zsolt Borbély 5d7972d053 Add missing argument of jerry_parse_and_save_snapshot in API reference (#1537)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-01-23 11:13:59 +01:00
Zoltan Herczeg 8b5d645df6 Track all NULL values in the property hashmap. (#1534)
There are two types of NULL values in the property hashmap: deleted
entries, and never used entries. The current implementation tracks
only the never used entries, and never scales back the hashmap.
After this patch property delete can also recreate the hashmap, or
remove it entirely if there are too few items in the array.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-01-19 11:34:24 +01:00
László Langó 6c708102d3 Minor fix in API reference (#1536)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-01-19 11:31:30 +01:00
Jan Jongboom ec14622cb1 target: mbedos5: Change to debug profiles (#1531)
In mbed OS 5.3 (which we target with JerryScript on mbed) we change the way debug builds are created. This patch changes the Makefile in JerryScript to reflect this.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2017-01-17 14:55:23 +01:00
László Langó 471ad284f6 Remove 'OBJECT_ID' from builtin headers. (#1529)
After 378d7f7 it is not used in the codebase and can be eliminated.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2017-01-17 08:58:46 +01:00
Zoltan Herczeg 4b5cf8ad26 HasInstance should accept the prototype of all functions. Fixes #1519. (#1520)
The regression-test-issue-736.js is also changed, since it expects
throwing an error, which does not happen anymore because the "x"
variable is undefined.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-01-16 13:43:54 +01:00
Geoff Gustafson 6e5b759319 Improve some wording in reference counting documentation (#1523)
JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson geoff@linux.intel.com
2017-01-16 09:59:30 +01:00
Paul Sokolovsky bd488e6efb targets: zephyr: Remove unused misc/shell.h header. (#1528)
It's also gone in Zephyr 1.7.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2017-01-16 09:25:39 +01:00
Paul Sokolovsky f1a80805c2 target: zephyr: Switch to MinSizeRel build type following mainline. (#1527)
Fixes #1526.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2017-01-16 09:24:31 +01:00
Zidong Jiang 4f3dc2f37c Update macro definitions in Curie-BSP target (#1525)
* add JERRY_JS_PARSER
* add CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
* add CONFIG_DISABLE_TYPEDARRAY_BUILTIN
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-01-16 09:22:15 +01:00
Robert Sipka 7139f0172a Copy the characters of a cesu-8 encoded substring into a specified buffer (#1516)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-01-13 13:27:07 +01:00
Zidong Jiang adfe61b4ed [ES2015 profile]add TypedArray intrinsic object (#1507)
* add %TypedArray% intrinsic object
* implement Int8Array
* will implement other types and prototype functions
in the following patches.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2017-01-13 11:04:34 +01:00
Jan Jongboom 177c30de78 target: mbedos5: Support for building on Windows (#1522)
This patch allows users to build for the mbedos5 target on Windows (normal
Windows and Cygwin). Also needs
https://github.com/ARMmbed/mbed-js-gulp/pull/14.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2017-01-13 09:57:38 +01:00
Robert Sipka c9afc2259d Refactor the ecma_string_substr function (#1517)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-01-13 09:22:55 +01:00
Zsolt Borbély f1ed5715e3 [API] Introduce jerry_parse_and_save_literals() (#1500)
This function can be used to save literals into a specific file in a list or C format.
These literals are valid identifiers, and doesn't match to any magic-string.
The '--save-literals-list-format FILE' and '--save-literals-c-format FILE'
options are used to save into the given file, when the snapshot-save is enabled.
The saved literals are sorted by size and lexicographically.
The C-format is useful for jerry_register_magic_strings() to generate the array
of external magic strings.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-01-11 14:18:09 +01:00
Zoltan Herczeg 7d83293762 Improve date helpers. (#1499)
Rework date to string conversion, and remove nan checks from inline
functions. Furtermore some inline functions are changed to normal
functions.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2017-01-11 08:27:29 +01:00
Jan Jongboom 00b220bde6 target: mbedos5: Sort magic strings (#1518)
Magic strings are expected to be sorted by length, then alphabetically after https://github.com/jerryscript-project/jerryscript/pull/1506 landed. This breaks the mbedos5 target against JerryScript master as it emits the pins in the order that it finds the pins. This patch sorts the pin names.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2017-01-11 08:26:40 +01:00
Zsolt Borbély eef6e57a4c Skip out license-check in case of test262 tests (#1504)
Can break testruns, when the test262 folder already present.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-01-09 09:44:40 +01:00
Zsolt Borbély 1c38c12531 [API] Improve the performance of the external magic id search (#1506)
After this patch, we have to provide external strings ordered by size and lexicographically.
We can do this with jerry_parse_and_save_literals() (#1500).

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-01-09 09:42:43 +01:00
Robert Sipka ff8ff982de Change the default build type to MinSizeRel. (#1513)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-01-09 09:14:21 +01:00
Robert Sipka 445ca1d6de Add jerry_string_to_utf8_char_buffer API function. (#1501)
Copy the characters of a string into a specified utf-8 string buffer.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-01-05 09:35:31 +01:00
Jan Jongboom 8ebbfda996 target: mbedos5: mbed CLI refuses to build if no .mbed file present (#1512)
With the newest release of mbed CLI (1.0.0) it error's when no .mbed file is present in the project root. This breaks builds for JerryScript on mbed OS 5. With this patch we create this file and builds succeed again. We cannot use `mbed new` because it also creates a new git repository in targets/mbedos5 folder which is not what we want.

Fixes #1511

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2017-01-05 08:42:19 +01:00
Akos Kiss 0026519040 Fix documentation errors (#1510)
Doxygen reported a few issues, which are fixed by this patch:
* ArrayBuffer-related documentation group names and titles were
  incorrect.
* Some Date-related helper functions used incorrect parameter
  documentation syntax.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-01-03 18:03:47 +01:00
Akos Kiss 3fa89baee0 Reduce scope of variable in JS lexer (#1509)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2017-01-03 17:59:52 +01:00
Zsolt Borbély 212f35c1f0 Fix test-api.c (#1503)
* Add missing feature-requirement for snapshot test
 * Fix wrong multiline alignments

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2017-01-03 05:39:55 +01:00
Kristof Kosztyo a3e9838728 Fix urls in the example (#1508)
The urls in the docs/03.API-EXAMPLE.md was pointing to
the old samsung.github.io pages.

JerryScript-DCO-1.0-Signed-off-by: Kristof Kosztyo kkristof@inf.u-szeged.hu
2017-01-02 11:32:58 +01:00
Robert Sipka 392f6d4a3b Modify the profile option to specify external compile definitions. (#1497)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-01-02 10:47:50 +01:00
Robert Sipka 080e78d7c2 Set memory heap size in the build script. (#1502)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2017-01-02 10:19:31 +01:00
Zoltan Herczeg 0c7d99e8e7 Reduce Math object binary size. (#1491)
Although many Math built-in functions have a similar structure
these code paths were implemented as separate C functions.
After this patch only one common dispatcher remains which shares
the common code paths of different built-in functions. This
reduces the binary size by 1 Kbyte.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-12-19 13:48:17 +01:00
Robert Sipka f2b17bca8b Warning fixes for Clang build. (#1490)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-19 09:47:42 +01:00
Tilmann Scheller 65c32f6a3b Add parameter names to function declarations. (#1498)
It's generally considered a bad programming practice to have function declarations without parameter names.

This is another legacy from the early days of the project. Fix in one go to minimize history disruption.

Used a custom clang-tidy check to create the bulk of the change.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-12-16 15:40:46 +01:00
Tilmann Scheller 1e99be90c3 Remove redundant extern keywords from function declarations/definitions. (#1495)
Extern keywords on function declarations/definitions provide no additional value since function declarations/definitions default to external linkage in C99, e.g. removing them won't change the semantics of the program.

The extern keywords were essentially a legacy from the early days of the project. This commit cleans this up across the whole codebase in one go to minimize history disruption.

The bulk of the changes in this commit were produced by a custom clang-tidy checker.

Note that variables declarations carrying the extern keyword are untouched by this commit since there the presence of the keyword actually has an impact on the semantics of the program.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-12-16 10:18:37 +01:00
Jan Jongboom defd97cc51 target: mbedos5: Update generate_pins.py to use the new Python API for querying targets, and use the new location of target PinNames.h file. Previously make source/pins.cpp just failed silently, and returned an empty file. Therefore using pin names from JS (LED1) would silently fail when building JerryScript against mbed OS 5.2.3. We missed this because it does not happen when you upgrade an existing mbed OS 5.1 project. Fixes #1493. (#1494)
JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2016-12-16 10:12:49 +01:00
Robert Sipka eec398181e Set PORT_DIR in the build script. (#1492)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-15 10:30:18 +01:00
Robert Sipka f3436840dd Build fix for STM32F4-Discovery board with NuttX. (#1489)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-13 15:12:55 +01:00
Zoltan Herczeg 7423226acc Reduce Date prototype binary size. (#1488)
Before this patch each built-in routine had a separate C
function. Although these functions shared a lot of common
operations compilers cannot eliminate these code duplications
in the final binary code. This patch introduces a single C
function which handles all date prototype routines. Each
shared code block has only one binary represenation.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-12-13 13:41:36 +01:00
Tilmann Scheller 58bcf12665 Add section about license headers and copyright notices to the Contribution Guidelines. (#1486)
Clarify that each contributed file needs to have a proper license header and that the addition of individual copyright notices is not permitted.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-12-13 11:17:47 +01:00
Robert Sipka ee93cb6320 Add JERRY_FEATURE_JS_PARSER to compile time enabled feature types. (#1487)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-13 10:05:59 +01:00
Zoltan Herczeg 6904b9bd65 Do not copy source string by JSON parser. (#1481)
The JSON parser required a zero terminated writable copy of
the original string. The requirement is eliminated from the
project to reduce peak memory consumption.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-12-13 08:36:01 +01:00
Jan Jongboom fb2818c137 target: mbedos5: Update to mbed OS 5.2.3 (#1468)
Update mbed OS target to latest version of mbed OS (5.2.3). Also rename all files in jerryscript-mbed-drivers/ to include -js.cpp, as our build tools now generate warnings for C++ files with the same name. mbed-events library is now mainlined, so no longer required to pull this library in as a separate dependency.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2016-12-13 08:34:38 +01:00
Jan Jongboom c079b577c8 target: mbedos5: Define JERRY_JS_PARSER macro, which is now required to be defined. Fixes build issues against mbedos5 target. (#1485)
JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2016-12-13 08:33:28 +01:00
Zidong Jiang 85b6e01bc2 Stop inlining the ArrayBuffer helper functions. (#1484)
Related issue #1468.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-12-12 20:07:51 +01:00
Robert Sipka e9ab1f14d3 Set js-parser feature in the build script. (#1482)
Renamed FEATURE_PARSER_DISABLE to FEATURE_JS_PARSER.
Fixed the build error that occurred in case of disabled js-parser.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-12 13:43:53 +01:00
Jan Jongboom 233b885ad8 target: mbedos5: Allow jerry_port_console and jerry_port_log to be overriden by user code (#1458)
We're building a REPL (as user-space program) on top of mbedos5 target. For this I need to override the jerry_port_console and jerry_port_log functions from the REPL. This commit wraps these functions in an ifndef, so we can define macros to not include these files.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2016-12-12 08:30:49 +01:00
Sergio Abraham Martinez Rodriguez db05d85a9a Add feature to remove parser. (#1476)
Remove the parser so we can save space if we are
only interested in running snapshots.

Removing the parser enables the snapshot execution.

JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez sergio.martinez.rodriguez@intel.com
2016-12-09 15:38:40 +01:00
Zidong Jiang 551aaa58e6 Fix unchecked size number conversion in ArrayBuffer (#1479)
Free_value after ecma_op_to_number and a related test file.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-12-09 14:54:34 +01:00
Robert Sipka 3ec395ff76 Create a minimal commandline tool to run benchmarks with it. (#1478)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-09 13:30:33 +01:00
Zoltan Herczeg 9d6ca800e1 Remove INSTANTIATED_MASK_32_63 internal property type. (#1474)
Furthermore the maximum number of properties is increased to 96.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-12-09 13:28:06 +01:00
Robert Sipka 4f8b7726d7 Check the compile time enabled feature via API function instead of check the MACRO is defined. (#1471)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-09 12:39:37 +01:00
Robert Sipka 9802130c71 Fix the order in cmake build settings/options and their status messages. (#1480)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-09 11:50:59 +01:00
Zidong Jiang fb2edd8556 Add ArrayBuffer regression tests (#1477)
Add a set of tests to ensure basic coverage of the ArrayBuffer built-in. Support for ArrayBuffer was added in #1467.

Closes #1475.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-12-09 08:04:49 +01:00
Tilmann Scheller 0511091e8a Streamline copyright notices across the codebase. (#1473)
Since the project is now hosted at the JS Foundation we can move to unified copyright notices for the project.

Starting with this commit all future contributions to the project should only carry the following copyright notice (except for third-party code which requires copyright information to be preserved):

"Copyright JS Foundation and other contributors, http://js.foundation" (without the quotes)

This avoids cluttering the codebase with contributor-specific copyright notices which have a higher maintenance overhead and tend to get outdated quickly. Also dropping the year from the copyright notices helps to avoid yearly code changes just to update the copyright notices.

Note that each contributor still retains full copyright ownership of his/her contributions and the respective authorship is tracked very accurately via Git.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-12-08 06:39:11 +01:00
Zidong Jiang 29d058cec4 Add ES2015 feature: ArrayBuffer (#1467)
This patch implements ArrayBuffer and ArrayBuffer.prototype built-in objects.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-12-07 14:04:01 +01:00
Robert Sipka eccfc1849e Bugfix: The unittest which test the API has failed in case of disabled error-messages (#1470)
and disabled snapshot_exec options.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-05 10:33:53 +01:00
LeeHayun bed094f74f Fixes the bug of ecma_date_make_day() (#1836) & ecma_date_week_day(). (#1466)
The ecma_date_make_day() handled any date in October on leap years incorrectly,
which was mentioned in issue #1836. The ecma_date_week_day() returned minus values
when return week_day before 1970 years which was also incorrect.

This change solves these bugs. In addition, this enhances the algorithm of accessing 'the ym-mn-1'
by replacing binary search to simple computation at ecma_date_make_day().

JerryScript-DCO-1.0-Signed-off-by: Hayun Lee lhy920806@gmail.com
2016-12-05 09:58:36 +01:00
Robert Sipka 4ef3c0caa8 Add API function to check if the specified feature is enabled. (#1465)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-05 09:26:02 +01:00
Robert Sipka 4c1fc7d789 Remove the restriction that the external magic strings must be ascii strings. (#1469)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-03 10:20:46 +01:00
Robert Sipka 23cf7fd177 Add an API function to calculate the UTF-8 encoded string length from Jerry string. (#1460)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-12-01 10:51:23 +01:00
Paul Sokolovsky 958344ee16 target: zephyr: Update to Zephyr 1.6 API. (#1462)
Zephyr 1.6 switched to "unified kernel API". Old API is supported, but
deprecated and leads to warnings.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2016-12-01 08:24:40 +01:00
Zsolt Borbély 7b2fc4f27a Remove leftover from main-unix.c (#1464)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-11-30 15:01:19 +01:00
Robert Sipka fb3e8cf8b8 Replace // double slash comments with /* */. (#1461)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-29 15:54:35 +01:00
Jan Jongboom 4d2c22a118 target: mbedos5: Add PwmOut and AnalogIn interfaces (#1455)
mbed OS 5 target is currently missing wrappers around PwmOut and AnalogIn interface, which are part of the standard library of mbed OS. This commit adds them. Tested with mbed CI test shield. I've followed the coding style in jerryscript-mbed, rather than JerryScript coding style.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2016-11-29 15:46:51 +01:00
Jan Jongboom 9c803672ff target: mbedos5: Add return value to setTimeout/setInterval and implement clearTimeout/clearInterval (#1457)
In the mbedos5 target the setTimeout and setInterval functions are not on spec, as they return 'undefined' instead of an event ID. Also clearTimeout and clearInterval are not implemented, so scheduled events cannot be canceled. This patch changes the behavior of the set* functions, and implements clear* functions.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2016-11-29 15:43:03 +01:00
Robert Sipka 0467239d03 Add an API function to calculate the UTF-8 encoded string size from Jerry string. (#1450)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-29 12:25:18 +01:00
Jan Jongboom 6a2f54456f target: mbedos5: Add carriage return in jerry_port_console (#1427)
Serial monitors (like screen on macOS / Linux) expect both CR and LF characters for new lines. Due to jerryscript only printing a line feed after calls to `print()` this makes log messages look wrong. This patch adds a CR when it encounters a LF character in jerry_port_console or jerry_port_log for the mbedos5 target.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom janjongboom@gmail.com
2016-11-28 13:11:31 +01:00
Zsolt Borbély 415ff37a8f Introduce jerry-snapshot.c for snapshot-related code (#1452)
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-11-28 13:11:06 +01:00
Zoltan Herczeg 25f58894ef Improve the performance of resolve reference. (#1453)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-11-28 13:10:49 +01:00
Zoltan Herczeg 6d67b8dff9 Reduce memory consumption of property names.
Property names were always required a string reference which consumed
a large amount of memory for arrays. This patch reduces this consumption
by directly storing the value part of certain strings.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-11-25 05:47:01 -08:00
Robert Sipka abaf4c8af8 Fix the calculation of the converted string length in ecma_new_ecma_string_from_utf8_converted_to_cesu8 function.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-25 14:15:55 +01:00
Tilmann Scheller 813a7020af Update various repository references across the project to be in sync with the new repository location. (#1448)
JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-11-25 10:34:22 +01:00
Tilmann Scheller 0d07b21d4b Update Travis CI status reference after repository move. (#1447)
Update URL to match the new repository location so the Travis CI badge will start working again.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-11-25 10:29:09 +01:00
Tilmann Scheller 83c39218f1 Update copyright notice in LICENSE and README. (#1446)
Update the LICENSE and README file to reflect that the project IP transfer from Samsung to the JS Foundation has been completed.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-11-25 09:39:16 +01:00
Robert Sipka b2e12233d0 Improve performance of search in the list of the magic strings. (#1441)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-24 09:16:16 +01:00
Robert Sipka 97303eb8e4 Add API documentation for jerry_create_string_from_utf8 and jerry_create_string_sz_from_utf8 functions. (#1444)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-24 08:12:09 +09:00
László Langó cf7b7a1090 Test 'test262' test suite on Travis CI (#1440)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-11-22 14:02:25 +01:00
László Langó 2622e938d8 Add missing error messages to 'ecma/builtin-objects' (#1443)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-11-22 14:01:59 +01:00
Zoltan Herczeg 132477f7d5 Change array length into a virtual property. (#1439)
This change allows easier access to array length which improves
the performance of inserting new items into an array and there
is no need to allocate length strings anymore. The trade-of is
that array length cannot be cached anymore.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-11-22 13:29:53 +01:00
László Langó 4a0f78bc4b Fix fopen call on non-existing files. (#1442)
The main implementation of unix platform hangs, if the engine was
built with jerry-libc. Open system call returns with a negative
error code if cannot open the file, but fopen must return NULL
when error happens.

Fixes #1437.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-11-21 11:28:07 +01:00
Kumar Gala 6ac0a39519 target: zephyr: Allow parallel build of Zephyr (#1436)
If we are building JerryScript from some other makefile that passes
down a -j option to make we should respect that when we build Zephyr.

JerryScript-DCO-1.0-Signed-off-by: Kumar Gala kumar.gala@linaro.org
2016-11-18 08:19:21 +01:00
Zoltan Herczeg 7131243dda Simplify ecma_property_types_t. (#1438)
Free a new bit in the property descriptor by combining internal
and special property types into one group. Also simplify checking
special properties since bit-and operation is not needed anymore.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-11-17 13:26:02 +01:00
László Langó b2fec888d4 Fix handling of return value of 'jerry_set_property call' in main-unix. (#1435)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-11-17 10:49:45 +01:00
László Langó 503ca7e54a Remove unused test file. (#1433)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-11-17 10:49:34 +01:00
Robert Sipka ffaca583f3 Add API functions to create string from a valid UTF-8 string. (#1430)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-16 10:34:12 +01:00
Istvan Kadar 405092e700 Prop hashmap allocation strategy based on gc pattern is implemented. (#1429)
The algorithm is the following:
* introduced a counter variable, which value can be [0-4]
* if its value is 0, property hashmap allocation is enabled
* JMEM_FREE_UNUSED_MEMORY_SEVERITY_LOW -> decrease the counter
* JMEM_FREE_UNUSED_MEMORY_SEVERITY_HIGH -> increase the number
* if JMEM_FREE_UNUSED_MEMORY_SEVERITY_HIGH happens twice in a row increase the counter to 4

According to the measurements this algorithm provides better runtime results in low memory conditions.

JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
2016-11-16 08:32:45 +01:00
Robert Sipka e443d95566 Add case insensitive argparse choices. (#1431)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-15 09:57:08 +01:00
Robert Sipka bf6cccf61c Extend the escape sequences test by verifying character codes. (#1428)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-14 13:22:38 +01:00
Robert Sipka dc5ae4638f Since glibc 2.20, the _BSD_SOURCE macro is deprecated. (#1425)
It now has the same effect as defining _DEFAULT_SOURCE, but generates a
compile-time warning (unless _DEFAULT_SOURCE is also defined). To allow
code that requires _BSD_SOURCE in glibc 2.19 and earlier and _DEFAULT_SOURCE
in glibc 2.20 and later to compile without warnings, define both _BSD_SOURCE and _DEFAULT_SOURCE.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-11-11 12:09:51 +01:00
Zoltan Herczeg 9f556e1c38 All strings whose are valid array indicies always use the UINT32_IN_DESC format. (#1422)
This patch reduces memory consumption for strings such as "0" or "123"
by 8 bytes and "4294967295" by 16 bytes. The hash computation is changed
for using the lower 16 bits for these strings which is much faster than
converting the value to string first and compute the hash. The trade-of
is a small overhead when strings are created or concatenated.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-11-07 15:37:36 +01:00
Zsolt Borbély 4c5ff4ad27 Webpage-related fixes (#1420)
* Fix webpage-generator script
   - Generate 'site.github.url' instead of 'site.baseurl' (#1248)
   - Include 'Reference counting' documentation
 * Remove trailing whitespaces from 05.PORT-API.md

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-11-07 17:18:12 +09:00
Levente Orban 8466b04187 Add how to install the modules (#1416)
JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
2016-11-03 10:42:10 +01:00
Akos Kiss b31074cc6b Ensure that Math.random() really covers [0,1) interval (#1417)
Legacy implementation made incorrect assumptions on how many bits
of useful information is returned by libc's `rand()`. If `RAND_MAX`
had more than 16 useful bits, it assumed that `rand()` could return
32 useful random bits. However, e.g., jerry-libc's `RAND_MAX` is
`0x7fffffff`, which denotes 31 useful bits only. The consequence
was that `Math.random()` covered only the lower half of the
standard-mandated `[0,1)` interval.

This path fixes the error and always uses the exact value of
`RAND_MAX` to compute the random value, which will thus fully cover
`[0,1)`.

Fixes #1414

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-11-01 15:43:16 +01:00
Daniel Thompson 36edae3257 target: zephyr: Cause pristine to remove entire build directory (#1418)
For a normal zephyr application the pristine target simply runs
"rm -rf outdir". However the JerryScript build overrides the output
directory [O=$(OUTPUT)] so Zephyr's implementation pristine is not able
to to a full aggressive clean up for all boards.

For this reason it is better for the JerryScript build wrapper to have
its own implementation of pristine.

JerryScript-DCO-1.0-Signed-off-by: Daniel Thompson daniel.thompson@linaro.org
2016-11-01 15:29:20 +01:00
Daniel Thompson e65a69b7c0 target: zephyr: Fix build when USE_CCACHE=1 (#1413)
Currently if USE_CCACHE=1 is set to one than the Zephyr build system
will include ccache in the CC variable. ccache cannot be passed to
cmake using EXTERNAL_CMAKE_C_COMPILER (even if we fix the quoting)
because it fails a PATH reachability test within cmake. For that
reasons we solve the build failure simply by removing ccahce from CC
before we pass it into cmake.

The problem described about is a regression due to commit ac1bf19c90
("build: Adopt outputexports") and the fix contained in this patch
restores the original behaviour (zephyr exploits ccache, jerryscript
library build does not).

JerryScript-DCO-1.0-Signed-off-by: Daniel Thompson daniel.thompson@linaro.org
2016-10-31 13:59:49 +01:00
Istvan Kadar ff6b3a9b02 Issue #1389 fixed in parser_compute_indicies by resolving local variable hiding. (#1410)
JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
2016-10-28 14:56:13 +02:00
Zoltan Herczeg ec4f4e6fdb Add an overview about reference counting. (#1412)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-10-28 13:25:47 +02:00
Paul Sokolovsky 5e02b7136a zephyr: Revamp jerry-port.c, add more functions. (#1411)
The file was named jerry-entry.c and not even built. Rename for clarity,
and add jerry_port_fatal(), jerry_port_get_current_time(),
jerry_port_get_time_zone() functions. User-visible result is that
if Date builtin is enabled (e.g. if building "full" config, its
Date.now() method can be used to measure relative time difference,
e.g. for benchmarking).

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2016-10-27 14:23:37 +02:00
Robert Sipka a02c586a51 Bugfix for string replace. (#1409)
Some test cases were failed with enabled show-opcodes build option.

Example source:
    "98765".replace(76)
    print ("\ud801\udc00".replace("\ud801", "#") === "#\udc00");

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-10-27 12:47:54 +02:00
László Langó a30b89c536 Improve Js2C converter (#1408)
* Rename 'jerry_targetjs.h' to 'jerry-targetjs.h',
   because we use dashes in filen ames instead of underscores.
 * Made destination and js souce directory configurable.
 * Updated esp8266 target to the recent changes.
 * Updated mbed and mbedos5 target to the recent changes.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-10-27 09:54:01 +02:00
Daniel Thompson ac1bf19c90 build: Adopt outputexports (#1407)
This patch simplifies the integration with the zephyr build system
whilst at the same time enriching the set of build targets to allow
zephyr to be configured using its kbuild features.

It works by exploiting "make outputexports", a feature of the zephyr
build system that makes the zephyr compiler configuration available to
other build systems in an easily accessible manner.

Whilst looking at the build we also correct the implementation of clean
so that it no longer destroys any custom zephyr configuration. Like any
other zephyr application one must use "make pristine" to remove the
config too.

JerryScript-DCO-1.0-Signed-off-by: Daniel Thompson daniel.thompson@linaro.org
2016-10-26 09:01:34 +02:00
Zoltan Herczeg 945fbef110 Rework function.bind (#1406)
The new code does not use value collections which reduces the argument array size by half.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-10-25 13:15:14 +02:00
László Langó dc1e26933f Print source code with a given context when a parse error happens (#1403)
Example source:
  var s = "hello";
  if (s)
    a[,] = s;

Output:
  var s = "hello";
  if (s)
    a[,] = s;
  ~~~~^
  Script Error: SyntaxError: Primary expression expected. [line: 3, column: 5]

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-10-25 13:13:20 +02:00
Zoltan Herczeg c8f2747209 Rework arguments object. (#1401)
Instead of allocating a helper object, argument names are appended right
after the arguments objects. This reduces memory consumption and improve
performance as well. In the future this could be further improved by a
bitfield, but that would require a reference to the byte code which
might increase memory consumption in a few corner cases.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-10-21 18:58:42 +09:00
László Langó 3e0d3e588f Add error messages to VM. (#1405)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-10-21 18:55:08 +09:00
Paul Sokolovsky fdf9e71caa target: zephyr: Make "OUTPUT" varible match Zephyr's "O" variable. (#1404)
JerryScript Zephyr port overrides standard Zephyr output location. But
components integrating Zephyr port may want to override it again. Make
sure that arbitrary overrides are possible, and just set the default
value to Zephyr port's custom preference.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
2016-10-21 11:52:19 +02:00
Robert Sipka b9f540fc90 Change the return type of 'vm_init_loop' function to void. (#1402)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-10-20 21:03:15 +09:00
Robert Sipka 922782109b Fix for Issue #1387. (#1397)
Check the return value of 'ecma_op_put_value_lex_env_base' function.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-10-20 09:13:11 +02:00
László Langó 28b4d3cb58 Remove trash from main-unix (#1400)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-10-20 15:48:56 +09:00
Zoltan Herczeg fd98d649b6 Remove several internal property types for primitive objects. (#1399)
Class and value internal properties are always exists for primitive
types (e.g. Boolean, Regex) so they can be stored right after the
object. This improve property access (since internal properties are
searched by a slow linear algorithm) and reduces memory consumption,
since only 8 byte is allocated for these two properties instead of
16 which is the size of a property pair.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-10-19 15:36:15 +02:00
slaff 2ef89eafbf Added console message implementation for ESP8266. (#1398)
JerryScript-DCO-1.0-Signed-off-by: Slavey Karadzhov slaff@attachix.com
2016-10-19 12:56:09 +02:00
Zoltan Herczeg 3ce48be152 Improve array length setting. (#1393)
The new set does not allocate memory when the size of the array is reduced.
Furthermore the [[PutObject]] method directly calls the new length setter.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-10-19 16:45:17 +09:00
László Langó a130059c8b Add error messages to ecam/operations. (#1396)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-10-19 09:37:51 +09:00
Zoltan Herczeg 6af70e5899 Change string length into a virtual property. (#1395)
Reduces the memory consumption of String objects.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-10-18 11:11:00 +02:00
Robert Sipka e8428383f1 Use 'ecma_make_boolean_value' where possible. (#1394)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-10-18 09:12:05 +02:00
Robert Sipka 42be0704b9 Added target to compile JerryScript beside Particle Device Firmware on Photon board. (#1391)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-10-17 20:54:08 +09:00
Sergio Abraham Martinez Rodriguez 535743412e [zephyr] Removed factory setting deprecated on zephyr (#1390)
The new zephyr build system doesn't support the arduino_101_factory
board.

This change restores the default BOARD to arduino_101 which
is the current recommended method.

If you are in an older SDK / Zephyr you can still use.

`make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory`

JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez sergio.martinez.rodriguez@intel.com
2016-10-10 08:40:58 +02:00
Akos Kiss 9915307bc0 Drop -gdwarf-4 from compiler flags (#1385)
`-g` is enough (most modern compilers use DWARF4 as default, at
least, e.g., GCC has switched from DWARF2 in 4.8), more future
proof (if a compiler moves to a newer version, it wont get forced
to a fixed older version), and less restrictive (some compilers
handle the "standard" `-g` only but don't understand its variants).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-10-04 11:51:03 +02:00
Akos Kiss 37c28f694a Undef VALGRIND_*_SPACE macros at the end of sources (#1382)
Defining the same macros in multiple source files can cause macro
re-definition warnings or errors in all-in-one builds.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-30 09:03:25 +02:00
Akos Kiss e16cc83ce7 Simplify the way libgcc is linked (#1380)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-30 09:02:42 +02:00
Daniel Thompson 8320a2cbc9 target: zephyr: Include toolchain headers using -isystem (#1381)
Currently the zephyr port fails to build with some cross-toolsets because
warnings from the system headers are being treated as errors. Using
-isystem for any includes in TOOLCHAIN_CFLAGS allows us to crank up the
warning levels without worrying about newlib headers breaking the build.

JerryScript-DCO-1.0-Signed-off-by: Daniel Thompson daniel.thompson@linaro.org
2016-09-30 07:45:50 +02:00
Daniel Thompson 7584ce26c2 target: zephyr: Select compile options by ARCH rather than BOARD (#1374)
Currently we need to modify the JerryScript Makefiles for every new
board we want to work with. It is better to study the zephyr configuration
and used the CONFIG_ options to determine the right compiler flags.

We expose the CONFIG_ options to make by adding machinary to the makefiles
to import the Zephyr .config file, allow us to make the decisions we
need.

JerryScript-DCO-1.0-Signed-off-by: Daniel Thompson daniel.thompson@linaro.org
2016-09-29 23:34:13 +02:00
Akos Kiss 509407bfd4 Update jerry-libc unreachable asserts (#1379)
Newer compilers (especially clang) warn (and fail) on
`assert (!"message");` constructs typically used to assert on
unreachable code paths (multiple occurrences in jerry-libc). A more
up-to-date approach is to use `assert (false && "message");`. This
patch applies the pattern to all relevant asserts in jerry-libc.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-29 16:17:46 +02:00
Akos Kiss e2aa714565 Improve the stdin handling of the command line tool (#1378)
This patch improves the command line tool in two ways:
* The tool can be instructed to read and execute a script from
  stdin by invoking it as `jerry -`.
* The tool can be instructed to suppress its prompt when in repl
  mode by invoking it as `jerry --no-prompt`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-28 14:14:05 +02:00
Akos Kiss 9b5d0cc7ec Add IRC notification to Travis CI configuration (#1376)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-26 16:07:29 +02:00
Akos Kiss e67078f5ca Revoke exec permission from non-scripts (#1377)
Several non-script files have been added with exec permission to
the repository. This patch revokes the erroneous permissions.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-26 08:27:29 +02:00
Zoltan Herczeg 0ad347b97f Improve define own property. (#1369)
This patch changes define own property to search a property only once.
Currently all existing properties are searched at least twice, sometimes
three times which is not optimal.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-09-23 10:06:36 +02:00
chokobole 547647af13 Type cast according to format string (#1368)
JerryScript-DCO-1.0-Signed-off-by: wonyong.kim wonyong.kim@samsung.com
2016-09-23 09:47:13 +02:00
Akos Kiss 40bed0f963 Fix compiler warnings in unit tests (#1373)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-22 15:48:14 +02:00
Akos Kiss e4f27199d7 Echo executed test commands in run-tests.py (#1372)
run-tests.py used to echo the build commands it executed, but did
not behave the same way when it executed test commands. To make its
behavior more traceable, this patch adds echo for test commands as
well.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-22 08:51:59 +02:00
Akos Kiss ee2e159ad6 Switch cppcheck to C99 mode (#1371)
From the beginning, we have been configuring cppcheck to check its
input as C++ source. However, the transition to C99 happened a
while ago. This patch switches cppcheck into C99 mode.

Some related changes:
* Progress reporting of cppcheck just clutters the output and makes
  warnings hard to discover. Thus, this patch puts cppcheck into a
  quieter mode where it prints anything only if a non-suppressed
  warning is found.
* The default warning format of cppcheck is a bit different from
  usual compiler error/warning format. This patch configures
  cppcheck to use a more familiar warning template.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-21 18:41:44 +02:00
Akos Kiss 70cd3d3184 Add license checking (#1353)
It's stated in the Guidelines that all contributions must be under
the Apache License 2.0. To avoid potential mistakes from manual
reviews, this patch adds the check-license.py script to
automatically check all source files for license headers.

Travis CI is also configured to run the check.

Fallout: it turned out that some files already in the code base
either miss a license header or have some minor typo differences.
The patch fixes up some of these deficiences.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-21 16:15:57 +02:00
Matthew Else 454d3af951 Initial support for mbed OS 5.1 (#1318)
- Wrappers for mbed I/O drivers
- Makefile for automating build process
- Script to generate pin definitions from mbed OS source tree
- Updates to js2c to enable building without a main.js file

JerryScript-DCO-1.0-Signed-off-by: Matthew Else Matthew.Else@arm.com
2016-09-21 15:48:03 +02:00
Akos Kiss 316223ebdb Fix doxygen-related documentation issues (#1357)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-21 10:43:40 +02:00
Akos Kiss 2300a68c88 Unify (and fix) the naming convention of structures (#1358)
The naming convention of the project for `struct`s is
`typedef struct x_t { } x_t`, but only if it has self-recursive
pointer members, otherwise `typedef struct { } x_t` is enough.
This patch applies this style consistently throughout the code
base.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-21 10:41:36 +02:00
Akos Kiss 513d9f4c9c Sync cmake and build.py defaults (#1360)
* Cmake had LTO OFF, build.py had LTO ON by default. ON became the
  common setting.
* Cmake had snapshot save/exec OFF, build.py had them ON by
  default. OFF became the common setting.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-20 16:20:48 +02:00
zherczeg 8b55a4ef7b Rewrite ecma_op_get_value_object_base to use ecma_op_object_find_own() call. (#1365)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-09-20 13:33:57 +02:00
Yanhui Shen a9d6978e4b Fixing ecma_builtin_number_prototype_helper_round. (#1362)
"ecma_builtin_number_prototype_helper_round" is used by following
functions:
* ecma_builtin_number_prototype_object_to_fixed
* ecma_builtin_number_prototype_object_to_exponential
* ecma_builtin_number_prototype_object_to_precision

The current implementation does not support currying numbers and will
produce illegal digit for some test cases. For example, the result of
"0.95.toFixed(1)" is "0.:".

This patch fixs the issue, however the implementation of "toFixed" is
still problematic, at least not meet section 15.7.4.5 8.a of the
specification. The related test case is:

* assert((0.995).toFixed(2) === "0.99");
* assert((9.995).toFixed(2) === "9.99");

Reference:
* http://www.ecma-international.org/ecma-262/5.1/#sec-15.7.4.5

JerryScript-DCO-1.0-Signed-off-by: Yanhui Shen shen.elf@gmail.com
2016-09-20 13:13:50 +02:00
Zidong Jiang 7b7d86f5fd Remove the vm_run_with_inline. (#1363)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-09-20 13:11:53 +02:00
zherczeg 9ab72d24b7 Improve ECMA_PROPERTY_VALUE_PTR computation. (#1364)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-09-20 12:50:53 +02:00
Akos Kiss 971dcae669 Define __attr_hot___ for __attribute__((hot)) (#1359)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-19 15:33:54 +02:00
Zoltan Herczeg dcaec22c0c Major property rework: introducing virtual properties.
Properties are changed to a type and value pair instead of a pointer to an internal
representation. Functions such as ecma_op_object_get_[own_]property do not
return with property pointers anymore.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-09-19 00:32:38 -07:00
Tilmann Scheller ea96430e77 Add contribution guidelines and DCO. (#1348)
The current content in CONTRIBUTING.md is largely based on the "Patch Submission Process" Wiki page.

This commit also moves the DCO from the Wiki into the source tree.

In addition, clarify in README.md that contributions need to be licensed under the Apache License 2.0 and signed with the DCO.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-09-16 15:50:56 +02:00
Akos Kiss d38ab71140 Improve the linking of libraries (#1338)
Although both jerry-libc and jerry-libm have configuration options
that enable/disable their build, in practice, only jerry-libc can be
replaced with the system (compiler-default) libc. If jerry-libm is
disabled, the build of jerry-main fails, as there is no way to
instruct the linker to link the system libm to the binary. (The
build system does have a way to pass flags to the linker, but those
flags are listed before the linked objects. For the references to
get resolved correctly, the libraries to be linked have to be
specified _after_ the objects.)

This patch adds the EXTERNAL_LINK_LIBS configuration option to
CMakeLists, which ensures that the specified libraries get
correctly passed to the linker. (E.g, replacing jerry-libm with
system libm becomes possible with
`JERRY_LIBM=OFF EXTERNAL_LINK_LIBS='-lm'`.)

Additionally, the patch also makes the following related changes:

* Removes the COMPILER_DEFAULT_LIBC configuration option, as it is
  (almost) always the opposite of JERRY_LIBC. Moreover, its name is
  misleading: its only role is to add `-nostdlib` to the linker
  flags.

* Makes use of transitive library dependencies: if a library has
  another library as dependency, and it is linked to a binary, its
  dependency is linked as well. Thus, jerry-libc, jerry-libm, and
  any external libraries are added to jerry-core as dependency, and
  then only jerry-core is linked to executables (cmake will take
  care of the rest).

* build.py and run-tests.py follow up the changes, along with some
  minor syntax changes.

* Moves static linking option to global CMakeLists, as unit test
  binaries should be linked the same way as jerry-main.

* Adds EXTERNAL_COMPILER_FLAGS and EXTERNAL_LINKER_FLAGS as last to
  the flag list, to allow user override of (nearly) anything.

The patch speculatively follows up the build system changes in the
mbed, riot-stm32f4, and zephyr targets.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-15 13:07:01 +02:00
Zidong Jiang 86ac6445e8 Fix bug in vm call_stack_size calculation (#1345)
call_stack_size should be register_count + maximum stack depth

* We don't add in the parser to save the size of snapshot header
* jerry_snapshot_version 5 -> 6

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-09-15 09:54:01 +02:00
Akos Kiss 9c50570ca3 Install ARM QEMU and GCC toolchain on Travis CI only if needed (#1350)
(Also some reorganization of the .travis.yml file.)

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-14 14:44:39 +02:00
Akos Kiss 697037af3f Remove obsolete dependencies from install scripts (#1349)
The new build script does not support ninja anymore, and we haven't
been building bare-metal arm targets for long. This patch removes
now-obsolete dependencies from install scripts.

This can also help to reduce the load on Travis CI (as it keeps
installing dependencies for each build job over and over again).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-14 11:02:44 +02:00
Tilmann Scheller a507c0863c Add a full copy of the Apache License 2.0 text to the project. (#1346)
Previously only a copy of the Apache License 2.0 header (for inclusion into source files) was distributed as part of the sources.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-09-13 16:22:42 +02:00
Yanhui Shen 15c53f7363 Fix getter's this value (#1344)
JerryScript-DCO-1.0-Signed-off-by: Yanhui Shen shen.elf@gmail.com
2016-09-13 08:53:26 +02:00
Akos Kiss baeb83db8f Move Travis CI detection logic from run-tests.py to check-signed-off.sh (#1341)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-12 15:11:14 +02:00
Zoltan Herczeg d9979be2f6 Rewrite property get/put to not use ecma_op_object_get_own_property
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-09-12 03:33:22 -07:00
Robert Sipka 0bc7840c5f Set the number of simultaneous jobs of the build. (#1336)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-09-12 09:20:24 +02:00
Akos Kiss 2e1c180658 Enable make install (#1335)
With the new build system, the conventional `cmake && make` already
works. However, the last step, i.e., `make install` was still
missing (didn't work). This patch adds the `install()` commands to
CMakeLists that are required to generate the `install` target in
the Makefile.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-09 13:32:36 +02:00
Zoltan Herczeg da02a37a02 Remove several ecma_op_object_get_[own_]property calls.
The ecma_op_object_get_[own_]property calls should be phased out from
the project eventually and virtual properties should be introduced instead.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-09-09 01:49:57 -07:00
Akos Kiss 7f80b76009 Make build.py's help output less of a "wall of text" (#1331)
`tools/build.py --help` prints a lot of output, which is sometimes
hard to comprehend, especially since some described options are
useful for developers only.

This patch:
* shortens how options are displayed in the output with the help of
  the "metavar" feature of the argparse module ("--option {on, off}"
  becomes "--option X" and the choices are listed in the description
  only); and
* hides all developer-specific options from "--help", and reveals
  them only for "--devhelp".

As a result, help output becomes more readable, especially for
ordinary users, and needs less space.

Some additional changes:
* the options are ordered in a more logical way (although that's
  somewhat subjective);
* help strings start with lowercase letters (it aligns better with
  argparse's overall style); and
* rename "--cpointer_32_bit" to "--cpointer-32bit" (underscores are
  alien to command line options).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-09 10:44:08 +02:00
Akos Kiss 2eb0c5ba1b Print warning at the correct log level in jerry-main (#1334)
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-09 09:00:28 +02:00
robertsipka dc83e995d2 Fix for Issue #744
Don't increment the current position in case of a continuation byte.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-09-08 14:05:14 +02:00
Sergio Abraham Martinez Rodriguez c61e822a45 Specify profile and be able to add extra parameters to configuration (#1333)
Also added jerryscript errors to default compilation

JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez sergio.martinez.rodriguez@intel.com
2016-09-08 13:04:35 +02:00
László Langó 5c330d7f8e Improve error messages
* Print location on parser errors.
 * Do not print messages on parse error if FEATURE_ERROR_MESSAGES is not set.
 * Minor style fixes

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-09-08 10:20:13 +02:00
László Langó cf94a25753 Change JERRY_ASSERT to TEST_ASSERT in unittests
JERRY_ASSERT does not check the condition in release builds.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-09-08 08:16:16 +02:00
Akos Kiss 7872f8145a Make jerry-main's link options configurable (#1328)
Until now,
* the link map of jerry-main has always been generated, even though
  it is not used that often;
* static linking has always been forced except for the OSX target.

This patch adds configuration options for these features.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-07 15:54:06 +02:00
Akos Kiss 8d478c142b Add tolerant mode to Signed-off-by check (#1322)
In tolerant mode, only the existence of the Signed-off-by line is
checked but the name and address is not matched against the author
of the commit.

The tools/run-tests.py script is extended to allow calling the
check script in tolerant mode and also to detect whether it is
being run by Travis CI.

The Travis CI config has been modified to check PRs in strict mode
but use tolerant mode for merges to master. This should enable the
use of the Merge button on the GitHub web interface. (The PR is
strictly checked when a contributor opens it but when a committer
merges it via the web interface and GitHub rewrites author details
from the contributor's profile, master will not turn red either.)

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-07 12:28:29 +02:00
Akos Kiss 714e8d261b Add git commit hash to jerry version info
Previously, jerry-core was built with various build identification
info (build date, git commit hash, git branch name), which was both
available from string constants of the library and also exposed by
jerry-main via the `--version` command line option. As of late,
jerry-core identifies itself only with API version number macros,
but sometimes it could be helpful to get access to the git commit
hash as well, even if that info does not become part of the API.

This patch moves the git commit hash retrieval logic from the build
scripts of jerry-core to jerry-main, and changes `--version` handler
to print the hash as well.

Resolves #1295

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-07 11:14:40 +02:00
Akos Kiss ebbacfc319 Make tools/settings.py lighter (#1327)
It should not import things it does not use and it should define
settings data only (i.e., definition of functions should not happen
there).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-07 08:29:06 +02:00
Robert Sipka caee6f738e Fix -Wsign-conversion Clang warning.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-09-06 15:56:41 +02:00
Zidong Jiang 27deda5712 remove the alloca.h because of #1294
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-09-06 12:07:31 +08:00
Robert Sipka 2314bc2770 Add the 'jerry-libm/include' path to specified include directories to jerry-core target
in case of enabled jerry-libm build.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-09-02 09:40:12 +02:00
Zsolt Borbély 6f262aea49 Include Port API documentation to webpage-generator script
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-09-01 16:08:53 +02:00
Akos Kiss 228f6f75f0 Fix warnings reported on OS X (#1307)
OS X build regularly reports some 39 warnings falling in 3 major
categories:

* "static function '...' is used in an inline function with
  external linkage [-Wstatic-in-inline]": Some semantics around
  `inline` have changed between C89 and C99, and gcc and clang seem
  to disagree on how strict they should be about them. Solution
  chosen is to use `-Wnostatic-in-inline` command line option for
  clang.

* "implicit conversion turns floating-point number into integer:
  'double' to 'bool' [-Wfloat-conversion]": `if (fmod (..., ...))`
  was used at different places, which is not nice anyway, thus the
  return value is compared explicitly against `ECMA_NUMBER_ZERO`.

* "format string is not a string literal [-Wformat-nonliteral]":
  Console and log port I/O functions have a printf-like interface,
  and the default implementations actually pass both format string
  and the remaining arguments to a vfprintf. However, clang is
  strict about the format string parameter of vfprintf and expects
  a literal there. By annotating the port I/O functions with
  `__attribute__ ((format (printf, ..., ...)))`, clang will check
  the format string being a literal string earlier, when the port
  functions are called, and will not complain within them when
  vfprintf is called.
  (Actually, this has revealed an incorrect format string, which
  has been fixed as well.)

(There were also some single conversion errors not listed above.)

The patch was tested on OS X (where all warnings disappeared), but
it should help clang compilation on other OS's as well.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-09-01 15:16:02 +02:00
László Langó 2a354b25a8 Add documentation to port API
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-09-01 14:32:31 +02:00
Zoltan Herczeg da47dedaed Add 32 bit compressed pointer support.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-09-01 04:16:54 -07:00
Zsolt Borbély 9ca78d380f [nuttx-stm32f4] Fix jerry_port_log function
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-09-01 12:51:27 +02:00
Youngil Choi 2c78ee7f54 FunctionExpression name binding should be immutable
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2016-09-01 14:50:26 +09:00
Youngil Choi 260b967853 SplitMatch operation should not set its return array element with [[Put]]
Related issue: #1076

JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2016-09-01 11:05:07 +09:00
Sergio Martinez 1ab45a1a2f Remove problems with gettimeofday, newlibc and zephyr SDK
Fix Zephyr build

With the changes to the zephyr sdk, gettimeofday is being guarded
by XOPEN_SOURCE_EXTENDED which requires at least 700 on XOPEN_SOURCE to be active

This little patch also helps on removing most of the warnings we had before
related to that issue.

More info on this feature:
http://man7.org/linux/man-pages/man7/feature_test_macros.7.html

Another option was to enable _GNU_SOURCE for this port.

There are still some harmless warnings related to __sputc_r for which we still require
the convertion warning.

Tested on qemu_cortex_m3, qemu_x86, arduino_101 and frdm_k64f.
Zephyr Sdk 0.8.2, Zephyr 1.5.0-rc4 & Zephyr ec39b216

Closes #1311.

JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez sergio.martinez.rodriguez@intel.com
2016-08-31 17:13:45 +02:00
István Kádár 6666927799 All-in-one build friendly jerry-libm.
Define constants are undefined at the end of the corresponding files of jerry-libm supporting all-in-one build.

JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
2016-08-31 16:28:54 +02:00
Zoltan Herczeg 548b3b98c2 Change return value to ecma_value_t for getting internal properties.
Removing a lot of ECMA_PROPERTY_VALUE_PTR macro calls. The only drawback
is free callbacks for native objects cannot be deleted anymore. Redefining
a free callback is a rare case, so this trade-of is acceptable.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-08-31 06:13:00 -07:00
Youngil Choi bfbe1821b5 vm_op_set_value should be able to throw error when ecma_op_to_string throws
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2016-08-31 21:06:54 +09:00
Peter Gal 17d1d37cca Improve the Curie build file generator a bit
Works with python 2 and 3.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
2016-08-31 11:35:21 +02:00
Zsolt Borbély 18f9308cd6 Minor stylefix for targets/nuttx-stm32f4/README.md
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-08-31 09:47:30 +02:00
Akos Kiss da7abc55f9 Disallow failures of Travis CI jobs on OS X
Related issue: #1296

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-08-30 16:36:04 +02:00
Akos Kiss 7f6911103f Update the prerequisites documentation
* Split list into two: what is needed for building and what is
  needed for development only.
* Remove g++ from install list.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-08-30 10:19:14 +02:00
Youngil Choi 9f65b76013 Fix bug in for-in bytecode replacement
JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
2016-08-30 16:57:49 +09:00
Akos Kiss a6d2e792f8 Improve the build system
* Remove JERRY_CORE CMake option: the building of the core
  JerryScript library should not be optional.
* Fix wording of comments, status and error messages.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-08-30 09:10:30 +02:00
Yanhui Shen ba2b7dd13f Use C99's variable length array instead of alloca
JerryScript-DCO-1.0-Signed-off-by: Yanhui Shen shen.elf@gmail.com
2016-08-30 14:29:19 +08:00
Akos Kiss 8edab96162 Fix JMEM_HEAP_END_OF_LIST for pointers larger than 32 bits
For 64 bit pointers, 0xffffffff as end-of-list marker pointer does
not work, as the marker is expected to be greater than the start
address of the heap area (and also max 0xffffffff away), but on 64
bit systems, the heap can start on higher addresses, i.e., above
0x100000000.

This patch changes JMEM_HEAP_END_OF_LIST from pointer to offset.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-08-29 12:23:48 +02:00
Geoff Gustafson 7c50dc1691 Assert that pointer passed to jmem_pools_free is not NULL
If a NULL pointer is passed here, the list of free chunks gets lost.

JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson geoff@linux.intel.com
2016-08-29 12:20:13 +02:00
Robert Sipka 8ea60072b3 Remove unused JERRY_ENABLE_PRETTY_PRINTER from the build system.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-08-29 10:24:01 +02:00
2930 changed files with 116525 additions and 35893 deletions
+77
View File
@@ -0,0 +1,77 @@
---
name: Bug report
about: Create a report to help us improve
---
First of all, when reporting a bug, give the issue a descriptive title.
In the body of the issue, optionally give a free-form text description of the
bug. Give the context necessary for others to understand the problem.
Then, provide information necessary to reproduce the bug.
Omit sections that are irrelevant for the bug report, but note that information
like git revision, build platform, build command, and test case are required in
almost all cases.
###### JerryScript revision
Identify the git hash(es) or tag(s) where the issue was observed.
###### Build platform
Name the build platform. E.g., copy the output of
`echo "$(lsb_release -ds) ($(uname -mrs))"` (on Linux),
`echo "$(sw_vers -productName) $(sw_vers -productVersion) ($(uname -mrs))"` (on macOS), or
`python -c "import platform; print(platform.platform())"` (should work everywhere).
###### Build steps
Describe how to build JerryScript. Give all the necessary details of the build
(e.g., environment variables, command(s), profile, command line options, etc.).
E.g.:
```sh
tools/build.py --clean --debug
```
Or:
```sh
mkdir build && cmake -H. -Bbuild && make -C build
```
Even if the bug was originally observed when JerryScript was integrated into a
larger project, try to reproduce it with as few external code as possible,
preferably by building the `jerry` command line tool.
###### Build log
Copy the build log if the reported issue is a build problem. Do a verbose build
if necessary. Try and trim the log to relevant parts.
###### Test case
Give the JavaScript input that should be passed to the engine to trigger the
bug. Try and post a reduced test case that is minimally necessary to reproduce
the issue. As a rule of thumb, use Markdown's fenced code block syntax for the
test case. Attach the file (renamed to .txt) if the test case contains
'problematic' bytes that cannot be copied in the bug report directly.
###### Execution platform
Unnecessary if the same as the build platform.
###### Execution steps
List the steps that trigger the bug.
E.g., if a bug is snapshot-specific:
```sh
build/bin/jerry-snapshot generate -o testcase.js.snapshot testcase.js
build/bin/jerry --exec-snapshot testcase.js.snapshot
```
Unnecessary if trivial (i.e., `build/bin/jerry testcase.js`).
###### Output
Copy relevant output from the standard output and/or error channels.
###### Backtrace
In case of a crash (assertion failure, etc.), try to copy the backtrace from a
debugger at the point of failure.
###### Expected behavior
Describe what should happen instead of current behavior. Unnecessary if trivial
(e.g., in case of a crash, the trivial expected behavior is not to crash).
+19
View File
@@ -0,0 +1,19 @@
**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**
Before submitting a PR, please, make sure that:
- Changes are in a separate branch, not in master.
- The branch contains only one commit on top of master (if not, squash them into
one commit).
- The commit has a descriptive commit message with a concise title (first line).
- The commit message contains `fixes #XXXX` or `closes #XXXX` to auto-close the
issue(s) that the PR fixes (if any).
- Tests for the changes have been added (for bug fixes / features).
- Documentation has been added / updated (if applicable).
- All new and existing tests passed locally (if not, fix them first and amend
the commit).
IMPORTANT: Please review the CONTRIBUTING.md file for detailed contributing
guidelines.
**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**
+12 -11
View File
@@ -1,11 +1,11 @@
# Produced files
.mbedignore
build/*
# IDE related files
nbproject
**.sublime-project
**.sublime-workspace
*.sublime-project
*.sublime-workspace
.idea
# Random Trash
@@ -14,27 +14,28 @@ nbproject
*~
core
vgcore.*
**.orig
**.directory
**.patch
*.orig
*.directory
*.patch
.tags*
cscope.*
__pycache__
*.pyc
.DS_Store
# ctags and ID database
tags
ID
# targets
jerry_targetjs.h
targets/mbedk64f/libjerry
targets/mbedk64f/build
targets/mbedk64f/yotta_modules
targets/mbedk64f/yotta_targets
jerry-targetjs.h
.output
targets/esp8266/output.map
targets/esp8266/libs
# Generated documentation
docs/doxygen
# Tests
tests/test262/
.vs
+182 -22
View File
@@ -1,30 +1,190 @@
language: c
# Default environment: Ubuntu Trusty 14.04.
os: linux
dist: trusty
sudo: required
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tools/apt-get-install-deps.sh; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tools/apt-get-install-qemu-arm.sh; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tools/brew-install-deps.sh; fi
install:
script: "python tools/run-tests.py $OPTS"
env:
- OPTS="--check-signed-off --check-cppcheck --check-vera"
- OPTS="--jerry-tests --jerry-test-suite"
- OPTS="--jerry-tests --jerry-test-suite --toolchain=cmake/toolchain_linux_armv7l.cmake" TIMEOUT=300
- OPTS=--buildoption-test
- OPTS=--unittests
# Default job task: run tests as defined in the $OPT environment variable.
# Jobs can redefine the 'script' stage in the matrix below.
script: tools/run-tests.py $OPTS
# All the job definitions in the matrix.
matrix:
include:
- os: osx
env: OPTS="--jerry-tests --jerry-test-suite"
- os: osx
env: OPTS=--unittests
allow_failures:
- os: osx
- name: "Checks"
install: pip install --user pylint==1.6.5
script:
- tools/run-tests.py --check-signed-off=travis --check-doxygen --check-vera --check-license --check-magic-strings --check-pylint
- travis_wait 40 tools/run-tests.py --check-cppcheck
addons:
apt:
packages: [doxygen, cppcheck, vera++]
- name: "Linux/x86-64 Build & Correctness Tests"
env:
- OPTS="--quiet --jerry-tests --jerry-test-suite"
- name: "Linux/x86 (cpointer-32bit) Build & Correctness Tests"
env:
- OPTS="--quiet --jerry-tests --jerry-test-suite --buildoptions=--compile-flag=-m32,--cpointer-32bit=on"
addons:
apt:
packages: [gcc-multilib]
- name: "Linux/ARM Build & Correctness Tests"
env:
- OPTS="--quiet --jerry-tests --jerry-test-suite --toolchain=cmake/toolchain_linux_armv7l.cmake --buildoptions=--linker-flag=-static"
- RUNTIME=qemu-arm-static
- TIMEOUT=300
addons:
apt:
packages: [gcc-arm-linux-gnueabihf, libc6-dev-armhf-cross, qemu-user-static]
- name: "OSX/x86-64 Build, Correctness & Unit Tests"
env:
- OPTS="--quiet --jerry-tests --jerry-test-suite --unittests"
os: osx
addons:
homebrew:
packages: [cmake, cppcheck, vera++]
- name: "Build Tests"
env:
- OPTS="--buildoption-test"
addons:
apt:
packages: [gcc-multilib]
- name: "Unit Tests"
env:
- OPTS="--unittests"
- name: "Unit Tests (INIT_FINI)"
env:
- OPTS="--unittests --buildoptions=--cmake-param=-DFEATURE_INIT_FINI=ON"
- name: "Debugger Tests"
env:
- OPTS="--jerry-debugger"
- name: "Conformance Tests"
env:
- OPTS="--test262"
- name: "ASAN Tests"
env:
# Skipping maximum stack usage related tests due to 'detect_stack_use_after_return=1' ASAN option.
# For more detailed description: https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn#compatibility
- OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js --buildoptions=--stack-limit=0,--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold"
- ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true
- TIMEOUT=600
compiler: gcc-5
addons:
apt:
sources: ubuntu-toolchain-r-test
packages: [gcc-5, gcc-5-multilib]
- name: "UBSAN Tests"
env:
- OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js,parser-oom2.js --buildoptions=--compile-flag=-fsanitize=undefined,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold"
- UBSAN_OPTIONS=print_stacktrace=1
- TIMEOUT=600
compiler: gcc-5
addons:
apt:
sources: ubuntu-toolchain-r-test
packages: [gcc-5, gcc-5-multilib]
- name: "Coverity Scan"
env:
# Declaration of the encrypted COVERITY_SCAN_TOKEN, created via the
# "travis encrypt" command using the project repo's public key.
- secure: "V7BdXv3FCVkFGEfKfWto6I+Sytou1zTCGyn49xurkBfKNsG/3vbkXfsbK1m6lCZxmY7W/1odpfjixpAPZgy2L4FgPZK6/UyVvC8pIFjDOubcEniN48haleSvm/ZFPLDifxDL2+VVFtK1oRYPtDBzzSoUCcfwovgk+Wy+tSBnhnyRLqO/WaI6PqFof7ECYMTRlJVjioZARVP4YmkBruIPmGDdR/3EvwowlxfuiFoPheix61ug4x3tpTBW2qWgvFjDyCZXFz4pJrBQPTAIbyKMxHcBykJjl9eR+dWAOsvE1Uw48tFOJxjKDfUttVQUPsyKFllmcCVS0fDYB5pzZOmRUPxJmox1jt8J1FY85Ri1PGY0THBPM2H7to4Yf2418Y3539epbN8p+79dwaM7e2OiJ2owukbWI7PoNqIz5DV5zxpIKsOQfeWuNLJOgsBePEIU7lz133Si/2d5W/7If46B1d+hZRBJfSYksgDqDU6G/voZkPf0K5bKe2O2BxiIW1DYk4yQ1ecZAkqGjZ8jG3zYGMG3mSF4VyuU4UGFG1Pg8fw7Ap5zuHxSVY1H9dtu4T6JQG3aj/x1omlzfw48DjgkwxVhf7Xvl3yfR7pzydYheLX3MZYtcVo7rWnglZFZoUjWDK1StbmzsvPftvwWtoDTWlzo4xeSXhahSJvJyc4U8Wc="
addons:
coverity_scan:
project:
name: "jerryscript-project/jerryscript"
description: "Ultra-lightweight JavaScript engine for the Internet of Things."
notification_email: rsipka.uszeged@partner.samsung.com
build_command: "tools/build.py --clean"
branch_pattern: master
script: skip # Changed to nop, Coverity Scan has already built the project by the time 'script' stage is reached.
- name: "SonarQube"
addons:
sonarcloud:
organization: "jerryscript-project"
script: tools/check-sonarqube.sh
cache:
directories:
- '${HOME}/.sonar/cache'
- name: "ESP8266 Build Test"
install: make -f ./targets/esp8266/Makefile.travis install-noapt
script: make -f ./targets/esp8266/Makefile.travis script
addons:
apt:
packages: [wget]
- name: "Mbed OS 5/K64F Build Test"
addons:
apt:
sources:
- sourceline: ppa:team-gcc-arm-embedded/ppa
packages: [gcc-arm-embedded]
language: python # NOTE: only way to ensure python>=2.7.10 on Trusty image
python: 3.6
install: make -f ./targets/mbedos5/Makefile.travis install
script: make -f ./targets/mbedos5/Makefile.travis script
- name: "NuttX/STM32F4 Build Test"
install: make -f targets/nuttx-stm32f4/Makefile.travis install-noapt
script: make -f targets/nuttx-stm32f4/Makefile.travis script
addons:
apt:
packages: [gcc-arm-none-eabi, libnewlib-arm-none-eabi, gperf]
- name: "RIOT/STM32F4 Build Test"
install: make -f ./targets/riot-stm32f4/Makefile.travis install-noapt
script: make -f ./targets/riot-stm32f4/Makefile.travis script
compiler: clang-3.9
addons:
apt:
sources:
- sourceline: ppa:team-gcc-arm-embedded/ppa
packages: [clang-3.9, gcc-arm-embedded, gcc-multilib]
- name: "Tizen RT/Artik053 Build Test"
addons:
apt:
sources:
- sourceline: ppa:team-gcc-arm-embedded/ppa
packages: [gcc-arm-embedded, genromfs]
install: make -f ./targets/tizenrt-artik053/Makefile.travis install
script: make -f ./targets/tizenrt-artik053/Makefile.travis script
- name: "Zephyr/Arduino 101 Build Test"
install: make -f ./targets/zephyr/Makefile.travis install-noapt
script: make -f ./targets/zephyr/Makefile.travis script
addons:
apt:
packages: [gperf, dfu-util, device-tree-compiler, python3-ply, python3-pip]
fast_finish: true
# The channel name "chat.freenode.net#jerryscript"
# is encrypted against Samsung/jerryscript
# to prevent IRC spam of forks.
#
# travis encrypt -r "Samsung/jerryscript" "chat.freenode.net#jerryscript"
notifications:
irc:
channels:
- secure: "4kML4uZywOPaT3r/bHCvZCeQWooyzZumESmKuHG2Y8/B29WtMBobsoRQZRfOmlUP5kshfjh0Itp5WFpdACiBCoorHch/8z3VT7fIbKF4UnxrAvNiFArqxXC0OWGIu93e7uyyXJCsQ/JiOXU7bD31Mh8LbnfS1z3wBAMXi+AwcaGiVVH4VTL6O8sR3ij5WmsqpECWhyWTgTP3MiLquZ+09Lv9mp5GGciEemq4p8VnaQt2BdyEBmUJJ1EAyMCJlKNObQudegOzYsY3CVON9C87dCuHf7DYstsxb8AzwRAKn8LHiaWhYaWLfvHqoXmc4w1ZgN0HZ5Qyx8KMkZkXKUiHxuCSoXDxNAHWTGQBsTDid5drZeqOFucOHEKJzkqaWSUKUF3pY/hq/h2kjAn230DlBNkJt+ikSxwy6Mm8GG8LnH5gRMl37zHDHrtyRsKR8GIst9B1B95LAOLA5t8U/ucGKXqLsohS8glXaM4jjh69it3GeHj6NhB8NbC/LsmRrhjKzV+VnjPI6gZvN+5tDiuxMbsMal+0DdWVNCst/aO3Jz0iaA5ahyo2ZwBb2efw3CekRLMKmHtnjqB0SWWXT3/t2+5zNoM6gBjo4RPOg7k5eTOXcfk8okWtQ5d3n8UtvZ5rSiDl3rssHwp1yHuuC8rGGov74DLvyDlpM6p/dmtu2o8="
on_success: always
on_failure: always
use_notice: true
template:
- "%{repository_name} (%{branch}@%{commit}): %{author} - %{commit_subject} [%{result}]"
- "Commit: %{compare_url}"
- "Build: %{build_url}"
+172 -128
View File
@@ -1,5 +1,4 @@
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,72 +13,121 @@
# limitations under the License.
cmake_minimum_required (VERSION 2.8.12)
project (Jerry C ASM)
project (Jerry C)
# Determining platform
set(PLATFORM "${CMAKE_SYSTEM_NAME}")
string(TOUPPER "${PLATFORM}" PLATFORM)
# Remove rdynamic option
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS )
# Determining compiler
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(USING_GCC 1)
endif()
# Components
set(JERRY_CORE ON CACHE BOOL "Use jerry-core?")
set(JERRY_LIBC ON CACHE BOOL "Use jerry-libc?")
set(JERRY_LIBM ON CACHE BOOL "Use jerry-libm?")
set(JERRY_CMDLINE ON CACHE BOOL "Use jerry command line tool?")
set(UNITTESTS OFF CACHE BOOL "Use unit tests?")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(USING_CLANG 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "TI")
set(USING_TI 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(USING_MSVC 1)
endif()
# Determining build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel")
endif()
# Optional components
set(JERRY_CMDLINE ON CACHE BOOL "Build jerry command line tool?")
set(JERRY_CMDLINE_TEST OFF CACHE BOOL "Build jerry test command line tool?")
set(JERRY_CMDLINE_SNAPSHOT OFF CACHE BOOL "Build jerry snapshot command line tool?")
set(JERRY_LIBFUZZER OFF CACHE BOOL "Build jerry with libfuzzer support?")
set(JERRY_PORT_DEFAULT ON CACHE BOOL "Build default jerry port implementation?")
set(JERRY_EXT ON CACHE BOOL "Build jerry-ext?")
set(JERRY_LIBM ON CACHE BOOL "Build and use jerry-libm?")
set(UNITTESTS OFF CACHE BOOL "Build unit tests?")
set(DOCTESTS OFF CACHE BOOL "Build doc tests?")
# Optional build settings
set(PORT_DIR "${CMAKE_SOURCE_DIR}/targets/default" CACHE STRING "Should we use default or external port?")
set(COMPILER_DEFAULT_LIBC OFF CACHE BOOL "Enable compiler default libc?")
set(ENABLE_LTO OFF CACHE BOOL "Enable LTO build?")
set(ENABLE_ALL_IN_ONE ON CACHE BOOL "Enable all-in-one build?")
set(ENABLE_STRIP ON CACHE BOOL "Discards all symbols from object files?")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries?")
set(ENABLE_LTO ON CACHE BOOL "Enable LTO build?")
set(ENABLE_STRIP ON CACHE BOOL "Enable stripping all symbols from release binary?")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
# Option overrides
if(NOT USING_CLANG)
set(JERRY_LIBFUZZER OFF)
set(JERRY_LIBFUZZER_MESSAGE " (FORCED BY COMPILER)")
endif()
if(JERRY_CMDLINE OR JERRY_CMDLINE_TEST OR JERRY_CMDLINE_SNAPSHOT OR JERRY_LIBFUZZER OR UNITTESTS OR DOCTESTS)
set(JERRY_PORT_DEFAULT ON)
set(JERRY_PORT_DEFAULT_MESSAGE " (FORCED BY CMDLINE OR LIBFUZZER OR TESTS)")
endif()
if(JERRY_CMDLINE OR DOCTESTS)
set(JERRY_EXT ON)
set(JERRY_EXT_MESSAGE " (FORCED BY CMDLINE OR TESTS)")
endif()
if("${PLATFORM}" STREQUAL "DARWIN")
set(ENABLE_LTO "OFF")
set(ENABLE_ALL_IN_ONE "ON")
set(JERRY_LIBC "OFF")
set(JERRY_LIBM "OFF")
set(COMPILER_DEFAULT_LIBC "ON")
set(JERRY_LIBM OFF)
set(ENABLE_LTO OFF)
set(ENABLE_STRIP OFF)
set(JERRY_LIBM_MESSAGE " (FORCED BY PLATFORM)")
set(ENABLE_LTO_MESSAGE " (FORCED BY PLATFORM)")
set(ENABLE_STRIP_MESSAGE " (FORCED BY PLATFORM)")
endif()
if(JERRY_LIBC AND COMPILER_DEFAULT_LIBC)
message(FATAL_ERROR "JERRY_LIBC and COMPILER_DEFAULT_LIBC is enabled at the same time!")
if(USING_TI)
set(ENABLE_STRIP OFF)
set(ENABLE_STRIP_MESSAGE " (FORCED BY COMPILER)")
endif()
if(USING_MSVC)
set(JERRY_LIBM OFF)
set(ENABLE_STRIP OFF)
set(JERRY_LIBM_MESSAGE " (FORCED BY COMPILER)")
set(ENABLE_STRIP_MESSAGE " (FORCED BY COMPILER)")
endif()
# Status messages
message(STATUS "CMAKE_SYSTEM_NAME " ${CMAKE_SYSTEM_NAME})
message(STATUS "CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
message(STATUS "JERRY_CORE " ${JERRY_CORE})
message(STATUS "JERRY_LIBC " ${JERRY_LIBC})
message(STATUS "JERRY_LIBM " ${JERRY_LIBM})
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE})
message(STATUS "UNITTESTS " ${UNITTESTS})
message(STATUS "PORT_DIR " ${PORT_DIR})
message(STATUS "COMPILER_DEFAULT_LIBC " ${COMPILER_DEFAULT_LIBC})
message(STATUS "ENABLE_LTO " ${ENABLE_LTO})
message(STATUS "ENABLE_ALL_IN_ONE " ${ENABLE_ALL_IN_ONE})
message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP})
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
message(STATUS "CMAKE_C_COMPILER_ID " ${CMAKE_C_COMPILER_ID})
message(STATUS "CMAKE_SYSTEM_NAME " ${CMAKE_SYSTEM_NAME})
message(STATUS "CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "BUILD_SHARED_LIBS " ${BUILD_SHARED_LIBS})
message(STATUS "ENABLE_LTO " ${ENABLE_LTO} ${ENABLE_LTO_MESSAGE})
message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP} ${ENABLE_STRIP_MESSAGE})
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE} ${JERRY_CMDLINE_MESSAGE})
message(STATUS "JERRY_CMDLINE_TEST " ${JERRY_CMDLINE_TEST} ${JERRY_CMDLINE_TEST_MESSAGE})
message(STATUS "JERRY_CMDLINE_SNAPSHOT " ${JERRY_CMDLINE_SNAPSHOT} ${JERRY_CMDLINE_SNAPSHOT_MESSAGE})
message(STATUS "JERRY_LIBFUZZER " ${JERRY_LIBFUZZER} ${JERRY_LIBFUZZER_MESSAGE})
message(STATUS "JERRY_PORT_DEFAULT " ${JERRY_PORT_DEFAULT} ${JERRY_PORT_DEFAULT_MESSAGE})
message(STATUS "JERRY_EXT " ${JERRY_EXT} ${JERRY_EXT_MESSAGE})
message(STATUS "JERRY_LIBM " ${JERRY_LIBM} ${JERRY_LIBM_MESSAGE})
message(STATUS "UNITTESTS " ${UNITTESTS})
message(STATUS "DOCTESTS " ${DOCTESTS})
# Setup directories
# Project binary dir
set(PROJECT_BINARY_DIR "${CMAKE_BINARY_DIR}")
# Note: This mimics a conventional file system layout in the build directory for
# the sake of convenient location of build artefacts. Proper installation to
# traditional locations is also supported, e.g., to /usr/local.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/")
# Library output directory
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/")
# Executable output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/")
# Archive targets output Directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/")
# Remove rdynamic option
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS )
# Compile/link flags
# Helper macros
@@ -96,9 +144,7 @@ endmacro()
macro(jerry_add_compile_warnings)
foreach(_warning ${ARGV})
jerry_add_compile_flags(-W${_warning})
if(CMAKE_COMPILER_IS_GNUCC)
jerry_add_compile_flags(-Werror=${_warning})
endif()
jerry_add_compile_flags(-Werror=${_warning})
endforeach()
endmacro()
@@ -106,88 +152,77 @@ macro(jerry_add_link_flags)
jerry_add_flags(LINKER_FLAGS_COMMON ${ARGV})
endmacro()
# build mode specific compile/link flags
set(CMAKE_C_FLAGS_RELEASE "-Os")
# Architecture-specific compile/link flags
jerry_add_compile_flags(${FLAGS_COMMON_ARCH})
jerry_add_flags(CMAKE_EXE_LINKER_FLAGS ${FLAGS_COMMON_ARCH})
# LTO
if(ENABLE_LTO)
jerry_add_compile_flags(-flto)
jerry_add_link_flags(-flto)
if(CMAKE_COMPILER_IS_GNUCC)
if(NOT "${PLATFORM}" STREQUAL "DARWIN")
jerry_add_compile_flags(-fno-fat-lto-objects)
endif()
if(USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-flto)
jerry_add_link_flags(-flto)
endif()
if(USING_GCC)
jerry_add_compile_flags(-fno-fat-lto-objects)
# Use gcc-ar and gcc-ranlib to support LTO
set(CMAKE_AR "gcc-ar")
set(CMAKE_RANLIB "gcc-ranlib")
endif()
endif()
# Define _BSD_SOURCE if we use default port and compiler default libc
if(${PORT_DIR} STREQUAL "${CMAKE_SOURCE_DIR}/targets/default" AND COMPILER_DEFAULT_LIBC)
set(DEFINES_JERRY ${DEFINES_JERRY} _BSD_SOURCE)
endif()
# Imported targets prefix
set(PREFIX_IMPORTED_LIB imported_)
# Imported libraries
if(("${PLATFORM}" STREQUAL "DARWIN") AND (NOT CMAKE_COMPILER_IS_GNUCC))
# libclang_rt.osx
set(IMPORTED_LIB "${PREFIX_IMPORTED_LIB}libclang_rt.osx")
add_library(${IMPORTED_LIB} STATIC IMPORTED)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${FLAGS_COMMON_ARCH} -print-file-name=
OUTPUT_VARIABLE IMPORTED_LIBCLANG_RT_LOCATION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(IMPORTED_LIBCLANG_RT_LOCATION "${IMPORTED_LIBCLANG_RT_LOCATION}/lib/darwin/libclang_rt.osx.a")
set_property(TARGET ${IMPORTED_LIB}
PROPERTY IMPORTED_LOCATION ${IMPORTED_LIBCLANG_RT_LOCATION})
else()
# libgcc
set(IMPORTED_LIB "${PREFIX_IMPORTED_LIB}libgcc")
add_library(${IMPORTED_LIB} STATIC IMPORTED)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${FLAGS_COMMON_ARCH} -print-file-name=libgcc.a
OUTPUT_VARIABLE IMPORTED_LIBGCC_LOCATION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set_property(TARGET ${IMPORTED_LIB}
PROPERTY IMPORTED_LOCATION ${IMPORTED_LIBGCC_LOCATION})
if(USING_TI)
jerry_add_link_flags(-lto)
endif()
endif()
# Compiler / Linker flags
jerry_add_compile_flags(-fno-builtin)
if(("${PLATFORM}" STREQUAL "DARWIN"))
if("${PLATFORM}" STREQUAL "DARWIN")
jerry_add_link_flags(-lSystem)
else()
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Sqc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
elseif(USING_GCC OR USING_CLANG)
jerry_add_link_flags(-Wl,-z,noexecstack)
endif()
# Turn off linking to compiler's default libc, in case jerry-libc or external is used
if(NOT COMPILER_DEFAULT_LIBC)
jerry_add_link_flags(-nostdlib)
if(USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-std=c99 -pedantic)
# Turn off stack protector
jerry_add_compile_flags(-fno-builtin -fno-stack-protector)
jerry_add_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations shadow strict-prototypes undef old-style-definition)
jerry_add_compile_flags(-Wno-stack-protector -Wno-attributes -Werror)
endif()
# Turn off stack protector
jerry_add_compile_flags(-fno-stack-protector)
# Debug information
jerry_add_compile_flags(-g -gdwarf-4)
jerry_add_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations)
jerry_add_compile_flags(-Wno-stack-protector -Wno-attributes)
if(CMAKE_COMPILER_IS_GNUCC)
if(JERRY_LIBC)
jerry_add_compile_flags(-Werror)
endif()
if(USING_GCC)
jerry_add_compile_warnings(logical-op)
else()
jerry_add_compile_flags(-Wno-nested-anon-types)
# TODO: Remove workaround for gcc 7 bug if the fallthrough comment detection is fixed.
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 7.0)
jerry_add_compile_flags(-Wno-implicit-fallthrough)
endif()
endif()
if(USING_CLANG)
jerry_add_compile_flags(-Wno-nested-anon-types -Wno-static-in-inline)
endif()
if(USING_TI)
jerry_add_compile_flags(--c99)
endif()
if(USING_MSVC)
jerry_add_link_flags(/OPT:NOREF)
# Disable MSVC warning 4996 globally because it stops us from using standard C functions.
jerry_add_compile_flags(/wd4996)
endif()
if(JERRY_LIBFUZZER)
jerry_add_compile_flags(-fsanitize=fuzzer-no-link)
endif()
# Strip binary
if(ENABLE_STRIP AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
jerry_add_link_flags(-s)
endif()
# External compiler & linker flags
if(DEFINED EXTERNAL_COMPILE_FLAGS)
jerry_add_compile_flags(${EXTERNAL_COMPILE_FLAGS})
endif()
@@ -196,18 +231,8 @@ if(DEFINED EXTERNAL_LINKER_FLAGS)
jerry_add_link_flags(${EXTERNAL_LINKER_FLAGS})
endif()
# C
jerry_add_compile_flags(-std=c99 -pedantic)
# Strip binary
if(ENABLE_STRIP AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
jerry_add_link_flags(-s)
endif()
# Jerry's libc
if(JERRY_LIBC)
add_subdirectory(jerry-libc)
endif()
# Used for placeholder to attach single source build targets
add_custom_target(generate-single-source)
# Jerry's libm
if(JERRY_LIBM)
@@ -215,16 +240,35 @@ if(JERRY_LIBM)
endif()
# Jerry's core
if(JERRY_CORE)
add_subdirectory(jerry-core)
add_subdirectory(jerry-core)
# Jerry's extension tools
if(JERRY_EXT)
add_subdirectory(jerry-ext)
endif()
# Jerry commandline tool
if(JERRY_CMDLINE)
# Jerry's default port implementation
if(JERRY_PORT_DEFAULT)
add_subdirectory(jerry-port/default)
endif()
# Jerry command line tool
if(JERRY_CMDLINE OR JERRY_CMDLINE_TEST OR JERRY_CMDLINE_SNAPSHOT OR JERRY_LIBFUZZER)
add_subdirectory(jerry-main)
endif()
# Unittests
if(UNITTESTS)
add_subdirectory(tests/unit)
add_subdirectory(tests/unit-core)
if(JERRY_LIBM)
add_subdirectory(tests/unit-libm)
endif()
if(JERRY_EXT)
add_subdirectory(tests/unit-ext)
endif()
endif()
# Doctests
if(DOCTESTS)
add_subdirectory(tests/unit-doc)
endif()
+98
View File
@@ -0,0 +1,98 @@
# Contribution Guidelines
## Patch Submission Process
The following guidelines on the submission process are provided to help you be more effective when submitting code to the JerryScript project.
When development is complete, a patch set should be submitted via GitHub pull requests. A review of the patch set will take place. When accepted, the patch set will be integrated into the master branch, verified, and tested. It is then the responsibility of the authoring developer to maintain the code throughout its lifecycle.
Please submit all patches in public by opening a pull request. Patches sent privately to Maintainers and Committers will not be considered. Because the JerryScript Project is an Open Source project, be prepared for feedback and criticism-it happens to everyone-. If asked to rework your code, be persistent and resubmit after making changes.
### 1. Scope the patch
Smaller patches are generally easier to understand and test, so please submit changes in the smallest increments possible, within reason. Smaller patches are less likely to have unintended consequences, and if they do, getting to the root cause is much easier for you and the Maintainers and Committers. Additionally, smaller patches are much more likely to be accepted.
### 2. Ensure all files have a proper license header and copyright notice
Any code that you want to contribute to the project must be licensed under the [Apache License 2.0](LICENSE). Contributions under a different license can not be accepted. Each file should start with the following header:
```c
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
```
Adding copyright notices other than the project-wide notice ("Copyright JS Foundation and other contributors, http://js.foundation") is not permitted. The only exception is adding third-party code which requires copyright notices to be preserved. Adding third-party code to the project generally requires a strong justification.
### 3. Sign your work with the JerryScript [Developer's Certificate of Origin](DCO.md)
The sign-off is a simple line at the end of the commit message of the patch, which certifies that you wrote it or otherwise have the right to pass it on as an Open Source patch. The sign-off is required for a patch to be accepted.
We have the same requirements for using the signed-off-by process as the Linux kernel.
In short, you need to include a signed-off-by tag in every patch.
You should use your real name and email address in the format below:
> JerryScript-DCO-1.0-Signed-off-by: Random J Developer random@developer.example.org
"JerryScript-DCO-1.0-Signed-off-by:" this is a developer's certification that he or she has the right to submit the patch for inclusion into the project. It is an agreement to the JerryScript [Developer's Certificate of Origin](DCO.md). **Code without a proper signoff cannot be merged into the mainline.**
### 4. Open a GitHub [pull request](https://github.com/jerryscript-project/jerryscript/pulls)
You can find instructions about opening a pull request [here](https://help.github.com/articles/creating-a-pull-request).
### 5. What if my patch is rejected?
It happens all the time, for many reasons, and not necessarily because the code is bad. Take the feedback, adapt your code, and try again. Remember, the ultimate goal is to preserve the quality of the code and maintain the focus of the Project through intensive review.
Maintainers and Committers typically have to process a lot of submissions, and the time for any individual response is generally limited. If the reason for rejection is unclear, please ask for more information from the Maintainers and Committers.
If you have a solid technical reason to disagree with feedback and you feel that reason has been overlooked, take the time to thoroughly explain it in your response.
### 6. Code review
Code review can be performed by all the members of the Project (not just Maintainers and Committers). Members can review code changes and share their opinion through comments guided by the following principles:
* Discuss code; never discuss the code's author
* Respect and acknowledge contributions, suggestions, and comments
* Listen and be open to all different opinions
* Help each other
Changes are submitted via pull requests and only the Maintainers and Committers should approve or reject the pull request (note that only Maintainers can give binding review scores).
Changes should be reviewed in reasonable amount of time. Maintainers and Committers should leave changes open for some time (at least 1 full business day) so others can offer feedback. Review times increase with the complexity of the review.
## Tips on GitHub Pull Requests
* [Fork](https://guides.github.com/activities/forking) the GitHub repository and clone it locally
* Connect your local repository to the original upstream repository by adding it as a remote
* Create a [branch](https://guides.github.com/introduction/flow) for your edits
* Pull in upstream changes often to stay up-to-date so that when you submit your pull request, merge conflicts will be less likely
For more details, see the GitHub [fork syncing](https://help.github.com/articles/syncing-a-fork) guidelines.
## How to add the DCO line to every single commit automatically
It is easy to forget adding the DCO line to the end of every commit message. Fortunately there is a nice way to do it automatically. Once you've cloned the repository into your local machine, you can add `prepare commit message hook` in `.git/hooks` directory like this:
```
#!/usr/bin/env python
import sys
commit_msg_filepath = sys.argv[1]
with open(commit_msg_filepath, "r+") as f:
content = f.read()
f.seek(0, 0)
f.write("%s\n\nJerryScript-DCO-1.0-Signed-off-by: <Your Name> <Your Email>" % content)
```
Please refer [Git Hooks](http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) for more information.
+22
View File
@@ -0,0 +1,22 @@
# JerryScript Developer's Certificate of Origin
The JerryScript project uses the signed-off-by language and process to give us a clear chain of trust for every patch received.
> By making a contribution to this project, I certify that:
> (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
> (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
> (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
> (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project, under the same open source license.
We have the same requirements for using the signed-off-by process as the Linux kernel.
In short, you need to include a signed-off-by tag in the commit message of every patch.
You should use your real name and email address in the format below:
> JerryScript-DCO-1.0-Signed-off-by: Random J Developer random@developer.example.org
"JerryScript-DCO-1.0-Signed-off-by:" this is a developer's certification that he or she has the right to submit the patch for inclusion into the project. It is an agreement to the Developer's Certificate of Origin (above). **Code without a proper signoff cannot be merged into the mainline.**
+34 -20
View File
@@ -76,7 +76,7 @@ CREATE_SUBDIRS = NO
# U+3044.
# The default value is: NO.
ALLOW_UNICODE_NAMES = NO
# ALLOW_UNICODE_NAMES = NO
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
# documentation generated by doxygen is written. Doxygen will use this
@@ -341,7 +341,7 @@ IDL_PROPERTY_SUPPORT = YES
# all members of a group must be documented explicitly.
# The default value is: NO.
DISTRIBUTE_GROUP_DOC = NO
DISTRIBUTE_GROUP_DOC = YES
# Set the SUBGROUPING tag to YES to allow class member groups of the same type
# (for instance a group of public functions) to be put as a subgroup of that
@@ -409,7 +409,7 @@ LOOKUP_CACHE_SIZE = 0
# normally produced when WARNINGS is set to YES.
# The default value is: NO.
EXTRACT_ALL = YES
EXTRACT_ALL = NO
# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
# be included in the documentation.
@@ -512,7 +512,7 @@ HIDE_SCOPE_NAMES = NO
# YES the compound reference will be hidden.
# The default value is: NO.
HIDE_COMPOUND_REFERENCE= NO
# HIDE_COMPOUND_REFERENCE= NO
# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
# the files that are included by a file in the documentation of that file.
@@ -730,7 +730,7 @@ WARN_IF_DOC_ERROR = YES
# parameter documentation, but not about the absence of documentation.
# The default value is: NO.
WARN_NO_PARAMDOC = NO
WARN_NO_PARAMDOC = YES
# The WARN_FORMAT tag determines the format of the warning messages that doxygen
# can produce. The string should contain the $file, $line, and $text tags, which
@@ -758,7 +758,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.
INPUT = jerry-core jerry-libc
INPUT = jerry-core jerry-ext jerry-port
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
@@ -778,7 +778,7 @@ INPUT_ENCODING = UTF-8
# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,
# *.qsf, *.as and *.js.
FILE_PATTERNS =
FILE_PATTERNS = *.h *.c
# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.
@@ -793,7 +793,21 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.
EXCLUDE =
# FIXME: None of these files are excluded light-heartedly. They should be
# removed one-by-one and warnings reported by doxygen should be fixed by those
# who are familiar with the undocumented parts.
EXCLUDE = \
jerry-core/ecma/base/ecma-globals.h \
jerry-core/ecma/base/ecma-helpers.h \
jerry-core/ecma/operations/ecma-exceptions.h \
jerry-core/include/jerryscript-debugger-transport.h \
jerry-core/jcontext/jcontext.h \
jerry-core/parser/js/byte-code.h \
jerry-core/parser/js/common.h \
jerry-core/parser/js/js-lexer.h \
jerry-core/parser/js/js-parser-internal.h \
jerry-core/parser/regexp/re-parser.h \
jerry-core/vm/vm-stack.h
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
@@ -809,7 +823,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*
EXCLUDE_PATTERNS =
EXCLUDE_PATTERNS = *.inc.h
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
@@ -991,7 +1005,7 @@ VERBATIM_HEADERS = YES
# compiled with the --with-libclang option.
# The default value is: NO.
CLANG_ASSISTED_PARSING = NO
# CLANG_ASSISTED_PARSING = NO
# If clang assisted parsing is enabled you can provide the compiler with command
# line options that you would normally use when invoking the compiler. Note that
@@ -999,7 +1013,7 @@ CLANG_ASSISTED_PARSING = NO
# specified with INPUT and INCLUDE_PATH.
# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
CLANG_OPTIONS =
# CLANG_OPTIONS =
#---------------------------------------------------------------------------
# Configuration options related to the alphabetical class index
@@ -1668,7 +1682,7 @@ LATEX_FOOTER =
# list).
# This tag requires that the tag GENERATE_LATEX is set to YES.
LATEX_EXTRA_STYLESHEET =
# LATEX_EXTRA_STYLESHEET =
# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the LATEX_OUTPUT output
@@ -1793,7 +1807,7 @@ RTF_EXTENSIONS_FILE =
# The default value is: NO.
# This tag requires that the tag GENERATE_RTF is set to YES.
RTF_SOURCE_CODE = NO
# RTF_SOURCE_CODE = NO
#---------------------------------------------------------------------------
# Configuration options related to the man page output
@@ -1828,7 +1842,7 @@ MAN_EXTENSION = .3
# MAN_EXTENSION with the initial . removed.
# This tag requires that the tag GENERATE_MAN is set to YES.
MAN_SUBDIR =
# MAN_SUBDIR =
# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
# will generate one additional man file for each entity documented in the real
@@ -1891,7 +1905,7 @@ DOCBOOK_OUTPUT = docbook
# The default value is: NO.
# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
DOCBOOK_PROGRAMLISTING = NO
# DOCBOOK_PROGRAMLISTING = NO
#---------------------------------------------------------------------------
# Configuration options for the AutoGen Definitions output
@@ -1960,7 +1974,7 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
MACRO_EXPANSION = NO
MACRO_EXPANSION = YES
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and
@@ -1968,7 +1982,7 @@ MACRO_EXPANSION = NO
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
EXPAND_ONLY_PREDEF = NO
EXPAND_ONLY_PREDEF = YES
# If the SEARCH_INCLUDES tag is set to YES, the include files in the
# INCLUDE_PATH will be searched if a #include is found.
@@ -2000,7 +2014,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED =
PREDEFINED = JERRY_STATIC_ASSERT(x,y)= JERRY_ATTR_FORMAT(x,y,z)=
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
@@ -2316,12 +2330,12 @@ DIAFILE_DIRS =
# generate a warning when it encounters a \startuml command in this case and
# will not generate output for the diagram.
PLANTUML_JAR_PATH =
# PLANTUML_JAR_PATH =
# When using plantuml, the specified paths are searched for files specified by
# the !include statement in a plantuml block.
PLANTUML_INCLUDE_PATH =
# PLANTUML_INCLUDE_PATH =
# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
# that will be shown in the graph. If the number of nodes in a graph becomes
+200 -10
View File
@@ -1,13 +1,203 @@
Copyright 2014-2016 Samsung Electronics Co., Ltd.
Copyright JS Foundation and other contributors, http://js.foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
http://www.apache.org/licenses/LICENSE-2.0
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright JS Foundation and other contributors, http://js.foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+30 -10
View File
@@ -1,7 +1,12 @@
![](https://github.com/Samsung/jerryscript/blob/master/LOGO.png)
![](https://github.com/jerryscript-project/jerryscript/blob/master/LOGO.png)
# JerryScript: JavaScript engine for the Internet of Things
[![License](https://img.shields.io/badge/licence-Apache%202.0-brightgreen.svg?style=flat)](LICENSE)
[![Build Status](https://travis-ci.org/Samsung/jerryscript.svg?branch=master)](https://travis-ci.org/Samsung/jerryscript)
[![Travis CI Build Status](https://travis-ci.org/jerryscript-project/jerryscript.svg?branch=master)](https://travis-ci.org/jerryscript-project/jerryscript)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/ct8reap35u2vooa5/branch/master?svg=true)](https://ci.appveyor.com/project/jerryscript-project/jerryscript/branch/master)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/12127/badge.svg)](https://scan.coverity.com/projects/jerryscript-project)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript?ref=badge_shield)
[![SonarQube](https://sonarcloud.io/api/project_badges/measure?project=jerryscript-project_jerryscript&metric=ncloc)](https://sonarcloud.io/dashboard?id=jerryscript-project_jerryscript)
[![IRC Channel](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://kiwiirc.com/client/irc.freenode.net/#jerryscript)
JerryScript is a lightweight JavaScript engine for resource-constrained devices such as microcontrollers. It can run on devices with less than 64 KB of RAM and less than 200 KB of flash memory.
@@ -13,15 +18,23 @@ Key characteristics of JerryScript:
* Snapshot support for precompiling JavaScript source code to byte code
* Mature C API, easy to embed in applications
Additional information can be found on our [project page](http://samsung.github.io/jerryscript) and [Wiki](https://github.com/Samsung/jerryscript/wiki).
Additional information can be found on our [project page](http://jerryscript.net) and [Wiki](https://github.com/jerryscript-project/jerryscript/wiki).
IRC channel: #jerryscript on [freenode](https://freenode.net)
Mailing list: jerryscript-dev@gna.org, you can subscribe [here](https://mail.gna.org/listinfo/jerryscript-dev) and access the mailing list archive [here](https://mail.gna.org/public/jerryscript-dev).
Memory usage and Binary footprint are measured at [here](https://jerryscript-project.github.io/jerryscript-test-results) with real target daily.
The following table shows the latest results on the devices:
| STM32F4-Discovery | [![Remote Testrunner](https://firebasestorage.googleapis.com/v0/b/jsremote-testrunner.appspot.com/o/status%2Fjerryscript%2Fstm32f4dis.svg?alt=media&token=1)](https://jerryscript-project.github.io/jerryscript-test-results/?view=stm32f4dis) |
| :---: | :---: |
| **Raspberry Pi 2** | [![Remote Testrunner](https://firebasestorage.googleapis.com/v0/b/jsremote-testrunner.appspot.com/o/status%2Fjerryscript%2Frpi2.svg?alt=media&token=1)](https://jerryscript-project.github.io/jerryscript-test-results/?view=rpi2) |
IRC channel: #jerryscript on [freenode](https://freenode.net)
Mailing list: jerryscript-dev@groups.io, you can subscribe [here](https://groups.io/g/jerryscript-dev) and access the mailing list archive [here](https://groups.io/g/jerryscript-dev/topics).
## Quick Start
### Getting the sources
```bash
git clone https://github.com/Samsung/jerryscript.git
git clone https://github.com/jerryscript-project/jerryscript.git
cd jerryscript
```
@@ -30,17 +43,24 @@ cd jerryscript
python tools/build.py
```
For additional information see [Getting Started](docs/01.GETTING-STARTED.md).
For additional information see [Getting Started](docs/00.GETTING-STARTED.md).
## Documentation
- [Getting Started](docs/01.GETTING-STARTED.md)
- [Getting Started](docs/00.GETTING-STARTED.md)
- [Configuration](docs/01.CONFIGURATION.md)
- [API Reference](docs/02.API-REFERENCE.md)
- [API Example](docs/03.API-EXAMPLE.md)
- [Internals](docs/04.INTERNALS.md)
- [Migration Guide](docs/16.MIGRATION-GUIDE.md)
## Contributing
The project can only accept contributions which are licensed under the [Apache License 2.0](LICENSE) and are signed according to the JerryScript [Developer's Certificate of Origin](DCO.md). For further information please see our [Contribution Guidelines](CONTRIBUTING.md).
## License
JerryScript is Open Source software under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). Complete license and copyright information can be found in the source code.
JerryScript is open source software under the [Apache License 2.0](LICENSE). Complete license and copyright information can be found in the source code.
> Copyright 2015 Samsung Electronics Co., Ltd.
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript?ref=badge_large)
> Copyright JS Foundation and other contributors, http://js.foundation
> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+36
View File
@@ -0,0 +1,36 @@
version: "{build}"
branches:
except:
- coverity_scan
- gh_pages
skip_tags: true
# Build matrix setup.
image:
- Visual Studio 2017
configuration:
- Debug
- Release
platform:
- x64
- Win32
environment:
matrix:
- FEATURE_DEBUGGER: ON
- FEATURE_DEBUGGER: OFF
# Steps of a job.
init:
- cmake -version
before_build:
- if "%PLATFORM%"=="Win32" cmake -G"Visual Studio 15 2017" -Bbuild -H. -DFEATURE_DEBUGGER=%FEATURE_DEBUGGER%
- if "%PLATFORM%"=="x64" cmake -G"Visual Studio 15 2017 Win64" -Bbuild -H. -DFEATURE_DEBUGGER=%FEATURE_DEBUGGER%
build:
project: build\Jerry.sln
parallel: true
verbosity: minimal
artifacts:
- path: build\bin\$(configuration)\
name: JerryScriptBinary
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+1 -2
View File
@@ -1,5 +1,4 @@
# Copyright 2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -12,19 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# application name
set(MBEDMODULE "jerry")
set(CMAKE_SYSTEM_NAME TizenRT)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_SYSTEM_VERSION ARTIK053)
# add include jerry-core
set(LJCORE ${CMAKE_CURRENT_LIST_DIR}/../../../)
include_directories(${LJCORE})
set(FLAGS_COMMON_ARCH -mcpu=cortex-r4 -mthumb -mfpu=vfpv3
-fno-builtin -fno-strict-aliasing -fomit-frame-pointer -fno-strength-reduce
-Wall -Werror -Wshadow -Wno-error=conversion)
# compile flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlittle-endian -mthumb -mcpu=cortex-m4" )
# link jerryscript
set(LJPATH ${CMAKE_CURRENT_LIST_DIR}/../libjerry)
set(LJFILES "")
set(LJFILES ${LJFILES} ${LJPATH}/libjerrylibm.a)
set(LJFILES ${LJFILES} ${LJPATH}/libjerrycore.a)
target_link_libraries(${MBEDMODULE} ${LJFILES})
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_C_COMPILER_WORKS TRUE)
+3 -4
View File
@@ -1,4 +1,4 @@
# Copyright 2015 Samsung Electronics Co., Ltd.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME MCU)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_SYSTEM_VERSION STM32F3)
set(FLAGS_COMMON_ARCH -mlittle-endian -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard)
CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_C_COMPILER_WORKS TRUE)
+3 -4
View File
@@ -1,4 +1,4 @@
# Copyright 2015 Samsung Electronics Co., Ltd.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME MCU)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_SYSTEM_VERSION STM32F4)
set(FLAGS_COMMON_ARCH -mlittle-endian -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard)
CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_C_COMPILER_WORKS TRUE)
+22
View File
@@ -0,0 +1,22 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(CMAKE_SYSTEM_NAME MCU)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_SYSTEM_VERSION STM32F7)
set(FLAGS_COMMON_ARCH -mthumb -mcpu=cortex-m7 -march=armv7e-m -mfloat-abi=hard)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_C_COMPILER_WORKS TRUE)
+33
View File
@@ -0,0 +1,33 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME MCU)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_SYSTEM_VERSION TIM4F)
set(FLAGS_COMMON_ARCH --little_endian --silicon_version=7M4 --float_support=FPv4SPD16)
CMAKE_FORCE_C_COMPILER(armcl TI)
SET (CMAKE_C_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-o4 -mf0 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE_INIT "-o4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-o2 -g")
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-o4 -mf0 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-o4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-o2 -g")
+2 -2
View File
@@ -1,4 +1,4 @@
# Copyright 2016 Samsung Electronics Co., Ltd.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,4 +15,4 @@
set(CMAKE_SYSTEM_NAME Openwrt)
set(CMAKE_SYSTEM_PROCESSOR mips)
set(CMAKE_C_COMPILER mipsel-openwrt-linux-gcc)
set(CMAKE_C_COMPILER mips-openwrt-linux-gcc)
@@ -1,4 +1,4 @@
# Copyright 2015 Samsung Electronics Co., Ltd.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Openwrt)
set(CMAKE_SYSTEM_PROCESSOR mips)
set(CMAKE_SYSTEM_NAME EXTERNAL)
set(CMAKE_SYSTEM_PROCESSOR "${EXTERNAL_CMAKE_SYSTEM_PROCESSOR}")
CMAKE_FORCE_C_COMPILER(${EXTERNAL_CMAKE_C_COMPILER} ${EXTERNAL_CMAKE_C_COMPILER_ID})
set(CMAKE_C_COMPILER mipsel-openwrt-linux-gcc)
@@ -2,19 +2,20 @@
Currently, only Ubuntu 14.04+ is officially supported as primary development environment.
There are several dependencies, that should be installed manually. The following list is required for building:
There are several dependencies, that should be installed manually. The following list is the absolute minimum for building:
- `gcc` or any C99-compliant compiler
- native
- arm-none-eabi
- `gcc` or any C99-compliant compiler (native or cross, e.g., arm-none-eabi)
- `cmake` >= `2.8.12.2`
Several scripts and tools help the building and development process, thus it is recommended to have the following installed as well:
- `bash` >= `4.3.11`
- `cppcheck` >= `1.61`
- `vera++` >= `1.2.1`
- `python` >= `2.7.6`
```bash
sudo apt-get install gcc g++ gcc-arm-none-eabi cmake cppcheck vera++ python
sudo apt-get install gcc gcc-arm-none-eabi cmake cppcheck vera++ python
```
To make our scripts run correctly, several shell utilities should be available on the system:
@@ -38,32 +39,40 @@ python tools/build.py --debug
python tools/build.py --debug --lto=off
```
**To enable more verbose outputs for debugging**
```bash
tools/build.py --debug --logging=on --error-messages=on --line-info=on
```
**Add custom arguments to CMake**
```bash
python tools/build.py --cmake-param=CMAKE_PARAM
```
**Set a profile mode (full, minimal)**
**Set a profile mode (ES5.1, subset of ES2015, minimal)**
```bash
python tools/build.py --feature=full|minimal
python tools/build.py --profile=es5.1|es2015-subset|minimal
```
**Use (jerry, compiler-default, external) libc**
See also the related [README.md](https://github.com/jerryscript-project/jerryscript/blob/master/jerry-core/profiles/README.md).
The default libc is jerry-libc, but you can use compiler-default libc or an external libc:
**Use (compiler-default, external) libc**
The default libc is the compiler-default libc but you can use an external libc as well:
- compiler-default libc:
```bash
python tools/build.py --jerry-libc=off --compiler-default-libc=on
python tools/build.py
```
- external libc:
```bash
python tools/build.py --jerry-libc=off --compiler-default-libc=off --compile-flag="-I/path/to/libc/include"
python tools/build.py --compile-flag="-nostdlib -I/path/to/ext-libc/include" --link-lib="ext-c"
```
**Add toolchain file**
@@ -80,6 +89,46 @@ For example the cross-compile to RaspberryPi 2 is something like this:
python tools/build.py --toolchain=cmake/toolchain_linux_armv7l.cmake
```
**Use system memory allocator**
```bash
python tools/build.py --system-allocator=on
```
*Note*: System allocator is only supported on 32 bit systems.
**Enable 32bit compressed pointers**
```bash
python tools/build.py --cpointer-32bit=on
```
*Note*: There is no compression/decompression on 32 bit systems, if enabled.
**Change default heap size (512K)**
```bash
python tools/build.py --mem-heap=256
```
If you would like to use more than 512K, then you must enable the 32 bit compressed pointers.
```bash
python tools/build.py --cpointer-32bit=on --mem-heap=1024
```
*Note*: The heap size will be allocated statically at compile time, when JerryScript memory
allocator is used.
**To build with libfuzzer support**
```bash
CC=clang python tools/build.py --libfuzzer=on --compile-flag=-fsanitize=address --lto=off
```
Check the documentation of libfuzzer to get the runtime settings of the created fuzzer
binary: https://llvm.org/docs/LibFuzzer.html.
**To get a list of all the available buildoptions for Linux**
```bash
+289
View File
@@ -0,0 +1,289 @@
# Configuration
JerryScript provides a large number of configuration options which can be used to enable or disable specific features, allowing users to fine tune the engine to best suit their needs.
A configuration option's value can be changed either by providing specific C preprocessor definitions, by adding CMake defininitions, or by using the arguments of the `tools/build.py` script.
This document lists the available configuration options, shows the configuration name for C, CMake, and python, and provides a brief description that explains the effect of the options.
### All-in-one build
Enables the All-in-one build process, which aggregates the contents of each source file, and uses this combined file to compile the JerryScript library.
This process can provide comparable results to link time optimization, and can be useful when LTO is not available otherwise.
| Options | |
|---------|----------------------------------------------|
| C: | `<none>` |
| CMake: | `-DENABLE_ALL_IN_ONE=ON/OFF` |
| Python: | `--all-in-one=ON/OFF` |
### Jerry debugger
Enables debugger support in the engine, which can be used to debug running JavaScript code. For more information on using the debugger see [Debugger](07.DEBUGGER.md).
The debugger is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_DEBUGGER=0/1` |
| CMake: | `-DJERRY_DEBUGGER=ON/OFF` |
| Python: | `--jerry-debugger=ON/OFF` |
### Line information
By default, all source code information is discarded after parsing is complete. This option can be used to augment the created bytecode to provide line information during runtime,
that can be used by the debugger to identify the currently executed source context. See [Debugger](07.DEBUGGER.md).
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_LINE_INFO=0/1` |
| CMake: | `-DJERRY_LINE_INFO=ON/OFF` |
| Python: | `--line-info=ON/OFF` |
### Profiles
This option can be used to enable/disable available JavaScript language features by providing profile files. Profile files contain a list of C definitions that configure each individual feature.
The `path` value for CMake and Python arguments should be a file path to the profile file, or one of `es2015-subset`, `es5.1`, or `minimal`, which are the pre-defined profiles.
To see how a profile file should be created, or what configuration options are available in C, see the profile [README](https://github.com/jerryscript-project/jerryscript/blob/master/jerry-core/profiles/README.md).
| Options | |
|---------|----------------------------------------------|
| C: | `<see description>` |
| CMake: | `-DJERRY_PROFILE="path"` |
| Python: | `--profile="path"` |
### External context
Enables external context support in the engine. By default, JerryScript uses a statically allocated context to store the current state of the engine internals.
When this option is enabled, an externally allocated memory region can be provided through the port API to the engine, to be used as the context.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_EXTERNAL_CONTEXT=0/1` |
| CMake: | `-DJERRY_EXTERNAL_CONTEXT=ON/OFF` |
| Python: | `--external-context=ON/OFF` |
### Snapshot execution
This option can be used to enable snapshot execution in the engine.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_SNAPSHOT_EXEC=0/1` |
| CMake: | `-DJERRY_SNAPSHOT_EXEC=ON/OFF` |
| Python: | `--snapshot-exec=ON/OFF` |
### Snapshot saving
This option can be used to enable snapshot saving in the engine.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_SNAPSHOT_SAVE=0/1` |
| CMake: | `-DJERRY_SNAPSHOT_SAVE=ON/OFF` |
| Python: | `--snapshot-save=ON/OFF` |
### Jerry parser
This option can be used to enable or disable the parser. When the parser is disabled all features that depend on source parsing are unavailable (eg. `jerry_parse`, `eval`, Function constructor).
This option can be useful in combination with the snapshot feature. The parser is enabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_PARSER=0/1` |
| CMake: | `-DJERRY_PARSER=ON/OFF` |
| Python: | `--js-parser=ON/OFF` |
### Dump bytecode
This option can be used to display created bytecode in a human readable format. See [Internals](04.INTERNALS.md#byte-code) for more details.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_PARSER_DUMP_BYTE_CODE=0/1` |
| CMake: | `-DJERRY_PARSER_DUMP_BYTE_CODE=ON/OFF` |
| Python: | `--show-opcodes=ON/OFF` |
### Dump RegExp bytecode
This option can be used to display created RegExp bytecode in a human readable format. The RegExp bytecode is different from the bytecode used by the virtual machine.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_REGEXP_DUMP_BYTE_CODE=0/1` |
| CMake: | `-DJERRY_REGEXP_DUMP_BYTE_CODE=ON/OFF` |
| Python: | `--show-regexp-opcodes=ON/OFF` |
### Strict RegExp
This option can be used to enable strict RegExp mode. The standard RegExp syntax is a lot stricter than what is common in current JavaScript implementations.
When enabled, this flag disables all of the non-standard, quality-of-life RegExp features, that are implemented to provide compatibility with other commonly used engines.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_REGEXP_STRICT_MODE=0/1` |
| CMake: | `-DJERRY_REGEXP_STRICT_MODE=ON/OFF` |
| Python: | `--regexp-strict-mode=ON/OFF` |
### Error messages
Enables error messages for thrown Error objects. By default, error messages are omitted to reduce memory usage.
Enabling this feature provides detailed error messages where available, like line information for Syntax errors, variable names for Reference errors, Type/Range error messages for built-in routines, etc.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_ERROR_MESSAGES=0/1` |
| CMake: | `--DJERRY_ERROR_MESSAGES=ON/OFF` |
| Python: | `--error-messages=ON/OFF` |
### Logging
This option can be used to enable log messages during runtime. When enabled the engine will use the `jerry_port_log` port API function to print relevant log messages.
This feature is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_LOGGING=0/1` |
| CMake: | `-DJERRY_LOGGING=ON/OFF` |
| Python: | `--logging=ON/OFF` |
### LCache
This option enables the LCache, allowing faster access to object properties. The LCache usases a statically allocated hash-map, which increases memory consumption.
See [Internals](04.INTERNALS.md#lcache) for further details.
This option is enabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_LCACHE=0/1` |
| CMake: | `<none>` |
| Python: | `<none>` |
### Property hashmaps
This option enables the creation of hashmaps for object properties, which allows faster property access, at the cost of increased memory consumption.
See [Internals](04.INTERNALS.md#property-hashmap) for further details.
This option is enabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_PROPRETY_HASHMAP=0/1` |
| CMake: | `<none>` |
| Python: | `<none>` |
### Memory statistics
This option can be used to provide memory usage statistics either upon engine termination, or during runtime using the `jerry_get_memory_stats` jerry API function.
The feature can create a significant performance overhead, and should only be used for measurement purposes. This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_MEM_STATS=0/1` |
| CMake: | `-DJERRY_MEM_STATS=ON/OFF` |
| Python: | `--mem-stats=ON/OFF` |
### Heap size
This option can be used to adjust the size of the internal heap, represented in kilobytes. The provided value should be an integer. Values larger than 512 require 32-bit compressed pointers to be enabled.
The default value is 512.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_GLOBAL_HEAP_SIZE=(int)` |
| CMake: | `--DJERRY_GLOBAL_HEAP_SIZE=(int)` |
| Python: | `--heap-size=(int)` |
### Stack limit
This option can be used to cap the stack usage of the engine, and prevent stack overflows due to recursion. The provided value should be an integer, which represents the allowed stack usage in kilobytes.
The default value is 0 (unlimited).
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_STACK_LIMIT=(int)` |
| CMake: | `-DJERRY_STACK_LIMIT=(int)` |
| Python: | `--stack-limit=(int)` |
### 32-bit compressed pointers
Enables 32-bit pointers instead of the default 16-bit compressed pointers. This allows the engine to use a much larger heap, but also comes with slightly increased memory usage, as objects can't be packed as tightly.
This option must be enabled when using the system allocator.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_CPOINTER_32_BIT=0/1` |
| CMake: | `-DJERRY_CPOINTER_32_BIT=ON/OFF` |
| Python: | `--cpointer-32bit=ON/OFF` |
### System allocator
This option enables the use of malloc/free instead of the internal JerryScript allocator. This feature requires 32-bit compressed pointers, and is unsupported on 64-bit architectures.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_SYSTEM_ALLOCATOR=0/1` |
| CMake: | `-DJERRY_SYSTEM_ALLOCATOR=ON/OFF` |
| Python: | `--system-allocator=ON/OFF` |
### Valgrind support
This option enables valgrind support for the internal allocator. When enabled, valgrind will be able to properly identify allocated memory regions, and report leaks or out-of-bounds memory accesses.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_VALGRIND=0/1` |
| CMake: | `-DJERRY_VALGRIND=ON/OFF` |
| Python: | `--valgrind=ON/OFF` |
### Memory stress test
This option can be used to stress test memory management, by running garbage collection before every allocation attempt.
This option is disabled by default.
| Options | |
|---------|----------------------------------------------|
| C: | `-DJERRY_MEM_GC_BEFORE_EACH_ALLOC=0/1` |
| CMake: | `-DJERRY_MEM_GC_BEFORE_EACH_ALLOC=ON/OFF` |
| Python: | `--mem-stress-test=ON/OFF` |
# Single source build mode
There is a special mode to use/"build" JerryScript. That is generating a single C file which can be
included into projects quickly. To achive this the following command can be executed to create
a set of files into the `gen_src` directory (Note that the command is executed in the jerryscript root directory
but can be adapted to run outside of the project root dir):
```sh
$ python tools/srcgenerator.py --output-dir gen_src --jerry-core --jerry-port-default --jerry-libm
```
The command creates the following files in the `gen_src` dir:
* `jerryscript.c`
* `jerryscript.h`
* `jerryscript-config.h`
* `jerryscript-port-default.c`
* `jerryscript-port-default.h`
* `jerryscript-libm.c`
* `math.h`
**Important**: the `jerryscript-config.h` contains the configurations mentioned above and
should be adapted to the required use-case. See the file contents for more details and for the
default configuration. (Note: This config file is created from the the `jerry-core/config.h` file.)
These files can be directly compiled with an application using the JerryScript API.
For example with the following command:
```sh
$ gcc -Wall -o demo_app demo_app.c gen_src/jerryscript.c gen_src/jerryscript-port-default.c jerryscript-libm.c -Igen_src/
```
Please note that the headers must be available on the include path.
In addition there is a `-DENABLE_ALL_IN_ONE_SOURCE=ON` CMake option to use this kind of sources during the build.
+4926 -263
View File
File diff suppressed because it is too large Load Diff
+708 -122
View File
File diff suppressed because it is too large Load Diff
+26 -24
View File
@@ -23,7 +23,7 @@ Expression parser is responsible for parsing JavaScript expressions. It is imple
JavaScript statements are parsed by this component. It uses the [Expression parser](#expression-parser) to parse the constituent expressions. The implementation of Statement parser is located in `./jerry-core/parser/js/js-parser-statm.c`.
Function `parser_parse_source` carries out the parsing and compiling of the input EcmaScript source code. When a function appears in the source `parser_parse_source` calls `parser_parse_function` which is responsible for processing the source code of functions recursively including argument parsing and context handling. After the parsing, function `parser_post_processing` dumps the created opcodes and returns an `ecma_compiled_code_t*` that points to the compiled bytecode sequence.
Function `parser_parse_source` carries out the parsing and compiling of the input ECMAScript source code. When a function appears in the source `parser_parse_source` calls `parser_parse_function` which is responsible for processing the source code of functions recursively including argument parsing and context handling. After the parsing, function `parser_post_processing` dumps the created opcodes and returns an `ecma_compiled_code_t*` that points to the compiled bytecode sequence.
The interactions between the major components shown on the following figure.
@@ -31,21 +31,21 @@ The interactions between the major components shown on the following figure.
# Byte-code
This section describes the compact byte-code (CBC) byte-code representation. The key focus is reducing memory consumption of the byte-code representation without sacrificing considerable performance. Other byte-code representations often focus on performance only so inventing this representation is an original research.
This section describes the compact byte-code (CBC) representation. The key focus is reducing memory consumption of the byte-code representation without sacrificing considerable performance. Other byte-code representations often focus on performance only so inventing this representation is an original research.
CBC is a CISC like instruction set which assigns shorter instructions for frequent operations. Many instructions represent multiple atomic tasks which reduces the byte code size. This technique is basically a data compression method.
CBC is a CISC like instruction set which assigns shorter instructions for frequent operations. Many instructions represent multiple atomic tasks which reduces the bytecode size. This technique is basically a data compression method.
## Compiled Code Format
The memory layout of the compiled byte code is the following.
The memory layout of the compiled bytecode is the following.
![CBC layout](img/CBC_layout.png)
The header is a `cbc_compiled_code` structure with several fields. These fields contain the key properties of the compiled code.
The literals part is an array of ecma values. These values can contain any EcmaScript value types, e.g. strings, numbers, function and regexp templates. The number of literals is stored in the `literal_end` field of the header.
The literals part is an array of ecma values. These values can contain any ECMAScript value types, e.g. strings, numbers, functions and regexp templates. The number of literals is stored in the `literal_end` field of the header.
CBC instruction list is a sequence of byte code instructions which represents the compiled code.
CBC instruction list is a sequence of bytecode instructions which represents the compiled code.
## Byte-code Format
@@ -55,7 +55,7 @@ The memory layout of a byte-code is the following:
Each byte-code starts with an opcode. The opcode is one byte long for frequent and two byte long for rare instructions. The first byte of the rare instructions is always zero (`CBC_EXT_OPCODE`), and the second byte represents the extended opcode. The name of common and rare instructions start with `CBC_` and `CBC_EXT_` prefix respectively.
The maximum number of opcodes is 511, since 255 common (zero value excluded) and 256 rare instructions can be defined. Currently around 230 frequent and 120 rare instructions are available.
The maximum number of opcodes is 511, since 255 common (zero value excluded) and 256 rare instructions can be defined. Currently around 215 frequent and 70 rare instructions are available.
There are three types of bytecode arguments in CBC:
@@ -63,7 +63,7 @@ There are three types of bytecode arguments in CBC:
* __literal argument__: An integer index which is greater or equal than zero and less than the `literal_end` field of the header. For further information see next section Literals (next).
* __relative branch__: An 1-3 byte long offset. The branch argument might also represent the end of an instruction range. For example the branch argument of `CBC_EXT_WITH_CREATE_CONTEXT` shows the end of a `with` statement. More precisely the position after the last instruction.
* __relative branch__: An 1-3 byte long offset. The branch argument might also represent the end of an instruction range. For example the branch argument of `CBC_EXT_WITH_CREATE_CONTEXT` shows the end of a `with` statement. More precisely the position after the last instruction in the with clause.
Argument combinations are limited to the following seven forms:
@@ -137,12 +137,12 @@ Byte-codes of this category serve for placing objects onto the stack. As there a
<span class="CSSTableGenerator" markdown="block">
| byte-code | description |
| --------------------- | ---------------------------------------------------- |
| CBC_PUSH_LITERAL | Pushes the value of the given literal argument. |
| CBC_PUSH_TWO_LITERALS | Pushes the value of the given two literal arguments. |
| CBC_PUSH_UNDEFINED | Pushes an undefined value. |
| CBC_PUSH_TRUE | Pushes a logical true. |
| byte-code | description |
| --------------------- | ----------------------------------------------------- |
| CBC_PUSH_LITERAL | Pushes the value of the given literal argument. |
| CBC_PUSH_TWO_LITERALS | Pushes the values of the given two literal arguments. |
| CBC_PUSH_UNDEFINED | Pushes an undefined value. |
| CBC_PUSH_TRUE | Pushes a logical true. |
| CBC_PUSH_PROP_LITERAL | Pushes a property whose base object is popped from the stack, and the property name is passed as a literal argument. |
</span>
@@ -196,7 +196,7 @@ Branch byte-codes are used to perform conditional and unconditional jumps in the
| CBC_JUMP_BACKWARD | Jumps backward by the 1 byte long relative offset argument. |
| CBC_JUMP_BACKWARD_2 | Jumps backward by the 2 byte long relative offset argument. |
| CBC_JUMP_BACKWARD_3 | Jumps backward by the 3 byte long relative offset argument. |
| CBC_BRANCH_IF_TRUE_FORWARD | Jumps if the value on the top of the stack is true by the 1 byte long relative offset argument. |
| CBC_BRANCH_IF_TRUE_FORWARD | Jumps forward if the value on the top of the stack is true by the 1 byte long relative offset argument. |
</span>
@@ -219,12 +219,14 @@ ECMA component of the engine is responsible for the following notions:
## Data Representation
The major structure for data representation is `ECMA_value`. The lower two bits of this structure encode value tag, which determines the type of the value:
The major structure for data representation is `ECMA_value`. The lower three bits of this structure encode value tag, which determines the type of the value:
* simple
* number
* string
* object
* symbol
* error
![ECMA value representation](img/ecma_value.png)
@@ -243,16 +245,17 @@ Compressed pointers were introduced to save heap space.
![Compressed Pointer](img/ecma_compressed.png)
These pointers are 8 byte aligned 16 bit long pointers which can address 512 Kb of memory which is also the maximum size of the JerryScript heap.
ECMA data elements are allocated in pools (pools are allocated on heap)
Chunk size of the pool is 8 bytes (reduces fragmentation).
These pointers are 8 byte aligned 16 bit long pointers which can address 512 Kb of
memory which is also the maximum size of the JerryScript heap. To support even more
memory the size of compressed pointers can be extended to 32 bit to cover the entire
address space of a 32 bit system by passing "--cpointer_32_bit on" to the build
system. These "uncompressed pointers" increases the memory consumption by around 20%.
### Number
There are two possible representation of numbers according to standard IEEE 754:
The default is 8-byte (double),
but the engine supports the 4-byte (single precision) representation by setting CONFIG_ECMA_NUMBER_TYPE as well.
but the engine supports the 4-byte (single precision) representation by setting JERRY_NUMBER_TYPE_FLOAT64 to 0 as well.
![Number](img/number.png)
@@ -260,7 +263,7 @@ Several references to single allocated number are not supported. Each reference
### String
Strings in JerryScript are not just character sequences, but can hold numbers and so-called magic ids too. For common character sequences there is a table in the read only memory that contains magic id and character sequence pairs. If a string is already in this table, the magic id of its string is stored, not the character sequence itself. Using numbers speeds up the property access. These techniques save memory.
Strings in JerryScript are not just character sequences, but can hold numbers and so-called magic ids too. For common character sequences (defined in `./jerry-core/lit/lit-magic-strings.ini`) there is a table in the read only memory that contains magic id and character sequence pairs. If a string is already in this table, the magic id of its string is stored, not the character sequence itself. Using numbers speeds up the property access. These techniques save memory.
### Object / Lexical Environment
@@ -274,7 +277,6 @@ The objects are represented as following structure:
* Reference counter - number of hard (non-property) references
* Next object pointer for the garbage collector
* GC's visited flag
* type (function object, lexical environment, etc.)
### Properties of Objects
@@ -322,7 +324,7 @@ Collections are array-like data structures, which are optimized to save memory.
### Exception Handling
In order to implement a sense of exception handling, the return values of JerryScript functions are able to indicate their faulty or "exceptional" operation. The return values are actually ECMA values (see section [Data Representation](#data-representation)) in which the error bit is set if an erroneous operation is occurred.
In order to implement a sense of exception handling, the return values of JerryScript functions are able to indicate their faulty or "exceptional" operation. The return values are ECMA values (see section [Data Representation](#data-representation)) and if an erroneous operation occurred the ECMA_VALUE_ERROR simple value is returned.
### Value Management and Ownership
+231 -70
View File
@@ -11,7 +11,8 @@ It is questionable whether a library should be able to terminate an application.
*
* @param code gives the cause of the error.
*
* Note: jerry expects the function not to return.
* Note:
* Jerry expects the function not to return.
*
* Example: a libc-based port may implement this with exit() or abort(), or both.
*/
@@ -24,8 +25,8 @@ Error codes
typedef enum
{
ERR_OUT_OF_MEMORY = 10,
ERR_SYSCALL = 11,
ERR_REF_COUNT_LIMIT = 12,
ERR_DISABLED_BYTE_CODE = 13,
ERR_FAILED_INTERNAL_ASSERTION = 120
} jerry_fatal_code_t;
```
@@ -35,20 +36,6 @@ typedef enum
These are the only I/O functions jerry calls.
```c
/**
* Print a string to the console. The function should implement a printf-like
* interface, where the first argument specifies a format string on how to
* stringify the rest of the parameter list.
*
* This function is only called with strings coming from the executed ECMAScript
* wanting to print something as the result of its normal operation.
*
* It should be the port that decides what a "console" is.
*
* Example: a libc-based port may implement this with vprintf().
*/
void jerry_port_console (const char *fmt, ...);
/**
* Jerry log levels. The levels are in severity order
* where the most serious levels come first.
@@ -62,52 +49,171 @@ typedef enum
} jerry_log_level_t;
/**
* Display or log a debug/error message. The function should implement a printf-like
* interface, where the first argument specifies the log level
* and the second argument specifies a format string on how to stringify the rest
* of the parameter list.
* Display or log a debug/error message, and sends it to the debugger client as well.
* The function should implement a printf-like interface, where the first argument
* specifies the log level and the second argument specifies a format string on how
* to stringify the rest of the parameter list.
*
* This function is only called with messages coming from the jerry engine as
* the result of some abnormal operation or describing its internal operations
* the result of some abnormal operation or describing its internal operations
* (e.g., data structure dumps or tracing info).
*
* It should be the port that decides whether error and debug messages are logged to
* the console, or saved to a database or to a file.
*
* Example: a libc-based port may implement this with vfprintf(stderr) or
*
* Example: a libc-based port may implement this with vfprintf(stderr) or
* vfprintf(logfile), or both, depending on log level.
*
* Note:
* This port function is called by jerry-core when JERRY_LOGGING is
* enabled. It is also common practice though to use this function in
* application code.
*/
void jerry_port_log (jerry_log_level_t level, const char *fmt, ...);
```
The `jerry_port_print_char` is currenlty not used by the jerry-core directly.
However, it provides a port specifc way for `jerry-ext` components to print
information.
```c
/**
* Print a character to stdout.
*/
void jerry_port_print_char (char c);
```
### ES2015 Module system helper functions
The module system requires two specific functions for opening and closing files.
It also requires a platform specific way of normalizing file paths.
```c
/**
* Opens file with the given path and reads its source.
* @return the source of the file
*/
uint8_t *
jerry_port_read_source (const char *file_name_p, /**< file name */
size_t *out_size_p) /**< [out] read bytes */
{
// open file from given path
// return its source
} /* jerry_port_read_source */
/**
* Release the previously opened file's content.
*/
void
jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
{
free (buffer_p);
} /* jerry_port_release_source */
/**
* Normalize a file path
*
* @return length of the path written to the output buffer
*/
size_t
jerry_port_normalize_path (const char *in_path_p, /**< input file path */
char *out_buf_p, /**< output buffer */
size_t out_buf_size, /**< size of output buffer */
char *base_file_p) /**< base file path */
{
// normalize in_path_p by expanding relative paths etc.
// if base_file_p is not NULL, in_path_p is relative to that file
// write to out_buf_p the normalized path
// return length of written path
} /* jerry_port_normalize_path */
```
## Date
```c
/**
* Jerry time zone structure
*/
typedef struct
{
int offset; /**< minutes from west */
int daylight_saving_time; /**< daylight saving time (1 - DST applies, 0 - not on DST) */
} jerry_time_zone_t;
/**
* Get timezone and daylight saving data
* Get local time zone adjustment, in milliseconds, for the given timestamp.
* The timestamp can be specified in either UTC or local time, depending on
* the value of is_utc. Adding the value returned from this function to
* a timestamp in UTC time should result in local time for the current time
* zone, and subtracting it from a timestamp in local time should result in
* UTC time.
*
* @return true - if success
* false - otherwise
* Ideally, this function should satisfy the stipulations applied to LocalTZA
* in section 20.3.1.7 of the ECMAScript version 9.0 spec.
*
* See Also:
* ECMA-262 v9, 20.3.1.7
*
* Note:
* This port function is called by jerry-core when
* JERRY_BUILTIN_DATE is set to 1. Otherwise this function is
* not used.
*
* @param unix_ms The unix timestamp we want an offset for, given in
* millisecond precision (could be now, in the future,
* or in the past). As with all unix timestamps, 0 refers to
* 1970-01-01, a day is exactly 86 400 000 milliseconds, and
* leap seconds cause the same second to occur twice.
* @param is_utc Is the given timestamp in UTC time? If false, it is in local
* time.
*
* @return milliseconds between local time and UTC for the given timestamp,
* if available
*. 0 if not available / we are in UTC.
*/
bool jerry_port_get_time_zone (jerry_time_zone_t *);
double jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc);
/**
* Get system time
*
* Note:
* This port function is called by jerry-core when
* JERRY_BUILTIN_DATE is set to 1. It is also common practice
* in application code to use this function for the initialization of the
* random number generator.
*
* @return milliseconds since Unix epoch
*/
double jerry_port_get_current_time (void);
```
## External context
Allow user to provide external buffer for isolated engine contexts, so that user
can configure the heap size at runtime and run multiple JS applications
simultaneously.
```c
/**
* Get the current context of the engine. Each port should provide its own
* implementation of this interface.
*
* Note:
* This port function is called by jerry-core when
* JERRY_EXTERNAL_CONTEXT is enabled. Otherwise this function is not
* used.
*
* @return the pointer to the engine context.
*/
struct jerry_context_t *jerry_port_get_current_context (void);
```
## Sleep
```c
/**
* Makes the process sleep for a given time.
*
* Note:
* This port function is called by jerry-core when JERRY_DEBUGGER is set to 1.
* Otherwise this function is not used.
*
* @param sleep_time milliseconds to sleep.
*/
void jerry_port_sleep (uint32_t sleep_time);
```
# How to port JerryScript
This section describes a basic port implementation which was created for Unix based systems.
@@ -116,7 +222,7 @@ This section describes a basic port implementation which was created for Unix ba
```c
#include <stdlib.h>
#include "jerry-port.h"
#include "jerryscript-port.h"
/**
* Default implementation of jerry_port_fatal.
@@ -131,20 +237,7 @@ void jerry_port_fatal (jerry_fatal_code_t code)
```c
#include <stdarg.h>
#include "jerry-port.h"
/**
* Provide console message implementation for the engine.
*/
void
jerry_port_console (const char *format, /**< format string */
...) /**< parameters */
{
va_list args;
va_start (args, format);
vfprintf (stdout, format, args);
va_end (args);
} /* jerry_port_console */
#include "jerryscript-port.h"
/**
* Provide log message implementation for the engine.
@@ -164,39 +257,45 @@ jerry_port_log (jerry_log_level_t level, /**< log level */
} /* jerry_port_log */
```
```c
/**
* Print a character to stdout with putchar.
*/
void
jerry_port_print_char (char c)
{
putchar (c);
} /* jerr_port_print_char */
```
## Date
```c
#include <time.h>
#include <sys/time.h>
#include "jerry-port.h"
#include "jerryscript-port.h"
/**
* Default implementation of jerry_port_get_time_zone.
* Default implementation of jerry_port_get_local_time_zone_adjustment.
*/
bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
double jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since unix epoch */
bool is_utc) /**< is the time above in UTC? */
{
struct timeval tv;
struct timezone tz;
/* gettimeofday may not fill tz, so zero-initializing */
tz.tz_minuteswest = 0;
tz.tz_dsttime = 0;
if (gettimeofday (&tv, &tz) != 0)
struct tm tm;
time_t now = (time_t) (unix_ms / 1000);
localtime_r (&now, &tm);
if (!is_utc)
{
return false;
now -= tm.tm_gmtoff;
localtime_r (&now, &tm);
}
tz_p->offset = tz.tz_minuteswest;
tz_p->daylight_saving_time = tz.tz_dsttime > 0 ? 1 : 0;
return true;
} /* jerry_port_get_time_zone */
return ((double) tm.tm_gmtoff) * 1000;
} /* jerry_port_get_local_time_zone_adjustment */
/**
* Default implementation of jerry_port_get_current_time.
*/
double jerry_port_get_current_time ()
double jerry_port_get_current_time (void)
{
struct timeval tv;
@@ -208,3 +307,65 @@ double jerry_port_get_current_time ()
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
} /* jerry_port_get_current_time */
```
## External context
```c
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
/**
* Pointer to the current context.
* Note that it is a global variable, and is not a thread safe implementation.
*/
static jerry_context_t *current_context_p = NULL;
/**
* Set the current_context_p as the passed pointer.
*/
void
jerry_port_default_set_current_context (jerry_context_t *context_p) /**< points to the created context */
{
current_context_p = context_p;
} /* jerry_port_default_set_current_context */
/**
* Get the current context.
*
* @return the pointer to the current context
*/
jerry_context_t *
jerry_port_get_current_context (void)
{
return current_context_p;
} /* jerry_port_get_current_context */
```
## Sleep
```c
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#ifdef HAVE_TIME_H
#include <time.h>
#elif defined (HAVE_UNISTD_H)
#include <unistd.h>
#endif /* HAVE_TIME_H */
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
void jerry_port_sleep (uint32_t sleep_time)
{
#ifdef HAVE_TIME_H
nanosleep (&(const struct timespec)
{
(time_t) sleep_time / 1000, ((long int) sleep_time % 1000) * 1000000L /* Seconds, nanoseconds */
}
, NULL);
#elif defined (HAVE_UNISTD_H)
usleep ((useconds_t) sleep_time * 1000);
#endif /* HAVE_TIME_H */
(void) sleep_time;
} /* jerry_port_sleep */
#endif /* defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1) */
```
+176
View File
@@ -0,0 +1,176 @@
## Reference counting in JerryScript
In JerryScript all `jerry_value_t` values are independent
references to internal objects. Values returned by JerryScript
API functions are always live references and must be released
by `jerry_release_value`.
```c
jerry_value_t global = jerry_get_global_object ();
/* The value stored in the 'global' variable contains a live
* reference to the global object. The system also keeps its
* own live reference to the global object. These two references
* are independent, and both must be destroyed before the global
* object can be freed. */
jerry_release_value (global);
/* Without jerry_release_value() the global object will not
* be freed even by jerry_cleanup(). After the reference
* is released it becomes a dead reference and cannot be
* used anymore. */
```
Multiple references might refer to the same internal object
even though their `jerry_value_t` representation might be different.
```c
jerry_value_t pi_ref1 = jerry_create_number (3.14);
jerry_value_t pi_ref2 = jerry_acquire_value (pi_ref1);
/* Both pi_ref1 and pi_ref2 refer to the same 3.14 value
* although they might not be equal in C (pi_ref1 != pi_ref2). */
/* Both references must be released. */
jerry_release_value (pi_ref1);
jerry_release_value (pi_ref2);
```
Releasing the same `jerry_value_t` twice to release two live
references is not allowed and it might cause crashes. Hence the
following code is an **INCORRECT WAY** of releasing the 3.14 value.
```c
jerry_release_value (pi_ref1);
jerry_release_value (pi_ref1);
```
JerryScript API functions returning with a `jerry_value_t` always
return with a new live reference. Passing a `jerry_value_t` to
an API function never releases its reference (unless explicitly
stated in the documentation). The next example shows this
behaviour through property getting and setting.
```c
jerry_value_t prop_value = jerry_get_property (...);
/* The prop_value must be released later because both the base
* object and the prop_value have an independent reference to
* the same JavaScript value. When the operation fails, the
* prop_value contains a live reference to an error object.
* This reference must be released as well. */
if (jerry_value_is_error (prop_value))
{
/* Errors can be handled here. */
}
else
{
/* The application has a live reference to the property
* value even if the base object is freed by the garbage
* collector. */
}
/* The prop_value must be released. */
jerry_release_value (prop_value);
/* Property setting is the same. */
jerry_value_t new_prop_value = jerry_create_number (2.718);
jerry_value_t result = jerry_set_property (..., new_prop_value);
/* If the property set is successful, a new reference is created
* for the value referenced by new_prop_value. The new_prop_value
* reference must be released regardless of whether the operation
* is successful. */
/* The new_prop_value can be passed to other JerryScript API
* functions before the jerry_release_value () call. */
jerry_release_value (new_prop_value);
/* The reference stored in the 'result' variable is live whether
* the operation is successful or not, and must also be freed. */
if (jerry_value_is_error (result))
{
/* Errors can be handled here. */
}
else
{
/* A reference to a true primitive value is returned. */
}
jerry_release_value (result);
```
The simplest form of setting a property without error checking
is the following:
```c
/* There are no 'ifs' in this snippet. */
jerry_release_value (jerry_set_property (..., new_prop_value));
jerry_release_value (new_prop_value);
```
The reference returned by a `jerry_external_handler_t` callback
transfers the ownership of the live reference. Otherwise the
referenced object could be freed by the garbage collector.
```c
jerry_value_t my_external_handler (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_count
{
/* Do not release function_obj, this_val, and args_p because
* these references are automatically released after the handler
* is returned. This approach reduces code size which is useful
* on embedded systems. However you can create other references
* to them by calling jerry_acquire_value () if needed. */
/* Since the ownership of the reference is transferred to the
* caller the following snippet is valid. */
/* If the value to be returned is needed for other purposes the
* jerry_acquire_value () can be used to create new references. */
return jerry_create_string (...);
}
```
Duplicating a `jerry_value_t` in C does not create another live reference.
```c
jerry_value_t undef = jerry_create_undefined ();
jerry_value_t undef2 = undef;
/* Releasing either undef or undef2 is valid but not both.
* After the release both references become dead (invalid). */
jerry_release_value (undef2);
/* Dead references can be reassigned again. */
undef = jerry_create_boolean (true);
```
References can be duplicated in C as long as only one of them is freed.
```c
jerry_value_t a = jerry_create_boolean (true);
jerry_value_t b = a;
jerry_value_t c = a;
/* A new reference is assigned to 'a'. */
a = jerry_create_boolean (false);
[...]
jerry_release_value (a);
/* The 'a' (boolean false) reference becomes dead (invalid). */
jerry_release_value (c);
/* Both 'b' and 'c' (boolean true) references become dead. */
/* Since all references are released, no memory leak occurs. */
```
+441
View File
@@ -0,0 +1,441 @@
## JerryScript debugger interface
JerryScript provides a remote debugger which allows debugging
JavaScript programs. The debugger has two main components:
a server which is part of the JerryScript binary and a
separate client application. Currently a Python-based debugger
client is available in the /jerry-debugger subdirectory.
This simple application demonstrates the communication protocol
between the client and server, and can be reused by integrated
development environments.
## Setting up the debugger server
The following arguments must be passed to `tools/build.py`:
`--jerry-debugger=on`
The transport layer of the communication protocol is pluggable.
At the moment, a WebSocket-based implementation is provided as a
JerryScript extension, which transmits messages over TCP/IP networks.
If necessary/implemented, any reliable stream or datagram based
protocol can be used for transmitting debugger messages.
## Debugging JavaScript applications
The debugger client must be connected to the server before the
JavaScript application runs. On-the-fly attachment is supported
for more than one file, right after the engine initialization
(this feature is available with the python client). The debugging
information (e.g. line index of each possible breakpoint location)
is not preserved by JerryScript. The client is expected to be run
on a system with much more resources and it should be capable of
storing this information. JerryScript frees all debug information
after it is transmitted to the client to save memory.
The following argument makes JerryScript wait for a client
connection:
`--start-debug-server`
The following argument makes JerryScript wait for a client
source code:
`--debugger-wait-source`
It is also recommended to increase the log level to see
the *Waiting for client connection* message:
`--log-level 2`
The Python client can connect to the server by specifying its
IP address on the command line. The address can be localhost
if the server and the client are running on the same machine.
After the connection is established the execution can be
controlled by the debugger. The debugger always stops at
the first possible breakpoint location. The effect is the
same as using the `stop` command. This allows inserting
breakpoints right before the meaningful part of the execution
starts.
All available commands of the client can be queried by the
`help` command.
## Integrating debugger support into applications using JerryScript
When using the extension-provided WebSocket transport layer, the
debugger can be enabled by calling `jerryx_debugger_after_connect
(jerryx_debugger_tcp_create (debug_port) && jerryx_debugger_ws_create ())`
after the `jerry_init ()` function. It initializes the debugger and
blocks until a client connects.
(Custom transport layers may be implemented and initialized similarly.
Currently, `jerryx_debugger_rp_create ()` for raw packet transport layer and
`jerryx_debugger_serial_create (const char* config)` for serial protocol
are also available.)
The resource name provided to `jerry_parse ()` is used by the client
to identify the resource name of the source code. This resource name
is usually a file name.
## JerryScript debugger C-API interface
The following section describes the debugger functions
available to the host application.
## JerryScript debugger types
## jerry_debugger_wait_for_source_callback_t
**Summary**
This callback function is called by
[jerry_debugger_wait_for_client_source](#jerry_debugger_wait_for_client_source)
when a source code is received successfully.
**Prototype**
```c
typedef jerry_value_t
(*jerry_debugger_wait_for_source_callback_t) (const jerry_char_t *resource_name_p,
size_t resource_name_size,
const jerry_char_t *source_p,
size_t source_size, void *user_p);
```
- `resource_name_p` - resource (usually a file) name of the source code
- `resource_name_size` - size of resource name
- `source_p` - source code character data
- `source_size` - size of source code
- `user_p` - custom pointer passed to [jerry_debugger_wait_for_client_source](#jerry_debugger_wait_for_client_source)
## JerryScript debugger functions
### jerry_debugger_is_connected
**Summary**
Returns true if a remote debugger client is connected.
**Prototype**
```c
bool
jerry_debugger_is_connected (void);
```
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
if (jerry_debugger_is_connected ())
{
printf ("A remote debugger client is connected.");
}
jerry_cleanup ();
}
```
### jerry_debugger_stop
**Summary**
Stops execution at the next available breakpoint if a remote
debugger client is connected and the engine is not waiting at
a breakpoint. The engine will stop regardless the breakpoint
is enabled or not.
**Prototype**
```c
void
jerry_debugger_stop (void)
```
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_debugger_stop ();
jerry_cleanup ();
}
```
**See also**
- [jerry_debugger_continue](#jerry_debugger_continue)
### jerry_debugger_continue
**Summary**
If the engine would stop at the next available breakpoint it
cancels this effect. The engine will still stop at enabled
breakpoints. This function effectively negates the effect of
[jerry_debugger_stop ()](#jerry_debugger_stop) calls or stop
requests issued by the debugger client.
**Prototype**
```c
void
jerry_debugger_continue (void)
```
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_debugger_continue ();
jerry_cleanup ();
}
```
**See also**
- [jerry_debugger_stop](#jerry_debugger_stop)
### jerry_debugger_stop_at_breakpoint
**Summary**
Enables or disables stopping at breakpoints. When stopping is
disabled all breakpoints are ignored including user enabled
breakpoints. This allows hidden execution of ECMAScript code.
**Prototype**
```c
void
jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint)
```
- `enable_stop_at_breakpoint` - enable (=`true`) or disable (=`false`) stopping at breakpoints
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_debugger_stop_at_breakpoint (true);
// Protected execution of JavaScript code.
const jerry_char_t script[] = "42";
jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
jerry_debugger_stop_at_breakpoint (false);
jerry_cleanup ();
}
```
### jerry_debugger_wait_for_client_source
**Summary**
Asks the client to provide the next source code. The function
waits until the whole source code is received. As a reply the
the client may request a context reset or notify that no more
source is available. These notifications are passed back as the
return value of the function.
**Prototype**
```c
jerry_debugger_wait_for_source_status_t
jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t callback_p,
void *user_p, jerry_value_t *return_value)
```
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
/**
* Runs the source code received by jerry_debugger_wait_for_client_source.
*/
static jerry_value_t
wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resource name */
size_t resource_name_size, /**< size of resource name */
const jerry_char_t *source_p, /**< source code */
size_t source_size, /**< source code size */
void *user_p __attribute__((unused))) /**< user pointer */
{
jerry_value_t ret_val = jerry_parse (resource_name_p,
resource_name_size,
source_p,
source_size,
JERRY_PARSE_NO_OPTS);
if (!jerry_value_is_error (ret_val))
{
jerry_value_t func_val = ret_val;
ret_val = jerry_run (func_val);
jerry_release_value (func_val);
}
return ret_val;
} /* wait_for_source_callback */
int
main (void)
{
jerry_debugger_wait_for_source_status_t receive_status;
do
{
/* Create a new JerryScript instance when a context reset is
* received. Applications usually registers their core bindings
* here as well (e.g. print, setTimeout). */
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
do
{
jerry_value_t run_result;
receive_status = jerry_debugger_wait_for_client_source (wait_for_source_callback,
NULL,
&run_result);
jerry_release_value (run_result);
}
while (receive_status == JERRY_DEBUGGER_SOURCE_RECEIVED);
jerry_cleanup ();
}
while (receive_status == JERRY_DEBUGGER_CONTEXT_RESET_RECEIVED);
if (receive_status == JERRY_DEBUGGER_SOURCE_RECEIVE_FAILED)
{
// Handle the failure (e.g. display an error).
}
return 0;
}
```
### jerry_debugger_send_output
**Summary**
Sends the program's output to the debugger client.
**Prototype**
```c
void
jerry_debugger_send_output (const jerry_char_t *buffer, jerry_size_t string_size)
```
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_char_t my_output[] = "Hey, this should be sent too!";
jerry_size_t my_output_size = sizeof (my_output);
jerry_debugger_send_output (my_output, my_output_size);
jerry_cleanup ();
}
```
### jerry_debugger_send_log
**Summary**
Sends the program's log to the debugger client.
**Prototype**
```c
void
jerry_debugger_send_log (jerry_log_level_t level, const jerry_char_t *buffer, jerry_size_t string_size)
```
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_char_t my_log[] = "Custom diagnostics";
jerry_size_t my_log_size = sizeof (my_log);
jerry_debugger_send_log (JERRY_LOG_LEVEL_DEBUG, my_log, my_log_size);
jerry_cleanup ();
}
```
+797
View File
@@ -0,0 +1,797 @@
# JerryScript Coding Standards
This text is a brief overview of JerryScript Coding Standards.
Each rule starts with a short description followed by several
examples. We believe examples are better than long explanations.
Please follow these guidelines when you submit a patch for
review.
## General rules
* Indentation is two spaces.
* Tab characters are not allowed.
* Maximum line length is 120 characters (excluding newline).
* No trailing white space is allowed.
* Run `tools/run-tests.py --check-vera` to check several
of the coding conventions automatically.
## Comments
Only block comments (`/* */`) are allowed in JerryScript.
Comments should be complete sentences (e.g. start with an
upper case letter), except for return value, field and
argument descriptions (see the exceptions below). The
text part of a comment should focus on explaining *why*
the code is doing something rather than *what* the code
is doing.
```diff
+++ Good +++
```
```c
/* A perfect comment. */
/* A perfect multiline
* comment. Each line should
* start with an asterisk. */
```
```diff
--- Bad ---
```
```c
// Double slash comments are not allowed.
/* not a complete sentence */
/* A bad mulitiline
comment. */
```
All types, constants and functions require a description in
JerryScript. These comments should start with `/**`. The starting
`/**` and ending `*/` must be on separate lines.
```diff
+++ Good +++
```
```c
/**
* A correct description.
*/
```
```diff
--- Bad ---
```
```c
/** An incorrect description. */
```
## Preprocessor defines
The name of a preprocessor macro must be an uppercase string
and these macros must be preceded by a description.
Abbreviations are allowed but not preferred in new code.
```diff
+++ Good +++
```
```c
/**
* Short description about the constant.
*/
#define JERRY_VALUE_SEVEN 7
/**
* Short description about the macro function.
*/
#define JERRY_ADD_TWO_NUMBERS(arg1, arg2) \
((arg1) + (arg2))
/**
* Although this is correct, a reviewer might request
* to change NUMS to NUMBERS. Hence it is recommended
* to use NUMBERS in the first place.
*/
#define JERRY_ADD_TWO_NUMS(arg1, arg2) \
((arg1) + (arg2))
```
```diff
--- Bad ---
```
```c
#define JERRY_CONSTANT_WITHOUT_DESCRIPTION 5
#define JeRrY_mIxEd_CaSe_NaMe "str"
```
## Conditional preprocessor directives
A comment is required after `#else` and `#endif` in JerryScript.
The defined keyword should be omitted from these comments.
```diff
+++ Good +++
```
```c
#ifdef JERRY_A
#else /* !JERRY_A */
#endif /* JERRY_A */
#ifdef JERRY_A
#if defined JERRY_B && defined JERRY_C && (JERRY_C > 6)
#else /* !(JERRY_B && JERRY_C && (JERRY_C > 6)) */
#endif /* JERRY_B && JERRY_C && (JERRY_C > 6) */
#endif /* JERRY_A */
```
```diff
--- Bad ---
```
```c
#ifdef JERRY_A
#endif
#ifdef JERRY_A
#endif /* defined JERRY_A */
#ifdef JERRY_B
/* Missing comment after else. */
#else
#endif /* JERRY_B */
```
## Code blocks
Each code block must be enclosed in curly braces even
if it is a single line statement. These braces must
be on separate lines. There must be a single space
before the opening parenthesis of the expression
after if/while/switch keywords.
```diff
+++ Good +++
```
```c
if (value > 6)
{
function_call ();
}
if (value > 1)
{
function_call_a ();
}
else
{
function_call_b ();
}
do
{
function_call ();
value++;
}
while (value < 6);
switch (value)
{
case A:
{
/* FALLTHRU comment is allowed if a
* switch-case is not terminated by
* break/continue/return. */
/* FALLTHRU */
}
case B:
case C:
{
break;
}
case D:
{
/* We can use continue if we are in a loop. */
continue;
}
default:
{
return;
}
}
```
```diff
--- Bad ---
```
```c
if (value > 6)
function_call_a ();
else
function_call_b ();
if (value > 6) {
function_call_a ();
}
if (value > 6) function_call_a ();
else { function_call_b (); }
if
(value > 6)
{
}
switch (value) {
case 0: break;
default: {
return 5;
}
}
switch (value)
{
case A:
{
if (value > 6)
{
CASE B:
{
/* This is allowed in C but
* not in JerryScript. */
break;
}
}
}
}
do
value++;
while (value < 5);
do {
value++;
} while (value < 5);
do
{
value++;
} while (value < 5);
```
## Newlines
A newline in JerryScript is a separator which separates different
parts of the source code. Its primary purpose is to improve
readability. Unlike other rules developers have some freedom
to add newlines to their code. However there are some rules.
* Only a single newline separator is allowed.
* Source files must be terminated by a newline.
* Global declarations must be separated by a newline.
* Newlines are not allowed after an opening curly brace or before
a closing curly brace
* No newlines are allowed between control statements (if-else, while,
for, switch, etc.) and their code blocks.
* There should be a newline after the variable declarations
if they are the first statements of a block.
```diff
+++ Good +++
```
```c
if (a > 5)
{
/* Newline must be present after the first
* variable declarations of a code block. */
int j = a - 1;
int k = a * 2;
return j + k;
}
while (a < 5)
{
a++;
/* It is recommended to put a newline after
* intermediate variable declarations. */
int i = a * 2;
b = i - 3;
}
/* It is a recommended to put newlines around asserts. */
a = b + 5;
JERRY_ASSERT (a < 20);
c = a + 7;
/* It is a good practice to put a newline after a multiline
* function call (see Function calls later). */
f (a,
b,
c);
a = 6;
```
```diff
--- Bad ---
```
```c
/* No newlines are allowed after an opening curly
* brace or before a closing curly brace */
while (a > 0)
{
a = 6;
}
if (a > 5)
{
while (b < 6)
{
b++;
}
}
/* Two or more newlines are not allowed. */
a = 6;
b = 7;
/* No newlines are allowed between control staments
* and their code blocks. */
if (a > 6)
{
}
else
{
}
do
{
}
while (a < 6);
```
## Expressions
Spaces are required around binary operators. No space is
needed otherwise.
```diff
+++ Good +++
```
```c
a = b + c;
a = (b + c) << 3;
a = b = c + ~d;
a += ++c + d++;
call_function (a * (b + !!c) - d + (e % f));
if (a)
{
}
```
```diff
--- Bad ---
```
```c
a=b+c;
a = b+c;
a += c + ( d );
/* Introduce temporary variables or macros
* if the expression is too long. Occures rarely.. */
a = b
+ c;
if ( a + b > 0 )
{
}
```
## Logical operators
All expressions with && and || logical operators must be
enclosed in parentheses. A single and multiline form is
allowed for these expressions. In the latter case each
line must start with the logical operator and each line
must be aligned to the column right after the opening
parenthesis.
```diff
+++ Good +++
```
```c
/* Single line form. */
a = ((c && d) || (e && f));
a = (c
&& d);
a = (c
&& (d || e)
&& f);
do
{
}
while (a
&& b);
/* This form is rarely used but it is ok. */
if (a
&& (b
|| c
|| d)
&& e)
{
}
```
```diff
--- Bad ---
```
```c
if (a || b ||
c)
{
}
/* Parentheses are missing. */
a = b || c;
/* Misaligned &&. */
if (a
&& b)
{
}
```
## Ternary conditional operators
A special form of ternary conditional operators are allowed
in JerryScript where the ? and : operators are on separate
lines in the same column.
```diff
+++ Good +++
```
```c
a = (b ? c
: d);
/* Single line form is accepted as well. */
a = (b ? c : d);
/* This form is rarely used but it is ok. */
if (a ? b
: (c ? d
: e))
{
}
```
```diff
--- Bad ---
```
```c
a = b ?
c : d;
while (a ? b
: c)
{
}
if (a
? b
: c)
{
}
```
## Function calls
There must be a space after the function name. Each argument
must be in the same or separated lines. In the former case
there must be a space before the next argument and in the
latter case all arguments must be aligned to the same column.
```diff
+++ Good +++
```
```c
function_a ();
function_b (a);
function_c (a, b, c);
function_c (a,
b,
c);
function_c (a,
b,
function_c (a,
b,
c);
```
```diff
--- Bad ---
```
```c
/* No space before the opening parenthesis. */
function_f();
function_f (
);
function_g(a);
function_g
(a
);
/* Two arguments on the same line. */
function_h (a, b,
c);
function_h (a,
b, c);
/* Misaligned arguments. */
function_h (a,
b,
c);
```
## Variable declarations
JerryScript is a pure C99 codebase so variable
declarations can be anywhere in the code including
inside for-loops. It is recommended to declare a
variable before the first use.
```diff
+++ Good +++
```
```c
for (int i = 0; i < 10; i++)
{
int j = i + 1;
while (j < 10)
{
++j;
}
}
/* Multiline form of for loops. */
for (int i = 0;
i < 10;
i++)
{
}
```
## Type casting
There must be a space after the closing parenthesis
of the type cast. Type casting has no multiline form
in JerryScript.
```diff
+++ Good +++
```
```c
int a = (int) double_variable;
int a = (int) (long) (float) double_variable;
```
```diff
--- Bad ---
```
```c
/* Wrong spaces. */
int a = ( int )double_variable;
/* No multiline form. */
int a = (int)
double_variable;
```
## Pointers and asterisk character
Each pointer in JerryScript must be a lowercase string
which is ending with a `_p` suffix. Furthermore there
must be a space before the asterisk character.
```diff
+++ Good +++
```
```c
int *int_p;
/* No need to add multiple _p-s for multiple indirections.
* It is recommended to avoid these constructs using typedef
* declarations. A reviewer might request such a change. */
int ***int_p;
/* This rule applies for type casting as well. */
char = *(char *) type_p;
```
```diff
--- Bad ---
```
```c
/* No _p after the name. */
int *ptr;
/* Wrong asterisk position. */
int* ptr_p;
char_p = * (char*)type_p;
```
## Types
Each type in JerryScript must be a lowercase string
which ends with a `_t` suffix. Furthermore each type
declaration must be preceded by a short description
of the type and each field must have a short description
as well.
```diff
+++ Good +++
```
```c
/**
* Short description of the following structure.
*/
typedef struct
{
/* Field descriptions do not start with capital letters
* and there is no full stop at the end. */
field1_t field1; /**< description of field 1 */
field2_t field2; /**< description of field 2 */
field_n_t field_n; /**< description of field n */
} structure_name_t;
/**
* Another integer type.
*/
typedef int jerry_int;
```
```diff
--- Bad ---
```
```c
typedef struct
{
field_t field_without_description;
} structure_without_description_t;
typedef struct { int a; } single_line_struct;
typedef
union {
}
wrong_newlines_t;
/*
* Bad comment format.
*/
typedef
char wrong_newlines_again_t;
```
## Function declarations
Function declarations in JerryScript are verbose but this format
reduces the maintenance cost and allows faster understanding of
the code.
```diff
+++ Good +++
```
```c
/**
* Short overview about the purpose of this function.
*
* A more detailed explanation if needed.
*
* Note:
* Extra notes if needed.
*
* @return short description about the value
* returned by the function
*/
return_value_type_t
function_name (argument1, /**< description of argument1 */
argument2, /**< description of argument2 */
...
argument_n, /**< description of argument n */
{
/* Function body. */
} /* function_name */
```
```diff
--- Bad ---
```
```c
static int
print (char *text) /**< description of text argument */
{
/* Missing comment before the function. */
} /* print */
/**
* Prints the text received by the function.
*
* @return number of characters printed by the function
*/
int print(char *text)
{
/* No description of text argument. */
/* Missing comment at the end of the function. */
}
```
+855
View File
@@ -0,0 +1,855 @@
# jerryx_arg types
## jerryx_arg_t
**Summary**
The structure defining a single validation/transformation step.
*Note*: For commonly used validators, `arg.h` provides helpers to create the `jerryx_arg_t`s.
For example, `jerryx_arg_number ()`, `jerryx_arg_boolean ()`, etc.
**Prototype**
```c
typedef struct
{
/** the transform function */
jerryx_arg_transform_func_t func;
/** pointer to destination where func should store the result */
void *dest;
/** extra information, specific to func */
uintptr_t extra_info;
} jerryx_arg_t;
```
**See also**
- [jerryx_arg_number](#jerryx_arg_number)
- [jerryx_arg_boolean](#jerryx_arg_boolean)
- [jerryx_arg_string](#jerryx_arg_string)
- [jerryx_arg_utf8_string](#jerryx_arg_utf8_string)
- [jerryx_arg_function](#jerryx_arg_function)
- [jerryx_arg_native_pointer](#jerryx_arg_native_pointer)
- [jerryx_arg_ignore](#jerryx_arg_ignore)
- [jerryx_arg_object_properties](#jerryx_arg_object_properties)
## jerryx_arg_object_props_t
**Summary**
The structure is used in `jerryx_arg_object_properties`. It provides the properties' names,
its corresponding JS-to-C mapping and other related information.
**Prototype**
```c
typedef struct
{
const jerry_char_t **name_p; /**< property name list of the JS object */
jerry_length_t name_cnt; /**< count of the name list */
const jerryx_arg_t *c_arg_p; /**< points to the array of transformation steps */
jerry_length_t c_arg_cnt; /**< the count of the `c_arg_p` array */
} jerryx_arg_object_props_t;
```
**See also**
- [jerryx_arg_object_properties](#jerryx_arg_object_properties)
## jerryx_arg_array_items_t
**Summary**
The structure is used in `jerryx_arg_array`. It provides the array items' corresponding
JS-to-C mappings and count.
**Prototype**
```c
typedef struct
{
const jerryx_arg_t *c_arg_p; /**< points to the array of transformation steps */
jerry_length_t c_arg_cnt; /**< the count of the `c_arg_p` array */
} jerryx_arg_array_items_t;
```
**See also**
- [jerryx_arg_array](#jerryx_arg_array)
## jerryx_arg_transform_func_t
**Summary**
Signature of the transform function.
Users can create custom transformations by implementing a transform function
and using `jerryx_arg_custom ()`.
The function is expected to return `undefined` if it ran successfully or
return an `Error` in case it failed. The function can use the iterator and the
helpers `jerryx_arg_js_iterator_pop ()` and `jerryx_arg_js_iterator_peek ()` to
get the next input value.
*Note*: A transform function is allowed to consume any number of input values!
This enables complex validation like handling different JS function signatures,
mapping multiple input arguments to a C struct, etc.
The function is expected to store the result of
a successful transformation into `c_arg_p->dest`. In case the validation did
not pass, the transform should not modify `c_arg_p->dest`.
Additional parameters can be provided to the function through `c_arg_p->extra_info`.
**Prototype**
```c
typedef jerry_value_t (*jerryx_arg_transform_func_t) (jerryx_arg_js_iterator_t *js_arg_iter_p,
const jerryx_arg_t *c_arg_p);
```
**See also**
- [jerryx_arg_custom](#jerryx_arg_custom)
- [jerryx_arg_js_iterator_pop](#jerryx_arg_js_iterator_pop)
- [jerryx_arg_js_iterator_peek](#jerryx_arg_js_iterator_peek)
## jerryx_arg_coerce_t
Enum that indicates whether an argument is allowed to be coerced into the expected JS type.
- JERRYX_ARG_COERCE - the transform will invoke toNumber, toBoolean, toString, etc.
- JERRYX_ARG_NO_COERCE - the type coercion is not allowed. The transform will fail if the type does not match the expectation.
**See also**
- [jerryx_arg_number](#jerryx_arg_number)
- [jerryx_arg_boolean](#jerryx_arg_boolean)
- [jerryx_arg_string](#jerryx_arg_string)
## jerryx_arg_optional_t
Enum that indicates whether an argument is optional or required.
- JERRYX_ARG_OPTIONAL - The argument is optional. If the argument is `undefined` the transform is successful and `c_arg_p->dest` remains untouched.
- JERRYX_ARG_REQUIRED - The argument is required. If the argument is `undefined` the transform will fail and `c_arg_p->dest` remains untouched.
**See also**
- [jerryx_arg_number](#jerryx_arg_number)
- [jerryx_arg_boolean](#jerryx_arg_boolean)
- [jerryx_arg_string](#jerryx_arg_string)
- [jerryx_arg_function](#jerryx_arg_function)
- [jerryx_arg_native_pointer](#jerryx_arg_native_pointer)
## jerryx_arg_round_t
Enum that indicates the rounding policy which will be chosen to transform an integer.
- JERRYX_ARG_ROUND - use round() method.
- JERRYX_ARG_FLOOR - use floor() method.
- JERRYX_ARG_CEIL - use ceil() method.
**See also**
- [jerryx_arg_uint8](#jerryx_arg_uint8)
- [jerryx_arg_uint16](#jerryx_arg_uint16)
- [jerryx_arg_uint32](#jerryx_arg_uint32)
- [jerryx_arg_int8](#jerryx_arg_int8)
- [jerryx_arg_int16](#jerryx_arg_int16)
- [jerryx_arg_int32](#jerryx_arg_int32)
## jerryx_arg_clamp_t
Indicates the clamping policy which will be chosen to transform an integer.
If the policy is NO_CLAMP, and the number is out of range,
then the transformer will throw a range error.
- JERRYX_ARG_CLAMP - clamp the number when it is out of range
- JERRYX_ARG_NO_CLAMP - throw a range error
**See also**
- [jerryx_arg_uint8](#jerryx_arg_uint8)
- [jerryx_arg_uint16](#jerryx_arg_uint16)
- [jerryx_arg_uint32](#jerryx_arg_uint32)
- [jerryx_arg_int8](#jerryx_arg_int8)
- [jerryx_arg_int16](#jerryx_arg_int16)
- [jerryx_arg_int32](#jerryx_arg_int32)
# Main functions
## jerryx_arg_transform_this_and_args
**Summary**
Validate the this value and the JS arguments, and assign them to the native arguments.
This function is useful to perform input validation inside external function handlers (see `jerry_external_handler_t`).
**Prototype**
```c
jerry_value_t
jerryx_arg_transform_this_and_args (const jerry_value_t this_val,
const jerry_value_t *js_arg_p,
const jerry_length_t js_arg_cnt,
const jerryx_arg_t *c_arg_p,
jerry_length_t c_arg_cnt)
```
- `this_val` - `this` value. Note this is processed as the first value, before the array of arguments.
- `js_arg_p` - points to the array with JS arguments.
- `js_arg_cnt` - the count of the `js_arg_p` array.
- `c_arg_p` - points to the array of validation/transformation steps
- `c_arg_cnt` - the count of the `c_arg_p` array.
- return value - a `jerry_value_t` representing `undefined` if all validators passed or an `Error` if a validator failed.
**Example**
[doctest]: # (test="compile")
```c
#include "jerryscript.h"
#include "jerryscript-ext/arg.h"
/* JS signature: function (requiredBool, requiredString, optionalNumber) */
static jerry_value_t
my_external_handler (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_count)
{
bool required_bool;
char required_str[16];
double optional_num = 1234.567; // default value
/* "mapping" defines the steps to transform input arguments to C variables. */
const jerryx_arg_t mapping[] =
{
/* `this` is the first value. No checking needed on `this` for this function. */
jerryx_arg_ignore (),
jerryx_arg_boolean (&required_bool, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_string (required_str, sizeof (required_str), JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&optional_num, JERRYX_ARG_NO_COERCE, JERRYX_ARG_OPTIONAL),
};
/* Validate and transform. */
const jerry_value_t rv = jerryx_arg_transform_this_and_args (this_val,
args_p,
args_count,
mapping,
4);
if (jerry_value_is_error (rv))
{
/* Handle error. */
return rv;
}
/*
* Validated and transformed successfully!
* required_bool, required_str and optional_num can now be used.
*/
return jerry_create_undefined (); /* Or return something more meaningful. */
}
```
**See also**
- [jerryx_arg_ignore](#jerryx_arg_ignore)
- [jerryx_arg_number](#jerryx_arg_number)
- [jerryx_arg_boolean](#jerryx_arg_boolean)
- [jerryx_arg_string](#jerryx_arg_string)
- [jerryx_arg_function](#jerryx_arg_function)
- [jerryx_arg_native_pointer](#jerryx_arg_native_pointer)
- [jerryx_arg_custom](#jerryx_arg_custom)
- [jerryx_arg_object_properties](#jerryx_arg_object_properties)
## jerryx_arg_transform_args
**Summary**
Validate an array of `jerry_value_t` and assign them to the native arguments.
**Prototype**
```c
jerry_value_t
jerryx_arg_transform_args (const jerry_value_t *js_arg_p,
const jerry_length_t js_arg_cnt,
const jerryx_arg_t *c_arg_p,
jerry_length_t c_arg_cnt)
```
- `js_arg_p` - points to the array with JS arguments.
- `js_arg_cnt` - the count of the `js_arg_p` array.
- `c_arg_p` - points to the array of validation/transformation steps
- `c_arg_cnt` - the count of the `c_arg_p` array.
- return value - a `jerry_value_t` representing `undefined` if all validators passed or an `Error` if a validator failed.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
## jerryx_arg_transform_object_properties
**Summary**
Validate the properties of a JS object and assign them to the native arguments.
*Note*: This function transforms properties of a single JS object into native C values.
To transform multiple objects in one pass (for example when converting multiple arguments
to an external handler), please use `jerryx_arg_object_properties` together with
`jerryx_arg_transform_this_and_args` or `jerryx_arg_transform_args`.
**Prototype**
```c
jerry_value_t
jerryx_arg_transform_object_properties (const jerry_value_t obj_val,
const jerry_char_t **name_p,
const jerry_length_t name_cnt,
const jerryx_arg_t *c_arg_p,
jerry_length_t c_arg_cnt);
```
- `obj_val` - the JS object.
- `name_p` - points to the array of property names.
- `name_cnt` - the count of the `name_p` array.
- `c_arg_p` - points to the array of validation/transformation steps
- `c_arg_cnt` - the count of the `c_arg_p` array.
- return value - a `jerry_value_t` representing `undefined` if all validators passed or an `Error` if a validator failed.
**See also**
- [jerryx_arg_object_properties](#jerryx_arg_object_properties)
## jerryx_arg_transform_array
**Summary**
Validate the JS array and assign its items to the native arguments.
*Note*: This function transforms items of a single JS array into native C values.
To transform multiple JS arguments in one pass, please use `jerryx_arg_array` together with
`jerryx_arg_transform_this_and_args` or `jerryx_arg_transform_args`.
**Prototype**
```c
jerry_value_t
jerryx_arg_transform_array (const jerry_value_t array_val,
const jerryx_arg_t *c_arg_p,
jerry_length_t c_arg_cnt);
```
- `array_val` - the JS array.
- `c_arg_p` - points to the array of validation/transformation steps
- `c_arg_cnt` - the count of the `c_arg_p` array.
- return value - a `jerry_value_t` representing `undefined` if all validators passed or an `Error` if a validator failed.
**See also**
- [jerryx_arg_array](#jerryx_arg_array)
# Helpers for commonly used validations
## jerryx_arg_uint8
## jerryx_arg_uint16
## jerryx_arg_uint32
## jerryx_arg_int8
## jerryx_arg_int16
## jerryx_arg_int32
**Summary**
All above jerryx_arg_[u]intX functions are used to create a validation/transformation step
(`jerryx_arg_t`) that expects to consume one `number` JS argument
and stores it into a C integer (uint8, int8, uint16, ...)
**Prototype**
Take jerryx_arg_int32 as an example
```c
static inline jerryx_arg_t
jerryx_arg_int32 (int32_t *dest,
jerryx_arg_round_t round_flag,
jerryx_arg_clamp_t clamp_flag,
jerryx_arg_coerce_t coerce_flag,
jerryx_arg_optional_t opt_flag);
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to the `int32_t` where the result should be stored.
- `round_flag` - the rounding policy.
- `clamp_flag` - the clamping policy.
- `coerce_flag` - whether type coercion is allowed.
- `opt_flag` - whether the argument is optional.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
## jerryx_arg_number
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to consume
one `number` JS argument and stores it into a C `double`.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_number (double *dest,
jerryx_arg_coerce_t coerce_flag,
jerryx_arg_optional_t opt_flag)
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to the `double` where the result should be stored.
- `coerce_flag` - whether type coercion is allowed.
- `opt_flag` - whether the argument is optional.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
## jerryx_arg_boolean
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to
consume one `boolean` JS argument and stores it into a C `bool`.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_boolean (bool *dest,
jerryx_arg_coerce_t coerce_flag,
jerryx_arg_optional_t opt_flag)
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to the `bool` where the result should be stored.
- `coerce_flag` - whether type coercion is allowed.
- `opt_flag` - whether the argument is optional.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
## jerryx_arg_string
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to
consume one `string` JS argument and stores it into a CESU-8 C `char` array.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_string (char *dest,
uint32_t size,
jerryx_arg_coerce_t coerce_flag,
jerryx_arg_optional_t opt_flag)
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to the native char array where the result should be stored.
- `size` - the size of native char array.
- `coerce_flag` - whether type coercion is allowed.
- `opt_flag` - whether the argument is optional.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
- [jerry_arg_utf8_string](#jerry_arg_utf8_string)
## jerryx_arg_utf8_string
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to
consume one `string` JS argument and stores it into a UTF-8 C `char` array.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_utf8_string (char *dest,
uint32_t size,
jerryx_arg_coerce_t coerce_flag,
jerryx_arg_optional_t opt_flag)
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to the native char array where the result should be stored.
- `size` - the size of native char array.
- `coerce_flag` - whether type coercion is allowed.
- `opt_flag` - whether the argument is optional.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
- [jerry_arg_string](#jerry_arg_string)
## jerryx_arg_function
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to
consume one `function` JS argument and stores it into a C `jerry_value_t`.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_function (jerry_value_t *dest,
jerryx_arg_optional_t opt_flag)
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to the `jerry_value_t` where the result should be stored.
- `opt_flag` - whether the argument is optional.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
## jerryx_arg_native_pointer
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to
consume one `object` JS argument that is 'backed' with a native pointer with
a given type info. In case the native pointer info matches, the transform
will succeed and the object's native pointer will be assigned to `*dest`.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_native_pointer (void **dest,
const jerry_object_native_info_t *info_p,
jerryx_arg_optional_t opt_flag)
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to where the resulting native pointer should be stored.
- `info_p` - expected the type info.
- `opt_flag` - whether the argument is optional.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
## jerryx_arg_object_properties
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to
consume one `object` JS argument and call `jerryx_arg_transform_object_properties` inside
to transform its properties to native arguments.
User should prepare the `jerryx_arg_object_props_t` instance, and pass it to this function.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_object_properties (const jerryx_arg_object_props_t *object_props_p,
jerryx_arg_optional_t opt_flag);
```
- return value - the created `jerryx_arg_t` instance.
- `object_props_p` - provides information for properties transform.
- `opt_flag` - whether the argument is optional.
**Example**
[doctest]: # (test="compile")
```c
#include "jerryscript.h"
#include "jerryscript-ext/arg.h"
/**
* The binding function expects args_p[0] is an object, which has 3 properties:
* "enable": boolean
* "data": number
* "extra_data": number, optional
*/
static jerry_value_t
my_external_handler (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_count)
{
bool required_bool;
double required_num;
double optional_num = 1234.567; // default value
/* "prop_name_p" defines the name list of the expected properties' names. */
const char *prop_name_p[] = { "enable", "data", "extra_data" };
/* "prop_mapping" defines the steps to transform properties to C variables. */
const jerryx_arg_t prop_mapping[] =
{
jerryx_arg_boolean (&required_bool, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&required_num, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&optional_num, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL)
};
/* Prepare the jerryx_arg_object_props_t instance. */
const jerryx_arg_object_props_t prop_info =
{
.name_p = (const jerry_char_t **) prop_name_p,
.name_cnt = 3,
.c_arg_p = prop_mapping,
.c_arg_cnt = 3
};
/* It is the mapping used in the jerryx_arg_transform_args. */
const jerryx_arg_t mapping[] =
{
jerryx_arg_object_properties (&prop_info, JERRYX_ARG_REQUIRED)
};
/* Validate and transform. */
const jerry_value_t rv = jerryx_arg_transform_args (args_p,
args_count,
mapping,
1);
if (jerry_value_is_error (rv))
{
/* Handle error. */
return rv;
}
/*
* Validated and transformed successfully!
* required_bool, required_num and optional_num can now be used.
*/
return jerry_create_undefined (); /* Or return something more meaningful. */
}
```
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
- [jerryx_arg_transform_object_properties](#jerryx_arg_transform_object_properties)
## jerryx_arg_array
**Summary**
Create a validation/transformation step (`jerryx_arg_t`) that expects to
consume one `array` JS argument and call `jerryx_arg_transform_array_items` inside
to transform its items to native arguments.
User should prepare the `jerryx_arg_array_items_t` instance, and pass it to this function.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_array (const jerryx_arg_array_items_t *array_items_p, jerryx_arg_optional_t opt_flag);
```
- return value - the created `jerryx_arg_t` instance.
- `array_items_p` - provides items information for transform.
- `opt_flag` - whether the argument is optional.
**Example**
[doctest]: # (test="compile")
```c
#include "jerryscript.h"
#include "jerryscript-ext/arg.h"
/**
* The binding function expects args_p[0] is an array, which has 3 items:
* first: boolean
* second: number
* third: number, optional
*/
static jerry_value_t
my_external_handler (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_count)
{
bool required_bool;
double required_num;
double optional_num = 1234.567; // default value
/* "item_mapping" defines the steps to transform array items to C variables. */
const jerryx_arg_t item_mapping[] =
{
jerryx_arg_boolean (&required_bool, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&required_num, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&optional_num, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL)
};
/* Prepare the jerryx_arg_array_items_t instance. */
const jerryx_arg_array_items_t array_info =
{
.c_arg_p = item_mapping,
.c_arg_cnt = 3
};
/* It is the mapping used in the jerryx_arg_transform_args. */
const jerryx_arg_t mapping[] =
{
jerryx_arg_array (&array_info, JERRYX_ARG_REQUIRED)
};
/* Validate and transform. */
const jerry_value_t rv = jerryx_arg_transform_args (args_p,
args_count,
mapping,
1);
if (jerry_value_is_error (rv))
{
/* Handle error. */
return rv;
}
/*
* Validated and transformed successfully!
* required_bool, required_num and optional_num can now be used.
*/
return jerry_create_undefined (); /* Or return something more meaningful. */
}
```
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
- [jerryx_arg_transform_object_properties](#jerryx_arg_transform_object_properties)
# Functions to create custom validations
## jerryx_arg_custom
**Summary**
Create a jerryx_arg_t instance with custom transform.
**Prototype**
```c
static inline jerryx_arg_t
jerryx_arg_custom (void *dest,
uintptr_t extra_info,
jerryx_arg_transform_func_t func)
```
- return value - the created `jerryx_arg_t` instance.
- `dest` - pointer to the native argument where the result should be stored.
- `extra_info` - the extra parameter data, specific to the transform function.
- `func` - the custom transform function.
**See also**
- [jerryx_arg_transform_this_and_args](#jerryx_arg_transform_this_and_args)
## jerryx_arg_js_iterator_pop
**Summary**
Pop the current `jerry_value_t` argument from the iterator.
It will change the `js_arg_idx` and `js_arg_p` value in the iterator.
**Prototype**
```c
jerry_value_t
jerryx_arg_js_iterator_pop (jerryx_arg_js_iterator_t *js_arg_iter_p)
```
- return value - the `jerry_value_t` argument that was popped.
- `js_arg_iter_p` - the JS arg iterator from which to pop.
## jerryx_arg_js_iterator_peek
**Summary**
Get the current JS argument from the iterator, without moving the iterator forward.
*Note:* Unlike `jerryx_arg_js_iterator_pop ()`, it will not change `js_arg_idx` and
`js_arg_p` value in the iterator.
**Prototype**
```c
jerry_value_t
jerryx_arg_js_iterator_peek (jerryx_arg_js_iterator_t *js_arg_iter_p)
```
- return value - the current `jerry_value_t` argument.
- `js_arg_iter_p` - the JS arg iterator from which to peek.
## jerryx_arg_js_iterator_restore
**Summary**
Restore the last item popped from the stack. This can be called as
many times as there are arguments on the stack -- if called when the
first element in the array is the current top of the stack, this
function does nothing.
*Note:* This function relies on the underlying implementation of the
arg stack as an array, as its function is to simply back up the "top
of stack" pointer to point to the previous element of the array.
*Note:* Like `jerryx_arg_js_iterator_pop ()`, this function will
change the `js_arg_idx` and `js_arg_p` values in the iterator.
**Prototype**
```c
jerry_value_t
jerryx_arg_js_iterator_restore (jerryx_arg_js_iterator_t *js_arg_iter_p)
```
- return value - the the new top of the stack.
- `js_arg_iter_p` - the JS arg iterator to restore.
## jerryx_arg_js_iterator_index
**Summary**
Get the index of the current JS argument from the iterator.
**Prototype**
```c
jerry_length_t
jerryx_arg_js_iterator_index (jerryx_arg_js_iterator_t *js_arg_iter_p)
```
- return value - the index of current JS argument.
- `js_arg_iter_p` - the JS arg iterator from which to peek.
+601
View File
@@ -0,0 +1,601 @@
# Common methods to handle properties
The `jerryscript-ext/handler.h` header defines a set of convenience methods
which makes the property access a bit straightforward.
## jerryx_set_property_str
**Summary**
Set a property on a target object with a given name.
*Note*:
- The property name must be a zero terminated UTF-8 string.
- There should be no '\0' (NULL) character in the name excluding the string terminator.
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
is no longer needed.
**Prototype**
```c
jerry_value_t
jerryx_set_property_str (const jerry_value_t target_object,
const char *name,
const jerry_value_t value);
```
- `target_object` - the object where the property should be set
- `name` - name of the property
- `value` - property value to be set
- return value
- JS true value, if success
- thrown error, if there was a problem setting the property
**Example**
[doctest]: # ()
```c
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
int
main (int argc, char **argv)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t global = jerry_get_global_object ();
jerry_value_t value = jerry_create_number (3.3);
jerry_value_t result = jerryx_set_property_str (global, "value", value);
if (jerry_value_is_error (result))
{
/* The error type/reason can be extracted via the `jerry_get_value_from_error` method */
printf ("Error during property configuration\r\n");
}
jerry_release_value (result);
jerry_release_value (value);
jerry_release_value (global);
jerry_cleanup();
return 0;
}
```
## jerryx_get_property_str
**Summary**
Get the value of a property from the specified object with the given name.
*Notes*:
- The property name must be a zero terminated UTF-8 string.
- There should be no '\0' (NULL) character in the name excluding the string terminator.
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
is no longer needed.
**Prototype**
```
jerry_value_t
jerryx_get_property_str (const jerry_value_t target_object,
const char *name);
```
- `target_object` - object on which the property name is accessed
- `name` - property name as an UTF-8 `char*`
- return value
- value of property, if success
- thrown error, if there was a problem accessing the property
**Example**
[doctest]: # ()
```c
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
int
main (int argc, char **argv)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t global = jerry_get_global_object ();
jerry_value_t math_object = jerryx_get_property_str (global, "Math");
/* use math_object */
jerry_release_value (math_object);
jerry_release_value (global);
jerry_cleanup();
return 0;
}
```
## jerryx_has_property_str
**Summary**
Check if a property exists on an object.
*Notes*:
- The operation performed is the same as what the `jerry_has_property` method.
- The property name must be a zero terminated UTF-8 string.
- There should be no '\0' (NULL) character in the name excluding the string terminator.
**Prototype**
```
bool
jerryx_has_property_str (const jerry_value_t target_object,
const char *name);
```
- `target_object` - object on which the property name is accessed
- `name` - property name as an UTF-8 `char*`
- return value
- true, if the given property name exsits on the object
- false, if there is no such property name or there was an error accessing the property
**Example**
[doctest]: # ()
```c
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
int
main (int argc, char **argv)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t global = jerry_get_global_object ();
bool have_math = jerryx_has_property_str (global, "Math");
jerry_release_value (global);
jerry_cleanup();
return have_math ? 0 : 1;
}
```
# Utility to register multiple properties in bulk
In some cases it is useful to register multiple properties for a given object
for this the following utility structures and methods are provided.
## jerryx_property_entry
**Summary**
Structure to define an array of properties with `name` and `value` fields which
can be registered to a target object.
The engine must be initialied before specifying the `jerry_value_t` in the struct.
**Prototype**
```c
typedef struct {
const char *name;
jerry_value_t value;
} jerryx_function_list_entry;
```
**See also**
- [jerryx_set_properties](#jerryx_set_properties)
## jerryx_register_result
**Summary**
Structure returned as the result of the [jerryx_set_properties](#jerryx_set_properties) operation.
The `result` field will either be a JavaScript undefined value or an error object.
In every case the `registered` field is used to indicated the number of
successfully registered methods.
This must be passed for the [jerryx_release_property_entry](#jerryx_release_property_entry) method
after the property registration.
If any error occured during the property registration the `result` field of the structure
must be manually released after processing the error value.
**Prototype**
```c
typedef struct {
jerry_value_t result;
uint32_t registered;
} jerryx_register_result;
```
**See also**
- [jerryx_set_properties](#jerryx_set_properties)
- [jerryx_release_property_entry](#jerryx_release_property_entry)
## jerryx_set_properties
**Summary**
Set multiple properties on a target object.
The properties are an array of (name, jerry_value_t) pairs and
this list must end with a (NULL, 0) entry.
Important notes:
* Each property value in the input array is released after a successful property registration.
* The method [jerryx_release_property_entry](#jerryx_release_property_entry) must be called if there is any failed registration
to release the values in the entries array.
It is safe to call this cleanup method in every case not just in case of failure.
* If the error value is reported via the result it must be freed manually.
**Prototype**
```c
jerryx_register_result
jerryx_set_properties (const jerry_value_t target_object,
const jerryx_property_entry entries[]);
```
- `target_object` - object on which the entries will be set.
- `entries` - array of (name, jerry_value_t) pairs.
- return a [jerryx_register_result](#jerryx_register_result).
- if everything is ok, the struct's `result` field is set to a JS undefined value.
- otherwise the `result` field is an error object indicating the problem.
- in every case the `registered` field contains the number of successfully registered properties.
**Example**
[doctest]: # ()
```c
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
static jerry_value_t
handler (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_cnt)
{
printf ("native handler called!\n");
return jerry_create_boolean (true);
}
int
main (int argc, char **argv)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_property_entry methods[] =
{
{ "demo", jerry_create_external_function (handler) },
{ NULL, 0 },
};
jerry_value_t global = jerry_get_global_object ();
jerryx_register_result reg = jerryx_set_properties (global, methods);
/* if `reg.result` is undefined all methods are registered */
if (jerry_value_is_error (reg.result))
{
printf ("Only registered %d properties\r\n", reg.registered);
/* clean up not registered property values */
jerryx_release_property_entry (methods, reg);
/* clean up the error */
jerry_release_value (reg.result);
}
jerry_release_value (global);
jerry_cleanup();
return 0;
}
```
**Convenience macros**
To make property registration convenient, there are a set of macros to use
when setting a property entry:
* `JERRYX_PROPERTY_NUMBER(NAME, NUMBER)` - creates a number entry.
* `JERRYX_PROPERTY_STRING(NAME, STR)` - creates an UTF-8 string entry. This string must be zero terminated.
* `JERRYX_PROPERTY_STRING_SZ(NAME, STR, SIZE)` - creates an UTF-8 string entry using only `SIZE` bytes from the string.
* `JERRYX_PROPERTY_BOOLEAN(NAME, VALUE)` - creates a boolean entry.
* `JERRYX_PROPERTY_FUNCTION(NAME, NATIVE)` - creates a native C function entry.
* `JERRYX_PROPERTY_UNDEFINED(NAME)` - creates an undefined property entry.
* `JERRYX_PROPERTY_LIST_END()` - indicates the end of the property list.
**Example usage of Convenience macros**
[doctest]: # ()
```c
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
static jerry_value_t
handler (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_cnt)
{
printf ("native handler called!\n");
return jerry_create_boolean (true);
}
int
main (int argc, char **argv)
{
jerry_init (JERRY_INIT_EMPTY);
/**
* Create a array of properties to be registered.
* This must be done after initializing the engine as creating `jerry_value_t`
* elements are invalid before `jerry_init`.
*/
jerryx_property_entry methods[] =
{
JERRYX_PROPERTY_FUNCTION ("demo", handler),
JERRYX_PROPERTY_NUMBER ("test_num", 2.3),
JERRYX_PROPERTY_UNDEFINED ("this_is_undefined"),
JERRYX_PROPERTY_LIST_END(),
};
jerry_value_t global = jerry_get_global_object ();
jerryx_register_result reg = jerryx_set_properties (global, methods);
/* if `reg.result` is undefined all methods are registered */
if (jerry_value_is_error (reg.result))
{
printf ("Only registered %d properties\r\n", reg.registered);
/* clean up not registered property values */
jerryx_release_property_entry (methods, reg);
/* clean up the error */
jerry_release_value (reg.result);
}
jerry_release_value (global);
jerry_cleanup();
return 0;
}
```
**See also**
- [jerryx_property_entry](#jerryx_property_entry)
- [jerryx_release_property_entry](#jerryx_release_property_entry)
- [jerryx_register_result](#jerryx_register_result)
## jerryx_release_property_entry
**Summary**
Release all `jerry_value_t` in a `jerryx_property_entry` array based on a previous [jerryx_set_properties](#jerryx_set_properties) call
and also the error value (if any) in the `jerryx_register_result` structure.
In case of a successful registration it is safe to call this method.
After the method call the `ęntries` array should not be used as all values are released.
**Prototype**
```
void
jerryx_release_property_entry (const jerryx_property_entry entries[],
const jerryx_register_result register_result);
```
- `entires` - array of [jerryx_property_entry](#jerryx_property_entry).
- `register_result` - result of a previous [jerryx_set_properties](#jerryx_set_properties) call.
**Example**
For example usage see [jerryx_set_properties](#jerryx_set_properties).
# Common external function handlers
## jerryx_handler_assert_fatal
**Summary**
Hard assert for scripts. The routine calls `jerry_port_fatal` on assertion failure.
**Prototype**
```c
jerry_value_t
jerryx_handler_assert_fatal (const jerry_value_t func_obj_val, const jerry_value_t this_p,
const jerry_value_t args_p[], const jerry_length_t args_cnt);
```
- `func_obj_val` - the function object that was called (unused).
- `this_p` - the `this` value of the call (unused).
- `args_p` - the array of function arguments.
- `args_cnt` - the number of function arguments.
- return value - `jerry_value_t` representing boolean true, if only one argument
was passed and that argument was a boolean true. Note that the function does
not return otherwise.
**See also**
- [jerryx_handler_register_global](#jerryx_handler_register_global)
## jerryx_handler_assert_throw
**Summary**
Soft assert for scripts. The routine throws an error on assertion failure.
**Prototype**
```c
jerry_value_t
jerryx_handler_assert_throw (const jerry_value_t func_obj_val, const jerry_value_t this_p,
const jerry_value_t args_p[], const jerry_length_t args_cnt);
```
- `func_obj_val` - the function object that was called (unused).
- `this_p` - the `this` value of the call (unused).
- `args_p` - the array of function arguments.
- `args_cnt` - the number of function arguments.
- return value - `jerry_value_t` representing boolean true, if only one argument
was passed and that argument was a boolean true, an error otherwise.
**See also**
- [jerryx_handler_register_global](#jerryx_handler_register_global)
## jerryx_handler_assert
**Summary**
An alias to `jerryx_handler_assert_fatal`.
**See also**
- [jerryx_handler_assert_fatal](#jerryx_handler_assert_fatal)
## jerryx_handler_gc
**Summary**
Expose garbage collector to scripts. If the first argument of the function
is logical true, it performs a high pressure gc. Otherwise a low pressure
gc is performed, which is also the default if no parameters passed.
**Prototype**
```c
jerry_value_t
jerryx_handler_gc (const jerry_value_t func_obj_val, const jerry_value_t this_p,
const jerry_value_t args_p[], const jerry_length_t args_cnt);
```
- `func_obj_val` - the function object that was called (unused).
- `this_p` - the `this` value of the call (unused).
- `args_p` - the array of function arguments (unused).
- `args_cnt` - the number of function arguments (unused).
- return value - `jerry_value_t` representing `undefined`.
**See also**
- [jerryx_handler_register_global](#jerryx_handler_register_global)
## jerryx_handler_print
**Summary**
Provide a `print` implementation for scripts. The routine converts all of its
arguments to strings and outputs them char-by-char using
`jerry_port_print_char`. The NUL character is output as "\u0000",
other characters are output bytewise.
*Note*: This implementation does not use standard C `printf` to print its
output. This allows more flexibility but also extends the core JerryScript
engine port API. Applications that want to use `jerryx_handler_print` must
ensure that their port implementation also provides
`jerry_port_print_char`.
**Prototype**
```c
jerry_value_t
jerryx_handler_print (const jerry_value_t func_obj_val, const jerry_value_t this_p,
const jerry_value_t args_p[], const jerry_length_t args_cnt);
```
- `func_obj_val` - the function object that was called (unused).
- `this_p` - the `this` value of the call (unused).
- `args_p` - the array of function arguments.
- `args_cnt` - the number of function arguments.
- return value - `jerry_value_t` representing `undefined` if all arguments could
be converted to strings, an `Error` otherwise.
**See also**
- [jerryx_handler_register_global](#jerryx_handler_register_global)
- [jerry_port_print_char](05.PORT-API.md#jerry_port_print_char)
# Handler registration helper
## jerryx_handler_register_global
**Summary**
Register a JavaScript function in the global object.
*Note*: Returned value must be freed with `jerry_release_value`, when it is no
longer needed.
**Prototype**
```c
jerry_value_t
jerryx_handler_register_global (const jerry_char_t *name_p,
jerry_external_handler_t handler_p);
```
- `name_p` - the name of the function to be registered.
- `handler_p` - the address of the external function handler.
- return value - `jerry_value_t` representing boolean true, if the operation was
successful, an `Error` otherwise.
**Example**
[doctest]: # (test="compile")
```c
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
static const struct {
const char *name_p;
jerry_external_handler_t handler_p;
} common_functions[] =
{
{ "assert", jerryx_handler_assert },
{ "gc", jerryx_handler_gc },
{ "print", jerryx_handler_print },
{ NULL, NULL }
};
static void
register_common_functions (void)
{
jerry_value_t ret = jerry_create_undefined ();
for (int i = 0; common_functions[i].name_p != NULL && !jerry_value_is_error (ret); i++)
{
ret = jerryx_handler_register_global ((const jerry_char_t *) common_functions[i].name_p,
common_functions[i].handler_p);
}
jerry_release_value (ret);
}
```
+50
View File
@@ -0,0 +1,50 @@
# Autorelease values
## JERRYX_AR_VALUE_T
**Summary**
Macro for `const jerry_value_t` for which jerry_release_value() is
automatically called when the variable goes out of scope.
*Note*: The macro depends on compiler support. For GCC and LLVM/clang, the macro is implemented
using the `__cleanup__` variable attribute. For other compilers, no support has been added yet.
**Example**
[doctest]: # (test="compile")
```c
#include "jerryscript.h"
#include "jerryscript-ext/autorelease.h"
static void
foo (bool enable)
{
JERRYX_AR_VALUE_T bar = jerry_create_string ((const jerry_char_t *) "...");
if (enable)
{
JERRYX_AR_VALUE_T baz = jerry_get_global_object ();
/* bar and baz can now be used. */
/*
* jerry_release_value (baz) and jerry_release_value (bar) is called automatically before
* returning, because `baz` and `bar` go out of scope.
*/
return;
}
/*
* jerry_release_value (bar) is called automatically when the function returns,
* because `bar` goes out of scope.
*/
}
```
**See also**
- [jerry_value_t](../docs/02.API-REFERENCE.md#jerry_value_t)
- [jerry_acquire_value](../docs/02.API-REFERENCE.md#jerry_acquire_value)
- [jerry_release_value](../docs/02.API-REFERENCE.md#jerry_release_value)
+313
View File
@@ -0,0 +1,313 @@
# Module API
This is a JerryScript extension that provides a means of loading modules. Fundamentally, a module is a name (stored as
a string) that resolves to a `jerry_value_t`. This extension provides the function `jerryx_module_resolve()` which
accepts the name of the module being requested as well as an array of so-called "resolvers" - structures containing two
function pointers: one for a function which computes a canonical name for the requested module or returns a reference
to the requested name, and one that converts a canonical name to a `jerry_value_t`, thus "resolving" or "loading" the
requested module.
The resolvers are first called in sequence to each compute the canonical name of the requested module. This is
accomplished by calling the `get_canonical_name` function pointer they provide. If the function pointer is `NULL`, the
requested module name is assumed to be what the resolver considers to be its canonical name. `jerryx_module_resolve`
searches its cache of loaded modules for each canonical name as returned by a `get_canonical_name` function pointer. If
one of the loaded modules in the cache corresponds to a canonical name, it is returned.
If no cached module is found, `jerryx_module_resolve` calls each resolver's `resolve` function pointer, passing it its
previously computed interpretation of the requested module's canonical name. If the resolver successfully creates the
`jerry_value_t` that represents the loaded module, it returns `true` and the `jerry_value_t` in its out parameter.
When `jerryx_module_resolve` receives a value of `true` from a resolver, it stops iterating over the remaining
resolvers in the sequence and, if the `jerry_value_t` returned from the resolver's `resolve` does not have the error
flag set, it will add the `jerry_value_t` to its cache under the module's canonical name and return it. Thus, on
subsequent calls to `jerryx_module_resolve` with a module name whose canonical name is associated with the
`jerry_value_t`, no `resolve` callback need be called again.
The purpose of having resolvers is to be able to account for the fact that different types of modules may be structured
differently and thus, for each type of module a module resolver must be supplied at the point where an instance of that
type of module is requested.
Individual modules may be removed from the cache by calling `jerryx_module_clear_cache`. This function behaves
identically to `jerryx_module_resolve` in that it first checks the cache for the requested module, except that it
removes the module if found. Additionally, it clears the entire cache of all modules if called using a JavaScript value
of `undefined` as its first parameter.
Additionally, this extension provides a means of easily defining so-called "native" JerryScript modules which can be
resolved using the native JerryScript module resolver `jerryx_module_native_resolver`, which can be passed to
`jerryx_module_resolve()`. Native modules are registered during application startup and by calling `dlopen()` by means
of library constructors, support for which can be turned on using the `FEATURE_INIT_FINI` build flag. In the absence of
such a flag, the module registration and unregistration functions are exposed as global symbols which can be called
explicitly.
## jerryx_module_resolve
**Summary**
Load a copy of a module into the current context or return one that was already loaded if it is found.
For each resolver passed in via `resolvers_p`, its `get_canonical_name` function pointer gets called in order to
establish the resolver's interpretation of what the canonical name for the module should be. If `get_canonical_name` is
`NULL`, it is assumed that the requested module's name as passed in is its canonical name.
Then, for each resolver passed in via `resolvers_p`, its `resolve` function pointer gets called with its interpretation
of what the module's canonical name should be, as computed in the previous step.
If the resolver's `resolve` function pointer returns `true`, the `jerry_value_t` returned in its out-parameter will be
returned by `jerryx_module_resolve` as the result of the request. If no error flag is set on the `jerry_value_t` it
will be cached under its canonical name so as to avoid loading the same module twice in the event of a subsequent call
to `jerryx_module_resolve` with a module name whose canonical name matches an already loaded module.
**Prototype**
```c
jerry_value_t
jerryx_module_resolve (const jerry_value_t name,
const jerryx_module_resolver_t *resolvers_p,
size_t resolver_count);
```
- `name` - the name of the module to load
- `resolvers_p` - the list of resolvers to call in sequence
- `resolver_count` - the number of resolvers in `resolvers_p`
- return value - `jerry_value_t` representing the module that was loaded, or the error that occurred in the process.
## jerryx_module_clear_cache
**Summary**
Remove a module from the current context's cache, or clear the cache entirely.
**Prototype**
```c
void
jerryx_module_clear_cache (const jerry_value_t name,
const jerryx_module_resolver_t *resolvers_p,
size_t resolver_count);
```
- `name` - the name of the module to remove from cache or a JavaScript `undefined` to clear the entire cache
- `resolvers_p` - the list of resolvers to call in sequence
- `resolver_count` - the number of resolvers in `resolvers_p`
## jerryx_module_native_resolver
**Summary**
The resolver for native JerryScript modules. A pointer to this structure can be passed in the second parameter to
`jerryx_module_resolve` to search for the module among the native JerryScript modules built into the binary. This
function is available only if the preprocessor directive `JERRYX_NATIVE_MODULES_SUPPORTED` is defined.
**Prototype**
```c
extern jerry_module_resolver_t jerryx_native_module_resolver;
```
# Module data types
## jerryx_module_get_canonical_name_t
**Summary**
The function pointer type for converting a module's requested name to its canonical name.
**Prototype**
```c
typedef jerry_value_t (*jerryx_module_get_canonical_name_t) (const jerry_value_t name);
```
## jerryx_module_resolve_t
**Summary**
Function pointer type for module resolution.
**Prototype**
```c
typedef bool (*jerryx_module_resolve_t) (const jerry_value_t canonical_name,
jerry_value_t *result);
```
## jerryx_module_resolver_t
**Summary**
Structure defining a module resolver.
**Prototype**
```c
typedef struct
{
jerryx_module_get_canonical_name_t get_canonical_name_p;
jerryx_module_resolve_t resolve_p;
} jerryx_module_resolver_t;
```
- `get_canonical_name_p` - function pointer to be called when the canonical name corresponding to the requested name
of a module must be established.
- `resolve_p` - function pointer to be called when a module with the given canonical name needs to be converted to the
`jerry_value_t` that will become the loaded module.
**Example**
```c
static bool
load_and_evaluate_js_file (const jerry_value_t name, jerry_value_t *result)
{
bool return_value = false;
char *js_file_contents = NULL;
int file_size = 0;
jerry_size_t name_size = jerry_get_utf8_string_size (name);
jerry_char_t name_string[name_size + 1];
jerry_string_to_utf8_char_buffer (name, name_string, name_size);
name_string[name_size] = 0;
FILE *js_file = fopen (name_string, "r");
if (js_file)
{
/* We have successfully opened the file. Now, we establish its size. */
file_size = fseek (js_file, 0, SEEK_END);
fseek (js_file, 0, SEEK_SET);
/* We allocate enough memory to store the contents of the file. */
js_file_contents = malloc (file_size);
if (js_file_contents)
{
/* We read the file into memory and call jerry_eval (), assigning the result to the out-parameter. */
fread (js_file_contents, file_size, 1, js_file);
(*result) = jerry_eval (js_file_contents, file_size, JERRY_PARSE_NO_OPTS);
/* We release the memory holding the contents of the file. */
free (js_file_contents);
return_value = true;
}
/* We close the file. */
fclose (js_file);
}
return return_value;
}
static jerry_value_t
canonicalize_file_path (const jerry_value_t name)
{
jerry_value_t absolute_path;
/**
* Since a file on the file system can be referred to by multiple relative paths, but only by one absolute path, the
* absolute path becomes the canonical name for the module. Thus, to establish this canonical name, we must search
* name for "./" and "../", follow symlinks, etc., then create absolute_path via jerry_create_string () and return
* it, because it is the canonical name for this module. Thus, we avoid loading the same JavaScript file twice.
*/
return absolute_path;
}
static jerryx_module_resolver_t js_file_loader
{
canonicalize_file_path,
load_and_evaluate_js_file
};
```
We can now load JavaScript files:
```c
static const jerryx_module_resolver_t *resolvers[] =
{
/*
* Consult the resolver for native JerryScript modules first, in case the requested module is a native JerryScript
* module.
*/
&jerryx_module_native_resolver,
/*
* If the requested module is not a native JerryScript module, assume it is a JavaScript file on disk and use the
* above-defined JavaScript file loader to load it.
*/
&js_file_loader
};
jerry_value_t js_module = jerryx_module_resolve (requested_module, resolvers, 2);
```
# Module helper macros
## JERRYX_NATIVE_MODULE
**Summary**
Helper macro to define a native JerryScript module. Currently declares a global static structure of type
`jerryx_native_module_t` and a constructor/destructor pair that calls `jerryx_native_module_register()` resp.
`jerryx_native_module_unregister()`. If the extension is built without the FEATURE_INIT_FINI flag, indicating that
support for library constructors and destructors is absent, the constructor and destructor are declared as global
symbols so that they may be called explicitly from within the application.
**Note**: The helper macro must appear at the bottom of a source file, and no semicolon must follow it.
**Prototype**
```c
#define JERRYX_NATIVE_MODULE(module_name, on_resolve_cb)
```
- `module_name` - the name of the module without quotes. This value is used as the prefix for the registration and unregistration funtions. For example, when `module_name` is `example_module`, this results in the declaration of two functions `example_module_register()` and `example_module_unregister()`. These functions are declared global if support for library constructors/destructors is absent, allowing you to call them from other parts of the code by
first forward-declaring them.
- `on_resolve_cb` - the function of type `jerryx_native_module_on_resolve_t` that will be called when the module needs to be
loaded.
**Example**
```c
#include "jerryscript.h"
#include "jerryscript-ext/module.h"
static jerry_value_t
my_module_on_resolve (void)
{
return jerry_create_external_function (very_useful_function);
} /* my_module_on_resolve */
/* Note that there is no semicolon at the end of the next line. This is how it must be. */
JERRYX_NATIVE_MODULE (my_module, my_module_on_resolve)
```
**Example Usage When Library Constructors Are Unavailable**
```c
#include "jerryscript.h"
#include "jerryscript-ext/module.h"
/**
* Forward-declare the module registration and unregistration function.
*/
extern void my_module_register (void);
extern void my_module_unregister (void);
int
main (int argc, char **argv)
{
jerryx_module_resolver_t resolvers[] =
{
jerryx_native_module_resolver
};
/* This plays the role of the library constructor. */
my_module_register ();
jerry_init (JERRY_INIT_EMPTY);
...
jerry_value_t my_module = jerryx_module_resolve ("my_module", resolvers, 1);
...
jerry_cleanup ();
/* This plays the role of the library destructor */
my_module_unregister();
return 0;
}
```
+217
View File
@@ -0,0 +1,217 @@
# JerryScript debugger transport interface
The transport interface support allows dynamic selection of transportation
layers which can encode/decode or send/receive messages transmitted between
the debugger client and server.
# Types
## jerry_debugger_transport_receive_context_t
**Summary**
This context represents the current status of processing received data.
The final state is returned by
[jerry_debugger_transport_receive](#jerry_debugger_transport_receive)
and must be passed to
[jerry_debugger_transport_receive_completed](#jerry_debugger_transport_receive_completed)
after the message is processed.
**Prototype**
```c
typedef struct
{
uint8_t *buffer_p; /**< buffer for storing the received data */
size_t received_length; /**< number of currently received bytes */
uint8_t *message_p; /**< start of the received message */
size_t message_length; /**< length of the received message */
size_t message_total_length; /**< total length for datagram protocols,
* 0 for stream protocols */
} jerry_debugger_transport_receive_context_t;
```
## jerry_debugger_transport_header_t
**Summary**
Shared header for each transport interface. It mostly contains callback functions
used by the JerryScript debugger server.
**Prototype**
```c
typedef struct jerry_debugger_transport_layer_t
{
/* The following fields must be filled before calling jerry_debugger_transport_add(). */
jerry_debugger_transport_close_t close; /**< close connection callback */
jerry_debugger_transport_send_t send; /**< send data callback */
jerry_debugger_transport_receive_t receive; /**< receive data callback */
/* The following fields are filled by jerry_debugger_transport_add(). */
struct jerry_debugger_transport_layer_t *next_p; /**< next transport layer */
} jerry_debugger_transport_header_t;
```
## jerry_debugger_transport_close_t
**Summary**
Called when the connection is closed. Must release all resources (including the
memory area for the transport interface) allocated for the transport interface.
**Prototype**
```c
typedef void (*jerry_debugger_transport_close_t) (struct jerry_debugger_transport_interface_t *header_p);
```
## jerry_debugger_transport_send_t
**Summary**
Called when a message needs to be sent. Must either transmit the message or call
the `header_p->next_p->send()` method.
**Prototype**
```c
typedef bool (*jerry_debugger_transport_send_t) (struct jerry_debugger_transport_interface_t *header_p,
uint8_t *message_p, size_t message_length);
```
## jerry_debugger_transport_receive_t
**Summary**
Called during message processing. If messages are available it must return with
the next message.
**Prototype**
```c
typedef bool (*jerry_debugger_transport_receive_t) (struct jerry_debugger_transport_interface_t *header_p,
jerry_debugger_transport_receive_context_t *context_p);
```
# Transport interface API functions
## jerry_debugger_transport_add
**Summary**
Add a new interface to the transporation interface chain. The interface
will be the first item of the interface chain.
**Prototype**
```c
void jerry_debugger_transport_add (jerry_debugger_transport_header_t *header_p,
size_t send_message_header_size, size_t max_send_message_size,
size_t receive_message_header_size, size_t max_receive_message_size);
```
- `header_p`: header of a transporation interface.
- `send_message_header_size`: size of the outgoing message header, can be 0.
- `max_send_message_size`: maximum outgoing message size supported by the interface.
- `receive_message_header_size`: size of the incoming message header, can be 0.
- `max_receive_message_size`: maximum incoming message size supported by the interface.
## jerry_debugger_transport_start
**Summary**
Starts the communication to the debugger client. Must be called after the
connection is successfully established.
**Prototype**
```c
void jerry_debugger_transport_start (void);
```
## jerry_debugger_transport_is_connected
**Summary**
Tells whether a debugger client is connected to the debugger server.
**Prototype**
```c
bool jerry_debugger_transport_is_connected (void);
```
- return value: `true`, if a client is connected, `false` otherwise.
## jerry_debugger_transport_close
**Summary**
Disconnect from the current debugger client. It does nothing if a client is
not connected.
**Prototype**
```c
void jerry_debugger_transport_close (void);
```
## jerry_debugger_transport_send
**Summary**
Send message to the client.
**Prototype**
```c
bool jerry_debugger_transport_send (const uint8_t *message_p, size_t message_length);
```
- `message_p`: message to be sent.
- `message_length`: message length in bytes.
- return value: `true`, if a client is still connected, `false` otherwise.
## jerry_debugger_transport_receive
**Summary**
Receive message from the client.
**Prototype**
```c
bool jerry_debugger_transport_receive (jerry_debugger_transport_receive_context_t *context_p);
```
- `context_p`: an unused [jerry_debugger_transport_receive_context_t](#jerry_debugger_transport_receive_context_t).
- return value: `true`, if a client is still connected, `false` otherwise.
## jerry_debugger_transport_receive_completed
**Summary**
Must be called after [jerry_debugger_transport_receive](#jerry_debugger_transport_receive)
returns with a valid message. Must not be called otherwise.
**Prototype**
```c
void jerry_debugger_transport_receive_completed (jerry_debugger_transport_receive_context_t *context_p);
```
- `context_p`: a [jerry_debugger_transport_receive_context_t](#jerry_debugger_transport_receive_context_t)
passed to [jerry_debugger_transport_receive](#jerry_debugger_transport_receive).
## jerry_debugger_transport_sleep
**Summary**
Can be used to wait for incoming messages. Currently the delay is 100ms.
**Prototype**
```c
void jerry_debugger_transport_sleep (void);
```
+112
View File
@@ -0,0 +1,112 @@
# Handle Scope
## jerryx_handle_scope
**Summary**
It is often necessary to make the lifespan of handles shorter than the lifespan of a native method. Even though the native code could only use the most recent handle, all of the associated objects would also be kept alive since they all share the same scope.
To handle this case, JerryScript HandleScope extension provides the ability to establish a new 'scope' to which newly created handles will be associated. Once those handles are no longer required, the scope can be 'closed' and any handles associated with the scope are invalidated. The methods available to open/close scopes are `jerryx_open_handle_scope` and `jerryx_close_handle_scope`.
JerryScript only supports a single nested hierarchy of scopes. There is only one active scope at any time, and all new handles will be associated with that scope while it is active. Scopes must be closed in the reverse order from which they are opened. In addition, all scopes created within a native method must be closed before returning from that method.
**Example**
[doctest]: # (test="compile")
```c
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
static jerry_value_t
create_object (void)
{
jerry_value_t obj = jerry_create_object ();
return obj;
} /* create_object */
static void
test_handle_scope_val (void)
{
jerryx_handle_scope scope;
jerryx_open_handle_scope (&scope);
jerry_value_t obj = jerryx_create_handle (create_object ());
jerryx_close_handle_scope (scope);
// now obj has been released
} /* test_handle_scope_val */
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
test_handle_scope_val ();
jerry_gc (JERRY_GC_PRESSURE_LOW);
jerry_cleanup ();
} /* main */
```
## jerryx_escapable_handle_scope
**Summary**
It is necessary in common cases that a handle has to be promote to outer scope and prevent from been garbage collected. To handle this case, a escapable handle scope has been proposed from which one object can be promoted to the outer scope. The method available to escape an object from been release at current scope is `jerryx_escape_handle`.
**Example**
[doctest]: # (test="compile")
```c
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
static jerry_value_t
create_object (void)
{
jerryx_escapable_handle_scope scope;
jerryx_open_escapable_handle_scope (&scope);
jerry_value_t obj = jerryx_create_handle (jerry_create_object ());
jerry_value_t escaped_obj;
jerryx_escape_handle(scope, obj, &escaped_obj);
jerryx_close_handle_scope (scope);
// escaped_obj has now been escaped to outer scope, thus not released at this point
return escaped_obj;
} /* create_object */
static void
test_handle_scope_val (void)
{
jerryx_handle_scope scope;
jerryx_open_handle_scope (&scope);
jerry_value_t obj = create_object ();
jerryx_close_handle_scope (scope);
// now obj has been released
} /* test_handle_scope_val */
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
test_handle_scope_val ();
jerry_gc (JERRY_GC_PRESSURE_LOW);
jerry_cleanup ();
} /* main */
```
**See also**
- [jerry_value_t](../docs/02.API-REFERENCE.md#jerry_value_t)
- [jerry_acquire_value](../docs/02.API-REFERENCE.md#jerry_acquire_value)
- [jerry_release_value](../docs/02.API-REFERENCE.md#jerry_release_value)
## Pre-allocated list of handle scopes and handles
To prevent trapping into system calls frequently, a pre-allocated dedicated list mechanism has been introduced to the implementation of JerryX handle scope.
To change the size of pre-allocation list, use build definition `JERRYX_HANDLE_PRELIST_SIZE` and `JERRYX_SCOPE_PRELIST_SIZE` to alter the default value of 20.
+158
View File
@@ -0,0 +1,158 @@
# ES6 module support for JerryScript
The module system allows users to write import and export statements in scripts, which can be used to separate the logic of the application into custom modules.
The standard's relevant part can be found [here](https://www.ecma-international.org/ecma-262/6.0/#sec-modules).
## General
If a script contains import statements, then JerryScript will open and evaluate the the referenced modules before the main script runs, resolving and creating bindings for the referenced identifiers in the process.
It is not necessary to use any specific filename extensions for modules, JerryScript will try to open the given file paths as they are, but will try to normalize them before doing so. The exact normalization process is dependant on the port implementation provided. It is the user's responsibility to verify that the given files are valid EcmaScript modules.
main.js
```js
import { exported_value } from "./module.js"
print (exported_value);
```
module.js
```js
var exported_value = 42;
export exported_value;
```
## Supported features
* exporting identifiers from the module's lexical environment
* specifying export names for the exported values
* importing exported identifiers from a module
* specifying local binding names for the imported values
* module namespace imports
* `import * as module from 'module.js`
* indirect export statements
* `export {variable} from 'module.js'`
* star export statements
* `export * from 'module.js'`
* importing a module for side-effects
* `import 'module.js'`
* default import and export statements
* `export default local_identifier`
* `import def from 'module.js'`
* anonymous default exports
* `export default function () {}`
### Example
```js
import {
engine,
version as v
} from "./module.js"
import { getFeatureDetails } from "./module_2.js"
var version = "v3.1415";
print("> main.js");
print(">> Engine: " + engine);
print(">> Version: " + v);
print (">> " + getFeatureDetails());
print (">> Script version: " + version);
```
```js
// module.js
var _engine = "JerryScript";
export _engine as engine;
export var version = "1.0 (e92ae0fb)";
```
```js
// module_2.js
var featureName = "EcmaScript 2015 modules";
var year = 2018;
export function getFeatureDetails() {
return "Feature name: " + featureName + " | developed in " + year;
}
```
### Module namespace import statements
A module namespace object can be imported. In this case the local binding will contain an object holding the exported values of the module, including local exports and all indirect exports. Ambiguous exported names are exluded from the namespace object.
```js
import * as module from './module.js';
print(">> Engine: " + module.engine);
print(">> Version: " + module.version);
```
### Indirect export statements
An export statement can transitively export variables from another module, either via named indirect exports or a star export statement. In this case the resolving process will follow the chain until it reaches a module containing a local binding for that export name. If there are multiple modules which satisfy the export, that means the export is ambiguous, and will result in a SyntaxError.
```js
import { a, b } from 'module.js'
print (a + b);
```
```js
// module.js
export var a = 2;
export { b } from 'module2.js'
```
```js
// module2.js
export var b = 40;
```
### Default imports and exports
Each module can optionally provide a single default export by using the `export default` statement. Default exports can either reference identifiers in the module's lexical environment, or be an anonymous default export, in which case they will only be accessible by an importing script.
```js
import defaultExport, { b as c } from 'module.js'
print (defaultExport); // 2
print (c ()); // 42
```
```js
// module.js
export default 2;
export function b () {
return 42;
}
```
### Importing modules for side-effects
Evaluate a module without importing anything. Any errors encountered in the module will be propagated.
```js
import 'module.js' // > module.js
// "> module.js" is printed
b (); // (ReferenceError) b is not defined
```
```js
// module.js
export function b () {
print ("> module.js");
return 42;
}
b ();
```
## Unsupported features
* **snapshot**
+772
View File
@@ -0,0 +1,772 @@
# Migration guide
This guide intends to describe the major changes between the JerryScript 1.0 and 2.0 versions.
In addtion it is designed to provide a guide on how to modify the 1.0 version code to a
2.0 compliant code.
During the development it was important to minimize the changes in the API functions and types.
Each API method removal or chang is described below providing a ***before*** and ***after***
code example.
For more information on the current API methods please check the [API reference](02.API-REFERENCE.md) document.
# Short list of removed/renamed headers, types, functions, and macros
***Removed legacy headers***
- `jerry-internal.h`
***Renamed headers***
- `jerry-api.h` to `jerryscript.h`
- `jerry-port.h` to `jerryscript-port.h`
***Removed API types***
- `jerry_char_ptr_t` usage replaced with `jerry_char_t *`
- `jerry_object_free_callback_t` replaced by `jerry_object_native_free_callback_t`
***Removed API methods***
- `jerry_get_memory_limits`
- `jerry_get_object_native_handle` replaced by `jerry_get_object_native_pointer`
- `jerry_set_object_native_handle` replaced by `jerry_set_object_native_pointer`
- `jerry_value_set_abort_flag` replaced by `jerry_create_abort_from_value`
- `jerry_value_has_abort_flag` replaced by `jerry_value_is_abort`
- `jerry_value_set_error_flag` replaced by `jerry_create_error_from_value`
- `jerry_value_has_error_flag` replaced by `jerry_value_is_error`
- `jerry_value_clear_error_flag` replaced by `jerry_get_value_from_error`
- `jerry_get_value_without_error_flag` replaced by `jerry_get_value_from_error`
- `jerry_parse_and_save_snapshot` replaced by `jerry_generate_snapshot`
- `jerry_parse_and_save_function_snapshot` replaced by `jerry_generate_function_snapshot`
***Removed unused configuration macros***
- `CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE`
- `CONFIG_MEM_STACK_LIMIT`
- `CONFIG_VM_STACK_FRAME_INLINED_VALUES_NUMBER`
- `CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE`
- All `CONFIG_..` macros have been renamed to use the `JERRY_` prefix format.
# Modified API functions
## Error manipulating functions
The most important changes in the API are releated to error handling and manipulation.
### jerry_value_set_abort_flag
This function was replaced with [`jerry_create_abort_from_value`](02.API-REFERENCE.md#jerry_create_abort_from_value).
Take note of the second argument of the new `jerry_create_abort_from_value` function which controls if the
first argument should be usable after the call or not.
**Before**
```c
{
jerry_value_t value;
// create or acquire value
// ...
jerry_value_set_abort_flag (&value);
jerry_release_value (value);
}
```
**After**
```c
{
jerry_value_t value;
// create or acquire value
// ...
jerry_value_t abort = jerry_create_abort_from_value (value, true);
// using the 'value' variable after release is invalid
jerry_release_value (abort);
}
```
- OR
```c
{
jerry_value_t value;
... // create or acquire value
jerry_value_t abort = jerry_create_abort_from_value (value, false);
// both 'abort' and 'value' can be used and must be released when they are no longer needed
jerry_release_value (abort);
jerry_release_value (value);
}
```
### jerry_value_has_abort_flag
This function was renamed to [`jerry_value_is_abort`](02.API-REFERENCE.md#jerry_value_is_abort).
**Before**
```c
{
jerry_value_t value;
// create or acquire value
// ...
if (jerry_value_has_abort_flag (value))
{
// ...
}
jerry_release_value (value);
}
```
**After**
```c
{
jerry_value_t value;
// create or acquire value
// ...
if (jerry_value_is_abort (value))
{
// ...
}
jerry_release_value (value);
}
```
### jerry_value_set_error_flag
This function was replaced with [`jerry_create_error_from_value`](02.API-REFERENCE.md#jerry_create_error_from_value).
Take note of the second argument of the new `jerry_create_error_from_value` function which controls if the
first argument should be usable after the call or not.
**Before**
```c
{
jerry_value_t value;
// create or acquire value
// ...
jerry_value_set_error_flag (&value);
jerry_release_value (value);
}
```
**After**
```c
{
jerry_value_t value;
// create or acquire value
// ...
jerry_value_t error = jerry_create_error_from_value (value, true);
// using the 'value' variable after release is invalid
jerry_release_value (error);
}
```
- OR
```c
{
jerry_value_t value;
// create or acquire value
// ...
jerry_value_t error = jerry_create_error_from_value (value, false);
// both 'error' and 'value' can be used and must be released when they are no longer needed
jerry_release_value (error);
jerry_release_value (value);
}
```
### jerry_value_has_error_flag
This function was renamed to [`jerry_value_is_error`](02.API-REFERENCE.md#jerry_value_is_error).
**Before**
```c
{
jerry_value_t value;
// create or acquire value
// ...
if (jerry_value_has_error_flag (value))
{
// ...
}
jerry_release_value (value);
}
```
**After**
```c
{
jerry_value_t value;
// create or acquire value
// ...
if (jerry_value_is_error (value))
{
// ...
}
jerry_release_value (value);
}
```
### jerry_value_clear_error_flag AND jerry_get_value_without_error_flag
These functions were merged into [`jerry_get_value_from_error`](02.API-REFERENCE.md#jerry_get_value_from_error).
Please note the second argument of the new function which controls if the first argument passed should be released
or not.
**Before**
```c
{
jerry_value_t value;
// create or acquire value
// ...
jerry_value_set_error_flag (&value);
jerry_value_clear_error_flag (&value);
// or
jerry_value_t real_value = jerry_get_value_without_error_flag (value);
jerry_release_value (value);
jerry_release_value (real_value);
}
```
**After**
```c
{
jerry_value_t value;
// create or acquire value
// ...
jerry_value_t error = jerry_create_error_from_value (value, true);
jerry_value_t real_value = jerry_get_value_from_error (error, true);
jerry_release_value (real_value);
}
```
## Other functions changed
### jerry_register_magic_strings
In case of the `jerry_register_magic_strings` function the change is that
the first argument's base type `jerry_char_ptr_t` was changed to `jerry_char_t*`.
For more details see: [`jerry_register_magic_strings`](02.API-REFERENCE.md#jerry_register_magic_strings).
In the following code parts please take note of the type used for the `magic_string_items` array.
**Before**
```c
{
// must be static, because 'jerry_register_magic_strings' does not copy
// the items must be sorted by size at first, then lexicographically
static const jerry_char_ptr_t magic_string_items[] = {
(const jerry_char_ptr_t) "magicstring1",
(const jerry_char_ptr_t) "magicstring2",
(const jerry_char_ptr_t) "magicstring3"
};
uint32_t num_magic_string_items = (uint32_t) (sizeof (magic_string_items) / sizeof (jerry_char_ptr_t));
// must be static, because 'jerry_register_magic_strings' does not copy
static const jerry_length_t magic_string_lengths[] = { 12, 12, 12 };
jerry_register_magic_strings (magic_string_items, num_magic_string_items, magic_string_lengths);
}
```
**After**
```c
{
// must be static, because 'jerry_register_magic_strings' does not copy
// the items must be sorted by size at first, then lexicographically
static const jerry_char_t *magic_string_items[] = {
(const jerry_char_t *) "magicstring1",
(const jerry_char_t *) "magicstring2",
(const jerry_char_t *) "magicstring3"
};
uint32_t num_magic_string_items = (uint32_t) (sizeof (magic_string_items) / sizeof (jerry_char_t *));
// must be static, because 'jerry_register_magic_strings' does not copy
static const jerry_length_t magic_string_lengths[] = { 12, 12, 12 };
jerry_register_magic_strings (magic_string_items, num_magic_string_items, magic_string_lengths);
}
```
## Snapshot generating API
### jerry_parse_and_save_snapshot
This function was replaced with [`jerry_generate_snapshot`](02.API-REFERENCE.md#jerry_generate_snapshot).
The function returns an error object if there was any problem during snapshot generation and
if there was no problem the return value is a number value containing the snapshot size in bytes.
**Before**
```c
{
static uint32_t global_mode_snapshot_buffer[256];
const jerry_char_t *code_to_snapshot_p = (const jerry_char_t *) "(function () { return 'string from snapshot'; }) ();";
size_t global_mode_snapshot_size =
jerry_parse_and_save_snapshot (code_to_snapshot_p,
strlen ((const char *) code_to_snapshot_p),
true,
false,
global_mode_snapshot_buffer,
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
// use "global_mode_snapshot_buffer"
}
```
**After**
```c
{
static uint32_t global_mode_snapshot_buffer[256];
const jerry_char_t *code_to_snapshot_p = (const jerry_char_t *) "(function () { return 'string from snapshot'; }) ();";
jerry_value_t generate_result;
generate_result = jerry_generate_snapshot (NULL,
0,
code_to_snapshot_p,
strlen ((const char *) code_to_snapshot_p),
global_mode_snapshot_buffer,
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
if (jerry_value_is_error (generate_result))
{
// There was a problem during snapshot generation, for example there is a SyntaxError.
// Use the "generate_result" to check the error.
}
else
{
size_t snapshot_size = (size_t) jerry_get_number_value (generate_result);
// use "global_mode_snapshot_buffer"
}
jerry_release_value (generate_result);
}
```
### jerry_parse_and_save_function_snapshot
This function was replaced with [`jerry_generate_function_snapshot`](02.API-REFERENCE.md#jerry_parse_and_save_function_snapshot).
The function returns an error object if there was any problem during snapshot generation and
if there was no problem the return value is a number value containing the snapshot size in bytes.
**Before**
```c
{
static uint32_t func_snapshot_buffer[1024];
const jerry_char_t *args_p = (const jerry_char_t *) "a, b";
const jerry_char_t *src_p = (const jerry_char_t *) "return a + b;";
size_t func_snapshot_size =
jerry_parse_and_save_function_snapshot (src_p,
strlen ((const char *) src_p),
args_p,
strlen ((const char *) args_p),
false,
func_snapshot_buffer,
sizeof (func_snapshot_buffer) / sizeof (uint32_t));
// check "function_snapshot_size" and use "func_snapshot_buffer"
}
```
**After**
```c
{
static uint32_t func_snapshot_buffer[1024];
const jerry_char_t *args_p = (const jerry_char_t *) "a, b";
const jerry_char_t *src_p = (const jerry_char_t *) "return a + b;";
jerry_value_t generate_result;
generate_result = jerry_generate_function_snapshot (NULL,
0,
src_p,
strlen ((const char *) src_p),
args_p,
strlen ((const char *) args_p),
0,
func_snapshot_buffer,
sizeof (func_snapshot_buffer) / sizeof (uint32_t));
if (jerry_value_is_error (generate_result))
{
// There was a problem during snapshot generation, for example there is a SyntaxError.
// Use the "generate_result" to check the error.
}
else
{
size_t snapshot_size = (size_t) jerry_get_number_value (generate_result);
// use "func_snapshot_buffer"
}
jerry_release_value (generate_result)
}
```
## Garbage collection
### jerry_gc
The [`jerry_gc`](02.API-REFERENCE.md#jerry_gc) function was modified to handle an argument which represents the pressure for the garbage collector.
For more information checkout the [`jerry_gc_mode_t`](02.API-REFERENCE.md#jerry_gc_mode_t) reference.
**Before**
```c
{
jerry_gc ();
}
```
**After**
```c
{
jerry_gc (JERRY_GC_PRESSURE_LOW);
}
```
## jerry_eval
The third argument of [`jerry_eval`](02.API-REFERENCE.md#jerry_eval) has been changed
from `bool` to [`jerry_parse_opts_t`](02.API-REFERENCE.md#jerry_parse_opts_t).
**Before**
```c
const jerry_char_t *str_to_eval = (const jerry_char_t *) "1 + 1";
jerry_value_t ret_val = jerry_eval (str_to_eval,
strlen ((const char *) str_to_eval),
false);
```
**After**
```c
const jerry_char_t *str_to_eval = (const jerry_char_t *) "1 + 1";
jerry_value_t ret_val = jerry_eval (str_to_eval,
strlen ((const char *) str_to_eval),
JERRY_PARSE_NO_OPTS);
```
## Port API
### jerry_port_get_time_zone
The port API of handling timezones has been changed. The previous interface did not
allow timezones to be handled correctly, even if the host system was up to the task.
Check [the related issue](https://github.com/jerryscript-project/jerryscript/issues/1661)
for more details.
The new port API function name is [jerry_port_get_local_time_zone_adjustment](05.PORT-API.md#date-1].
Below is the default implementations for both versions:
**Before**
```c
bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
{
struct timeval tv;
struct timezone tz;
/* gettimeofday may not fill tz, so zero-initializing */
tz.tz_minuteswest = 0;
tz.tz_dsttime = 0;
if (gettimeofday (&tv, &tz) != 0)
{
return false;
}
tz_p->offset = tz.tz_minuteswest;
tz_p->daylight_saving_time = tz.tz_dsttime > 0 ? 1 : 0;
return true;
} /* jerry_port_get_time_zone */
```
**After**
```c
double jerry_port_get_local_time_zone_adjustment (double unix_ms,
bool is_utc)
{
struct tm tm;
time_t now = (time_t) (unix_ms / 1000);
localtime_r (&now, &tm);
if (!is_utc)
{
now -= tm.tm_gmtoff;
localtime_r (&now, &tm);
}
return ((double) tm.tm_gmtoff) * 1000;
} /* jerry_port_get_local_time_zone_adjustment */
```
## Native pointers
The assignment of native pointers (previously called handles) have been changed
since v1.0. In the previous version only one native pointer could be assigned to
a `jerry_value_t`. Now it is allowed to register multiple native infos, which
can be accessed with the corresponding
[`jerry_object_native_info_t`](02.API-REFERENCE.md#jerry_object_native_info_t).
The old functions were removed and replaced by new ones.
- `jerry_object_free_callback_t` callback type is replaced by `jerry_object_native_info_t`
- `jerry_get_object_native_handle` is replaced by [`jerry_get_object_native_pointer`](02.API-REFERENCE.md#jerry_get_object_native_pointer)
- `jerry_set_object_native_handle` is replaced by [`jerry_set_object_native_pointer`](02.API-REFERENCE.md#jerry_set_object_native_pointer)
**Before**
```c
struct
{
int data;
} my_info;
static void
handler_construct_freecb (uintptr_t native_p)
{
// Invoked when the JS object is released and the
// native data should be freed.
struct my_info *info = (struct my_info *) native_p;
free (info);
}
void
demo (void)
{
jerry_value_t this_val;
// create or acquire this_val
// ...
struct my_info *info = (struct my_info *) malloc (sizeof (struct my_info));
info->data = 11;
// setting the native handle
jerry_set_object_native_handle (this_val,
(uintptr_t) info,
handler_construct_freecb);
// ...
// reading back the native handle
uintptr_t ptr = (uintptr_t) NULL;
bool is_ok = jerry_get_object_native_handle (this_val, &ptr);
if (is_ok)
{
struct my_info *obj_info = (struct my_info *) ptr;
// use "obj_info"
}
}
```
**After**
```c
struct
{
int data;
} my_info;
static void
handler_construct_freecb (void *native_p)
{
// Invoked when the JS object is released and the
// native data should be freed.
struct my_info *info = (struct my_info *) native_p;
free (info);
}
static const jerry_object_native_info_t my_info_type_info =
{
.free_cb = handler_construct_freecb
};
void
demo (void)
{
jerry_value_t this_val;
// create or acquire this_val
// ...
struct my_info *info = (struct my_info *) malloc (sizeof (struct my_info));
info->data = 11;
// setting the native handle
jerry_set_object_native_pointer (this_val,
info,
&my_info_type_info);
// ...
// reading back the native handle pointed by the "my_info_type_info" variable
void *ptr = NULL;
bool has_p = jerry_get_object_native_pointer (this_val, &ptr, &my_info_type_info);
if (has_p)
{
struct my_info *obj_info = (struct my_info *) ptr;
// use "obj_info"
}
}
```
# New API functions
In this section the new API functions are listed.
## Built-in objects
***ArrayBuffer***
- [`jerry_create_arraybuffer`](02.API-REFERENCE.md#jerry_create_arraybuffer)
- [`jerry_create_arraybuffer_external`](02.API-REFERENCE.md#jerry_create_arraybuffer_external)
- [`jerry_get_arraybuffer_pointer`](02.API-REFERENCE.md#jerry_get_arraybuffer_pointer)
***DataView***
- [`jerry_create_dataview`](02.API-REFERENCE.md#jerry_create_dataview)
- [`jerry_value_is_dataview`](02.API-REFERENCE.md#jerry_value_is_dataview)
- [`jerry_get_dataview_buffer`](02.API-REFERENCE.md#jerry_get_dataview_buffer)
***JSON***
- [`jerry_json_parse`](02.API-REFERENCE.md#jerry_json_parse)
- [`jerry_json_stringify`](02.API-REFERENCE.md#jerry_json_stringify)
***Number***
- [`jerry_create_number_infinity`](02.API-REFERENCE.md#jerry_create_number_infinity)
- [`jerry_create_number_nan`](02.API-REFERENCE.md#jerry_create_number_nan)
***Promise***
- [`jerry_run_all_enqueued_jobs`](02.API-REFERENCE.md#jerry_run_all_enqueued_jobs)
- [`jerry_create_promise`](02.API-REFERENCE.md#jerry_create_promise)
- [`jerry_resolve_or_reject_promise`](02.API-REFERENCE.md#jerry_resolve_or_reject_promise)
- [`jerry_value_is_promise`](02.API-REFERENCE.md#jerry_value_is_promise)
***RegExp***
- [`jerry_create_regexp`](02.API-REFERENCE.md#jerry_create_regexp)
- [`jerry_create_regexp_sz`](02.API-REFERENCE.md#jerry_create_regexp_sz)
***String***
- [`jerry_substring_to_utf8_char_buffer`](02.API-REFERENCE.md#jerry_substring_to_utf8_char_buffer)
- [`jerry_get_utf8_string_size`](02.API-REFERENCE.md#jerry_get_utf8_string_size)
- [`jerry_get_utf8_string_length`](02.API-REFERENCE.md#jerry_get_utf8_string_length)
- [`jerry_create_string_from_utf8`](02.API-REFERENCE.md#jerry_create_string_from_utf8)
- [`jerry_create_string_sz_from_utf8`](02.API-REFERENCE.md#jerry_create_string_sz_from_utf8)
***Symbol***
- [`jerry_create_symbol`](02.API-REFERENCE.md#jerry_create_symbol)
- [`jerry_get_symbol_descriptive_string`](02.API-REFERENCE.md#jerry_get_symbol_descriptive_string)
- [`jerry_value_is_symbol`](02.API-REFERENCE.md#jerry_value_is_symbol)
***TypedArray***
- [`jerry_create_typedarray`](02.API-REFERENCE.md#jerry_create_typedarray)
- [`jerry_create_typedarray_for_arraybuffer`](02.API-REFERENCE.md#jerry_create_typedarray_for_arraybuffer)
- [`jerry_create_typedarray_for_arraybuffer_sz`](02.API-REFERENCE.md#jerry_create_typedarray_for_arraybuffer_sz)
- [`jerry_get_typedarray_type`](02.API-REFERENCE.md#jerry_get_typedarray_type)
- [`jerry_get_typedarray_length`](02.API-REFERENCE.md#jerry_get_typedarray_length)
- [`jerry_get_typedarray_buffer`](02.API-REFERENCE.md#jerry_get_typedarray_buffer)
- [`jerry_value_is_typedarray`](02.API-REFERENCE.md#jerry_value_is_typedarray)
## Instances and memory management
***JerryScript instances***
- [`jerry_create_context`](02.API-REFERENCE.md#jerry_create_context)
- [`jerry_get_context_data`](02.API-REFERENCE.md#jerry_get_context_data)
***Memory management***
- [`jerry_heap_alloc`](02.API-REFERENCE.md#jerry_heap_alloc)
- [`jerry_heap_free`](02.API-REFERENCE.md#jerry_heap_free)
## Operations with JavaScript values
***Binary operations***
- [`jerry_binary_operation`](02.API-REFERENCE.md#jerry_binary_operation)
***Error manipulating***
- [`jerry_get_error_type`](02.API-REFERENCE.md#jerry_get_error_type)
- [`jerry_get_backtrace`](02.API-REFERENCE.md#jerry_get_backtrace)
***Native pointers***
- [`jerry_delete_object_native_pointer`](02.API-REFERENCE.md#jerry_delete_object_native_pointer)
- [`jerry_objects_foreach_by_native_info`](02.API-REFERENCE.md#jerry_objects_foreach_by_native_info)
***Property***
- [`jerry_delete_property_by_index`](02.API-REFERENCE.md#jerry_delete_property_by_index)
- [`jerry_objects_foreach`](02.API-REFERENCE.md#jerry_objects_foreach)
## Debugger
- [`jerry_debugger_is_connected`](07.DEBUGGER.md#jerry_debugger_is_connected)
- [`jerry_debugger_stop`](07.DEBUGGER.md#jerry_debugger_stop)
- [`jerry_debugger_continue`](07.DEBUGGER.md#jerry_debugger_continue)
- [`jerry_debugger_stop_at_breakpoint`](07.DEBUGGER.md#jerry_debugger_stop_at_breakpoint)
- [`jerry_debugger_wait_for_client_source`](07.DEBUGGER.md#jerry_debugger_wait_for_client_source)
- [`jerry_debugger_send_output`](07.DEBUGGER.md#jerry_debugger_send_output)
- [`jerry_debugger_send_log`](07.DEBUGGER.md#jerry_debugger_send_log)
## Other
- [`jerry_is_feature_enabled`](02.API-REFERENCE.md#jerry_is_feature_enabled)
- [`jerry_parse_and_save_literals`](02.API-REFERENCE.md#jerry_parse_and_save_literals)
- [`jerry_set_vm_exec_stop_callback`](02.API-REFERENCE.md#jerry_set_vm_exec_stop_callback)
## Port API functions
- [`jerry_port_normalize_path`](05.PORT-API.md#jerry_port_normalize_path)
- [`jerry_port_read_source`](05.PORT-API.md#jerry_port_read_source)
- [`jerry_port_release_source`](05.PORT-API.md#jerry_port_release_source)
- [`jerry_port_print_char`](05.PORT-API.md#jerry_port_print_char)
- [`jerry_port_get_current_context`](05.PORT-API.md#jerry_port_get_current_context)
- [`jerry_port_fatal`](05.PORT-API.md#jerry_port_fatal)
- [`jerry_port_sleep`](05.PORT-API.md#jerry_port_sleep)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

+327 -148
View File
@@ -1,5 +1,4 @@
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged.
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,37 +16,102 @@ cmake_minimum_required (VERSION 2.8.12)
set(JERRY_CORE_NAME jerry-core)
project (${JERRY_CORE_NAME} C)
# Optional build settings
set(ENABLE_ALL_IN_ONE OFF CACHE BOOL "Enable all-in-one build?")
# Optional features
set(FEATURE_PROFILE "full" CACHE STRING "Profile types: full, minimal")
set(FEATURE_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?")
set(FEATURE_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
set(FEATURE_VALGRIND_FREYA OFF CACHE BOOL "Enable Valgrind-Freya support?")
set(FEATURE_MEM_STRESS_TEST OFF CACHE BOOL "Enable mem-stress test?")
set(FEATURE_MEM_STATS OFF CACHE BOOL "Enable memory statistics?")
set(FEATURE_PARSER_DUMP OFF CACHE BOOL "Enable parser byte-code dumps?")
set(FEATURE_REGEXP_DUMP OFF CACHE BOOL "Enable regexp byte-code dumps?")
set(FEATURE_SNAPSHOT_SAVE OFF CACHE BOOL "Allow to save snapshot files?")
set(FEATURE_SNAPSHOT_EXEC OFF CACHE BOOL "Allow to execute snapshot files?")
set(MEM_HEAP_SIZE_KB "512" CACHE STRING "Size of memory heap, in kilobytes")
set(JERRY_CPOINTER_32_BIT OFF CACHE BOOL "Enable 32 bit compressed pointers?")
set(JERRY_DEBUGGER OFF CACHE BOOL "Enable JerryScript debugger?")
set(JERRY_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?")
set(JERRY_EXTERNAL_CONTEXT OFF CACHE BOOL "Enable external context?")
set(JERRY_PARSER ON CACHE BOOL "Enable javascript-parser?")
set(JERRY_LINE_INFO OFF CACHE BOOL "Enable line info?")
set(JERRY_LOGGING OFF CACHE BOOL "Enable logging?")
set(JERRY_MEM_STATS OFF CACHE BOOL "Enable memory statistics?")
set(JERRY_MEM_GC_BEFORE_EACH_ALLOC OFF CACHE BOOL "Enable mem-stress test?")
set(JERRY_PARSER_DUMP_BYTE_CODE OFF CACHE BOOL "Enable parser byte-code dumps?")
set(JERRY_PROFILE "es5.1" CACHE STRING "Use default or other profile?")
set(JERRY_REGEXP_STRICT_MODE OFF CACHE BOOL "Enable regexp strict mode?")
set(JERRY_REGEXP_DUMP_BYTE_CODE OFF CACHE BOOL "Enable regexp byte-code dumps?")
set(JERRY_SNAPSHOT_EXEC OFF CACHE BOOL "Enable executing snapshot files?")
set(JERRY_SNAPSHOT_SAVE OFF CACHE BOOL "Enable saving snapshot files?")
set(JERRY_SYSTEM_ALLOCATOR OFF CACHE BOOL "Enable system allocator?")
set(JERRY_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
set(JERRY_VM_EXEC_STOP OFF CACHE BOOL "Enable VM execution stopping?")
set(JERRY_GLOBAL_HEAP_SIZE "(512)" CACHE STRING "Size of memory heap, in kilobytes")
set(JERRY_STACK_LIMIT "(0)" CACHE STRING "Maximum stack usage size, in kilobytes")
# Option overrides
if(USING_MSVC)
set(ENABLE_ALL_IN_ONE ON) # FIXME: This should not be needed but right now it is. To be tracked down and followed up.
set(ENABLE_ALL_IN_ONE_MESSAGE " (FORCED BY COMPILER)")
endif()
if(JERRY_SYSTEM_ALLOCATOR)
set(JERRY_CPOINTER_32_BIT ON)
set(JERRY_CPOINTER_32_BIT_MESSAGE " (FORCED BY SYSTEM ALLOCATOR)")
endif()
if (JERRY_GLOBAL_HEAP_SIZE GREATER 512)
set(JERRY_CPOINTER_32_BIT ON)
set(JERRY_CPOINTER_32_BIT_MESSAGE " (FORCED BY HEAP SIZE)")
endif()
if(NOT JERRY_PARSER)
set(JERRY_SNAPSHOT_EXEC ON)
set(JERRY_PARSER_DUMP OFF)
set(JERRY_SNAPSHOT_EXEC_MESSAGE " (FORCED BY DISABLED JS PARSER)")
set(JERRY_PARSER_DUMP_MESSAGE " (FORCED BY DISABLED JS PARSER)")
endif()
if(JERRY_CMDLINE_SNAPSHOT)
set(JERRY_SNAPSHOT_SAVE ON)
set(JERRY_SNAPSHOT_SAVE_MESSAGE " (FORCED BY SNAPSHOT TOOL)")
endif()
if(JERRY_MEM_STATS OR JERRY_PARSER_DUMP_BYTE_CODE OR JERRY_REGEXP_DUMP_BYTE_CODE)
set(JERRY_LOGGING ON)
set(JERRYRE_LOGGING_MESSAGE " (FORCED BY STATS OR DUMP)")
endif()
# Status messages
message(STATUS "FEATURE_PROFILE " ${FEATURE_PROFILE})
message(STATUS "FEATURE_ERROR_MESSAGES " ${FEATURE_ERROR_MESSAGES})
message(STATUS "FEATURE_VALGRIND " ${FEATURE_VALGRIND})
message(STATUS "FEATURE_VALGRIND_FREYA " ${FEATURE_VALGRIND_FREYA})
message(STATUS "FEATURE_MEM_STRESS_TEST " ${FEATURE_MEM_STRESS_TEST})
message(STATUS "FEATURE_MEM_STATS " ${FEATURE_MEM_STATS})
message(STATUS "FEATURE_PARSER_DUMP " ${FEATURE_PARSER_DUMP})
message(STATUS "FEATURE_REGEXP_DUMP " ${FEATURE_REGEXP_DUMP})
message(STATUS "FEATURE_SNAPSHOT_SAVE " ${FEATURE_SNAPSHOT_SAVE})
message(STATUS "FEATURE_SNAPSHOT_EXEC " ${FEATURE_SNAPSHOT_EXEC})
message(STATUS "MEM_HEAP_SIZE_KB " ${MEM_HEAP_SIZE_KB})
message(STATUS "ENABLE_ALL_IN_ONE " ${ENABLE_ALL_IN_ONE} ${ENABLE_ALL_IN_ONE_MESSAGE})
message(STATUS "JERRY_CPOINTER_32_BIT " ${JERRY_CPOINTER_32_BIT} ${JERRY_CPOINTER_32_BIT_MESSAGE})
message(STATUS "JERRY_DEBUGGER " ${JERRY_DEBUGGER})
message(STATUS "JERRY_ERROR_MESSAGES " ${JERRY_ERROR_MESSAGES})
message(STATUS "JERRY_EXTERNAL_CONTEXT " ${JERRY_EXTERNAL_CONTEXT})
message(STATUS "JERRY_PARSER " ${JERRY_PARSER})
message(STATUS "JERRY_LINE_INFO " ${JERRY_LINE_INFO})
message(STATUS "JERRY_LOGGING " ${JERRY_LOGGING} ${JERRY_LOGGING_MESSAGE})
message(STATUS "JERRY_MEM_STATS " ${JERRY_MEM_STATS})
message(STATUS "JERRY_MEM_GC_BEFORE_EACH_ALLOC " ${JERRY_MEM_GC_BEFORE_EACH_ALLOC})
message(STATUS "JERRY_PARSER_DUMP_BYTE_CODE " ${JERRY_PARSER_DUMP_BYTE_CODE} ${JERRY_PARSER_DUMP_MESSAGE})
message(STATUS "JERRY_PROFILE " ${JERRY_PROFILE})
message(STATUS "JERRY_REGEXP_STRICT_MODE " ${JERRY_REGEXP_STRICT_MODE})
message(STATUS "JERRY_REGEXP_DUMP_BYTE_CODE " ${JERRY_REGEXP_DUMP_BYTE_CODE})
message(STATUS "JERRY_SNAPSHOT_EXEC " ${JERRY_SNAPSHOT_EXEC} ${JERRY_SNAPSHOT_EXEC_MESSAGE})
message(STATUS "JERRY_SNAPSHOT_SAVE " ${JERRY_SNAPSHOT_SAVE} ${JERRY_SNAPSHOT_SAVE_MESSAGE})
message(STATUS "JERRY_SYSTEM_ALLOCATOR " ${JERRY_SYSTEM_ALLOCATOR})
message(STATUS "JERRY_VALGRIND " ${JERRY_VALGRIND})
message(STATUS "JERRY_VM_EXEC_STOP " ${JERRY_VM_EXEC_STOP})
message(STATUS "JERRY_GLOBAL_HEAP_SIZE " ${JERRY_GLOBAL_HEAP_SIZE})
message(STATUS "JERRY_STACK_LIMIT " ${JERRY_STACK_LIMIT})
# Include directories
set(INCLUDE_CORE
set(INCLUDE_CORE_PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(INCLUDE_CORE_PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/api"
"${CMAKE_CURRENT_SOURCE_DIR}/debugger"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/base"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects/typedarray"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/operations"
"${CMAKE_CURRENT_SOURCE_DIR}/jcontext"
"${CMAKE_CURRENT_SOURCE_DIR}/jmem"
@@ -57,35 +121,25 @@ set(INCLUDE_CORE
"${CMAKE_CURRENT_SOURCE_DIR}/parser/regexp"
"${CMAKE_CURRENT_SOURCE_DIR}/vm")
set(INCLUDE_CORE_PUBLIC ${INCLUDE_CORE_PUBLIC} PARENT_SCOPE) # for jerry-port
set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} PARENT_SCOPE) # for tests/unit-core
# Sources
# Jerry core
file(GLOB SOURCE_CORE_API *.c)
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.c)
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.c)
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.c)
file(GLOB SOURCE_CORE_JCONTEXT jcontext/*.c)
file(GLOB SOURCE_CORE_JMEM jmem/*.c)
file(GLOB SOURCE_CORE_JRT jrt/*.c)
file(GLOB SOURCE_CORE_LIT lit/*.c)
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.c)
file(GLOB SOURCE_CORE_PARSER_REGEXP parser/regexp/*.c)
file(GLOB SOURCE_CORE_VM vm/*.c)
set(SOURCE_CORE_FILES
${SOURCE_CORE_API}
${SOURCE_CORE_ECMA_BASE}
${SOURCE_CORE_ECMA_BUILTINS}
${SOURCE_CORE_ECMA_OPERATIONS}
${SOURCE_CORE_JCONTEXT}
${SOURCE_CORE_JMEM}
${SOURCE_CORE_JRT}
${SOURCE_CORE_LIT}
${SOURCE_CORE_PARSER_JS}
${SOURCE_CORE_PARSER_REGEXP}
${SOURCE_CORE_VM})
# Jerry port
file(GLOB SOURCE_PORT_FILES "${PORT_DIR}/*.c")
file(GLOB SOURCE_CORE_FILES
api/*.c
debugger/*.c
ecma/base/*.c
ecma/builtin-objects/*.c
ecma/builtin-objects/typedarray/*.c
ecma/operations/*.c
jcontext/*.c
jmem/*.c
jrt/*.c
lit/*.c
parser/js/*.c
parser/regexp/*.c
vm/*.c)
# All-in-one build
if(ENABLE_ALL_IN_ONE)
@@ -97,133 +151,258 @@ if(ENABLE_ALL_IN_ONE)
file(APPEND ${ALL_IN_FILE} "#include \"${FILE}\"\n")
endforeach()
foreach(FILE ${SOURCE_PORT_FILES})
file(APPEND ${ALL_IN_FILE} "#include \"${FILE}\"\n")
endforeach()
set(SOURCE_CORE_FILES ${ALL_IN_FILE})
endif()
set(SOURCE_CORE ${ALL_IN_FILE})
else()
set(SOURCE_CORE ${SOURCE_CORE_FILES} ${SOURCE_PORT_FILES})
# "Single" JerryScript source/header build.
# The process will create the following files:
# * jerryscript.c
# * jerryscript.h
# * jerryscript-config.h
if(ENABLE_ALL_IN_ONE_SOURCE)
# Create single C/H file
file(GLOB HEADER_CORE_FILES *.h)
# Generated files
set(ALL_IN_FILE "${CMAKE_BINARY_DIR}/src/jerryscript.c")
set(ALL_IN_FILE_H "${CMAKE_BINARY_DIR}/src/jerryscript.h")
set(JERRYSCRIPT_CONFIG_H "${CMAKE_BINARY_DIR}/src/jerryscript-config.h")
add_custom_command(OUTPUT ${ALL_IN_FILE} ${ALL_IN_FILE_H}
COMMAND python ${CMAKE_SOURCE_DIR}/tools/srcgenerator.py
--jerry-core
--output-dir ${CMAKE_BINARY_DIR}/src
DEPENDS ${SOURCE_CORE_FILES}
${HEADER_CORE_FILES}
${CMAKE_SOURCE_DIR}/tools/srcgenerator.py
${CMAKE_SOURCE_DIR}/tools/srcmerger.py
)
# The "true" jerryscript-config.h will be generated by the configure_file below,
# which contains the default options and the ones passed for the CMake.
# The input for this is the jerryscript-config.h generated by the command above.
set(JERRYSCRIPT_GEN_CONFIG_H ${CMAKE_CURRENT_BINARY_DIR}/jerryscript-config.h)
add_custom_command(OUTPUT ${JERRYSCRIPT_CONFIG_H}
COMMAND ${CMAKE_COMMAND} -E copy ${JERRYSCRIPT_GEN_CONFIG_H} ${JERRYSCRIPT_CONFIG_H}
DEPENDS ${ALL_IN_FILE_C} ${ALL_IN_FILE_H})
add_custom_target(generate-single-source-jerry DEPENDS ${ALL_IN_FILE} ${ALL_IN_FILE_H})
add_dependencies(generate-single-source generate-single-source-jerry)
set(SOURCE_CORE_FILES ${ALL_IN_FILE} ${ALL_IN_FILE_H} ${JERRYSCRIPT_CONFIG_H})
endif()
# Third-party
# Valgrind
set(INCLUDE_THIRD_PARTY_VALGRIND "${CMAKE_SOURCE_DIR}/third-party/valgrind")
# Definitions
# Get version information from git
if(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/.git")
execute_process(COMMAND git symbolic-ref -q HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE JERRY_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE JERRY_GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
set(JERRY_GIT_BRANCH "UNDEFINED")
set(JERRY_GIT_COMMIT "UNDEFINED")
endif()
# Get build date
execute_process(COMMAND date +%d/%m/%Y
OUTPUT_VARIABLE JERRY_BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(DEFINES_JERRY
${DEFINES_JERRY}
JERRY_BUILD_DATE="${JERRY_BUILD_DATE}"
JERRY_COMMIT_HASH="${JERRY_GIT_COMMIT}"
JERRY_BRANCH_NAME="${JERRY_GIT_BRANCH}")
# build mode specific compile/link flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_PRETTY_PRINTER)
else()
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_NDEBUG)
endif()
# Profile modes
# Minimal profile
if(FEATURE_PROFILE STREQUAL "minimal")
set(DEFINES_JERRY ${DEFINES_JERRY}
CONFIG_DISABLE_NUMBER_BUILTIN
CONFIG_DISABLE_STRING_BUILTIN
CONFIG_DISABLE_BOOLEAN_BUILTIN
CONFIG_DISABLE_ERROR_BUILTINS
CONFIG_DISABLE_ARRAY_BUILTIN
CONFIG_DISABLE_MATH_BUILTIN
CONFIG_DISABLE_JSON_BUILTIN
CONFIG_DISABLE_DATE_BUILTIN
CONFIG_DISABLE_REGEXP_BUILTIN
CONFIG_DISABLE_ANNEXB_BUILTIN)
elseif(NOT FEATURE_PROFILE STREQUAL "full")
message(FATAL_ERROR "FEATURE_PROFILE='${FEATURE_PROFILE}' doesn't supported")
endif()
set(DEFINES_JERRY ${DEFINES_JERRY} $<$<NOT:$<CONFIG:Debug>>:JERRY_NDEBUG>)
# Jerry heap-section
if(DEFINED JERRY_HEAP_SECTION_ATTR)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_HEAP_SECTION_ATTR=${JERRY_HEAP_SECTION_ATTR})
if(DEFINED JERRY_ATTR_GLOBAL_HEAP)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ATTR_GLOBAL_HEAP=${JERRY_ATTR_GLOBAL_HEAP})
endif()
# Helper macro to set 0/1 switch as Jerry Defines
macro(jerry_add_define01 NAME)
if(${NAME})
set(DEFINES_JERRY ${DEFINES_JERRY} ${NAME}=1)
else()
set(DEFINES_JERRY ${DEFINES_JERRY} ${NAME}=0)
endif()
endmacro(jerry_add_define01)
# Checks the optional features
# Enable 32 bit cpointers
jerry_add_define01(JERRY_CPOINTER_32_BIT)
# Fill error messages for builtin error objects
if(FEATURE_ERROR_MESSAGES)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_ERROR_MESSAGES)
endif()
jerry_add_define01(JERRY_ERROR_MESSAGES)
# Valgrind
if(FEATURE_VALGRIND)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_VALGRIND)
set(INCLUDE_CORE ${INCLUDE_CORE} ${INCLUDE_THIRD_PARTY_VALGRIND})
endif()
# Use external context instead of static one
jerry_add_define01(JERRY_EXTERNAL_CONTEXT)
# Valgrind Freya
if(FEATURE_VALGRIND_FREYA)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_VALGRIND_FREYA)
set(INCLUDE_CORE ${INCLUDE_CORE} ${INCLUDE_THIRD_PARTY_VALGRIND})
endif()
# JS-Parser
jerry_add_define01(JERRY_PARSER)
# Memory management stress-test mode
if(FEATURE_MEM_STRESS_TEST)
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_GC_BEFORE_EACH_ALLOC)
endif()
# JS line info
jerry_add_define01(JERRY_LINE_INFO)
# Logging
jerry_add_define01(JERRY_LOGGING)
# Memory statistics
if(FEATURE_MEM_STATS)
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_STATS)
endif()
jerry_add_define01(JERRY_MEM_STATS)
# Enable debugger
jerry_add_define01(JERRY_DEBUGGER)
# Memory management stress-test mode
jerry_add_define01(JERRY_MEM_GC_BEFORE_EACH_ALLOC)
# Parser byte-code dumps
if(FEATURE_PARSER_DUMP)
set(DEFINES_JERRY ${DEFINES_JERRY} PARSER_DUMP_BYTE_CODE)
jerry_add_define01(JERRY_PARSER_DUMP_BYTE_CODE)
# Profile
if (NOT IS_ABSOLUTE ${JERRY_PROFILE})
set(JERRY_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/profiles/${JERRY_PROFILE}.profile")
endif()
if(EXISTS ${JERRY_PROFILE})
file(READ "${JERRY_PROFILE}" PROFILE_SETTINGS)
string(REGEX REPLACE "^#.*$" "" PROFILE_SETTINGS "${PROFILE_SETTINGS}")
string(REGEX REPLACE "[\r|\n]" ";" PROFILE_SETTINGS "${PROFILE_SETTINGS}")
# Process entries and save them as CMake variables.
# This is required to correctly generate the jerryscript-config.h file.
foreach(PROFILE_ENTRY ${PROFILE_SETTINGS})
string(REPLACE "=" ";" PROFILE_ENTRY "${PROFILE_ENTRY}")
list(GET PROFILE_ENTRY 0 PROFILE_KEY)
list(GET PROFILE_ENTRY 1 PROFILE_VALUE)
set(${PROFILE_KEY} ${PROFILE_VALUE})
endforeach()
set(DEFINES_JERRY ${DEFINES_JERRY} ${PROFILE_SETTINGS})
else()
message(FATAL_ERROR "Profile file: '${JERRY_PROFILE}' doesn't exist!")
endif()
# RegExp strict mode
jerry_add_define01(JERRY_REGEXP_STRICT_MODE)
# RegExp byte-code dumps
if(FEATURE_REGEXP_DUMP)
set(DEFINES_JERRY ${DEFINES_JERRY} REGEXP_DUMP_BYTE_CODE)
endif()
# Snapshot save
if(FEATURE_SNAPSHOT_SAVE)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_SNAPSHOT_SAVE)
endif()
jerry_add_define01(JERRY_REGEXP_DUMP_BYTE_CODE)
# Snapshot exec
if(FEATURE_SNAPSHOT_EXEC)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_SNAPSHOT_EXEC)
jerry_add_define01(JERRY_SNAPSHOT_EXEC)
# Snapshot save
jerry_add_define01(JERRY_SNAPSHOT_SAVE)
# Enable system allocator
jerry_add_define01(JERRY_SYSTEM_ALLOCATOR)
# Valgrind
jerry_add_define01(JERRY_VALGRIND)
if(JERRY_VALGRIND)
set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} ${INCLUDE_THIRD_PARTY_VALGRIND})
endif()
# Enable VM execution stopping
jerry_add_define01(JERRY_VM_EXEC_STOP)
# Size of heap
math(EXPR MEM_HEAP_AREA_SIZE "${MEM_HEAP_SIZE_KB} * 1024")
set(DEFINES_JERRY ${DEFINES_JERRY} CONFIG_MEM_HEAP_AREA_SIZE=${MEM_HEAP_AREA_SIZE})
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_GLOBAL_HEAP_SIZE=${JERRY_GLOBAL_HEAP_SIZE})
add_library(${JERRY_CORE_NAME} STATIC ${SOURCE_CORE})
# Maximum size of stack memory usage
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_STACK_LIMIT=${JERRY_STACK_LIMIT})
## This function is to read "config.h" for default values
function(read_set_defines FILE PREFIX OUTPUTVAR)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}" INPUT_FILE_CONTENTS)
# match all "#define <PREFIX>\n" lines
# notes:
# * before the "#" there must be a newline and any number of spaces.
# * after the "#" there can be any number of spaces.
string(REGEX MATCHALL "\r?\n[ ]*#[ ]*define ${PREFIX}[^\n]*"
RAW_DEFINES "${INPUT_FILE_CONTENTS}")
set(SELECTED_VARS )
# Transform the defines to a list of (<name>; <value>; <name 2>; <value 2>; ...) list
foreach(DEFINE_ENTRY ${RAW_DEFINES})
# by default every define value is empty
set(DEFINE_VALUE " ")
# split up the define at the space between the define name and value (if there is any)
# first remove "#define" part of the string
string(REGEX REPLACE "\r?\n[ ]*#[ ]*define[ ]+" "" DEFINE_KEY_VALUE "${DEFINE_ENTRY}")
string(FIND "${DEFINE_KEY_VALUE}" " " DEFINE_KEY_IDX)
string(LENGTH "${DEFINE_KEY_VALUE}" DEFINE_LENGTH)
if (DEFINE_KEY_IDX EQUAL "-1")
set(DEFINE_KEY ${DEFINE_KEY_VALUE})
else()
string(SUBSTRING "${DEFINE_KEY_VALUE}" 0 ${DEFINE_KEY_IDX} DEFINE_KEY)
string(SUBSTRING "${DEFINE_KEY_VALUE}" ${DEFINE_KEY_IDX} -1 DEFINE_VALUE)
string(STRIP "${DEFINE_VALUE}" DEFINE_VALUE)
endif()
list(APPEND SELECTED_VARS ${DEFINE_KEY} ${DEFINE_VALUE})
endforeach()
set(${OUTPUTVAR} ${SELECTED_VARS} PARENT_SCOPE)
endfunction(read_set_defines)
# CONFIG_DEFAULTS contains define name and values which have the JERRY_ prefix
# as a list of (<name>; <value>; <name 2>; <value 2>; ...)
read_set_defines("config.h" JERRY_ CONFIG_DEFAULTS)
## Process the default values and build options to generate build config defines
list(LENGTH CONFIG_DEFAULTS CONFIG_DEFAULT_LENGTH)
math(EXPR CONFIG_DEFAULT_LENGTH "${CONFIG_DEFAULT_LENGTH} - 1")
set(JERRY_MODIFIED_OPTIONS)
foreach(CONFIG_IDX RANGE 0 ${CONFIG_DEFAULT_LENGTH} 2)
list(GET CONFIG_DEFAULTS ${CONFIG_IDX} KEY)
math(EXPR VALUE_IDX "${CONFIG_IDX} + 1")
list(GET CONFIG_DEFAULTS ${VALUE_IDX} VALUE)
# ${KEY} is the value for the given variable (aka define)
# normalize ON/OFF cmake values to 1/0 for easier processing.
if(${KEY} STREQUAL "ON")
set(${KEY} 1)
elseif(${KEY} STREQUAL "OFF")
set(${KEY} 0)
endif()
# Generate "#define JERRY_<CONFIG> <CONFIG_VALUE>" entries if it is different from
# the config default.
# If the define loaded from the config file have a different value than the
# relevant option passed for the CMake means that it does not have a default value.
if(DEFINED ${KEY} AND NOT (${KEY} STREQUAL ${VALUE}))
set(JERRY_MODIFIED_OPTIONS "${JERRY_MODIFIED_OPTIONS}#define ${KEY} ${${KEY}}\n")
endif()
endforeach()
# Generate the jerryscript-config.h file into the build directory
# This file will contain the options different from the default (aka it's the build config).
if(JERRY_MODIFIED_OPTIONS)
set(JERRY_BUILD_CFG
"Generated differences from default by CMake based on build options:\n${JERRY_MODIFIED_OPTIONS}")
else()
set(JERRY_BUILD_CFG "JerryScript configuration")
endif()
configure_file(config.h jerryscript-config.h @ONLY)
add_library(${JERRY_CORE_NAME} ${SOURCE_CORE_FILES})
target_compile_definitions(${JERRY_CORE_NAME} PUBLIC ${DEFINES_JERRY})
target_include_directories(${JERRY_CORE_NAME} PUBLIC ${INCLUDE_CORE})
target_include_directories(${JERRY_CORE_NAME} PUBLIC ${INCLUDE_CORE_PUBLIC})
target_include_directories(${JERRY_CORE_NAME} PRIVATE ${INCLUDE_CORE_PRIVATE})
if (JERRY_LIBC)
target_include_directories(${JERRY_CORE_NAME} SYSTEM PRIVATE "${CMAKE_SOURCE_DIR}/jerry-libc/include")
set(JERRY_CORE_PKGCONFIG_REQUIRES)
set(JERRY_CORE_PKGCONFIG_LIBS)
if(JERRY_LIBM)
target_link_libraries(${JERRY_CORE_NAME} jerry-libm)
set(JERRY_CORE_PKGCONFIG_REQUIRES libjerry-libm)
endif()
separate_arguments(EXTERNAL_LINK_LIBS)
foreach(EXT_LIB ${EXTERNAL_LINK_LIBS})
target_link_libraries(${JERRY_CORE_NAME} ${EXT_LIB})
set(JERRY_CORE_PKGCONFIG_LIBS "${JERRY_CORE_PKGCONFIG_LIBS} -l${EXT_LIB}")
endforeach()
configure_file(libjerry-core.pc.in libjerry-core.pc @ONLY)
install(TARGETS ${JERRY_CORE_NAME} DESTINATION lib)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libjerry-core.pc DESTINATION lib/pkgconfig)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jerryscript-config.h DESTINATION include)
install(DIRECTORY ${INCLUDE_CORE_PUBLIC}/ DESTINATION include)
+250
View File
@@ -0,0 +1,250 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "debugger.h"
#include "jcontext.h"
#include "jerryscript.h"
#if ENABLED (JERRY_DEBUGGER)
/**
* Minimum number of bytes transmitted or received.
*/
#define JERRY_DEBUGGER_TRANSPORT_MIN_BUFFER_SIZE 64
/**
* Sleep time in milliseconds between each jerry_debugger_receive call
*/
#define JERRY_DEBUGGER_TRANSPORT_TIMEOUT 100
/**
* Add a new transport layer.
*/
void
jerry_debugger_transport_add (jerry_debugger_transport_header_t *header_p, /**< transport implementation */
size_t send_message_header_size, /**< header bytes reserved for outgoing messages */
size_t max_send_message_size, /**< maximum number of bytes transmitted in a message */
size_t receive_message_header_size, /**< header bytes reserved for incoming messages */
size_t max_receive_message_size) /**< maximum number of bytes received in a message */
{
JERRY_ASSERT (max_send_message_size > JERRY_DEBUGGER_TRANSPORT_MIN_BUFFER_SIZE
&& max_receive_message_size > JERRY_DEBUGGER_TRANSPORT_MIN_BUFFER_SIZE);
header_p->next_p = JERRY_CONTEXT (debugger_transport_header_p);
JERRY_CONTEXT (debugger_transport_header_p) = header_p;
uint8_t *payload_p;
size_t max_send_size;
size_t max_receive_size;
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{
payload_p = JERRY_CONTEXT (debugger_send_buffer_payload_p);
max_send_size = JERRY_CONTEXT (debugger_max_send_size);
max_receive_size = JERRY_CONTEXT (debugger_max_receive_size);
}
else
{
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_CONNECTED);
payload_p = JERRY_CONTEXT (debugger_send_buffer);
max_send_size = JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE;
max_receive_size = JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE;
}
JERRY_ASSERT (max_send_size > JERRY_DEBUGGER_TRANSPORT_MIN_BUFFER_SIZE + send_message_header_size);
JERRY_ASSERT (max_receive_size > JERRY_DEBUGGER_TRANSPORT_MIN_BUFFER_SIZE + receive_message_header_size);
JERRY_CONTEXT (debugger_send_buffer_payload_p) = payload_p + send_message_header_size;
max_send_size = max_send_size - send_message_header_size;
max_receive_size = max_receive_size - receive_message_header_size;
if (max_send_size > max_send_message_size)
{
max_send_size = max_send_message_size;
}
if (max_receive_size > max_receive_message_size)
{
max_receive_size = max_receive_message_size;
}
JERRY_CONTEXT (debugger_max_send_size) = (uint8_t) max_send_size;
JERRY_CONTEXT (debugger_max_receive_size) = (uint8_t) max_receive_size;
} /* jerry_debugger_transport_add */
/**
* Starts the communication to the debugger client.
* Must be called after the connection is successfully established.
*/
void
jerry_debugger_transport_start (void)
{
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
if (jerry_debugger_send_configuration (JERRY_CONTEXT (debugger_max_receive_size)))
{
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = NULL;
}
} /* jerry_debugger_transport_start */
/**
* Returns true if a debugger client is connected.
*
* @return true - a debugger client is connected,
* false - otherwise
*/
bool
jerry_debugger_transport_is_connected (void)
{
return (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) != 0;
} /* jerry_debugger_transport_is_connected */
/**
* Notifies the debugger server that the connection is closed.
*/
void
jerry_debugger_transport_close (void)
{
if (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED))
{
return;
}
JERRY_CONTEXT (debugger_flags) = JERRY_DEBUGGER_VM_IGNORE;
jerry_debugger_transport_header_t *current_p = JERRY_CONTEXT (debugger_transport_header_p);
JERRY_ASSERT (current_p != NULL);
do
{
jerry_debugger_transport_header_t *next_p = current_p->next_p;
current_p->close (current_p);
current_p = next_p;
}
while (current_p != NULL);
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "Debugger client connection closed.\n");
jerry_debugger_free_unreferenced_byte_code ();
} /* jerry_debugger_transport_close */
/**
* Send data over the current connection
*
* @return true - data sent successfully,
* false - connection closed
*/
bool
jerry_debugger_transport_send (const uint8_t *message_p, /**< message to be sent */
size_t message_length) /**< message length in bytes */
{
JERRY_ASSERT (jerry_debugger_transport_is_connected ());
JERRY_ASSERT (message_length > 0);
jerry_debugger_transport_header_t *header_p = JERRY_CONTEXT (debugger_transport_header_p);
uint8_t *payload_p = JERRY_CONTEXT (debugger_send_buffer_payload_p);
size_t max_send_size = JERRY_CONTEXT (debugger_max_send_size);
do
{
size_t fragment_length = (message_length <= max_send_size ? message_length
: max_send_size);
memcpy (payload_p, message_p, fragment_length);
if (!header_p->send (header_p, payload_p, fragment_length))
{
return false;
}
message_p += fragment_length;
message_length -= fragment_length;
}
while (message_length > 0);
return true;
} /* jerry_debugger_transport_send */
/**
* Receive data from the current connection
*
* Note:
* A message is received if message_start_p is not NULL
*
* @return true - function successfully completed,
* false - connection closed
*/
bool
jerry_debugger_transport_receive (jerry_debugger_transport_receive_context_t *context_p) /**< [out] receive
* context */
{
JERRY_ASSERT (jerry_debugger_transport_is_connected ());
context_p->buffer_p = JERRY_CONTEXT (debugger_receive_buffer);
context_p->received_length = JERRY_CONTEXT (debugger_received_length);
context_p->message_p = NULL;
context_p->message_length = 0;
context_p->message_total_length = 0;
jerry_debugger_transport_header_t *header_p = JERRY_CONTEXT (debugger_transport_header_p);
return header_p->receive (header_p, context_p);
} /* jerry_debugger_transport_receive */
/**
* Clear the message buffer after the message is processed
*/
void
jerry_debugger_transport_receive_completed (jerry_debugger_transport_receive_context_t *context_p) /**< receive
* context */
{
JERRY_ASSERT (context_p->message_p != NULL);
JERRY_ASSERT (context_p->buffer_p == JERRY_CONTEXT (debugger_receive_buffer));
size_t message_total_length = context_p->message_total_length;
size_t received_length = context_p->received_length;
JERRY_ASSERT (message_total_length <= received_length);
if (message_total_length == 0 || message_total_length == received_length)
{
/* All received data is processed. */
JERRY_CONTEXT (debugger_received_length) = 0;
return;
}
uint8_t *buffer_p = context_p->buffer_p;
received_length -= message_total_length;
memmove (buffer_p, buffer_p + message_total_length, received_length);
JERRY_CONTEXT (debugger_received_length) = (uint16_t) received_length;
} /* jerry_debugger_transport_receive_completed */
/**
* Suspend execution for a predefined time (JERRY_DEBUGGER_TRANSPORT_TIMEOUT ms).
*/
void
jerry_debugger_transport_sleep (void)
{
jerry_port_sleep (JERRY_DEBUGGER_TRANSPORT_TIMEOUT);
} /* jerry_debugger_transport_sleep */
#endif /* ENABLED (JERRY_DEBUGGER) */
+230
View File
@@ -0,0 +1,230 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "debugger.h"
#include "jcontext.h"
#include "jerryscript.h"
/**
* Checks whether the debugger is connected.
*
* @return true - if the debugger is connected
* false - otherwise
*/
bool
jerry_debugger_is_connected (void)
{
#if ENABLED (JERRY_DEBUGGER)
return JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED;
#else /* !ENABLED (JERRY_DEBUGGER) */
return false;
#endif /* ENABLED (JERRY_DEBUGGER) */
} /* jerry_debugger_is_connected */
/**
* Stop execution at the next available breakpoint.
*/
void
jerry_debugger_stop (void)
{
#if ENABLED (JERRY_DEBUGGER)
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
&& !(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_BREAKPOINT_MODE))
{
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = NULL;
}
#endif /* ENABLED (JERRY_DEBUGGER) */
} /* jerry_debugger_stop */
/**
* Continue execution.
*/
void
jerry_debugger_continue (void)
{
#if ENABLED (JERRY_DEBUGGER)
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
&& !(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_BREAKPOINT_MODE))
{
JERRY_DEBUGGER_CLEAR_FLAGS (JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = NULL;
}
#endif /* ENABLED (JERRY_DEBUGGER) */
} /* jerry_debugger_continue */
/**
* Sets whether the engine should stop at breakpoints.
*/
void
jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint) /**< enable/disable stop at breakpoint */
{
#if ENABLED (JERRY_DEBUGGER)
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED
&& !(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_BREAKPOINT_MODE))
{
if (enable_stop_at_breakpoint)
{
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_IGNORE);
}
else
{
JERRY_DEBUGGER_CLEAR_FLAGS (JERRY_DEBUGGER_VM_IGNORE);
}
}
#else /* !ENABLED (JERRY_DEBUGGER) */
JERRY_UNUSED (enable_stop_at_breakpoint);
#endif /* ENABLED (JERRY_DEBUGGER) */
} /* jerry_debugger_stop_at_breakpoint */
/**
* Sets whether the engine should wait and run a source.
*
* @return enum JERRY_DEBUGGER_SOURCE_RECEIVE_FAILED - if the source is not received
* JERRY_DEBUGGER_SOURCE_RECEIVED - if a source code received
* JERRY_DEBUGGER_SOURCE_END - the end of the source codes
* JERRY_DEBUGGER_CONTEXT_RESET_RECEIVED - the end of the context
*/
jerry_debugger_wait_for_source_status_t
jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t callback_p, /**< callback function */
void *user_p, /**< user pointer passed to the callback */
jerry_value_t *return_value) /**< [out] parse and run return value */
{
*return_value = jerry_create_undefined ();
#if ENABLED (JERRY_DEBUGGER)
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
&& !(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_BREAKPOINT_MODE))
{
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_CLIENT_SOURCE_MODE);
jerry_debugger_uint8_data_t *client_source_data_p = NULL;
jerry_debugger_wait_for_source_status_t ret_type = JERRY_DEBUGGER_SOURCE_RECEIVE_FAILED;
/* Notify the client about that the engine is waiting for a source. */
jerry_debugger_send_type (JERRY_DEBUGGER_WAIT_FOR_SOURCE);
while (true)
{
if (jerry_debugger_receive (&client_source_data_p))
{
if (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED))
{
break;
}
/* Stop executing the current context. */
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONTEXT_RESET_MODE))
{
ret_type = JERRY_DEBUGGER_CONTEXT_RESET_RECEIVED;
JERRY_DEBUGGER_CLEAR_FLAGS (JERRY_DEBUGGER_CONTEXT_RESET_MODE);
break;
}
/* Stop waiting for a new source file. */
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CLIENT_NO_SOURCE))
{
ret_type = JERRY_DEBUGGER_SOURCE_END;
JERRY_DEBUGGER_CLEAR_FLAGS (JERRY_DEBUGGER_CLIENT_SOURCE_MODE);
break;
}
/* The source arrived. */
if (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CLIENT_SOURCE_MODE))
{
JERRY_ASSERT (client_source_data_p != NULL);
jerry_char_t *resource_name_p = (jerry_char_t *) (client_source_data_p + 1);
size_t resource_name_size = strlen ((const char *) resource_name_p);
*return_value = callback_p (resource_name_p,
resource_name_size,
resource_name_p + resource_name_size + 1,
client_source_data_p->uint8_size - resource_name_size - 1,
user_p);
ret_type = JERRY_DEBUGGER_SOURCE_RECEIVED;
break;
}
}
jerry_debugger_transport_sleep ();
}
JERRY_ASSERT (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CLIENT_SOURCE_MODE)
|| !(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED));
if (client_source_data_p != NULL)
{
/* The data may partly arrived. */
jmem_heap_free_block (client_source_data_p,
client_source_data_p->uint8_size + sizeof (jerry_debugger_uint8_data_t));
}
return ret_type;
}
return JERRY_DEBUGGER_SOURCE_RECEIVE_FAILED;
#else /* !ENABLED (JERRY_DEBUGGER) */
JERRY_UNUSED (callback_p);
JERRY_UNUSED (user_p);
return JERRY_DEBUGGER_SOURCE_RECEIVE_FAILED;
#endif /* ENABLED (JERRY_DEBUGGER) */
} /* jerry_debugger_wait_for_client_source */
/**
* Send the output of the program to the debugger client.
* Currently only sends print output.
*/
void
jerry_debugger_send_output (const jerry_char_t *buffer, /**< buffer */
jerry_size_t str_size) /**< string size */
{
#if ENABLED (JERRY_DEBUGGER)
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{
jerry_debugger_send_string (JERRY_DEBUGGER_OUTPUT_RESULT,
JERRY_DEBUGGER_OUTPUT_OK,
(const uint8_t *) buffer,
sizeof (uint8_t) * str_size);
}
#else /* !ENABLED (JERRY_DEBUGGER) */
JERRY_UNUSED (buffer);
JERRY_UNUSED (str_size);
#endif /* ENABLED (JERRY_DEBUGGER) */
} /* jerry_debugger_send_output */
/**
* Send the log of the program to the debugger client.
*/
void
jerry_debugger_send_log (jerry_log_level_t level, /**< level of the diagnostics message */
const jerry_char_t *buffer, /**< buffer */
jerry_size_t str_size) /**< string size */
{
#if ENABLED (JERRY_DEBUGGER)
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{
jerry_debugger_send_string (JERRY_DEBUGGER_OUTPUT_RESULT,
(uint8_t) (level + 2),
(const uint8_t *) buffer,
sizeof (uint8_t) * str_size);
}
#else /* !ENABLED (JERRY_DEBUGGER) */
JERRY_UNUSED (level);
JERRY_UNUSED (buffer);
JERRY_UNUSED (str_size);
#endif /* ENABLED (JERRY_DEBUGGER) */
} /* jerry_debugger_send_log */
File diff suppressed because it is too large Load Diff
+53
View File
@@ -0,0 +1,53 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JERRY_SNAPSHOT_H
#define JERRY_SNAPSHOT_H
#include "ecma-globals.h"
/**
* Snapshot header
*/
typedef struct
{
/* The size of this structure is recommended to be divisible by
* uint32_t alignment. Otherwise some bytes after the header are wasted. */
uint32_t magic; /**< four byte magic number */
uint32_t version; /**< version number */
uint32_t global_flags; /**< global configuration and feature flags */
uint32_t lit_table_offset; /**< byte offset of the literal table */
uint32_t number_of_funcs; /**< number of primary ECMAScript functions */
uint32_t func_offsets[1]; /**< function offsets (lowest bit: global(0) or eval(1) context) */
} jerry_snapshot_header_t;
/**
* Jerry snapshot magic marker.
*/
#define JERRY_SNAPSHOT_MAGIC (0x5952524Au)
/**
* Snapshot configuration flags.
*/
typedef enum
{
/* 8 bits are reserved for dynamic features */
JERRY_SNAPSHOT_HAS_REGEX_LITERAL = (1u << 0), /**< byte code has regex literal */
JERRY_SNAPSHOT_HAS_CLASS_LITERAL = (1u << 1), /**< byte code has class literal */
/* 24 bits are reserved for compile time features */
JERRY_SNAPSHOT_FOUR_BYTE_CPOINTER = (1u << 8) /**< deprecated, an unused placeholder now */
} jerry_snapshot_global_flags_t;
#endif /* !JERRY_SNAPSHOT_H */
File diff suppressed because it is too large Load Diff
+647 -104
View File
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,147 +13,691 @@
* limitations under the License.
*/
#ifndef CONFIG_H
#define CONFIG_H
#ifndef JERRYSCRIPT_CONFIG_H
#define JERRYSCRIPT_CONFIG_H
// @JERRY_BUILD_CFG@
/**
* Limit of data (system heap, engine's data except engine's own heap)
*/
#define CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE (1024)
/**
* Limit of stack size
*/
#define CONFIG_MEM_STACK_LIMIT (4096)
/**
* Size of pool chunk
* Built-in configurations
*
* Should not be less than size of any of ECMA Object Model's data types.
* Allowed values for built-in defines:
* 0: Disable the given built-in.
* 1: Enable the given built-in.
*/
#define CONFIG_MEM_POOL_CHUNK_SIZE (8)
/*
* By default all built-ins are enabled if they are not defined.
*/
#ifndef JERRY_BUILTINS
# define JERRY_BUILTINS 1
#endif /* !defined (JERRY_BUILTINS) */
#ifndef JERRY_BUILTIN_ANNEXB
# define JERRY_BUILTIN_ANNEXB JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_ANNEXB) */
#ifndef JERRY_BUILTIN_ARRAY
# define JERRY_BUILTIN_ARRAY JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_ARRAY) */
#ifndef JERRY_BUILTIN_DATE
# define JERRY_BUILTIN_DATE JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_DATE) */
#ifndef JERRY_BUILTIN_ERRORS
# define JERRY_BUILTIN_ERRORS JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_ERRORS) */
#ifndef JERRY_BUILTIN_BOOLEAN
# define JERRY_BUILTIN_BOOLEAN JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_BOOLEAN) */
#ifndef JERRY_BUILTIN_JSON
# define JERRY_BUILTIN_JSON JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_JSON) */
#ifndef JERRY_BUILTIN_MATH
# define JERRY_BUILTIN_MATH JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_MATH) */
#ifndef JERRY_BUILTIN_NUMBER
# define JERRY_BUILTIN_NUMBER JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_NUMBER) */
#ifndef JERRY_BUILTIN_REGEXP
# define JERRY_BUILTIN_REGEXP JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_REGEXP) */
#ifndef JERRY_BUILTIN_STRING
# define JERRY_BUILTIN_STRING JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_STRING) */
/**
* Size of heap
* ES2015 (a.k.a es6) related features, by default all of them are enabled.
*/
#ifndef CONFIG_MEM_HEAP_AREA_SIZE
# define CONFIG_MEM_HEAP_AREA_SIZE (512 * 1024)
#elif CONFIG_MEM_HEAP_AREA_SIZE > (512 * 1024)
# error "Currently, maximum 512 kilobytes heap size is supported"
#endif /* !CONFIG_MEM_HEAP_AREA_SIZE */
#ifndef JERRY_ES2015
# define JERRY_ES2015 1
#endif /* !defined (JERRY_ES2015) */
#ifndef JERRY_ES2015_BUILTIN
# define JERRY_ES2015_BUILTIN JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN) */
#ifndef JERRY_ES2015_BUILTIN_DATAVIEW
# define JERRY_ES2015_BUILTIN_DATAVIEW JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN_DATAVIEW) */
#ifndef JERRY_ES2015_BUILTIN_ITERATOR
# define JERRY_ES2015_BUILTIN_ITERATOR JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN_ITERATOR) */
#ifndef JERRY_ES2015_BUILTIN_MAP
# define JERRY_ES2015_BUILTIN_MAP JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN_MAP) */
#ifndef JERRY_ES2015_BUILTIN_SET
# define JERRY_ES2015_BUILTIN_SET JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN_SET) */
#ifndef JERRY_ES2015_BUILTIN_PROMISE
# define JERRY_ES2015_BUILTIN_PROMISE JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN_PROMISE) */
#ifndef JERRY_ES2015_BUILTIN_SYMBOL
# define JERRY_ES2015_BUILTIN_SYMBOL JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN_SYMBOL) */
#ifndef JERRY_ES2015_BUILTIN_TYPEDARRAY
# define JERRY_ES2015_BUILTIN_TYPEDARRAY JERRY_ES2015
#endif /* !defined (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
#ifndef JERRY_ES2015_ARROW_FUNCTION
# define JERRY_ES2015_ARROW_FUNCTION JERRY_ES2015
#endif /* !defined (JERRY_ES2015_ARROW_FUNCTION) */
#ifndef JERRY_ES2015_CLASS
# define JERRY_ES2015_CLASS JERRY_ES2015
#endif /* !defined (JERRY_ES2015_CLASS) */
#ifndef JERRY_ES2015_FOR_OF
# define JERRY_ES2015_FOR_OF JERRY_ES2015
#endif /* !defined (JERRY_ES2015_FOR_OF) */
#ifndef JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER
# define JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER JERRY_ES2015
#endif /* !defined (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER) */
#ifndef JERRY_ES2015_FUNCTION_REST_PARAMETER
# define JERRY_ES2015_FUNCTION_REST_PARAMETER JERRY_ES2015
#endif /* !defined (JERRY_ES2015_FUNCTION_REST_PARAMETER) */
#ifndef JERRY_ES2015_OBJECT_INITIALIZER
# define JERRY_ES2015_OBJECT_INITIALIZER JERRY_ES2015
#endif /* !defined (JERRY_ES2015_OBJECT_INITIALIZER) */
#ifndef JERRY_ES2015_MODULE_SYSTEM
# define JERRY_ES2015_MODULE_SYSTEM JERRY_ES2015
#endif /* !defined (JERRY_ES2015_MODULE_SYSTEM) */
#ifndef JERRY_ES2015_TEMPLATE_STRINGS
# define JERRY_ES2015_TEMPLATE_STRINGS JERRY_ES2015
#endif /* !defined (JERRY_ES2015_TEMPLATE_STRINGS) */
/**
* Max heap usage limit
* Engine internal and misc configurations.
*/
#define CONFIG_MEM_HEAP_MAX_LIMIT 8192
/**
* Desired limit of heap usage
*/
#define CONFIG_MEM_HEAP_DESIRED_LIMIT (JERRY_MIN (CONFIG_MEM_HEAP_AREA_SIZE / 32, CONFIG_MEM_HEAP_MAX_LIMIT))
/**
* Log2 of maximum possible offset in the heap
* Specifies the compressed pointer representation
*
* The option affects size of compressed pointer that in turn
* affects size of ECMA Object Model's data types.
* Allowed values:
* 0: use 16 bit representation
* 1: use 32 bit representation
*
* In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE.
*
* On the other hand, value 2 ^ CONFIG_MEM_HEAP_OFFSET_LOG should not be less than CONFIG_MEM_HEAP_AREA_SIZE.
* Default value: 0
* For more details see: jmem/jmem.h
*/
#define CONFIG_MEM_HEAP_OFFSET_LOG (19)
#ifndef JERRY_CPOINTER_32_BIT
# define JERRY_CPOINTER_32_BIT 0
#endif /* !defined (JERRY_CPOINTER_32_BIT) */
/**
* Number of lower bits in key of literal hash table.
* Enable/Disable the engine's JavaScript debugger interface
*
* Allowed values:
* 0: Disable the debugger parts.
* 1: Enable the debugger.
*/
#define CONFIG_LITERAL_HASH_TABLE_KEY_BITS (7)
#ifndef JERRY_DEBUGGER
# define JERRY_DEBUGGER 0
#endif /* !defined (JERRY_DEBUGGER) */
/**
* Width of fields used for holding counter of references to ecma-strings and ecma-objects
* Enable/Disable built-in error messages for error objects.
*
* The option affects maximum number of simultaneously existing:
* - references to one string;
* - stack references to one object
* The number is ((2 ^ CONFIG_ECMA_REFERENCE_COUNTER_WIDTH) - 1).
* Allowed values:
* 0: Disable error messages.
* 1: Enable error message.
*
* Also the option affects size of ECMA Object Model's data types.
* In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE.
* Default value: 0
*/
#define CONFIG_ECMA_REFERENCE_COUNTER_WIDTH (12)
#ifndef JERRY_ERROR_MESSAGES
# define JERRY_ERROR_MESSAGES 0
#endif /* !defined (JERRY_ERROR_MESSAGES) */
#define CONFIG_ECMA_REFERENCE_COUNTER_LIMIT ((1u << CONFIG_ECMA_REFERENCE_COUNTER_WIDTH) - 1u)
/**
* Enable/Disable external context.
*
* Allowed values:
* 0: Disable external context.
* 1: Enable external context support.
*
* Default value: 0
*/
#ifndef JERRY_EXTERNAL_CONTEXT
# define JERRY_EXTERNAL_CONTEXT 0
#endif /* !defined (JERRY_EXTERNAL_CONTEXT) */
/**
* Maximum size of heap in kilobytes
*
* Default value: 512 KiB
*/
#ifndef JERRY_GLOBAL_HEAP_SIZE
# define JERRY_GLOBAL_HEAP_SIZE (512)
#endif /* !defined (JERRY_GLOBAL_HEAP_SIZE) */
/**
* Maximum stack usage size in kilobytes
*
* Note: This feature cannot be used when 'detect_stack_use_after_return=1' ASAN option is enabled.
* For more detailed description:
* - https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn#compatibility
*
* Default value: 0, unlimited
*/
#ifndef JERRY_STACK_LIMIT
# define JERRY_STACK_LIMIT (0)
#endif /* !defined (JERRY_STACK_LIMIT) */
/**
* Enable/Disable property lookup cache.
*
* Allowed values:
* 0: Disable lookup cache.
* 1: Enable lookup cache.
*
* Default value: 1
*/
#ifndef JERRY_LCACHE
# define JERRY_LCACHE 1
#endif /* !defined (JERRY_LCACHE) */
/**
* Enable/Disable line-info management inside the engine.
*
* Allowed values:
* 0: Disable line-info in the engine.
* 1: Enable line-info management.
*
* Default value: 0
*/
#ifndef JERRY_LINE_INFO
# define JERRY_LINE_INFO 0
#endif /* !defined (JERRY_LINE_INFO) */
/**
* Enable/Disable logging inside the engine.
*
* Allowed values:
* 0: Disable internal logging.
* 1: Enable internal logging.
*
* Default value: 0
*/
#ifndef JERRY_LOGGING
# define JERRY_LOGGING 0
#endif /* !defined (JERRY_LOGGING) */
/**
* Enable/Disable gc call before every allocation.
*
* Allowed values:
* 0: Disable gc call before each allocation.
* 1: Enable and force gc call before each allocation.
*
* Default value: 0
* Warning!: This is an advanced option and will slow down the engine!
* Only enable it for debugging purposes.
*/
#ifndef JERRY_MEM_GC_BEFORE_EACH_ALLOC
# define JERRY_MEM_GC_BEFORE_EACH_ALLOC 0
#endif /* !defined (JERRY_MEM_GC_BEFORE_EACH_ALLOC) */
/**
* Enable/Disable the collection if run-time memory statistics.
*
* Allowed values:
* 0: Disable run-time memory information collection.
* 1: Enable run-time memory statistics collection.
*
* Default value: 0
*/
#ifndef JERRY_MEM_STATS
# define JERRY_MEM_STATS 0
#endif /* !defined (JERRY_MEM_STATS) */
/**
* Use 32-bit/64-bit float for ecma-numbers
*/
#define CONFIG_ECMA_NUMBER_FLOAT32 (1u) /* 32-bit float */
#define CONFIG_ECMA_NUMBER_FLOAT64 (2u) /* 64-bit float */
#ifndef CONFIG_ECMA_NUMBER_TYPE
# define CONFIG_ECMA_NUMBER_TYPE CONFIG_ECMA_NUMBER_FLOAT64
#else /* CONFIG_ECMA_NUMBER_TYPE */
# if (CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32 \
&& CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT64)
# error "ECMA-number storage is configured incorrectly"
# endif /* CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32
&& CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT64 */
#endif /* !CONFIG_ECMA_NUMBER_TYPE */
/**
* Representation for ecma-characters
*/
#define CONFIG_ECMA_CHAR_ASCII (1) /* ASCII */
#define CONFIG_ECMA_CHAR_UTF16 (2) /* UTF-16 */
#ifndef CONFIG_ECMA_CHAR_ENCODING
# define CONFIG_ECMA_CHAR_ENCODING CONFIG_ECMA_CHAR_ASCII
#else /* CONFIG_ECMA_CHAR_ENCODING */
# if (CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_ASCII \
&& CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_UTF16)
# error "ECMA-char encoding is configured incorrectly"
# endif /* CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_ASCII
&& CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_UTF16 */
#endif /* !CONFIG_ECMA_CHAR_ENCODING */
/**
* Disable ECMA lookup cache
*/
// #define CONFIG_ECMA_LCACHE_DISABLE
/**
* Disable ECMA property hashmap
*/
// #define CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
/**
* Share of newly allocated since last GC objects among all currently allocated objects,
* after achieving which, GC is started upon low severity try-give-memory-back requests.
* This option is for expert use only!
*
* Share is calculated as the following:
* 1.0 / CONFIG_ECMA_GC_NEW_OBJECTS_SHARE_TO_START_GC
* Allowed values:
* 1: use 64-bit floating point number mode
* 0: use 32-bit floating point number mode
*
* Default value: 1
*/
#define CONFIG_ECMA_GC_NEW_OBJECTS_SHARE_TO_START_GC (16)
#ifndef JERRY_NUMBER_TYPE_FLOAT64
# define JERRY_NUMBER_TYPE_FLOAT64 1
#endif /* !defined (JERRY_NUMBER_TYPE_FLOAT64 */
/**
* Link Global Environment to an empty declarative lexical environment
* instead of lexical environment bound to Global Object.
* Enable/Disable the JavaScript parser.
*
* Allowed values:
* 0: Disable the JavaScript parser and all related functionallity.
* 1: Enable the JavaScript parser.
*
* Default value: 1
*/
// #define CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE
#ifndef JERRY_PARSER
# define JERRY_PARSER 1
#endif /* !defined (JERRY_PARSER) */
/**
* Number of ecma values inlined into VM stack frame
* Enable/Disable JerryScript byte code dump functions during parsing.
* To dump the JerryScript byte code the engine must be initialized with opcodes
* display flag. This option does not influence RegExp byte code dumps.
*
* Allowed values:
* 0: Disable all bytecode dump functions.
* 1: Enable bytecode dump functions.
*
* Default value: 0
*/
#define CONFIG_VM_STACK_FRAME_INLINED_VALUES_NUMBER (16)
#ifndef JERRY_PARSER_DUMP_BYTE_CODE
# define JERRY_PARSER_DUMP_BYTE_CODE 0
#endif /* defined (JERRY_PARSER_DUMP_BYTE_CODE) */
/**
* Run GC after execution of each byte-code instruction
* Enable/Disable ECMA property hashmap.
*
* Allowed values:
* 0: Disable property hasmap.
* 1: Enable property hashmap.
*
* Default value: 1
*/
// #define CONFIG_VM_RUN_GC_AFTER_EACH_OPCODE
#ifndef JERRY_PROPRETY_HASHMAP
# define JERRY_PROPRETY_HASHMAP 1
#endif /* !defined (JERRY_PROPRETY_HASHMAP) */
/**
* Flag, indicating whether to enable parser-time byte-code optimizations
* Enable/Disable byte code dump functions for RegExp objects.
* To dump the RegExp byte code the engine must be initialized with
* regexp opcodes display flag. This option does not influence the
* JerryScript byte code dumps.
*
* Allowed values:
* 0: Disable all bytecode dump functions.
* 1: Enable bytecode dump functions.
*
* Default value: 0
*/
#define CONFIG_PARSER_ENABLE_PARSE_TIME_BYTE_CODE_OPTIMIZER
#ifndef JERRY_REGEXP_DUMP_BYTE_CODE
# define JERRY_REGEXP_DUMP_BYTE_CODE 0
#endif /* !defined (JERRY_REGEXP_DUMP_BYTE_CODE) */
#endif /* !CONFIG_H */
/**
* Enables/disables the RegExp strict mode
*
* Default value: 0
*/
#ifndef JERRY_REGEXP_STRICT_MODE
# define JERRY_REGEXP_STRICT_MODE 0
#endif /* !defined (JERRY_REGEXP_STRICT_MODE) */
/**
* Enable/Disable the snapshot execution functions.
*
* Allowed values:
* 0: Disable snapshot execution.
* 1: Enable snapshot execution.
*
* Default value: 0
*/
#ifndef JERRY_SNAPSHOT_EXEC
# define JERRY_SNAPSHOT_EXEC 0
#endif /* !defined (JERRY_SNAPSHOT_EXEC) */
/**
* Enable/Disable the snapshot save functions.
*
* Allowed values:
* 0: Disable snapshot save functions.
* 1: Enable snapshot save functions.
*/
#ifndef JERRY_SNAPSHOT_SAVE
# define JERRY_SNAPSHOT_SAVE 0
#endif /* !defined (JERRY_SNAPSHOT_SAVE) */
/**
* Enable/Disable usage of system allocator.
*
* Allowed values:
* 0: Disable usage of system allocator.
* 1: Enable usage of system allocator.
*
* Default value: 0
*/
#ifndef JERRY_SYSTEM_ALLOCATOR
# define JERRY_SYSTEM_ALLOCATOR 0
#endif /* !defined (JERRY_SYSTEM_ALLOCATOR) */
/**
* Enables/disables the unicode case conversion in the engine.
* By default Unicode case conversion is enabled.
*/
#ifndef JERRY_UNICODE_CASE_CONVERSION
# define JERRY_UNICODE_CASE_CONVERSION 1
#endif /* !defined (JERRY_UNICODE_CASE_CONVERSION) */
/**
* Configures if the internal memory allocations are exposed to Valgrind or not.
*
* Allowed values:
* 0: Disable the Valgrind specific memory allocation notifications.
* 1: Enable the Valgrind specific allocation notifications.
*/
#ifndef JERRY_VALGRIND
# define JERRY_VALGRIND 0
#endif /* !defined (JERRY_VALGRIND) */
/**
* Enable/Disable the vm execution stop callback function.
*
* Allowed values:
* 0: Disable vm exec stop callbacks.
* 1: Enable vm exec stop callback functionality.
*/
#ifndef JERRY_VM_EXEC_STOP
# define JERRY_VM_EXEC_STOP 0
#endif /* !defined (JERRY_VM_EXEC_STOP) */
/**
* Advanced section configurations.
*/
/**
* Allow configuring attributes on a few constant data inside the engine.
*
* One of the main usages:
* Normally compilers store const(ant)s in ROM. Thus saving RAM.
* But if your compiler does not support it then the directive below can force it.
*
* For the moment it is mainly meant for the following targets:
* - ESP8266
*
* Example configuration for moving (some) constatns into a given section:
* # define JERRY_ATTR_CONST_DATA __attribute__((section(".rodata.const")))
*/
#ifndef JERRY_ATTR_CONST_DATA
# define JERRY_ATTR_CONST_DATA
#endif /* !defined (JERRY_ATTR_CONST_DATA) */
/**
* The JERRY_ATTR_GLOBAL_HEAP allows adding extra attributes for the Jerry global heap.
*
* Example on how to move the global heap into it's own section:
* #define JERRY_ATTR_GLOBAL_HEAP __attribute__((section(".text.globalheap")))
*/
#ifndef JERRY_ATTR_GLOBAL_HEAP
# define JERRY_ATTR_GLOBAL_HEAP
#endif /* !defined (JERRY_ATTR_GLOBAL_HEAP) */
/**
* Sanity check for macros to see if the values are 0 or 1
*
* If a new feature is added this should be updated.
*/
/**
* Check base builtins.
*/
#if !defined (JERRY_BUILTIN_ANNEXB) \
|| ((JERRY_BUILTIN_ANNEXB != 0) && (JERRY_BUILTIN_ANNEXB != 1))
# error "Invalid value for JERRY_BUILTIN_ANNEXB macro."
#endif
#if !defined (JERRY_BUILTIN_ARRAY) \
|| ((JERRY_BUILTIN_ARRAY != 0) && (JERRY_BUILTIN_ARRAY != 1))
# error "Invalid value for JERRY_BUILTIN_ARRAY macro."
#endif
#if !defined (JERRY_BUILTIN_BOOLEAN) \
|| ((JERRY_BUILTIN_BOOLEAN != 0) && (JERRY_BUILTIN_BOOLEAN != 1))
# error "Invalid value for JERRY_BUILTIN_BOOLEAN macro."
#endif
#if !defined (JERRY_BUILTIN_DATE) \
|| ((JERRY_BUILTIN_DATE != 0) && (JERRY_BUILTIN_DATE != 1))
# error "Invalid value for JERRY_BUILTIN_DATE macro."
#endif
#if !defined (JERRY_BUILTIN_ERRORS) \
|| ((JERRY_BUILTIN_ERRORS != 0) && (JERRY_BUILTIN_ERRORS != 1))
# error "Invalid value for JERRY_BUILTIN_ERRORS macro."
#endif
#if !defined (JERRY_BUILTIN_JSON) \
|| ((JERRY_BUILTIN_JSON != 0) && (JERRY_BUILTIN_JSON != 1))
# error "Invalid value for JERRY_BUILTIN_JSON macro."
#endif
#if !defined (JERRY_BUILTIN_MATH) \
|| ((JERRY_BUILTIN_MATH != 0) && (JERRY_BUILTIN_MATH != 1))
# error "Invalid value for JERRY_BUILTIN_MATH macro."
#endif
#if !defined (JERRY_BUILTIN_NUMBER) \
|| ((JERRY_BUILTIN_NUMBER != 0) && (JERRY_BUILTIN_NUMBER != 1))
# error "Invalid value for JERRY_BUILTIN_NUMBER macro."
#endif
#if !defined (JERRY_BUILTIN_REGEXP) \
|| ((JERRY_BUILTIN_REGEXP != 0) && (JERRY_BUILTIN_REGEXP != 1))
# error "Invalid value for JERRY_BUILTIN_REGEXP macro."
#endif
#if !defined (JERRY_BUILTIN_STRING) \
|| ((JERRY_BUILTIN_STRING != 0) && (JERRY_BUILTIN_STRING != 1))
# error "Invalid value for JERRY_BUILTIN_STRING macro."
#endif
#if !defined (JERRY_BUILTINS) \
|| ((JERRY_BUILTINS != 0) && (JERRY_BUILTINS != 1))
# error "Invalid value for JERRY_BUILTINS macro."
#endif
/**
* Check ES2015 features
*/
#if !defined (JERRY_ES2015) \
|| ((JERRY_ES2015 != 0) && (JERRY_ES2015 != 1))
# error "Invalid value for JERRY_ES2015 macro."
#endif
#if !defined (JERRY_ES2015_ARROW_FUNCTION) \
|| ((JERRY_ES2015_ARROW_FUNCTION != 0) && (JERRY_ES2015_ARROW_FUNCTION != 1))
# error "Invalid value for JERRY_ES2015_ARROW_FUNCTION macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN) \
|| ((JERRY_ES2015_BUILTIN != 0) && (JERRY_ES2015_BUILTIN != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN_ITERATOR) \
|| ((JERRY_ES2015_BUILTIN_ITERATOR != 0) && (JERRY_ES2015_BUILTIN_ITERATOR != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN_ITERATOR macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN_DATAVIEW) \
|| ((JERRY_ES2015_BUILTIN_DATAVIEW != 0) && (JERRY_ES2015_BUILTIN_DATAVIEW != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN_DATAVIEW macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN_MAP) \
|| ((JERRY_ES2015_BUILTIN_MAP != 0) && (JERRY_ES2015_BUILTIN_MAP != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN_MAP macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN_SET) \
|| ((JERRY_ES2015_BUILTIN_SET != 0) && (JERRY_ES2015_BUILTIN_SET != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN_SET macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN_PROMISE) \
|| ((JERRY_ES2015_BUILTIN_PROMISE != 0) && (JERRY_ES2015_BUILTIN_PROMISE != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN_PROMISE macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN_SYMBOL) \
|| ((JERRY_ES2015_BUILTIN_SYMBOL != 0) && (JERRY_ES2015_BUILTIN_SYMBOL != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN_SYMBOL macro."
#endif
#if !defined (JERRY_ES2015_BUILTIN_TYPEDARRAY) \
|| ((JERRY_ES2015_BUILTIN_TYPEDARRAY != 0) && (JERRY_ES2015_BUILTIN_TYPEDARRAY != 1))
# error "Invalid value for JERRY_ES2015_BUILTIN_TYPEDARRAY macro."
#endif
#if !defined (JERRY_ES2015_CLASS) \
|| ((JERRY_ES2015_CLASS != 0) && (JERRY_ES2015_CLASS != 1))
# error "Invalid value for JERRY_ES2015_CLASS macro."
#endif
#if !defined (JERRY_ES2015_FOR_OF) \
|| ((JERRY_ES2015_FOR_OF != 0) && (JERRY_ES2015_FOR_OF != 1))
# error "Invalid value for JERRY_ES2015_FOR_OF macro."
#endif
#if !defined (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER) \
|| ((JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER != 0) && (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER != 1))
# error "Invalid value for JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER macro."
#endif
#if !defined (JERRY_ES2015_FUNCTION_REST_PARAMETER) \
|| ((JERRY_ES2015_FUNCTION_REST_PARAMETER != 0) && (JERRY_ES2015_FUNCTION_REST_PARAMETER != 1))
# error "Invalid value for JERRY_ES2015_FUNCTION_REST_PARAMETER macro."
#endif
#if !defined (JERRY_ES2015_OBJECT_INITIALIZER) \
|| ((JERRY_ES2015_OBJECT_INITIALIZER != 0) && (JERRY_ES2015_OBJECT_INITIALIZER != 1))
# error "Invalid value for JERRY_ES2015_OBJECT_INITIALIZER macro."
#endif
#if !defined (JERRY_ES2015_MODULE_SYSTEM) \
|| ((JERRY_ES2015_MODULE_SYSTEM != 0) && (JERRY_ES2015_MODULE_SYSTEM != 1))
# error "Invalid value for JERRY_ES2015_MODULE_SYSTEM macro."
#endif
#if !defined (JERRY_ES2015_TEMPLATE_STRINGS) \
|| ((JERRY_ES2015_TEMPLATE_STRINGS != 0) && (JERRY_ES2015_TEMPLATE_STRINGS != 1))
# error "Invalid value for JERRY_ES2015_TEMPLATE_STRINGS macro."
#endif
/**
* Internal options.
*/
#if !defined (JERRY_CPOINTER_32_BIT) \
|| ((JERRY_CPOINTER_32_BIT != 0) && (JERRY_CPOINTER_32_BIT != 1))
# error "Invalid value for 'JERRY_CPOINTER_32_BIT' macro."
#endif
#if !defined (JERRY_DEBUGGER) \
|| ((JERRY_DEBUGGER != 0) && (JERRY_DEBUGGER != 1))
# error "Invalid value for 'JERRY_DEBUGGER' macro."
#endif
#if !defined (JERRY_ERROR_MESSAGES) \
|| ((JERRY_ERROR_MESSAGES != 0) && (JERRY_ERROR_MESSAGES != 1))
# error "Invalid value for 'JERRY_ERROR_MESSAGES' macro."
#endif
#if !defined (JERRY_EXTERNAL_CONTEXT) \
|| ((JERRY_EXTERNAL_CONTEXT != 0) && (JERRY_EXTERNAL_CONTEXT != 1))
# error "Invalid value for 'JERRY_EXTERNAL_CONTEXT' macro."
#endif
#if !defined (JERRY_GLOBAL_HEAP_SIZE) || (JERRY_GLOBAL_HEAP_SIZE <= 0)
# error "Invalid value for 'JERRY_GLOBAL_HEAP_SIZE' macro."
#endif
#if !defined (JERRY_STACK_LIMIT) || (JERRY_STACK_LIMIT < 0)
# error "Invalid value for 'JERRY_STACK_LIMIT' macro."
#endif
#if !defined (JERRY_LCACHE) \
|| ((JERRY_LCACHE != 0) && (JERRY_LCACHE != 1))
# error "Invalid value for 'JERRY_LCACHE' macro."
#endif
#if !defined (JERRY_LINE_INFO) \
|| ((JERRY_LINE_INFO != 0) && (JERRY_LINE_INFO != 1))
# error "Invalid value for 'JERRY_LINE_INFO' macro."
#endif
#if !defined (JERRY_LOGGING) \
|| ((JERRY_LOGGING != 0) && (JERRY_LOGGING != 1))
# error "Invalid value for 'JERRY_LOGGING' macro."
#endif
#if !defined (JERRY_MEM_GC_BEFORE_EACH_ALLOC) \
|| ((JERRY_MEM_GC_BEFORE_EACH_ALLOC != 0) && (JERRY_MEM_GC_BEFORE_EACH_ALLOC != 1))
# error "Invalid value for 'JERRY_MEM_GC_BEFORE_EACH_ALLOC' macro."
#endif
#if !defined (JERRY_MEM_STATS) \
|| ((JERRY_MEM_STATS != 0) && (JERRY_MEM_STATS != 1))
# error "Invalid value for 'JERRY_MEM_STATS' macro."
#endif
#if !defined (JERRY_NUMBER_TYPE_FLOAT64) \
|| ((JERRY_NUMBER_TYPE_FLOAT64 != 0) && (JERRY_NUMBER_TYPE_FLOAT64 != 1))
# error "Invalid value for 'JERRY_NUMBER_TYPE_FLOAT64' macro."
#endif
#if !defined (JERRY_PARSER) \
|| ((JERRY_PARSER != 0) && (JERRY_PARSER != 1))
# error "Invalid value for 'JERRY_PARSER' macro."
#endif
#if !defined (JERRY_PARSER_DUMP_BYTE_CODE) \
|| ((JERRY_PARSER_DUMP_BYTE_CODE != 0) && (JERRY_PARSER_DUMP_BYTE_CODE != 1))
# error "Invalid value for 'JERRY_PARSER_DUMP_BYTE_CODE' macro."
#endif
#if !defined (JERRY_PROPRETY_HASHMAP) \
|| ((JERRY_PROPRETY_HASHMAP != 0) && (JERRY_PROPRETY_HASHMAP != 1))
# error "Invalid value for 'JERRY_PROPRETY_HASHMAP' macro."
#endif
#if !defined (JERRY_REGEXP_DUMP_BYTE_CODE) \
|| ((JERRY_REGEXP_DUMP_BYTE_CODE != 0) && (JERRY_REGEXP_DUMP_BYTE_CODE != 1))
# error "Invalid value for 'JERRY_REGEXP_DUMP_BYTE_CODE' macro."
#endif
#if !defined (JERRY_REGEXP_STRICT_MODE) \
|| ((JERRY_REGEXP_STRICT_MODE != 0) && (JERRY_REGEXP_STRICT_MODE != 1))
# error "Invalid value for 'JERRY_REGEXP_STRICT_MODE' macro."
#endif
#if !defined (JERRY_SNAPSHOT_EXEC) \
|| ((JERRY_SNAPSHOT_EXEC != 0) && (JERRY_SNAPSHOT_EXEC != 1))
# error "Invalid value for 'JERRY_SNAPSHOT_EXEC' macro."
#endif
#if !defined (JERRY_SNAPSHOT_SAVE) \
|| ((JERRY_SNAPSHOT_SAVE != 0) && (JERRY_SNAPSHOT_SAVE != 1))
# error "Invalid value for 'JERRY_SNAPSHOT_SAVE' macro."
#endif
#if !defined (JERRY_SYSTEM_ALLOCATOR) \
|| ((JERRY_SYSTEM_ALLOCATOR != 0) && (JERRY_SYSTEM_ALLOCATOR != 1))
# error "Invalid value for 'JERRY_SYSTEM_ALLOCATOR' macro."
#endif
#if !defined (JERRY_UNICODE_CASE_CONVERSION) \
|| ((JERRY_UNICODE_CASE_CONVERSION != 0) && (JERRY_UNICODE_CASE_CONVERSION != 1))
# error "Invalid value for 'JERRY_UNICODE_CASE_CONVERSION' macro."
#endif
#if !defined (JERRY_VALGRIND) \
|| ((JERRY_VALGRIND != 0) && (JERRY_VALGRIND != 1))
# error "Invalid value for 'JERRY_VALGRIND' macro."
#endif
#if !defined (JERRY_VM_EXEC_STOP) \
|| ((JERRY_VM_EXEC_STOP != 0) && (JERRY_VM_EXEC_STOP != 1))
# error "Invalid value for 'JERRY_VM_EXEC_STOP' macro."
#endif
#define ENABLED(FEATURE) ((FEATURE) == 1)
#define DISABLED(FEATURE) ((FEATURE) != 1)
/**
* Cross component requirements check.
*/
/**
* The date module can only use the float 64 number types.
* Do a check for this.
*/
#if ENABLED (JERRY_BUILTIN_DATE) && !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
# error "Date does not support float32"
#endif
#endif /* !JERRYSCRIPT_CONFIG_H */
File diff suppressed because it is too large Load Diff
+491
View File
@@ -0,0 +1,491 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DEBUGGER_H
#define DEBUGGER_H
#include "ecma-globals.h"
#include "jerryscript-debugger-transport.h"
#if ENABLED (JERRY_DEBUGGER)
/* JerryScript debugger protocol is a simplified version of RFC-6455 (WebSockets). */
/**
* Frequency of calling jerry_debugger_receive() by the VM.
*/
#define JERRY_DEBUGGER_MESSAGE_FREQUENCY 5
/**
* This constant represents that the string to be sent has no subtype.
*/
#define JERRY_DEBUGGER_NO_SUBTYPE 0
/**
* Limited resources available for the engine, so it is important to
* check the maximum buffer size. It needs to be between 64 and 256 bytes.
*/
#if JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE < 64 || JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE > 256
#error Please define the MAX_BUFFER_SIZE between 64 and 256 bytes.
#endif /* JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE < 64 || JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE > 256 */
/**
* Calculate the maximum number of items for a given type
* which can be transmitted in one message.
*/
#define JERRY_DEBUGGER_SEND_MAX(type) \
((size_t) ((JERRY_CONTEXT (debugger_max_send_size) - sizeof (jerry_debugger_send_type_t)) / sizeof (type)))
/**
* Calculate the size of a message when a count number of items transmitted.
*/
#define JERRY_DEBUGGER_SEND_SIZE(count, type) \
((size_t) ((count * sizeof (type)) + sizeof (jerry_debugger_send_type_t)))
/**
* Debugger operation modes:
*
* The debugger has two operation modes: run mode and breakpoint mode.
*
* In run mode the debugger server accepts only a limited number of message
* types from the debugger client (e.g. stop execution, set breakpoint).
*
* In breakpoint mode the JavaScript execution is stopped at a breakpoint and
* more message types are accepted (e.g. get backtrace, evaluate expression).
*
* Switching between modes:
*
* When the JavaScript execution stops at a breakpoint the server sends a
* JERRY_DEBUGGER_BREAKPOINT_HIT message to the client. The client can only
* issue breakpoint mode commands after this message is received.
*
* Certain breakpoint mode commands (e.g. continue) resumes the JavaScript
* execution and the client must not send any breakpoint mode messages
* until the JERRY_DEBUGGER_BREAKPOINT_HIT is received again.
*
* The debugger server starts in run mode but stops at the first available
* breakpoint.
*/
/**
* Debugger option flags.
*/
typedef enum
{
JERRY_DEBUGGER_CONNECTED = 1u << 0, /**< debugger is connected */
JERRY_DEBUGGER_BREAKPOINT_MODE = 1u << 1, /**< debugger waiting at a breakpoint */
JERRY_DEBUGGER_VM_STOP = 1u << 2, /**< stop at the next breakpoint even if disabled */
JERRY_DEBUGGER_VM_IGNORE = 1u << 3, /**< ignore all breakpoints */
JERRY_DEBUGGER_VM_IGNORE_EXCEPTION = 1u << 4, /**< debugger doesn't stop at any exception */
JERRY_DEBUGGER_VM_EXCEPTION_THROWN = 1u << 5, /**< no need to stop for this exception */
JERRY_DEBUGGER_PARSER_WAIT = 1u << 6, /**< debugger should wait after parsing is completed */
JERRY_DEBUGGER_PARSER_WAIT_MODE = 1u << 7, /**< debugger is waiting after parsing is completed */
JERRY_DEBUGGER_CLIENT_SOURCE_MODE = 1u << 8, /**< debugger waiting for client code */
JERRY_DEBUGGER_CLIENT_NO_SOURCE = 1u << 9, /**< debugger leaving the client source loop */
JERRY_DEBUGGER_CONTEXT_RESET_MODE = 1u << 10, /**< debugger and engine reinitialization mode */
} jerry_debugger_flags_t;
/**
* Set debugger flags.
*/
#define JERRY_DEBUGGER_SET_FLAGS(flags) \
JERRY_CONTEXT (debugger_flags) = (JERRY_CONTEXT (debugger_flags) | (uint32_t) (flags))
/**
* Clear debugger flags.
*/
#define JERRY_DEBUGGER_CLEAR_FLAGS(flags) \
JERRY_CONTEXT (debugger_flags) = (JERRY_CONTEXT (debugger_flags) & (uint32_t) ~(flags))
/**
* Set and clear debugger flags.
*/
#define JERRY_DEBUGGER_UPDATE_FLAGS(flags_to_set, flags_to_clear) \
JERRY_CONTEXT (debugger_flags) = ((JERRY_CONTEXT (debugger_flags) | (uint32_t) (flags_to_set)) \
& (uint32_t) ~(flags_to_clear))
/**
* Types for the package.
*/
typedef enum
{
/* Messages sent by the server to client. */
/* This is a handshake message, sent once during initialization. */
JERRY_DEBUGGER_CONFIGURATION = 1, /**< debugger configuration */
/* These messages are sent by the parser. */
JERRY_DEBUGGER_PARSE_ERROR = 2, /**< parse error */
JERRY_DEBUGGER_BYTE_CODE_CP = 3, /**< byte code compressed pointer */
JERRY_DEBUGGER_PARSE_FUNCTION = 4, /**< parsing a new function */
JERRY_DEBUGGER_BREAKPOINT_LIST = 5, /**< list of line offsets */
JERRY_DEBUGGER_BREAKPOINT_OFFSET_LIST = 6, /**< list of byte code offsets */
JERRY_DEBUGGER_SOURCE_CODE = 7, /**< source code fragment */
JERRY_DEBUGGER_SOURCE_CODE_END = 8, /**< source code last fragment */
JERRY_DEBUGGER_SOURCE_CODE_NAME = 9, /**< source code name fragment */
JERRY_DEBUGGER_SOURCE_CODE_NAME_END = 10, /**< source code name last fragment */
JERRY_DEBUGGER_FUNCTION_NAME = 11, /**< function name fragment */
JERRY_DEBUGGER_FUNCTION_NAME_END = 12, /**< function name last fragment */
JERRY_DEBUGGER_WAITING_AFTER_PARSE = 13, /**< engine waiting for a parser resume */
/* These messages are generic messages. */
JERRY_DEBUGGER_RELEASE_BYTE_CODE_CP = 14, /**< invalidate byte code compressed pointer */
JERRY_DEBUGGER_MEMSTATS_RECEIVE = 15, /**< memstats sent to the client */
JERRY_DEBUGGER_BREAKPOINT_HIT = 16, /**< notify breakpoint hit */
JERRY_DEBUGGER_EXCEPTION_HIT = 17, /**< notify exception hit */
JERRY_DEBUGGER_EXCEPTION_STR = 18, /**< exception string fragment */
JERRY_DEBUGGER_EXCEPTION_STR_END = 19, /**< exception string last fragment */
JERRY_DEBUGGER_BACKTRACE_TOTAL = 20, /**< number of total frames */
JERRY_DEBUGGER_BACKTRACE = 21, /**< backtrace data */
JERRY_DEBUGGER_BACKTRACE_END = 22, /**< last backtrace data */
JERRY_DEBUGGER_EVAL_RESULT = 23, /**< eval result */
JERRY_DEBUGGER_EVAL_RESULT_END = 24, /**< last part of eval result */
JERRY_DEBUGGER_WAIT_FOR_SOURCE = 25, /**< engine waiting for source code */
JERRY_DEBUGGER_OUTPUT_RESULT = 26, /**< output sent by the program to the debugger */
JERRY_DEBUGGER_OUTPUT_RESULT_END = 27, /**< last output result data */
JERRY_DEBUGGER_SCOPE_CHAIN = 28, /**< scope chain */
JERRY_DEBUGGER_SCOPE_CHAIN_END = 29, /**< last output of scope chain */
JERRY_DEBUGGER_SCOPE_VARIABLES = 30, /**< scope variables */
JERRY_DEBUGGER_SCOPE_VARIABLES_END = 31, /**< last output of scope variables */
JERRY_DEBUGGER_CLOSE_CONNECTION = 32, /**< close connection with the client */
JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT, /**< number of different type of output messages by the debugger */
/* Messages sent by the client to server. */
/* The following messages are accepted in both run and breakpoint modes. */
JERRY_DEBUGGER_FREE_BYTE_CODE_CP = 1, /**< free byte code compressed pointer */
JERRY_DEBUGGER_UPDATE_BREAKPOINT = 2, /**< update breakpoint status */
JERRY_DEBUGGER_EXCEPTION_CONFIG = 3, /**< exception handler config */
JERRY_DEBUGGER_PARSER_CONFIG = 4, /**< parser config */
JERRY_DEBUGGER_MEMSTATS = 5, /**< list memory statistics */
JERRY_DEBUGGER_STOP = 6, /**< stop execution */
/* The following message is only available in waiting after parse mode. */
JERRY_DEBUGGER_PARSER_RESUME = 7, /**< stop waiting after parse */
/* The following four messages are only available in client switch mode. */
JERRY_DEBUGGER_CLIENT_SOURCE = 8, /**< first message of client source */
JERRY_DEBUGGER_CLIENT_SOURCE_PART = 9, /**< next message of client source */
JERRY_DEBUGGER_NO_MORE_SOURCES = 10, /**< no more sources notification */
JERRY_DEBUGGER_CONTEXT_RESET = 11, /**< context reset request */
/* The following messages are only available in breakpoint
* mode and they switch the engine to run mode. */
JERRY_DEBUGGER_CONTINUE = 12, /**< continue execution */
JERRY_DEBUGGER_STEP = 13, /**< next breakpoint, step into functions */
JERRY_DEBUGGER_NEXT = 14, /**< next breakpoint in the same context */
JERRY_DEBUGGER_FINISH = 15, /**< Continue running just after the function in the current stack frame returns */
/* The following messages are only available in breakpoint
* mode and this mode is kept after the message is processed. */
JERRY_DEBUGGER_GET_BACKTRACE = 16, /**< get backtrace */
JERRY_DEBUGGER_EVAL = 17, /**< first message of evaluating a string */
JERRY_DEBUGGER_EVAL_PART = 18, /**< next message of evaluating a string */
JERRY_DEBUGGER_GET_SCOPE_CHAIN = 19, /**< get type names of the scope chain */
JERRY_DEBUGGER_GET_SCOPE_VARIABLES = 20, /**< get variables of a scope */
JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT, /**< number of different type of input messages */
} jerry_debugger_header_type_t;
/**
* Debugger option flags.
*/
typedef enum
{
JERRY_DEBUGGER_LITTLE_ENDIAN = 1u << 0, /**< little endian */
} jerry_debugger_configuration_flags_t;
/**
* Subtypes of eval.
*/
typedef enum
{
JERRY_DEBUGGER_EVAL_EVAL = 0, /**< evaluate expression */
JERRY_DEBUGGER_EVAL_THROW = 1, /**< evaluate expression and throw the result */
JERRY_DEBUGGER_EVAL_ABORT = 2, /**< evaluate expression and abrot with the result */
} jerry_debugger_eval_type_t;
/**
* Subtypes of eval_result.
*/
typedef enum
{
JERRY_DEBUGGER_EVAL_OK = 1, /**< eval result, no error */
JERRY_DEBUGGER_EVAL_ERROR = 2, /**< eval result when an error has occurred */
} jerry_debugger_eval_result_type_t;
/**
* Subtypes of output_result.
*
* Note:
* This enum has to be kept in sync with jerry_log_level_t with an offset
* of +2.
*/
typedef enum
{
JERRY_DEBUGGER_OUTPUT_OK = 1, /**< output result, no error */
JERRY_DEBUGGER_OUTPUT_ERROR = 2, /**< output result, error */
JERRY_DEBUGGER_OUTPUT_WARNING = 3, /**< output result, warning */
JERRY_DEBUGGER_OUTPUT_DEBUG = 4, /**< output result, debug */
JERRY_DEBUGGER_OUTPUT_TRACE = 5, /**< output result, trace */
} jerry_debugger_output_subtype_t;
/**
* Types of scopes.
*/
typedef enum
{
JERRY_DEBUGGER_SCOPE_WITH = 1, /**< with */
JERRY_DEBUGGER_SCOPE_LOCAL = 2, /**< local */
JERRY_DEBUGGER_SCOPE_CLOSURE = 3, /**< closure */
JERRY_DEBUGGER_SCOPE_GLOBAL = 4, /**< global */
JERRY_DEBUGGER_SCOPE_NON_CLOSURE = 5 /**< non closure */
} jerry_debugger_scope_chain_type_t;
/**
* Type of scope variables.
*/
typedef enum
{
JERRY_DEBUGGER_VALUE_NONE = 1,
JERRY_DEBUGGER_VALUE_UNDEFINED = 2,
JERRY_DEBUGGER_VALUE_NULL = 3,
JERRY_DEBUGGER_VALUE_BOOLEAN = 4,
JERRY_DEBUGGER_VALUE_NUMBER = 5,
JERRY_DEBUGGER_VALUE_STRING = 6,
JERRY_DEBUGGER_VALUE_FUNCTION = 7,
JERRY_DEBUGGER_VALUE_ARRAY = 8,
JERRY_DEBUGGER_VALUE_OBJECT = 9
} jerry_debugger_scope_variable_type_t;
/**
* Byte data for evaluating expressions and receiving client source.
*/
typedef struct
{
uint32_t uint8_size; /**< total size of the client source */
uint32_t uint8_offset; /**< current offset in the client source */
} jerry_debugger_uint8_data_t;
/**
* Delayed free of byte code data.
*/
typedef struct
{
uint16_t size; /**< size of the byte code header divided by JMEM_ALIGNMENT */
jmem_cpointer_t prev_cp; /**< previous byte code data to be freed */
} jerry_debugger_byte_code_free_t;
/**
* Outgoing message: JerryScript configuration.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t configuration; /**< configuration option bits */
uint8_t version[sizeof (uint32_t)]; /**< debugger version */
uint8_t max_message_size; /**< maximum incoming message size */
uint8_t cpointer_size; /**< size of compressed pointers */
} jerry_debugger_send_configuration_t;
/**
* Outgoing message: message without arguments.
*/
typedef struct
{
uint8_t type; /**< type of the message */
} jerry_debugger_send_type_t;
/**
* Incoming message: message without arguments.
*/
typedef struct
{
uint8_t type; /**< type of the message */
} jerry_debugger_receive_type_t;
/**
* Outgoing message: string (Source file name or function name).
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t string[]; /**< string data */
} jerry_debugger_send_string_t;
/**
* Outgoing message: uint32 value.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t line[sizeof (uint32_t)]; /**< value data */
uint8_t column[sizeof (uint32_t)]; /**< value data */
} jerry_debugger_send_parse_function_t;
/**
* Outgoing message: byte code compressed pointer.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t byte_code_cp[sizeof (jmem_cpointer_t)]; /**< byte code compressed pointer */
} jerry_debugger_send_byte_code_cp_t;
/**
* Incoming message: byte code compressed pointer.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t byte_code_cp[sizeof (jmem_cpointer_t)]; /**< byte code compressed pointer */
} jerry_debugger_receive_byte_code_cp_t;
/**
* Incoming message: update (enable/disable) breakpoint status.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t is_set_breakpoint; /**< set or clear breakpoint */
uint8_t byte_code_cp[sizeof (jmem_cpointer_t)]; /**< byte code compressed pointer */
uint8_t offset[sizeof (uint32_t)]; /**< breakpoint offset */
} jerry_debugger_receive_update_breakpoint_t;
/**
* Outgoing message: send memory statistics
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t allocated_bytes[sizeof (uint32_t)]; /**< allocated bytes */
uint8_t byte_code_bytes[sizeof (uint32_t)]; /**< byte code bytes */
uint8_t string_bytes[sizeof (uint32_t)]; /**< string bytes */
uint8_t object_bytes[sizeof (uint32_t)]; /**< object bytes */
uint8_t property_bytes[sizeof (uint32_t)]; /**< property bytes */
} jerry_debugger_send_memstats_t;
/**
* Outgoing message: notify breakpoint hit.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t byte_code_cp[sizeof (jmem_cpointer_t)]; /**< byte code compressed pointer */
uint8_t offset[sizeof (uint32_t)]; /**< breakpoint offset */
} jerry_debugger_send_breakpoint_hit_t;
/**
* Stack frame descriptor for sending backtrace information.
*/
typedef struct
{
uint8_t byte_code_cp[sizeof (jmem_cpointer_t)]; /**< byte code compressed pointer */
uint8_t offset[sizeof (uint32_t)]; /**< last breakpoint offset */
} jerry_debugger_frame_t;
/**
* Outgoing message: backtrace information.
*/
typedef struct
{
uint8_t type; /**< type of the message */
jerry_debugger_frame_t frames[]; /**< frames */
} jerry_debugger_send_backtrace_t;
/**
* Outgoing message: scope chain.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t scope_types[]; /**< scope types */
} jerry_debugger_send_scope_chain_t;
/**
* Outgoing message: number of total frames in backtrace.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t frame_count[sizeof (uint32_t)]; /**< total number of frames */
} jerry_debugger_send_backtrace_total_t;
/**
* Incoming message: set behaviour when exception occures.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t enable; /**< non-zero: enable stop at exception */
} jerry_debugger_receive_exception_config_t;
/**
* Incoming message: set parser configuration.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t enable_wait; /**< non-zero: wait after parsing is completed */
} jerry_debugger_receive_parser_config_t;
/**
* Incoming message: get backtrace.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t min_depth[sizeof (uint32_t)]; /**< minimum depth*/
uint8_t max_depth[sizeof (uint32_t)]; /**< maximum depth (0 - unlimited) */
uint8_t get_total_frame_count; /**< non-zero: if total frame count is also requested */
} jerry_debugger_receive_get_backtrace_t;
/**
* Incoming message: first message of evaluating expression.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t eval_size[sizeof (uint32_t)]; /**< total size of the message */
} jerry_debugger_receive_eval_first_t;
/**
* Incoming message: get scope variables
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t chain_index[sizeof (uint32_t)]; /**< index element of the scope */
} jerry_debugger_receive_get_scope_variables_t;
/**
* Incoming message: first message of client source.
*/
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t code_size[sizeof (uint32_t)]; /**< total size of the message */
} jerry_debugger_receive_client_source_first_t;
void jerry_debugger_free_unreferenced_byte_code (void);
bool jerry_debugger_receive (jerry_debugger_uint8_data_t **message_data_p);
void jerry_debugger_breakpoint_hit (uint8_t message_type);
void jerry_debugger_send_type (jerry_debugger_header_type_t type);
bool jerry_debugger_send_configuration (uint8_t max_message_size);
void jerry_debugger_send_data (jerry_debugger_header_type_t type, const void *data, size_t size);
bool jerry_debugger_send_string (uint8_t message_type, uint8_t sub_type, const uint8_t *string_p, size_t string_length);
bool jerry_debugger_send_function_cp (jerry_debugger_header_type_t type, ecma_compiled_code_t *compiled_code_p);
bool jerry_debugger_send_parse_function (uint32_t line, uint32_t column);
void jerry_debugger_send_memstats (void);
bool jerry_debugger_send_exception_string (void);
#endif /* ENABLED (JERRY_DEBUGGER) */
#endif /* !DEBUGGER_H */
+125 -52
View File
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,30 +16,19 @@
#include "ecma-alloc.h"
#include "ecma-globals.h"
#include "ecma-gc.h"
#include "ecma-lcache.h"
#include "jrt.h"
#include "jmem-poolman.h"
#include "jmem.h"
JERRY_STATIC_ASSERT (sizeof (ecma_property_value_t) == sizeof (ecma_value_t),
size_of_ecma_property_value_t_must_be_equal_to_size_of_ecma_value_t);
JERRY_STATIC_ASSERT (((sizeof (ecma_property_value_t) - 1) & sizeof (ecma_property_value_t)) == 0,
size_of_ecma_property_value_t_must_be_power_of_2);
JERRY_STATIC_ASSERT (sizeof (ecma_property_pair_t) == sizeof (uint64_t) * 2,
size_of_ecma_property_pair_t_must_be_equal_to_16_bytes);
JERRY_STATIC_ASSERT (sizeof (ecma_object_t) <= sizeof (uint64_t),
size_of_ecma_object_t_must_be_less_than_or_equal_to_8_bytes);
JERRY_STATIC_ASSERT (sizeof (ecma_extended_object_t) <= sizeof (uint64_t) * 2,
size_of_ecma_extended_object_t_must_be_less_than_or_equal_to_16_bytes);
JERRY_STATIC_ASSERT (sizeof (ecma_collection_header_t) == sizeof (uint64_t),
size_of_ecma_collection_header_t_must_be_less_than_or_equal_to_8_bytes);
JERRY_STATIC_ASSERT (sizeof (ecma_collection_chunk_t) == sizeof (uint64_t),
size_of_ecma_collection_chunk_t_must_be_less_than_or_equal_to_8_bytes);
JERRY_STATIC_ASSERT (sizeof (ecma_string_t) == sizeof (uint64_t),
size_of_ecma_string_t_must_be_less_than_or_equal_to_8_bytes);
JERRY_STATIC_ASSERT (sizeof (ecma_getter_setter_pointers_t) <= sizeof (uint64_t),
size_of_ecma_getter_setter_pointers_t_must_be_less_than_or_equal_to_8_bytes);
JERRY_STATIC_ASSERT (sizeof (ecma_extended_object_t) - sizeof (ecma_object_t) <= sizeof (uint64_t),
size_of_ecma_extended_object_part_must_be_less_than_or_equal_to_8_bytes);
/** \addtogroup ecma ECMA
* @{
@@ -62,79 +50,164 @@ JERRY_STATIC_ASSERT (sizeof (ecma_getter_setter_pointers_t) <= sizeof (uint64_t)
*/
/**
* Template of an allocation routine.
* Allocate memory for ecma-number
*
* @return pointer to allocated memory
*/
#define ALLOC(ecma_type) ecma_ ## ecma_type ## _t * \
ecma_alloc_ ## ecma_type (void) \
{ \
ecma_ ## ecma_type ## _t *p ## ecma_type = (ecma_ ## ecma_type ## _t *) jmem_pools_alloc (); \
\
JERRY_ASSERT (p ## ecma_type != NULL); \
\
return p ## ecma_type; \
}
ecma_number_t *
ecma_alloc_number (void)
{
return (ecma_number_t *) jmem_pools_alloc (sizeof (ecma_number_t));
} /* ecma_alloc_number */
/**
* Deallocation routine template
* Dealloc memory from an ecma-number
*/
#define DEALLOC(ecma_type) void \
ecma_dealloc_ ## ecma_type (ecma_ ## ecma_type ## _t *p ## ecma_type) \
{ \
jmem_pools_free ((uint8_t *) p ## ecma_type); \
}
void
ecma_dealloc_number (ecma_number_t *number_p) /**< number to be freed */
{
jmem_pools_free ((uint8_t *) number_p, sizeof (ecma_number_t));
} /* ecma_dealloc_number */
/**
* Declaration of alloc/free routine for specified ecma-type.
* Allocate memory for ecma-object
*
* @return pointer to allocated memory
*/
#define DECLARE_ROUTINES_FOR(ecma_type) \
ALLOC (ecma_type) \
DEALLOC (ecma_type)
inline ecma_object_t * JERRY_ATTR_ALWAYS_INLINE
ecma_alloc_object (void)
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_allocate_object_bytes (sizeof (ecma_object_t));
#endif /* ENABLED (JERRY_MEM_STATS) */
DECLARE_ROUTINES_FOR (object)
DECLARE_ROUTINES_FOR (number)
DECLARE_ROUTINES_FOR (collection_header)
DECLARE_ROUTINES_FOR (collection_chunk)
DECLARE_ROUTINES_FOR (string)
DECLARE_ROUTINES_FOR (getter_setter_pointers)
DECLARE_ROUTINES_FOR (external_pointer)
return (ecma_object_t *) jmem_pools_alloc (sizeof (ecma_object_t));
} /* ecma_alloc_object */
/**
* Dealloc memory from an ecma-object
*/
inline void JERRY_ATTR_ALWAYS_INLINE
ecma_dealloc_object (ecma_object_t *object_p) /**< object to be freed */
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_free_object_bytes (sizeof (ecma_object_t));
#endif /* ENABLED (JERRY_MEM_STATS) */
jmem_pools_free (object_p, sizeof (ecma_object_t));
} /* ecma_dealloc_object */
/**
* Allocate memory for extended object
*
* @return pointer to allocated memory
*/
inline ecma_extended_object_t * __attr_always_inline___
ecma_alloc_extended_object (void)
inline ecma_extended_object_t * JERRY_ATTR_ALWAYS_INLINE
ecma_alloc_extended_object (size_t size) /**< size of object */
{
return jmem_heap_alloc_block (sizeof (ecma_extended_object_t));
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_allocate_object_bytes (size);
#endif /* ENABLED (JERRY_MEM_STATS) */
return jmem_heap_alloc_block (size);
} /* ecma_alloc_extended_object */
/**
* Dealloc memory of an extended object
*/
inline void __attr_always_inline___
ecma_dealloc_extended_object (ecma_extended_object_t *ext_object_p) /**< property pair to be freed */
inline void JERRY_ATTR_ALWAYS_INLINE
ecma_dealloc_extended_object (ecma_object_t *object_p, /**< extended object */
size_t size) /**< size of object */
{
jmem_heap_free_block (ext_object_p, sizeof (ecma_extended_object_t));
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_free_object_bytes (size);
#endif /* ENABLED (JERRY_MEM_STATS) */
jmem_heap_free_block (object_p, size);
} /* ecma_dealloc_extended_object */
/**
* Allocate memory for ecma-string descriptor
*
* @return pointer to allocated memory
*/
inline ecma_string_t * JERRY_ATTR_ALWAYS_INLINE
ecma_alloc_string (void)
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_allocate_string_bytes (sizeof (ecma_string_t));
#endif /* ENABLED (JERRY_MEM_STATS) */
return (ecma_string_t *) jmem_pools_alloc (sizeof (ecma_string_t));
} /* ecma_alloc_string */
/**
* Dealloc memory from ecma-string descriptor
*/
inline void JERRY_ATTR_ALWAYS_INLINE
ecma_dealloc_string (ecma_string_t *string_p) /**< string to be freed */
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_free_string_bytes (sizeof (ecma_string_t));
#endif /* ENABLED (JERRY_MEM_STATS) */
jmem_pools_free (string_p, sizeof (ecma_string_t));
} /* ecma_dealloc_string */
/**
* Allocate memory for string with character data
*
* @return pointer to allocated memory
*/
inline ecma_string_t * JERRY_ATTR_ALWAYS_INLINE
ecma_alloc_string_buffer (size_t size) /**< size of string */
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_allocate_string_bytes (size);
#endif /* ENABLED (JERRY_MEM_STATS) */
return jmem_heap_alloc_block (size);
} /* ecma_alloc_string_buffer */
/**
* Dealloc memory of a string with character data
*/
inline void JERRY_ATTR_ALWAYS_INLINE
ecma_dealloc_string_buffer (ecma_string_t *string_p, /**< string with data */
size_t size) /**< size of string */
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_free_string_bytes (size);
#endif /* ENABLED (JERRY_MEM_STATS) */
jmem_heap_free_block (string_p, size);
} /* ecma_dealloc_string_buffer */
/**
* Allocate memory for ecma-property pair
*
* @return pointer to allocated memory
*/
inline ecma_property_pair_t * __attr_always_inline___
inline ecma_property_pair_t * JERRY_ATTR_ALWAYS_INLINE
ecma_alloc_property_pair (void)
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_allocate_property_bytes (sizeof (ecma_property_pair_t));
#endif /* ENABLED (JERRY_MEM_STATS) */
return jmem_heap_alloc_block (sizeof (ecma_property_pair_t));
} /* ecma_alloc_property_pair */
/**
* Dealloc memory of an ecma-property
*/
inline void __attr_always_inline___
inline void JERRY_ATTR_ALWAYS_INLINE
ecma_dealloc_property_pair (ecma_property_pair_t *property_pair_p) /**< property pair to be freed */
{
#if ENABLED (JERRY_MEM_STATS)
jmem_stats_free_property_bytes (sizeof (ecma_property_pair_t));
#endif /* ENABLED (JERRY_MEM_STATS) */
jmem_heap_free_block (property_pair_p, sizeof (ecma_property_pair_t));
} /* ecma_dealloc_property_pair */
+25 -61
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,108 +30,72 @@
*
* @return pointer to allocated memory
*/
extern ecma_object_t *ecma_alloc_object (void);
ecma_object_t *ecma_alloc_object (void);
/**
* Dealloc memory from an ecma-object
*/
extern void ecma_dealloc_object (ecma_object_t *);
void ecma_dealloc_object (ecma_object_t *object_p);
/**
* Allocate memory for extended object
*
* @return pointer to allocated memory
*/
ecma_extended_object_t *ecma_alloc_extended_object (size_t size);
/**
* Dealloc memory of an extended object
*/
void ecma_dealloc_extended_object (ecma_object_t *object_p, size_t size);
/**
* Allocate memory for ecma-number
*
* @return pointer to allocated memory
*/
extern ecma_number_t *ecma_alloc_number (void);
ecma_number_t *ecma_alloc_number (void);
/**
* Dealloc memory from an ecma-number
*/
extern void ecma_dealloc_number (ecma_number_t *);
/**
* Allocate memory for header of a collection
*
* @return pointer to allocated memory
*/
extern ecma_collection_header_t *ecma_alloc_collection_header (void);
/**
* Dealloc memory from the collection's header
*/
extern void ecma_dealloc_collection_header (ecma_collection_header_t *);
/**
* Allocate memory for non-first chunk of a collection
*
* @return pointer to allocated memory
*/
extern ecma_collection_chunk_t *ecma_alloc_collection_chunk (void);
/**
* Dealloc memory from non-first chunk of a collection
*/
extern void ecma_dealloc_collection_chunk (ecma_collection_chunk_t *);
void ecma_dealloc_number (ecma_number_t *number_p);
/**
* Allocate memory for ecma-string descriptor
*
* @return pointer to allocated memory
*/
extern ecma_string_t *ecma_alloc_string (void);
ecma_string_t *ecma_alloc_string (void);
/**
* Dealloc memory from ecma-string descriptor
*/
extern void ecma_dealloc_string (ecma_string_t *);
void ecma_dealloc_string (ecma_string_t *string_p);
/**
* Allocate memory for getter-setter pointer pair
* Allocate memory for string with character data
*
* @return pointer to allocated memory
*/
extern ecma_getter_setter_pointers_t *ecma_alloc_getter_setter_pointers (void);
ecma_string_t *ecma_alloc_string_buffer (size_t size);
/**
* Dealloc memory from getter-setter pointer pair
* Dealloc memory of a string with character data
*/
extern void ecma_dealloc_getter_setter_pointers (ecma_getter_setter_pointers_t *);
/**
* Allocate memory for external pointer
*
* @return pointer to allocated memory
*/
extern ecma_external_pointer_t *ecma_alloc_external_pointer (void);
/**
* Dealloc memory from external pointer
*/
extern void ecma_dealloc_external_pointer (ecma_external_pointer_t *);
/*
* Allocate memory for extended object
*
* @return pointer to allocated memory
*/
extern ecma_extended_object_t *ecma_alloc_extended_object (void);
/**
* Dealloc memory of an extended object
*/
extern void ecma_dealloc_extended_object (ecma_extended_object_t *);
void ecma_dealloc_string_buffer (ecma_string_t *string_p, size_t size);
/**
* Allocate memory for ecma-property pair
*
* @return pointer to allocated memory
*/
extern ecma_property_pair_t *ecma_alloc_property_pair (void);
ecma_property_pair_t *ecma_alloc_property_pair (void);
/**
* Dealloc memory from an ecma-property pair
*/
extern void ecma_dealloc_property_pair (ecma_property_pair_t *);
void ecma_dealloc_property_pair (ecma_property_pair_t *property_pair_p);
/**
* @}
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
#define ECMA_GC_H
#include "ecma-globals.h"
#include "jmem-allocator.h"
#include "jmem.h"
/** \addtogroup ecma ECMA
* @{
@@ -26,11 +26,11 @@
* @{
*/
extern void ecma_init_gc_info (ecma_object_t *);
extern void ecma_ref_object (ecma_object_t *);
extern void ecma_deref_object (ecma_object_t *);
extern void ecma_gc_run (jmem_free_unused_memory_severity_t);
extern void ecma_free_unused_memory (jmem_free_unused_memory_severity_t);
void ecma_init_gc_info (ecma_object_t *object_p);
void ecma_ref_object (ecma_object_t *object_p);
void ecma_deref_object (ecma_object_t *object_p);
void ecma_gc_run (void);
void ecma_free_unused_memory (jmem_pressure_t pressure);
/**
* @}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+11 -7
View File
@@ -1,5 +1,4 @@
/* Copyright 2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +38,6 @@
#include <math.h>
#include "config.h"
#include "ecma-helpers.h"
/** \addtogroup ecma ECMA
@@ -56,11 +54,17 @@
*/
/**
* Floating point format definitions
* Floating point format definitions (next float value)
*/
#define ECMA_NEXT_FLOAT(value) (nextafter ((value), INFINITY))
/**
* Floating point format definitions (previous float value)
*/
#define ECMA_PREV_FLOAT(value) (nextafter ((value), -INFINITY))
/**
* Value of epsilon
*/
#define ERROL0_EPSILON 0.0000001
/**
@@ -75,7 +79,7 @@ typedef struct
/**
* Normalize the number by factoring in the error.
*/
static inline void __attr_always_inline___
static inline void JERRY_ATTR_ALWAYS_INLINE
ecma_normalize_high_prec_data (ecma_high_prec_t *hp_data_p) /**< [in, out] float pair */
{
double val = hp_data_p->value;
@@ -87,7 +91,7 @@ ecma_normalize_high_prec_data (ecma_high_prec_t *hp_data_p) /**< [in, out] float
/**
* Multiply the high-precision number by ten.
*/
static inline void __attr_always_inline___
static inline void JERRY_ATTR_ALWAYS_INLINE
ecma_multiply_high_prec_by_10 (ecma_high_prec_t *hp_data_p) /**< [in, out] high-precision number */
{
double value = hp_data_p->value;
@@ -129,7 +133,7 @@ ecma_divide_high_prec_by_10 (ecma_high_prec_t *hp_data_p) /**< [in, out] high-pr
*
* @return number of generated digits
*/
inline lit_utf8_size_t __attr_always_inline___
inline lit_utf8_size_t JERRY_ATTR_ALWAYS_INLINE
ecma_errol0_dtoa (double val, /**< ecma number */
lit_utf8_byte_t *buffer_p, /**< buffer to generate digits into */
int32_t *exp_p) /**< [out] exponent */
@@ -1,5 +1,4 @@
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +15,7 @@
#include "ecma-alloc.h"
#include "ecma-globals.h"
#include "ecma-objects.h"
#include "ecma-helpers.h"
/** \addtogroup ecma ECMA
@@ -26,141 +26,184 @@
*/
/**
* Create internal property with specified identifier and store external pointer in the property.
*
* Note:
* property identifier should be one of the following:
* - ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE;
* - ECMA_INTERNAL_PROPERTY_FREE_CALLBACK.
* Create a native pointer property to store the native pointer and its type info.
*
* @return true - if property was just created with specified value,
* false - otherwise, if property existed before the call, it's value was updated.
* false - otherwise, if property existed before the call, it's value was updated
*/
bool
ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to create property in */
ecma_internal_property_id_t id, /**< identifier of internal
* property to create */
ecma_external_pointer_t ptr_value) /**< value to store in the property */
ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create property in */
void *native_p, /**< native pointer */
void *info_p) /**< native pointer's type info */
{
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
|| id == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
bool is_new;
ecma_property_t *prop_p = ecma_find_internal_property (obj_p, id);
bool is_new = (property_p == NULL);
if (prop_p == NULL)
ecma_native_pointer_t *native_pointer_p;
if (property_p == NULL)
{
prop_p = ecma_create_internal_property (obj_p, id);
ecma_property_value_t *value_p;
value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_CONFIGURABLE_WRITABLE, &property_p);
is_new = true;
ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY (property_p);
native_pointer_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p);
}
else
{
is_new = false;
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
ecma_native_pointer_t *iter_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
/* There should be at least 1 native pointer in the chain */
JERRY_ASSERT (iter_p != NULL);
while (true)
{
if (iter_p->info_p == info_p)
{
/* The native info already exists -> update the corresponding data */
iter_p->data_p = native_p;
return false;
}
if (iter_p->next_p == NULL)
{
/* The native info does not exist -> append a new element to the chain */
break;
}
iter_p = iter_p->next_p;
}
native_pointer_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
iter_p->next_p = native_pointer_p;
}
JERRY_STATIC_ASSERT (sizeof (uint32_t) <= sizeof (ECMA_PROPERTY_VALUE_PTR (prop_p)->value),
size_of_internal_property_value_must_be_greater_than_or_equal_to_4_bytes);
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
ECMA_PROPERTY_VALUE_PTR (prop_p)->value = (ecma_value_t) ptr_value;
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
ecma_external_pointer_t *handler_p;
if (is_new)
{
handler_p = ecma_alloc_external_pointer ();
ECMA_SET_NON_NULL_POINTER (ECMA_PROPERTY_VALUE_PTR (prop_p)->value, handler_p);
}
else
{
handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
}
*handler_p = ptr_value;
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
native_pointer_p->data_p = native_p;
native_pointer_p->info_p = info_p;
native_pointer_p->next_p = NULL;
return is_new;
} /* ecma_create_external_pointer_property */
} /* ecma_create_native_pointer_property */
/**
* Get value of external pointer stored in the object's property with specified identifier
* Get value of native package stored in the object's property with specified identifier
*
* Note:
* property identifier should be one of the following:
* - ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE;
* - ECMA_INTERNAL_PROPERTY_FREE_CALLBACK.
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER
*
* @return true - if property exists and it's value is returned through out_pointer_p,
* false - otherwise (value returned through out_pointer_p is NULL).
* @return native pointer data if property exists
* NULL otherwise
*/
ecma_native_pointer_t *
ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */
void *info_p) /**< native pointer's type info */
{
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
if (property_p == NULL)
{
return NULL;
}
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t,
value_p->value);
JERRY_ASSERT (native_pointer_p != NULL);
while (native_pointer_p != NULL)
{
if (native_pointer_p->info_p == info_p)
{
return native_pointer_p;
}
native_pointer_p = native_pointer_p->next_p;
}
return NULL;
} /* ecma_get_native_pointer_value */
/**
* Delete the previously set native pointer by the native type info from the specified object.
*
* Note:
* If the specified object has no matching native pointer for the given native type info
* the function has no effect.
*
* @return true - if the native pointer has been deleted succesfully
* false - otherwise
*/
bool
ecma_get_external_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */
ecma_internal_property_id_t id, /**< identifier of internal property
* to get value from */
ecma_external_pointer_t *out_pointer_p) /**< [out] value of the external pointer */
ecma_delete_native_pointer_property (ecma_object_t *obj_p, /**< object to delete property from */
void *info_p) /**< native pointer's type info */
{
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
|| id == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
ecma_property_t *prop_p = ecma_find_internal_property (obj_p, id);
if (prop_p == NULL)
if (property_p == NULL)
{
*out_pointer_p = (ecma_external_pointer_t) NULL;
return false;
}
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
*out_pointer_p = ECMA_PROPERTY_VALUE_PTR (prop_p)->value;
ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t,
value_p->value);
ecma_native_pointer_t *prev_p = NULL;
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
JERRY_ASSERT (native_pointer_p != NULL);
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
*out_pointer_p = *handler_p;
while (native_pointer_p != NULL)
{
if (native_pointer_p->info_p == info_p)
{
if (prev_p == NULL)
{
if (native_pointer_p->next_p == NULL)
{
/* Only one native pointer property exists, so the property can be deleted as well. */
ecma_op_object_delete (obj_p, name_p, false);
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
return true;
}
else
{
/* There are at least two native pointers and the first one should be deleted.
In this case the second element's data is copied to the head of the chain, and freed as well. */
ecma_native_pointer_t *next_p = native_pointer_p->next_p;
memcpy (native_pointer_p, next_p, sizeof (ecma_native_pointer_t));
jmem_heap_free_block (next_p, sizeof (ecma_native_pointer_t));
return true;
}
}
else
{
/* There are at least two native pointers and not the first element should be deleted.
In this case the current element's next element reference is copied to the previous element. */
prev_p->next_p = native_pointer_p->next_p;
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
return true;
}
}
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
prev_p = native_pointer_p;
native_pointer_p = native_pointer_p->next_p;
}
return true;
} /* ecma_get_external_pointer_value */
/**
* Free memory associated with external pointer stored in the property
*
* Note:
* property identifier should be one of the following:
* - ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE;
* - ECMA_INTERNAL_PROPERTY_FREE_CALLBACK.
*/
void
ecma_free_external_pointer_in_property (ecma_property_t *prop_p) /**< internal property */
{
JERRY_ASSERT (ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
|| ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (prop_p) == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
/* no additional memory was allocated for the pointer storage */
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
ecma_dealloc_external_pointer (handler_p);
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
} /* ecma_free_external_pointer_in_property */
return false;
} /* ecma_delete_native_pointer_property */
/**
* @}
+38 -89
View File
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2015-2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,11 +31,13 @@ JERRY_STATIC_ASSERT (ECMA_DIRECT_SHIFT == ECMA_VALUE_SHIFT + 1,
JERRY_STATIC_ASSERT (((1 << (ECMA_DIRECT_SHIFT - 1)) | ECMA_TYPE_DIRECT) == ECMA_DIRECT_TYPE_SIMPLE_VALUE,
currently_directly_encoded_values_start_after_direct_type_simple_value);
/**
* Position of the sign bit in ecma-numbers
*/
#define ECMA_NUMBER_SIGN_POS (ECMA_NUMBER_FRACTION_WIDTH + \
ECMA_NUMBER_BIASED_EXP_WIDTH)
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
JERRY_STATIC_ASSERT (sizeof (ecma_number_t) == sizeof (uint32_t),
size_of_ecma_number_t_must_be_equal_to_4_bytes);
@@ -111,7 +112,7 @@ ecma_number_unpack (ecma_number_t num, /**< ecma-number */
*/
const int32_t ecma_number_exponent_bias = 127;
#elif CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64
#elif ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
JERRY_STATIC_ASSERT (sizeof (ecma_number_t) == sizeof (uint64_t),
size_of_ecma_number_t_must_be_equal_to_8_bytes);
@@ -185,7 +186,7 @@ ecma_number_unpack (ecma_number_t num, /**< ecma-number */
*/
const int32_t ecma_number_exponent_bias = 1023;
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32 */
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
/**
* Get fraction of number
@@ -239,7 +240,7 @@ ecma_number_get_sign_field (ecma_number_t num) /**< ecma-number */
fraction is filled with anything but not all zero bits,
* false - otherwise
*/
bool __attr_always_inline___
inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
{
bool is_nan = (num != num);
@@ -292,7 +293,7 @@ ecma_number_make_infinity (bool sign) /**< true - for negative Infinity,
* @return true - if sign bit of ecma-number is set
* false - otherwise
*/
bool __attr_always_inline___
inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_number_is_negative (ecma_number_t num) /**< ecma-number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
@@ -330,7 +331,7 @@ ecma_number_is_zero (ecma_number_t num) /**< ecma-number */
*
* @return true - if biased exponent is filled with 1 bits and
* fraction is filled with zero bits,
* false - otherwise.
* false - otherwise
*/
bool
ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */
@@ -350,7 +351,7 @@ ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */
*
* @return shift of dot in the fraction
*/
int32_t
static int32_t
ecma_number_get_fraction_and_exponent (ecma_number_t num, /**< ecma-number */
uint64_t *out_fraction_p, /**< [out] fraction of the number */
int32_t *out_exponent_p) /**< [out] exponent of the number */
@@ -361,7 +362,7 @@ ecma_number_get_fraction_and_exponent (ecma_number_t num, /**< ecma-number */
uint64_t fraction = ecma_number_get_fraction_field (num);
int32_t exponent;
if (unlikely (biased_exp == 0))
if (JERRY_UNLIKELY (biased_exp == 0))
{
/* IEEE-754 2008, 3.4, d */
if (ecma_number_is_zero (num))
@@ -409,7 +410,7 @@ ecma_number_get_fraction_and_exponent (ecma_number_t num, /**< ecma-number */
*
* @return ecma-number
*/
ecma_number_t
static ecma_number_t
ecma_number_make_normal_positive_from_fraction_and_exponent (uint64_t fraction, /**< fraction */
int32_t exponent) /**< exponent */
{
@@ -521,7 +522,7 @@ ecma_number_get_prev (ecma_number_t num) /**< ecma-number */
if (ecma_number_is_negative (num))
{
return ecma_number_negate (ecma_number_get_next (num));
return -ecma_number_get_next (num);
}
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
@@ -556,7 +557,7 @@ ecma_number_get_next (ecma_number_t num) /**< ecma-number */
if (ecma_number_is_negative (num))
{
return ecma_number_negate (ecma_number_get_prev (num));
return -ecma_number_get_prev (num);
}
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
@@ -582,35 +583,6 @@ ecma_number_get_next (ecma_number_t num) /**< ecma-number */
fraction);
} /* ecma_number_get_next */
/**
* Negate ecma-number
*
* @return negated number
*/
ecma_number_t
ecma_number_negate (ecma_number_t num) /**< ecma-number */
{
ecma_number_t negated = -num;
#ifndef JERRY_NDEBUG
bool sign;
uint32_t biased_exp;
uint64_t fraction;
ecma_number_unpack (num, &sign, &biased_exp, &fraction);
sign = !sign;
ecma_number_t negated_ieee754 = ecma_number_pack (sign, biased_exp, fraction);
JERRY_ASSERT (negated == negated_ieee754
|| (ecma_number_is_nan (negated)
&& ecma_number_is_nan (negated_ieee754)));
#endif /* !JERRY_NDEBUG */
return negated;
} /* ecma_number_negate */
/**
* Truncate fractional part of the number
*
@@ -638,7 +610,7 @@ ecma_number_trunc (ecma_number_t num) /**< ecma-number */
exponent);
if (sign)
{
return ecma_number_negate (tmp);
return -tmp;
}
else
{
@@ -671,65 +643,42 @@ ecma_number_calc_remainder (ecma_number_t left_num, /**< left operand */
&& !ecma_number_is_zero (right_num)
&& !ecma_number_is_infinity (right_num));
const ecma_number_t q = ecma_number_trunc (ecma_number_divide (left_num, right_num));
ecma_number_t r = ecma_number_substract (left_num, ecma_number_multiply (right_num, q));
const ecma_number_t q = ecma_number_trunc (left_num / right_num);
ecma_number_t r = left_num - right_num * q;
if (ecma_number_is_zero (r)
&& ecma_number_is_negative (left_num))
{
r = ecma_number_negate (r);
r = -r;
}
return r;
} /* ecma_number_calc_remainder */
/**
* ECMA-number addition.
*
* @return number - result of addition.
*/
ecma_number_t
ecma_number_add (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
{
return left_num + right_num;
} /* ecma_number_add */
/**
* ECMA-number substraction.
*
* @return number - result of substraction.
*/
ecma_number_t
ecma_number_substract (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
{
return ecma_number_add (left_num, ecma_number_negate (right_num));
} /* ecma_number_substract */
/**
* ECMA-number multiplication.
* ECMA-integer number multiplication.
*
* @return number - result of multiplication.
*/
ecma_number_t
ecma_number_multiply (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
ecma_integer_multiply (ecma_integer_value_t left_integer, /**< left operand */
ecma_integer_value_t right_integer) /**< right operand */
{
return left_num * right_num;
} /* ecma_number_multiply */
/**
* ECMA-number division.
*
* @return number - result of division.
*/
ecma_number_t
ecma_number_divide (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
{
return left_num / right_num;
} /* ecma_number_divide */
#if defined (__GNUC__) || defined (__clang__)
/* Check if left_integer is power of 2 */
if (JERRY_UNLIKELY ((left_integer & (left_integer - 1)) == 0))
{
/* Right shift right_integer with log2 (left_integer) */
return ecma_make_integer_value (right_integer << (__builtin_ctz ((unsigned int) left_integer)));
}
else if (JERRY_UNLIKELY ((right_integer & (right_integer - 1)) == 0))
{
/* Right shift left_integer with log2 (right_integer) */
return ecma_make_integer_value (left_integer << (__builtin_ctz ((unsigned int) right_integer)));
}
#endif /* defined (__GNUC__) || defined (__clang__) */
return ecma_make_integer_value (left_integer * right_integer);
} /* ecma_integer_multiply */
/**
* @}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,60 +25,26 @@
* @{
*/
/**
* The type of ecma error and ecma collection chunk must be the same.
*/
JERRY_STATIC_ASSERT (ECMA_TYPE_ERROR == ECMA_TYPE_POINTER,
ecma_type_error_must_be_the_same_as_ecma_type_pointer);
/**
* Allocate a collection of ecma values.
*
* @return pointer to the collection's header
*/
ecma_collection_header_t *
ecma_new_values_collection (const ecma_value_t values_buffer[], /**< ecma values */
ecma_length_t values_number, /**< number of ecma values */
bool do_ref_if_object) /**< if the value is object value,
increase reference counter of the object */
ecma_new_values_collection (void)
{
JERRY_ASSERT (values_buffer != NULL || values_number == 0);
ecma_collection_header_t *header_p;
header_p = (ecma_collection_header_t *) jmem_pools_alloc (sizeof (ecma_collection_header_t));
const size_t values_in_chunk = JERRY_SIZE_OF_STRUCT_MEMBER (ecma_collection_chunk_t, data) / sizeof (ecma_value_t);
ecma_collection_header_t *header_p = ecma_alloc_collection_header ();
header_p->unit_number = values_number;
jmem_cpointer_t *next_chunk_cp_p = &header_p->first_chunk_cp;
ecma_collection_chunk_t *last_chunk_p = NULL;
ecma_value_t *cur_value_buf_iter_p = NULL;
ecma_value_t *cur_value_buf_end_p = NULL;
for (ecma_length_t value_index = 0;
value_index < values_number;
value_index++)
{
if (cur_value_buf_iter_p == cur_value_buf_end_p)
{
ecma_collection_chunk_t *chunk_p = ecma_alloc_collection_chunk ();
ECMA_SET_POINTER (*next_chunk_cp_p, chunk_p);
next_chunk_cp_p = &chunk_p->next_chunk_cp;
cur_value_buf_iter_p = (ecma_value_t *) chunk_p->data;
cur_value_buf_end_p = cur_value_buf_iter_p + values_in_chunk;
last_chunk_p = chunk_p;
}
JERRY_ASSERT (cur_value_buf_iter_p + 1 <= cur_value_buf_end_p);
if (do_ref_if_object)
{
*cur_value_buf_iter_p++ = ecma_copy_value (values_buffer[value_index]);
}
else
{
*cur_value_buf_iter_p++ = ecma_copy_value_if_not_object (values_buffer[value_index]);
}
}
*next_chunk_cp_p = ECMA_NULL_POINTER;
ECMA_SET_POINTER (header_p->last_chunk_cp, last_chunk_p);
header_p->item_count = 0;
header_p->first_chunk_cp = ECMA_NULL_POINTER;
header_p->last_chunk_cp = ECMA_NULL_POINTER;
return header_p;
} /* ecma_new_values_collection */
@@ -89,49 +54,44 @@ ecma_new_values_collection (const ecma_value_t values_buffer[], /**< ecma values
*/
void
ecma_free_values_collection (ecma_collection_header_t *header_p, /**< collection's header */
bool do_deref_if_object) /**< if the value is object value,
decrement reference counter of the object */
uint32_t flags) /**< combination of ecma_collection_flag_t flags */
{
JERRY_ASSERT (header_p != NULL);
const size_t values_in_chunk = JERRY_SIZE_OF_STRUCT_MEMBER (ecma_collection_chunk_t, data) / sizeof (ecma_value_t);
ecma_collection_chunk_t *chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
header_p->first_chunk_cp);
ecma_length_t value_index = 0;
while (chunk_p != NULL)
jmem_pools_free (header_p, sizeof (ecma_collection_header_t));
if (chunk_p == NULL)
{
JERRY_ASSERT (value_index < header_p->unit_number);
ecma_value_t *cur_value_buf_iter_p = (ecma_value_t *) chunk_p->data;
ecma_value_t *cur_value_buf_end_p = cur_value_buf_iter_p + values_in_chunk;
while (cur_value_buf_iter_p != cur_value_buf_end_p
&& value_index < header_p->unit_number)
{
JERRY_ASSERT (cur_value_buf_iter_p < cur_value_buf_end_p);
if (do_deref_if_object)
{
ecma_free_value (*cur_value_buf_iter_p);
}
else
{
ecma_free_value_if_not_object (*cur_value_buf_iter_p);
}
cur_value_buf_iter_p++;
value_index++;
}
ecma_collection_chunk_t *next_chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
chunk_p->next_chunk_cp);
ecma_dealloc_collection_chunk (chunk_p);
chunk_p = next_chunk_p;
return;
}
ecma_dealloc_collection_header (header_p);
do
{
ecma_value_t *item_p = chunk_p->items;
JERRY_ASSERT (!ecma_is_value_pointer (*item_p));
do
{
if (!(flags & ECMA_COLLECTION_NO_COPY)
&& (!ecma_is_value_object (*item_p)
|| !(flags & ECMA_COLLECTION_NO_REF_OBJECTS)))
{
ecma_free_value (*item_p);
}
item_p++;
}
while (!ecma_is_value_pointer (*item_p));
ecma_collection_chunk_t *next_chunk_p = (ecma_collection_chunk_t *) ecma_get_pointer_from_value (*item_p);
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
chunk_p = next_chunk_p;
}
while (chunk_p != NULL);
} /* ecma_free_values_collection */
/**
@@ -139,233 +99,99 @@ ecma_free_values_collection (ecma_collection_header_t *header_p, /**< collection
*/
void
ecma_append_to_values_collection (ecma_collection_header_t *header_p, /**< collection's header */
ecma_value_t v, /**< ecma value to append */
bool do_ref_if_object) /**< if the value is object value,
increase reference counter of the object */
ecma_value_t value, /**< ecma value to append */
uint32_t flags) /**< combination of ecma_collection_flag_t flags */
{
const size_t values_in_chunk = JERRY_SIZE_OF_STRUCT_MEMBER (ecma_collection_chunk_t, data) / sizeof (ecma_value_t);
ecma_length_t item_index;
ecma_collection_chunk_t *chunk_p;
size_t values_number = header_p->unit_number;
size_t pos_of_new_value_in_chunk = values_number % values_in_chunk;
values_number++;
if ((ecma_length_t) values_number == values_number)
if (JERRY_UNLIKELY (header_p->item_count == 0))
{
header_p->unit_number = (ecma_length_t) values_number;
item_index = 0;
chunk_p = (ecma_collection_chunk_t *) jmem_heap_alloc_block (sizeof (ecma_collection_chunk_t));
ECMA_SET_POINTER (header_p->first_chunk_cp, chunk_p);
header_p->last_chunk_cp = header_p->first_chunk_cp;
}
else
{
jerry_fatal (ERR_OUT_OF_MEMORY);
}
item_index = header_p->item_count % ECMA_COLLECTION_CHUNK_ITEMS;
ecma_collection_chunk_t *chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
header_p->last_chunk_cp);
chunk_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
header_p->last_chunk_cp);
if (pos_of_new_value_in_chunk == 0)
{
/* all chunks are currently filled with values */
chunk_p = ecma_alloc_collection_chunk ();
chunk_p->next_chunk_cp = ECMA_NULL_POINTER;
if (header_p->last_chunk_cp == ECMA_NULL_POINTER)
if (JERRY_UNLIKELY (item_index == 0))
{
JERRY_ASSERT (header_p->first_chunk_cp == ECMA_NULL_POINTER);
JERRY_ASSERT (ecma_is_value_pointer (chunk_p->items[ECMA_COLLECTION_CHUNK_ITEMS])
&& ecma_get_pointer_from_value (chunk_p->items[ECMA_COLLECTION_CHUNK_ITEMS]) == NULL);
ECMA_SET_NON_NULL_POINTER (header_p->first_chunk_cp, chunk_p);
ecma_collection_chunk_t *next_chunk_p;
next_chunk_p = (ecma_collection_chunk_t *) jmem_heap_alloc_block (sizeof (ecma_collection_chunk_t));
chunk_p->items[ECMA_COLLECTION_CHUNK_ITEMS] = ecma_make_pointer_value ((void *) next_chunk_p);
ECMA_SET_POINTER (header_p->last_chunk_cp, next_chunk_p);
chunk_p = next_chunk_p;
}
else
{
ecma_collection_chunk_t *last_chunk_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
header_p->last_chunk_cp);
JERRY_ASSERT (last_chunk_p->next_chunk_cp == ECMA_NULL_POINTER);
ECMA_SET_NON_NULL_POINTER (last_chunk_p->next_chunk_cp, chunk_p);
JERRY_ASSERT (ecma_is_value_pointer (chunk_p->items[item_index])
&& ecma_get_pointer_from_value (chunk_p->items[item_index]) == NULL);
}
ECMA_SET_NON_NULL_POINTER (header_p->last_chunk_cp, chunk_p);
}
else
if (!(flags & ECMA_COLLECTION_NO_COPY)
&& (!ecma_is_value_object (value)
|| !(flags & ECMA_COLLECTION_NO_REF_OBJECTS)))
{
/* last chunk can be appended with the new value */
JERRY_ASSERT (chunk_p != NULL);
value = ecma_copy_value (value);
}
ecma_value_t *values_p = (ecma_value_t *) chunk_p->data;
JERRY_ASSERT ((uint8_t *) (values_p + pos_of_new_value_in_chunk + 1) <= (uint8_t *) (chunk_p + 1));
if (do_ref_if_object)
{
values_p[pos_of_new_value_in_chunk] = ecma_copy_value (v);
}
else
{
values_p[pos_of_new_value_in_chunk] = ecma_copy_value_if_not_object (v);
}
chunk_p->items[item_index] = value;
chunk_p->items[item_index + 1] = ecma_make_pointer_value (NULL);
header_p->item_count++;
} /* ecma_append_to_values_collection */
/**
* Remove last element of the collection
*
* Warning:
* the function invalidates all iterators that are configured to access the passed collection
*/
void
ecma_remove_last_value_from_values_collection (ecma_collection_header_t *header_p) /**< collection's header */
{
JERRY_ASSERT (header_p != NULL && header_p->unit_number > 0);
const size_t values_in_chunk = JERRY_SIZE_OF_STRUCT_MEMBER (ecma_collection_chunk_t, data) / sizeof (ecma_value_t);
size_t values_number = header_p->unit_number;
size_t pos_of_value_to_remove_in_chunk = (values_number - 1u) % values_in_chunk;
ecma_collection_chunk_t *last_chunk_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
header_p->last_chunk_cp);
ecma_value_t *values_p = (ecma_value_t *) last_chunk_p->data;
JERRY_ASSERT ((uint8_t *) (values_p + pos_of_value_to_remove_in_chunk + 1) <= (uint8_t *) (last_chunk_p + 1));
ecma_value_t value_to_remove = values_p[pos_of_value_to_remove_in_chunk];
ecma_free_value (value_to_remove);
header_p->unit_number--;
if (pos_of_value_to_remove_in_chunk == 0)
{
ecma_collection_chunk_t *chunk_to_remove_p = last_chunk_p;
/* free last chunk */
if (header_p->first_chunk_cp == header_p->last_chunk_cp)
{
header_p->first_chunk_cp = ECMA_NULL_POINTER;
header_p->last_chunk_cp = ECMA_NULL_POINTER;
}
else
{
ecma_collection_chunk_t *chunk_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
header_p->first_chunk_cp);
while (chunk_iter_p->next_chunk_cp != header_p->last_chunk_cp)
{
chunk_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
chunk_iter_p->next_chunk_cp);
}
ecma_collection_chunk_t *new_last_chunk_p = chunk_iter_p;
JERRY_ASSERT (ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
new_last_chunk_p->next_chunk_cp) == chunk_to_remove_p);
ECMA_SET_NON_NULL_POINTER (header_p->last_chunk_cp, new_last_chunk_p);
new_last_chunk_p->next_chunk_cp = ECMA_NULL_POINTER;
}
ecma_dealloc_collection_chunk (chunk_to_remove_p);
}
} /* ecma_remove_last_value_from_values_collection */
/**
* Allocate a collection of ecma-strings.
*
* @return pointer to the collection's header
*/
ecma_collection_header_t *
ecma_new_strings_collection (ecma_string_t *string_ptrs_buffer[], /**< pointers to ecma-strings */
ecma_length_t strings_number) /**< number of ecma-strings */
{
JERRY_ASSERT (string_ptrs_buffer != NULL || strings_number == 0);
ecma_collection_header_t *new_collection_p;
new_collection_p = ecma_new_values_collection (NULL, 0, false);
for (ecma_length_t string_index = 0;
string_index < strings_number;
string_index++)
{
ecma_append_to_values_collection (new_collection_p,
ecma_make_string_value (string_ptrs_buffer[string_index]),
false);
}
return new_collection_p;
} /* ecma_new_strings_collection */
/**
* Initialize new collection iterator for the collection
*
* @return pointer to the first item
*/
void
ecma_collection_iterator_init (ecma_collection_iterator_t *iterator_p, /**< context of iterator */
ecma_collection_header_t *collection_p) /**< header of collection */
ecma_value_t *
ecma_collection_iterator_init (ecma_collection_header_t *header_p) /**< header of collection */
{
iterator_p->header_p = collection_p;
iterator_p->next_chunk_cp = (collection_p != NULL ? collection_p->first_chunk_cp : JMEM_CP_NULL);
iterator_p->current_index = 0;
iterator_p->current_value_p = NULL;
iterator_p->current_chunk_end_p = NULL;
if (JERRY_UNLIKELY (!header_p || header_p->item_count == 0))
{
return NULL;
}
ecma_collection_chunk_t *chunk_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
header_p->first_chunk_cp);
return chunk_p->items;
} /* ecma_collection_iterator_init */
/**
* Move collection iterator to next element if there is any.
*
* @return true - if iterator moved,
* false - otherwise (current element is last element in the collection)
* @return pointer to the next item
*/
bool
ecma_collection_iterator_next (ecma_collection_iterator_t *iterator_p) /**< context of iterator */
ecma_value_t *
ecma_collection_iterator_next (ecma_value_t *ecma_value_p) /**< current value */
{
if (iterator_p->header_p == NULL
|| unlikely (iterator_p->header_p->unit_number == 0))
JERRY_ASSERT (ecma_value_p != NULL);
ecma_value_p++;
if (JERRY_UNLIKELY (ecma_is_value_pointer (*ecma_value_p)))
{
return false;
ecma_value_p = ((ecma_collection_chunk_t *) ecma_get_pointer_from_value (*ecma_value_p))->items;
JERRY_ASSERT (ecma_value_p == NULL || !ecma_is_value_pointer (*ecma_value_p));
return ecma_value_p;
}
const size_t values_in_chunk = JERRY_SIZE_OF_STRUCT_MEMBER (ecma_collection_chunk_t, data) / sizeof (ecma_value_t);
if (iterator_p->current_value_p == NULL)
{
JERRY_ASSERT (iterator_p->current_index == 0);
ecma_collection_chunk_t *first_chunk_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
iterator_p->header_p->first_chunk_cp);
iterator_p->next_chunk_cp = first_chunk_p->next_chunk_cp;
iterator_p->current_value_p = (ecma_value_t *) &first_chunk_p->data;
iterator_p->current_chunk_end_p = (iterator_p->current_value_p + values_in_chunk);
}
else
{
if (iterator_p->current_index + 1 == iterator_p->header_p->unit_number)
{
return false;
}
JERRY_ASSERT (iterator_p->current_index + 1 < iterator_p->header_p->unit_number);
iterator_p->current_index++;
iterator_p->current_value_p++;
}
if (iterator_p->current_value_p == iterator_p->current_chunk_end_p)
{
ecma_collection_chunk_t *next_chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
iterator_p->next_chunk_cp);
JERRY_ASSERT (next_chunk_p != NULL);
iterator_p->next_chunk_cp = next_chunk_p->next_chunk_cp;
iterator_p->current_value_p = (ecma_value_t *) &next_chunk_p->data;
iterator_p->current_chunk_end_p = iterator_p->current_value_p + values_in_chunk;
}
else
{
JERRY_ASSERT (iterator_p->current_value_p < iterator_p->current_chunk_end_p);
}
return true;
return ecma_value_p;
} /* ecma_collection_iterator_next */
/**
File diff suppressed because it is too large Load Diff
+324 -245
View File
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2015-2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +17,7 @@
#define ECMA_HELPERS_H
#include "ecma-globals.h"
#include "jmem-allocator.h"
#include "jmem.h"
#include "lit-strings.h"
/** \addtogroup ecma ECMA
@@ -51,6 +50,13 @@
*/
#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer)
typedef enum
{
ECMA_STRING_FLAG_EMPTY = 0,
ECMA_STRING_FLAG_IS_ASCII,
ECMA_STRING_FLAG_MUST_BE_FREED
} ecma_string_flag_t;
/**
* Convert ecma-string's contents to a cesu-8 string and put it into a buffer.
*/
@@ -58,280 +64,353 @@
utf8_ptr, /**< [out] output buffer pointer */ \
utf8_str_size) /**< [out] output buffer size */ \
lit_utf8_size_t utf8_str_size; \
bool utf8_ptr ## must_be_freed; \
const lit_utf8_byte_t *utf8_ptr = ecma_string_raw_chars (ecma_str_ptr, &utf8_str_size, &utf8_ptr ## must_be_freed); \
utf8_ptr ## must_be_freed = false; /* it was used as 'is_ascii' in 'ecma_string_raw_chars', so we must reset it */ \
\
if (utf8_ptr == NULL) \
{ \
utf8_ptr = (const lit_utf8_byte_t *) jmem_heap_alloc_block (utf8_str_size); \
ecma_string_to_utf8_bytes (ecma_str_ptr, (lit_utf8_byte_t *) utf8_ptr, utf8_str_size); \
utf8_ptr ## must_be_freed = true; \
}
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
/**
* Set an internal property value of pointer
*/
#define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) \
(field) = ((ecma_value_t) pointer)
/**
* Get an internal property value of pointer
*/
#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) \
((type *) field)
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
/**
* Set an internal property value of non-null pointer so that it will correspond
* to specified non_compressed_pointer.
*/
#define ECMA_SET_INTERNAL_VALUE_POINTER(field, non_compressed_pointer) \
ECMA_SET_NON_NULL_POINTER (field, non_compressed_pointer)
/**
* Get an internal property value of pointer from specified compressed pointer.
*/
#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) \
ECMA_GET_POINTER (type, field)
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
uint8_t utf8_ptr ## flags = ECMA_STRING_FLAG_EMPTY; \
const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, &utf8_str_size, &utf8_ptr ## flags);
/**
* Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING'
*/
#define ECMA_FINALIZE_UTF8_STRING(utf8_ptr, /**< pointer to character buffer */ \
utf8_str_size) /**< buffer size */ \
if (utf8_ptr ## must_be_freed) \
if (utf8_ptr ## flags & ECMA_STRING_FLAG_MUST_BE_FREED) \
{ \
JERRY_ASSERT (utf8_ptr != NULL); \
jmem_heap_free_block ((void *) utf8_ptr, utf8_str_size); \
}
/* ecma-helpers-value.c */
extern bool ecma_is_value_direct (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_simple (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_empty (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_undefined (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_null (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_boolean (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_true (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_false (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_array_hole (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_integer_number (ecma_value_t) __attr_pure___;
extern bool ecma_are_values_integer_numbers (ecma_value_t, ecma_value_t) __attr_pure___;
extern bool ecma_is_value_float_number (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_number (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_string (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_object (ecma_value_t) __attr_pure___;
extern void ecma_check_value_type_is_spec_defined (ecma_value_t);
extern ecma_value_t ecma_make_simple_value (const ecma_simple_value_t value) __attr_const___;
extern ecma_value_t ecma_make_boolean_value (bool) __attr_const___;
extern ecma_value_t ecma_make_integer_value (ecma_integer_value_t) __attr_const___;
extern ecma_value_t ecma_make_nan_value (void);
extern ecma_value_t ecma_make_number_value (ecma_number_t);
extern ecma_value_t ecma_make_int32_value (int32_t);
extern ecma_value_t ecma_make_uint32_value (uint32_t);
extern ecma_value_t ecma_make_string_value (const ecma_string_t *);
extern ecma_value_t ecma_make_object_value (const ecma_object_t *);
extern ecma_value_t ecma_make_error_value (ecma_value_t);
extern ecma_value_t ecma_make_error_obj_value (const ecma_object_t *);
extern ecma_integer_value_t ecma_get_integer_from_value (ecma_value_t) __attr_pure___;
extern ecma_number_t ecma_get_float_from_value (ecma_value_t) __attr_pure___;
extern ecma_number_t ecma_get_number_from_value (ecma_value_t) __attr_pure___;
extern uint32_t ecma_get_uint32_from_value (ecma_value_t) __attr_pure___;
extern ecma_string_t *ecma_get_string_from_value (ecma_value_t) __attr_pure___;
extern ecma_object_t *ecma_get_object_from_value (ecma_value_t) __attr_pure___;
extern ecma_value_t ecma_get_value_from_error_value (ecma_value_t) __attr_pure___;
extern ecma_value_t ecma_invert_boolean_value (ecma_value_t) __attr_pure___;
extern ecma_value_t ecma_copy_value (ecma_value_t);
extern ecma_value_t ecma_fast_copy_value (ecma_value_t);
extern ecma_value_t ecma_copy_value_if_not_object (ecma_value_t);
extern ecma_value_t ecma_update_float_number (ecma_value_t, ecma_number_t);
extern void ecma_value_assign_value (ecma_value_t *, ecma_value_t);
extern void ecma_value_assign_number (ecma_value_t *, ecma_number_t);
extern void ecma_value_assign_uint32 (ecma_value_t *, uint32_t);
extern void ecma_free_value (ecma_value_t);
extern void ecma_fast_free_value (ecma_value_t);
extern void ecma_free_value_if_not_object (ecma_value_t);
/* ecma-helpers-string.c */
extern ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *, lit_utf8_size_t);
extern ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t);
extern ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t);
extern ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t);
extern ecma_string_t *ecma_new_ecma_string_from_magic_string_id (lit_magic_string_id_t);
extern ecma_string_t *ecma_new_ecma_string_from_magic_string_ex_id (lit_magic_string_ex_id_t);
extern ecma_string_t *ecma_new_ecma_length_string ();
extern ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *, ecma_string_t *);
extern void ecma_ref_ecma_string (ecma_string_t *);
extern void ecma_deref_ecma_string (ecma_string_t *);
extern ecma_number_t ecma_string_to_number (const ecma_string_t *);
extern bool ecma_string_get_array_index (const ecma_string_t *, uint32_t *);
extern lit_utf8_size_t __attr_return_value_should_be_checked___
ecma_string_copy_to_utf8_buffer (const ecma_string_t *, lit_utf8_byte_t *, lit_utf8_size_t);
extern void ecma_string_to_utf8_bytes (const ecma_string_t *, lit_utf8_byte_t *, lit_utf8_size_t);
extern const lit_utf8_byte_t *ecma_string_raw_chars (const ecma_string_t *, lit_utf8_size_t *, bool *);
extern void ecma_init_ecma_string_from_uint32 (ecma_string_t *, uint32_t);
extern void ecma_init_ecma_length_string (ecma_string_t *);
extern bool ecma_string_is_empty (const ecma_string_t *);
extern bool ecma_string_is_length (const ecma_string_t *);
extern bool ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *, const ecma_string_t *);
extern bool ecma_compare_ecma_strings (const ecma_string_t *, const ecma_string_t *);
extern bool ecma_compare_ecma_strings_relational (const ecma_string_t *, const ecma_string_t *);
extern ecma_length_t ecma_string_get_length (const ecma_string_t *);
extern lit_utf8_size_t ecma_string_get_size (const ecma_string_t *);
extern ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *, ecma_length_t);
extern ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t);
extern ecma_string_t *ecma_get_magic_string_ex (lit_magic_string_ex_id_t);
extern bool ecma_is_string_magic (const ecma_string_t *, lit_magic_string_id_t *);
extern lit_string_hash_t ecma_string_hash (const ecma_string_t *);
extern ecma_string_t *ecma_string_substr (const ecma_string_t *, ecma_length_t, ecma_length_t);
extern ecma_string_t *ecma_string_trim (const ecma_string_t *);
/* ecma-helpers-number.c */
extern ecma_number_t ecma_number_make_nan (void);
extern ecma_number_t ecma_number_make_infinity (bool);
extern bool ecma_number_is_nan (ecma_number_t);
extern bool ecma_number_is_negative (ecma_number_t);
extern bool ecma_number_is_zero (ecma_number_t);
extern bool ecma_number_is_infinity (ecma_number_t);
extern int32_t
ecma_number_get_fraction_and_exponent (ecma_number_t, uint64_t *, int32_t *);
extern ecma_number_t
ecma_number_make_normal_positive_from_fraction_and_exponent (uint64_t, int32_t);
extern ecma_number_t
ecma_number_make_from_sign_mantissa_and_exponent (bool, uint64_t, int32_t);
extern ecma_number_t ecma_number_get_prev (ecma_number_t);
extern ecma_number_t ecma_number_get_next (ecma_number_t);
extern ecma_number_t ecma_number_negate (ecma_number_t);
extern ecma_number_t ecma_number_trunc (ecma_number_t);
extern ecma_number_t ecma_number_calc_remainder (ecma_number_t, ecma_number_t);
extern ecma_number_t ecma_number_add (ecma_number_t, ecma_number_t);
extern ecma_number_t ecma_number_substract (ecma_number_t, ecma_number_t);
extern ecma_number_t ecma_number_multiply (ecma_number_t, ecma_number_t);
extern ecma_number_t ecma_number_divide (ecma_number_t, ecma_number_t);
extern lit_utf8_size_t ecma_number_to_decimal (ecma_number_t, lit_utf8_byte_t *, int32_t *);
/* ecma-helpers-values-collection.c */
extern ecma_collection_header_t *ecma_new_values_collection (const ecma_value_t[], ecma_length_t, bool);
extern void ecma_free_values_collection (ecma_collection_header_t *, bool);
extern void ecma_append_to_values_collection (ecma_collection_header_t *, ecma_value_t, bool);
extern void ecma_remove_last_value_from_values_collection (ecma_collection_header_t *);
extern ecma_collection_header_t *ecma_new_strings_collection (ecma_string_t *[], ecma_length_t);
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
/**
* Context of ecma values' collection iterator
* Set an internal property value from pointer.
*/
typedef struct
{
ecma_collection_header_t *header_p; /**< collection header */
jmem_cpointer_t next_chunk_cp; /**< compressed pointer to next chunk */
ecma_length_t current_index; /**< index of current element */
const ecma_value_t *current_value_p; /**< pointer to current element */
const ecma_value_t *current_chunk_beg_p; /**< pointer to beginning of current chunk's data */
const ecma_value_t *current_chunk_end_p; /**< pointer to place right after the end of current chunk's data */
} ecma_collection_iterator_t;
#define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) \
(field) = ((ecma_value_t) pointer)
extern void
ecma_collection_iterator_init (ecma_collection_iterator_t *, ecma_collection_header_t *);
extern bool
ecma_collection_iterator_next (ecma_collection_iterator_t *);
/**
* Set an internal property value from pointer. Pointer can be NULL.
*/
#define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) \
(field) = ((ecma_value_t) pointer)
/**
* Convert an internal property value to pointer.
*/
#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) \
((type *) field)
/**
* Convert an internal property value to pointer. Result can be NULL.
*/
#define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) \
((type *) field)
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
/**
* Set an internal property value from pointer.
*/
#define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) \
ECMA_SET_NON_NULL_POINTER (field, pointer)
/**
* Set an internal property value from pointer. Pointer can be NULL.
*/
#define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) \
ECMA_SET_POINTER (field, pointer)
/**
* Convert an internal property value to pointer.
*/
#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) \
ECMA_GET_NON_NULL_POINTER (type, field)
/**
* Convert an internal property value to pointer. Result can be NULL.
*/
#define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) \
ECMA_GET_POINTER (type, field)
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
/**
* Convert boolean to bitfield value.
*/
#define ECMA_BOOL_TO_BITFIELD(x) ((x) ? 1 : 0)
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
/**
* JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol
*/
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (ecma_is_value_symbol ((value)))
#else /* !ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
/**
* JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol
*/
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (false)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
/* ecma-helpers-value.c */
bool JERRY_ATTR_CONST ecma_is_value_direct (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_simple (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_empty (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_undefined (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_null (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_boolean (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_true (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_false (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_found (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_array_hole (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_integer_number (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_are_values_integer_numbers (ecma_value_t first_value, ecma_value_t second_value);
bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value);
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value);
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_non_direct_string (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_object (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_error_reference (ecma_value_t value);
bool JERRY_ATTR_CONST ecma_is_value_pointer (ecma_value_t value);
void ecma_check_value_type_is_spec_defined (ecma_value_t value);
ecma_value_t JERRY_ATTR_CONST ecma_make_boolean_value (bool boolean_value);
ecma_value_t JERRY_ATTR_CONST ecma_make_integer_value (ecma_integer_value_t integer_value);
ecma_value_t ecma_make_nan_value (void);
ecma_value_t ecma_make_number_value (ecma_number_t ecma_number);
ecma_value_t ecma_make_int32_value (int32_t int32_number);
ecma_value_t ecma_make_uint32_value (uint32_t uint32_number);
ecma_value_t JERRY_ATTR_PURE ecma_make_string_value (const ecma_string_t *ecma_string_p);
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
ecma_value_t JERRY_ATTR_PURE ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p);
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
ecma_value_t JERRY_ATTR_PURE ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p);
ecma_value_t JERRY_ATTR_PURE ecma_make_magic_string_value (lit_magic_string_id_t id);
ecma_value_t JERRY_ATTR_PURE ecma_make_object_value (const ecma_object_t *object_p);
ecma_value_t JERRY_ATTR_PURE ecma_make_error_reference_value (const ecma_error_reference_t *error_ref_p);
ecma_value_t JERRY_ATTR_PURE ecma_make_pointer_value (const void *any_p);
ecma_integer_value_t JERRY_ATTR_CONST ecma_get_integer_from_value (ecma_value_t value);
ecma_number_t JERRY_ATTR_PURE ecma_get_float_from_value (ecma_value_t value);
ecma_number_t JERRY_ATTR_PURE ecma_get_number_from_value (ecma_value_t value);
ecma_string_t JERRY_ATTR_PURE *ecma_get_string_from_value (ecma_value_t value);
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
ecma_string_t JERRY_ATTR_PURE *ecma_get_symbol_from_value (ecma_value_t value);
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
ecma_string_t JERRY_ATTR_PURE *ecma_get_prop_name_from_value (ecma_value_t value);
ecma_object_t JERRY_ATTR_PURE *ecma_get_object_from_value (ecma_value_t value);
ecma_error_reference_t JERRY_ATTR_PURE *ecma_get_error_reference_from_value (ecma_value_t value);
void * JERRY_ATTR_PURE ecma_get_pointer_from_value (ecma_value_t value);
ecma_value_t JERRY_ATTR_CONST ecma_invert_boolean_value (ecma_value_t value);
ecma_value_t ecma_copy_value (ecma_value_t value);
ecma_value_t ecma_fast_copy_value (ecma_value_t value);
ecma_value_t ecma_copy_value_if_not_object (ecma_value_t value);
ecma_value_t ecma_update_float_number (ecma_value_t float_value, ecma_number_t new_number);
void ecma_value_assign_value (ecma_value_t *value_p, ecma_value_t ecma_value);
void ecma_value_assign_number (ecma_value_t *value_p, ecma_number_t ecma_number);
void ecma_free_value (ecma_value_t value);
void ecma_fast_free_value (ecma_value_t value);
void ecma_free_value_if_not_object (ecma_value_t value);
void ecma_free_number (ecma_value_t value);
lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value);
/* ecma-helpers-string.c */
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc);
bool ecma_prop_name_is_symbol (ecma_string_t *string_p);
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
#if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET)
ecma_string_t *ecma_new_map_key_string (ecma_value_t value);
bool ecma_prop_name_is_map_key (ecma_string_t *string_p);
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET) */
ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size);
ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p,
lit_utf8_size_t string_size);
ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit);
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit);
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number);
ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number);
ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num);
ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id);
ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_p,
const lit_utf8_byte_t *cesu8_string2_p,
lit_utf8_size_t cesu8_string2_size,
lit_utf8_size_t cesu8_string2_length);
ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p);
ecma_string_t *ecma_append_magic_string_to_string (ecma_string_t *string1_p, lit_magic_string_id_t string2_id);
void ecma_ref_ecma_string (ecma_string_t *string_p);
void ecma_deref_ecma_string (ecma_string_t *string_p);
ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
uint32_t ecma_string_get_array_index (const ecma_string_t *str_p);
lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT
ecma_string_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p,
lit_utf8_byte_t *buffer_p,
lit_utf8_size_t buffer_size);
lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT
ecma_string_copy_to_utf8_buffer (const ecma_string_t *string_desc_p,
lit_utf8_byte_t *buffer_p,
lit_utf8_size_t buffer_size);
lit_utf8_size_t
ecma_substring_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p,
ecma_length_t start_pos,
ecma_length_t end_pos,
lit_utf8_byte_t *buffer_p,
lit_utf8_size_t buffer_size);
lit_utf8_size_t
ecma_substring_copy_to_utf8_buffer (const ecma_string_t *string_desc_p,
ecma_length_t start_pos,
ecma_length_t end_pos,
lit_utf8_byte_t *buffer_p,
lit_utf8_size_t buffer_size);
void ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p,
lit_utf8_size_t buffer_size);
const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p, lit_utf8_size_t *size_p, uint8_t *flags_p);
bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id);
bool ecma_string_is_empty (const ecma_string_t *string_p);
bool ecma_string_is_length (const ecma_string_t *string_p);
jmem_cpointer_t ecma_string_to_property_name (ecma_string_t *prop_name_p, ecma_property_t *name_type_p);
ecma_string_t *ecma_string_from_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp);
lit_string_hash_t ecma_string_get_property_name_hash (ecma_property_t property, jmem_cpointer_t prop_name_cp);
uint32_t ecma_string_get_property_index (ecma_property_t property, jmem_cpointer_t prop_name_cp);
bool ecma_string_compare_to_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp,
const ecma_string_t *string_p);
bool ecma_compare_ecma_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p);
bool ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p);
bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, const ecma_string_t *string2_p);
ecma_length_t ecma_string_get_length (const ecma_string_t *string_p);
ecma_length_t ecma_string_get_utf8_length (const ecma_string_t *string_p);
lit_utf8_size_t ecma_string_get_size (const ecma_string_t *string_p);
lit_utf8_size_t ecma_string_get_utf8_size (const ecma_string_t *string_p);
ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, ecma_length_t index);
lit_magic_string_id_t ecma_get_string_magic (const ecma_string_t *string_p);
lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, ecma_length_t start_pos, ecma_length_t end_pos);
ecma_string_t *ecma_string_trim (const ecma_string_t *string_p);
/* ecma-helpers-number.c */
ecma_number_t ecma_number_make_nan (void);
ecma_number_t ecma_number_make_infinity (bool sign);
bool ecma_number_is_nan (ecma_number_t num);
bool ecma_number_is_negative (ecma_number_t num);
bool ecma_number_is_zero (ecma_number_t num);
bool ecma_number_is_infinity (ecma_number_t num);
ecma_number_t
ecma_number_make_from_sign_mantissa_and_exponent (bool sign, uint64_t mantissa, int32_t exponent);
ecma_number_t ecma_number_get_prev (ecma_number_t num);
ecma_number_t ecma_number_get_next (ecma_number_t num);
ecma_number_t ecma_number_trunc (ecma_number_t num);
ecma_number_t ecma_number_calc_remainder (ecma_number_t left_num, ecma_number_t right_num);
ecma_value_t ecma_integer_multiply (ecma_integer_value_t left_integer, ecma_integer_value_t right_integer);
lit_utf8_size_t ecma_number_to_decimal (ecma_number_t num, lit_utf8_byte_t *out_digits_p, int32_t *out_decimal_exp_p);
lit_utf8_size_t ecma_number_to_binary_floating_point_number (ecma_number_t num,
lit_utf8_byte_t *out_digits_p,
int32_t *out_decimal_exp_p);
/* ecma-helpers-values-collection.c */
ecma_collection_header_t *ecma_new_values_collection (void);
void ecma_free_values_collection (ecma_collection_header_t *header_p, uint32_t flags);
void ecma_append_to_values_collection (ecma_collection_header_t *header_p, ecma_value_t v, uint32_t flags);
ecma_value_t *
ecma_collection_iterator_init (ecma_collection_header_t *header_p);
ecma_value_t *
ecma_collection_iterator_next (ecma_value_t *iterator_p);
/* ecma-helpers.c */
extern ecma_object_t *ecma_create_object (ecma_object_t *, bool, bool, ecma_object_type_t);
extern ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *);
extern ecma_object_t *ecma_create_object_lex_env (ecma_object_t *, ecma_object_t *, bool);
extern bool ecma_is_lexical_environment (const ecma_object_t *) __attr_pure___;
extern bool ecma_get_object_extensible (const ecma_object_t *) __attr_pure___;
extern void ecma_set_object_extensible (ecma_object_t *, bool);
extern ecma_object_type_t ecma_get_object_type (const ecma_object_t *) __attr_pure___;
extern void ecma_set_object_type (ecma_object_t *, ecma_object_type_t);
extern ecma_object_t *ecma_get_object_prototype (const ecma_object_t *) __attr_pure___;
extern bool ecma_get_object_is_builtin (const ecma_object_t *) __attr_pure___;
extern void ecma_set_object_is_builtin (ecma_object_t *);
extern ecma_lexical_environment_type_t ecma_get_lex_env_type (const ecma_object_t *) __attr_pure___;
extern ecma_object_t *ecma_get_lex_env_outer_reference (const ecma_object_t *) __attr_pure___;
extern ecma_property_header_t *ecma_get_property_list (const ecma_object_t *) __attr_pure___;
extern ecma_object_t *ecma_get_lex_env_binding_object (const ecma_object_t *) __attr_pure___;
extern bool ecma_get_lex_env_provide_this (const ecma_object_t *) __attr_pure___;
ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type);
ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p);
ecma_object_t *ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p,
ecma_lexical_environment_type_t type);
bool JERRY_ATTR_PURE ecma_is_lexical_environment (const ecma_object_t *object_p);
bool JERRY_ATTR_PURE ecma_get_object_extensible (const ecma_object_t *object_p);
void ecma_set_object_extensible (ecma_object_t *object_p, bool is_extensible);
ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (const ecma_object_t *object_p);
ecma_object_t JERRY_ATTR_PURE *ecma_get_object_prototype (const ecma_object_t *object_p);
bool JERRY_ATTR_PURE ecma_get_object_is_builtin (const ecma_object_t *object_p);
void ecma_set_object_is_builtin (ecma_object_t *object_p);
uint8_t ecma_get_object_builtin_id (ecma_object_t *object_p);
ecma_lexical_environment_type_t JERRY_ATTR_PURE ecma_get_lex_env_type (const ecma_object_t *object_p);
ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_outer_reference (const ecma_object_t *object_p);
ecma_property_header_t JERRY_ATTR_PURE *ecma_get_property_list (const ecma_object_t *object_p);
ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p);
extern ecma_property_t *ecma_create_internal_property (ecma_object_t *, ecma_internal_property_id_t);
extern ecma_property_t *ecma_find_internal_property (ecma_object_t *, ecma_internal_property_id_t);
extern ecma_property_t *ecma_get_internal_property (ecma_object_t *, ecma_internal_property_id_t);
ecma_property_value_t *
ecma_create_named_data_property (ecma_object_t *object_p, ecma_string_t *name_p, uint8_t prop_attributes,
ecma_property_t **out_prop_p);
ecma_property_value_t *
ecma_create_named_accessor_property (ecma_object_t *object_p, ecma_string_t *name_p, ecma_object_t *get_p,
ecma_object_t *set_p, uint8_t prop_attributes, ecma_property_t **out_prop_p);
ecma_property_t *
ecma_find_named_property (ecma_object_t *obj_p, ecma_string_t *name_p);
ecma_property_value_t *
ecma_get_named_data_property (ecma_object_t *obj_p, ecma_string_t *name_p);
extern ecma_property_t *
ecma_create_named_data_property (ecma_object_t *, ecma_string_t *, uint8_t);
extern ecma_property_t *
ecma_create_named_accessor_property (ecma_object_t *, ecma_string_t *, ecma_object_t *, ecma_object_t *, uint8_t);
extern ecma_property_t *
ecma_find_named_property (ecma_object_t *, ecma_string_t *);
extern ecma_property_t *
ecma_get_named_property (ecma_object_t *, ecma_string_t *);
extern ecma_property_t *
ecma_get_named_data_property (ecma_object_t *, ecma_string_t *);
void ecma_free_property (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p);
extern void ecma_free_property (ecma_object_t *, ecma_string_t *, ecma_property_t *);
void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p);
uint32_t ecma_delete_array_properties (ecma_object_t *object_p, uint32_t new_length, uint32_t old_length);
extern void ecma_delete_property (ecma_object_t *, ecma_property_t *);
void ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p,
ecma_value_t value);
extern ecma_value_t ecma_get_named_data_property_value (const ecma_property_t *);
extern void ecma_set_named_data_property_value (ecma_property_t *, ecma_value_t);
extern void ecma_named_data_property_assign_value (ecma_object_t *, ecma_property_t *, ecma_value_t);
ecma_object_t *ecma_get_named_accessor_property_getter (const ecma_property_value_t *prop_value_p);
ecma_object_t *ecma_get_named_accessor_property_setter (const ecma_property_value_t *prop_value_p);
void ecma_set_named_accessor_property_getter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p,
ecma_object_t *getter_p);
void ecma_set_named_accessor_property_setter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p,
ecma_object_t *setter_p);
bool ecma_is_property_writable (ecma_property_t property);
void ecma_set_property_writable_attr (ecma_property_t *property_p, bool is_writable);
bool ecma_is_property_enumerable (ecma_property_t property);
void ecma_set_property_enumerable_attr (ecma_property_t *property_p, bool is_enumerable);
bool ecma_is_property_configurable (ecma_property_t property);
void ecma_set_property_configurable_attr (ecma_property_t *property_p, bool is_configurable);
extern ecma_value_t ecma_get_internal_property_value (const ecma_property_t *);
extern void ecma_set_internal_property_value (ecma_property_t *, ecma_value_t);
#if ENABLED (JERRY_LCACHE)
bool ecma_is_property_lcached (ecma_property_t *property_p);
void ecma_set_property_lcached (ecma_property_t *property_p, bool is_lcached);
#endif /* ENABLED (JERRY_LCACHE) */
extern ecma_object_t *ecma_get_named_accessor_property_getter (const ecma_property_t *);
extern ecma_object_t *ecma_get_named_accessor_property_setter (const ecma_property_t *);
extern void ecma_set_named_accessor_property_getter (ecma_object_t *, ecma_property_t *, ecma_object_t *);
extern void ecma_set_named_accessor_property_setter (ecma_object_t *, ecma_property_t *, ecma_object_t *);
extern bool ecma_is_property_writable (ecma_property_t *);
extern void ecma_set_property_writable_attr (ecma_property_t *, bool);
extern bool ecma_is_property_enumerable (ecma_property_t *);
extern void ecma_set_property_enumerable_attr (ecma_property_t *, bool);
extern bool ecma_is_property_configurable (ecma_property_t *);
extern void ecma_set_property_configurable_attr (ecma_property_t *, bool);
ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p);
extern bool ecma_is_property_lcached (ecma_property_t *);
extern void ecma_set_property_lcached (ecma_property_t *, bool);
ecma_value_t ecma_create_error_reference (ecma_value_t value, bool is_exception);
ecma_value_t ecma_create_error_reference_from_context (void);
ecma_value_t ecma_create_error_object_reference (ecma_object_t *object_p);
void ecma_ref_error_reference (ecma_error_reference_t *error_ref_p);
void ecma_deref_error_reference (ecma_error_reference_t *error_ref_p);
ecma_value_t ecma_clear_error_reference (ecma_value_t value, bool set_abort_flag);
extern ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
extern void ecma_free_property_descriptor (ecma_property_descriptor_t *);
extern ecma_property_descriptor_t ecma_get_property_descriptor_from_property (ecma_property_t *);
extern ecma_property_t *ecma_get_next_property_pair (ecma_property_pair_t *);
extern void ecma_bytecode_ref (ecma_compiled_code_t *);
extern void ecma_bytecode_deref (ecma_compiled_code_t *);
void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p);
void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
#if (JERRY_STACK_LIMIT != 0)
uintptr_t ecma_get_current_stack_usage (void);
#endif /* (JERRY_STACK_LIMIT != 0) */
/* ecma-helpers-external-pointers.c */
extern bool
ecma_create_external_pointer_property (ecma_object_t *, ecma_internal_property_id_t, ecma_external_pointer_t);
extern bool
ecma_get_external_pointer_value (ecma_object_t *, ecma_internal_property_id_t, ecma_external_pointer_t *);
extern void
ecma_free_external_pointer_in_property (ecma_property_t *);
bool ecma_create_native_pointer_property (ecma_object_t *obj_p, void *native_p, void *info_p);
ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p, void *info_p);
bool ecma_delete_native_pointer_property (ecma_object_t *obj_p, void *info_p);
/* ecma-helpers-conversion.c */
extern ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *, lit_utf8_size_t);
extern lit_utf8_size_t ecma_uint32_to_utf8_string (uint32_t, lit_utf8_byte_t *, lit_utf8_size_t);
extern uint32_t ecma_number_to_uint32 (ecma_number_t);
extern int32_t ecma_number_to_int32 (ecma_number_t);
extern lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t, lit_utf8_byte_t *, lit_utf8_size_t);
ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size);
lit_utf8_size_t ecma_uint32_to_utf8_string (uint32_t value, lit_utf8_byte_t *out_buffer_p, lit_utf8_size_t buffer_size);
uint32_t ecma_number_to_uint32 (ecma_number_t num);
int32_t ecma_number_to_int32 (ecma_number_t num);
lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t num, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size);
/* ecma-helpers-errol.c */
extern lit_utf8_size_t ecma_errol0_dtoa (double, lit_utf8_byte_t *, int32_t *);
lit_utf8_size_t ecma_errol0_dtoa (double val, lit_utf8_byte_t *buffer_p, int32_t *exp_p);
/**
* @}
+17 -8
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +17,10 @@
#include "ecma-gc.h"
#include "ecma-helpers.h"
#include "ecma-init-finalize.h"
#include "ecma-lcache.h"
#include "ecma-lex-env.h"
#include "ecma-literal-storage.h"
#include "jmem-allocator.h"
#include "jmem.h"
#include "jcontext.h"
/** \addtogroup ecma ECMA
* @{
@@ -35,10 +35,21 @@
void
ecma_init (void)
{
ecma_lcache_init ();
ecma_init_global_lex_env ();
jmem_register_free_unused_memory_callback (ecma_free_unused_memory);
#if ENABLED (JERRY_PROPRETY_HASHMAP)
JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) = ECMA_PROP_HASHMAP_ALLOC_ON;
JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_HIGH_PRESSURE_GC;
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
#if (JERRY_STACK_LIMIT != 0)
volatile int sp;
JERRY_CONTEXT (stack_base) = (uintptr_t)&sp;
#endif /* (JERRY_STACK_LIMIT != 0) */
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
ecma_job_queue_init ();
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
} /* ecma_init */
/**
@@ -47,11 +58,9 @@ ecma_init (void)
void
ecma_finalize (void)
{
jmem_unregister_free_unused_memory_callback (ecma_free_unused_memory);
ecma_finalize_global_lex_env ();
ecma_finalize_builtins ();
ecma_gc_run (JMEM_FREE_UNUSED_MEMORY_SEVERITY_LOW);
ecma_gc_run ();
ecma_finalize_lit_storage ();
} /* ecma_finalize */
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@
* @{
*/
extern void ecma_init (void);
extern void ecma_finalize (void);
void ecma_init (void);
void ecma_finalize (void);
/**
* @}
+62 -77
View File
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,39 +26,35 @@
* @{
*/
#ifndef CONFIG_ECMA_LCACHE_DISABLE
#if ENABLED (JERRY_LCACHE)
/**
* Mask for hash bits
*/
#define ECMA_LCACHE_HASH_MASK (ECMA_LCACHE_HASH_ROWS_COUNT - 1)
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
/**
* Bitshift index for creating property identifier
*/
#define ECMA_LCACHE_HASH_ENTRY_ID_SHIFT (8 * sizeof (jmem_cpointer_t))
/**
* Initialize LCache
* Create property identifier
*/
void
ecma_lcache_init (void)
{
#ifndef CONFIG_ECMA_LCACHE_DISABLE
memset (JERRY_HASH_TABLE_CONTEXT (table), 0, sizeof (jerry_hash_table_t));
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
} /* ecma_lcache_init */
#define ECMA_LCACHE_CREATE_ID(object_cp, name_cp) \
(((ecma_lcache_hash_entry_id_t) (object_cp) << ECMA_LCACHE_HASH_ENTRY_ID_SHIFT) | (name_cp))
#ifndef CONFIG_ECMA_LCACHE_DISABLE
/**
* Invalidate specified LCache entry
*/
static inline void __attr_always_inline___
static inline void JERRY_ATTR_ALWAYS_INLINE
ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to invalidate */
{
JERRY_ASSERT (entry_p != NULL);
JERRY_ASSERT (entry_p->object_cp != ECMA_NULL_POINTER);
JERRY_ASSERT (entry_p->prop_name_cp != ECMA_NULL_POINTER);
JERRY_ASSERT (entry_p->id != 0);
JERRY_ASSERT (entry_p->prop_p != NULL);
entry_p->object_cp = ECMA_NULL_POINTER;
entry_p->id = 0;
ecma_set_property_lcached (entry_p->prop_p, false);
} /* ecma_lcache_invalidate_entry */
@@ -68,42 +63,40 @@ ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to i
*
* @return row index
*/
static inline size_t __attr_always_inline___
static inline size_t JERRY_ATTR_ALWAYS_INLINE
ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to object */
const ecma_string_t *prop_name_p) /**< proeprty name */
jmem_cpointer_t name_cp) /**< compressed pointer to property name */
{
/* Randomize the hash of the property name with the object pointer using a xor operation,
/* Randomize the property name with the object pointer using a xor operation,
* so properties of different objects with the same name can be cached effectively. */
return (size_t) ((ecma_string_hash (prop_name_p) ^ object_cp) & ECMA_LCACHE_HASH_MASK);
return (size_t) ((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK);
} /* ecma_lcache_row_index */
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
/**
* Insert an entry into LCache
*/
void
ecma_lcache_insert (ecma_object_t *object_p, /**< object */
ecma_string_t *prop_name_p, /**< property name */
jmem_cpointer_t name_cp, /**< property name */
ecma_property_t *prop_p) /**< property */
{
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (prop_name_p != NULL);
JERRY_ASSERT (prop_p != NULL && !ecma_is_property_lcached (prop_p));
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_INTERNAL);
#ifndef CONFIG_ECMA_LCACHE_DISABLE
jmem_cpointer_t object_cp;
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
size_t row_index = ecma_lcache_row_index (object_cp, prop_name_p);
ecma_lcache_hash_entry_t *entries_p = JERRY_HASH_TABLE_CONTEXT (table)[row_index];
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
ecma_lcache_hash_entry_t *entries_p = JERRY_CONTEXT (lcache) [row_index];
int32_t entry_index;
uint32_t entry_index;
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
{
if (entries_p[entry_index].object_cp == ECMA_NULL_POINTER)
if (entries_p[entry_index].id == 0)
{
break;
}
@@ -119,17 +112,14 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
{
entries_p[i] = entries_p[i - 1];
}
entry_index = 0;
}
ecma_lcache_hash_entry_t *entry_p = entries_p + entry_index;
ECMA_SET_NON_NULL_POINTER (entry_p->object_cp, object_p);
ECMA_SET_NON_NULL_POINTER (entry_p->prop_name_cp, prop_name_p);
entry_p->prop_p = prop_p;
entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp);
ecma_set_property_lcached (entry_p->prop_p, true);
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
} /* ecma_lcache_insert */
/**
@@ -138,49 +128,46 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
* @return a pointer to an ecma_property_t if the lookup is successful
* NULL otherwise
*/
inline ecma_property_t * __attr_always_inline___
inline ecma_property_t * JERRY_ATTR_ALWAYS_INLINE
ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
const ecma_string_t *prop_name_p) /**< property's name */
{
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (prop_name_p != NULL);
#ifndef CONFIG_ECMA_LCACHE_DISABLE
jmem_cpointer_t object_cp;
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
size_t row_index = ecma_lcache_row_index (object_cp, prop_name_p);
ecma_lcache_hash_entry_t *entry_p = JERRY_HASH_TABLE_CONTEXT (table) [row_index];
ecma_property_t prop_name_type;
jmem_cpointer_t prop_name_cp;
if (ECMA_IS_DIRECT_STRING (prop_name_p))
{
prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p);
prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p);
}
else
{
prop_name_type = ECMA_DIRECT_STRING_PTR;
ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p);
}
size_t row_index = ecma_lcache_row_index (object_cp, prop_name_cp);
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
ecma_string_container_t prop_container = ECMA_STRING_GET_CONTAINER (prop_name_p);
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp);
while (entry_p < entry_end_p)
{
if (entry_p->object_cp == object_cp)
if (entry_p->id == id && ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type)
{
ecma_string_t *entry_prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
entry_p->prop_name_cp);
JERRY_ASSERT ((prop_name_p->hash & ECMA_LCACHE_HASH_MASK) == (entry_prop_name_p->hash & ECMA_LCACHE_HASH_MASK));
if (prop_name_p == entry_prop_name_p
|| (prop_container > ECMA_STRING_CONTAINER_HEAP_LONG_UTF8_STRING
&& prop_container == ECMA_STRING_GET_CONTAINER (entry_prop_name_p)
&& prop_name_p->u.common_field == entry_prop_name_p->u.common_field))
{
ecma_property_t *prop_p = entry_p->prop_p;
JERRY_ASSERT (prop_p != NULL && ecma_is_property_lcached (prop_p));
return prop_p;
}
else
{
/* They can be equal, but generic string comparison is too costly. */
}
JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p));
return entry_p->prop_p;
}
entry_p++;
}
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
return NULL;
} /* ecma_lcache_lookup */
@@ -190,41 +177,39 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
*/
void
ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */
ecma_string_t *prop_name_p, /**< property's name */
jmem_cpointer_t name_cp, /**< property name */
ecma_property_t *prop_p) /**< property */
{
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (prop_name_p != NULL);
JERRY_ASSERT (prop_p != NULL && ecma_is_property_lcached (prop_p));
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_INTERNAL);
#ifndef CONFIG_ECMA_LCACHE_DISABLE
jmem_cpointer_t object_cp;
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
size_t row_index = ecma_lcache_row_index (object_cp, prop_name_p);
ecma_lcache_hash_entry_t *entry_p = JERRY_HASH_TABLE_CONTEXT (table) [row_index];
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
for (uint32_t entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
while (true)
{
if (entry_p->object_cp != ECMA_NULL_POINTER && entry_p->prop_p == prop_p)
/* The property must be present. */
JERRY_ASSERT (entry_p - JERRY_CONTEXT (lcache) [row_index] < ECMA_LCACHE_HASH_ROW_LENGTH);
if (entry_p->id != 0 && entry_p->prop_p == prop_p)
{
JERRY_ASSERT (ECMA_GET_NON_NULL_POINTER (ecma_string_t,
entry_p->prop_name_cp) == prop_name_p);
JERRY_ASSERT (entry_p->object_cp == object_cp);
JERRY_ASSERT (entry_p->id == ECMA_LCACHE_CREATE_ID (object_cp, name_cp));
ecma_lcache_invalidate_entry (entry_p);
return;
}
entry_p++;
}
/* The property must be present. */
JERRY_UNREACHABLE ();
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
} /* ecma_lcache_invalidate */
#endif /* ENABLED (JERRY_LCACHE) */
/**
* @}
* @}
+8 -5
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +23,13 @@
* @{
*/
extern void ecma_lcache_init (void);
extern void ecma_lcache_insert (ecma_object_t *, ecma_string_t *, ecma_property_t *);
extern ecma_property_t *ecma_lcache_lookup (ecma_object_t *, const ecma_string_t *);
extern void ecma_lcache_invalidate (ecma_object_t *, ecma_string_t *, ecma_property_t *);
#if ENABLED (JERRY_LCACHE)
void ecma_lcache_insert (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p);
ecma_property_t *ecma_lcache_lookup (ecma_object_t *object_p, const ecma_string_t *prop_name_p);
void ecma_lcache_invalidate (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p);
#endif /* ENABLED (JERRY_LCACHE) */
/**
* @}
+247 -262
View File
@@ -1,5 +1,4 @@
/* Copyright 2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,6 +13,7 @@
* limitations under the License.
*/
#include "ecma-alloc.h"
#include "ecma-literal-storage.h"
#include "ecma-helpers.h"
#include "jcontext.h"
@@ -25,9 +25,6 @@
* @{
*/
JERRY_STATIC_ASSERT (sizeof (ecma_lit_storage_item_t) <= sizeof (uint64_t),
size_of_ecma_lit_storage_item_t_must_be_less_than_or_equal_to_8_bytes);
/**
* Free string list
*/
@@ -50,7 +47,7 @@ ecma_free_string_list (ecma_lit_storage_item_t *string_list_p) /**< string list
ecma_lit_storage_item_t *prev_item = string_list_p;
string_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, string_list_p->next_cp);
jmem_pools_free (prev_item);
jmem_pools_free (prev_item, sizeof (ecma_lit_storage_item_t));
}
} /* ecma_free_string_list */
@@ -60,6 +57,9 @@ ecma_free_string_list (ecma_lit_storage_item_t *string_list_p) /**< string list
void
ecma_finalize_lit_storage (void)
{
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
ecma_free_string_list (JERRY_CONTEXT (symbol_list_first_p));
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
ecma_free_string_list (JERRY_CONTEXT (string_list_first_p));
ecma_free_string_list (JERRY_CONTEXT (number_list_first_p));
} /* ecma_finalize_lit_storage */
@@ -69,12 +69,17 @@ ecma_finalize_lit_storage (void)
*
* @return ecma_string_t compressed pointer
*/
jmem_cpointer_t
ecma_value_t
ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string to be searched */
lit_utf8_size_t size) /**< size of the string */
{
ecma_string_t *string_p = ecma_new_ecma_string_from_utf8 (chars_p, size);
if (ECMA_IS_DIRECT_STRING (string_p))
{
return ecma_make_string_value (string_p);
}
ecma_lit_storage_item_t *string_list_p = JERRY_CONTEXT (string_list_first_p);
jmem_cpointer_t *empty_cpointer_p = NULL;
@@ -98,7 +103,7 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
{
/* Return with string if found in the list. */
ecma_deref_ecma_string (string_p);
return string_list_p->values[i];
return ecma_make_string_value (value_p);
}
}
}
@@ -112,10 +117,11 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
if (empty_cpointer_p != NULL)
{
*empty_cpointer_p = result;
return result;
return ecma_make_string_value (string_p);
}
ecma_lit_storage_item_t *new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc ();
ecma_lit_storage_item_t *new_item_p;
new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t));
new_item_p->values[0] = result;
for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
@@ -126,7 +132,7 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
JMEM_CP_SET_POINTER (new_item_p->next_cp, JERRY_CONTEXT (string_list_first_p));
JERRY_CONTEXT (string_list_first_p) = new_item_p;
return result;
return ecma_make_string_value (string_p);
} /* ecma_find_or_create_literal_string */
/**
@@ -134,11 +140,18 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
*
* @return ecma_string_t compressed pointer
*/
jmem_cpointer_t
ecma_value_t
ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be searched */
{
ecma_value_t num = ecma_make_number_value (number_arg);
if (ecma_is_value_integer_number (num))
{
return num;
}
JERRY_ASSERT (ecma_is_value_float_number (num));
ecma_lit_storage_item_t *number_list_p = JERRY_CONTEXT (number_list_first_p);
jmem_cpointer_t *empty_cpointer_p = NULL;
@@ -159,22 +172,12 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
number_list_p->values[i]);
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
JERRY_ASSERT (ecma_is_value_float_number (value_p->u.lit_number));
if (ecma_is_value_integer_number (num))
if (ecma_get_float_from_value (value_p->u.lit_number) == number_arg)
{
if (value_p->u.lit_number == num)
{
return number_list_p->values[i];
}
}
else
{
if (ecma_is_value_float_number (value_p->u.lit_number)
&& ecma_get_float_from_value (value_p->u.lit_number) == ecma_get_float_from_value (num))
{
ecma_free_value (num);
return number_list_p->values[i];
}
ecma_free_value (num);
return value_p->u.lit_number;
}
}
}
@@ -182,7 +185,7 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
number_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, number_list_p->next_cp);
}
ecma_string_t *string_p = (ecma_string_t *) jmem_pools_alloc ();
ecma_string_t *string_p = ecma_alloc_string ();
string_p->refs_and_container = ECMA_STRING_REF_ONE | ECMA_STRING_LITERAL_NUMBER;
string_p->u.lit_number = num;
@@ -192,10 +195,11 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
if (empty_cpointer_p != NULL)
{
*empty_cpointer_p = result;
return result;
return num;
}
ecma_lit_storage_item_t *new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc ();
ecma_lit_storage_item_t *new_item_p;
new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t));
new_item_p->values[0] = result;
for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
@@ -206,308 +210,289 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
JMEM_CP_SET_POINTER (new_item_p->next_cp, JERRY_CONTEXT (number_list_first_p));
JERRY_CONTEXT (number_list_first_p) = new_item_p;
return result;
return num;
} /* ecma_find_or_create_literal_number */
/**
* Log2 of snapshot literal alignment.
*/
#define JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG 2
#define JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG 1
/**
* Snapshot literal alignment.
*/
#define JERRY_SNAPSHOT_LITERAL_ALIGNMENT (1u << JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG)
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
/**
* Literal offset shift.
*/
#define JERRY_SNAPSHOT_LITERAL_SHIFT (ECMA_VALUE_SHIFT + 1)
/**
* Literal value is number.
*/
#define JERRY_SNAPSHOT_LITERAL_IS_NUMBER (1u << ECMA_VALUE_SHIFT)
#if ENABLED (JERRY_SNAPSHOT_SAVE)
/**
* Append the value at the end of the appropriate list if it is not present there.
*/
void ecma_save_literals_append_value (ecma_value_t value, /**< value to be appended */
ecma_collection_header_t *lit_pool_p) /**< list of known values */
{
/* Unlike direct numbers, direct strings are converted to character literals. */
if (!ecma_is_value_string (value) && !ecma_is_value_float_number (value))
{
return;
}
ecma_value_t *iterator_p = ecma_collection_iterator_init (lit_pool_p);
while (iterator_p != NULL)
{
/* Strings / numbers are direct strings or stored in the literal storage.
* Therefore direct comparison is enough to find the same strings / numbers. */
if (*iterator_p == value)
{
return;
}
iterator_p = ecma_collection_iterator_next (iterator_p);
}
ecma_append_to_values_collection (lit_pool_p, value, ECMA_COLLECTION_NO_COPY);
} /* ecma_save_literals_append_value */
/**
* Add names from a byte-code data to a list.
*/
void
ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< byte-code data */
ecma_collection_header_t *lit_pool_p) /**< list of known values */
{
ecma_value_t *literal_p;
uint32_t argument_end = 0;
uint32_t register_end;
uint32_t const_literal_end;
uint32_t literal_end;
JERRY_ASSERT (compiled_code_p->status_flags & CBC_CODE_FLAGS_FUNCTION);
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
{
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p;
uint8_t *byte_p = (uint8_t *) compiled_code_p;
literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint16_arguments_t));
register_end = args_p->register_end;
const_literal_end = args_p->const_literal_end - register_end;
literal_end = args_p->literal_end - register_end;
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (compiled_code_p))
{
argument_end = args_p->argument_end;
}
}
else
{
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p;
uint8_t *byte_p = (uint8_t *) compiled_code_p;
literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint8_arguments_t));
register_end = args_p->register_end;
const_literal_end = args_p->const_literal_end - register_end;
literal_end = args_p->literal_end - register_end;
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (compiled_code_p))
{
argument_end = args_p->argument_end;
}
}
for (uint32_t i = 0; i < argument_end; i++)
{
ecma_save_literals_append_value (literal_p[i], lit_pool_p);
}
for (uint32_t i = 0; i < const_literal_end; i++)
{
ecma_save_literals_append_value (literal_p[i], lit_pool_p);
}
for (uint32_t i = const_literal_end; i < literal_end; i++)
{
ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
literal_p[i]);
if ((bytecode_p->status_flags & CBC_CODE_FLAGS_FUNCTION)
&& bytecode_p != compiled_code_p)
{
ecma_save_literals_add_compiled_code (bytecode_p, lit_pool_p);
}
}
if (argument_end != 0)
{
uint8_t *byte_p = (uint8_t *) compiled_code_p;
byte_p += ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG;
literal_p = ((ecma_value_t *) byte_p) - argument_end;
for (uint32_t i = 0; i < argument_end; i++)
{
ecma_save_literals_append_value (literal_p[i], lit_pool_p);
}
}
} /* ecma_save_literals_add_compiled_code */
/**
* Save literals to specified snapshot buffer.
*
* @return true, if save was performed successfully (i.e. buffer size is sufficient),
* false - otherwise.
* Note:
* Frees 'lit_pool_p' regardless of success.
*
* @return true - if save was performed successfully (i.e. buffer size is sufficient),
* false - otherwise
*/
bool
ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot buffer */
ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, /**< list of known values */
uint32_t *buffer_p, /**< [out] output snapshot buffer */
size_t buffer_size, /**< size of the buffer */
size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal identifiers
* to the literal offsets
* in snapshot */
uint32_t *out_map_len_p, /**< [out] number of literals */
uint32_t *out_lit_table_size_p) /**< [out] number of bytes, saved to snapshot buffer */
uint32_t *out_map_len_p) /**< [out] number of literals */
{
/* Count literals and literal space. */
uint32_t string_count = 0;
uint32_t number_count = 0;
uint32_t lit_table_size = 2 * sizeof (uint32_t);
ecma_lit_storage_item_t *string_list_p = JERRY_CONTEXT (string_list_first_p);
while (string_list_p != NULL)
if (lit_pool_p->item_count == 0)
{
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
{
if (string_list_p->values[i] != JMEM_CP_NULL)
{
ecma_string_t *string_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
string_list_p->values[i]);
*out_map_p = NULL;
*out_map_len_p = 0;
}
lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint16_t) + ecma_string_get_size (string_p),
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
string_count++;
}
uint32_t lit_table_size = 0;
size_t max_lit_table_size = buffer_size - *in_out_buffer_offset_p;
if (max_lit_table_size > (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT))
{
max_lit_table_size = (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT);
}
ecma_value_t *iterator_p = ecma_collection_iterator_init (lit_pool_p);
/* Compute the size of the literal pool. */
while (iterator_p != NULL)
{
if (ecma_is_value_float_number (*iterator_p))
{
lit_table_size += (uint32_t) sizeof (ecma_number_t);
}
else
{
ecma_string_t *string_p = ecma_get_string_from_value (*iterator_p);
lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint16_t) + ecma_string_get_size (string_p),
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
}
string_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, string_list_p->next_cp);
}
ecma_lit_storage_item_t *number_list_p = JERRY_CONTEXT (number_list_first_p);
while (number_list_p != NULL)
{
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
/* Check whether enough space is available and the maximum size is not reached. */
if (lit_table_size > max_lit_table_size)
{
if (number_list_p->values[i] != JMEM_CP_NULL)
{
lit_table_size += (uint32_t) sizeof (ecma_number_t);
number_count++;
}
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
return false;
}
number_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, number_list_p->next_cp);
iterator_p = ecma_collection_iterator_next (iterator_p);
}
/* Check whether enough space is available. */
if (*in_out_buffer_offset_p + lit_table_size > buffer_size)
{
return false;
}
/* Check whether the maximum literal table size is reached. */
if ((lit_table_size >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG) > UINT16_MAX)
{
return false;
}
uint32_t total_count = string_count + number_count;
lit_mem_to_snapshot_id_map_entry_t *map_p;
ecma_length_t total_count = lit_pool_p->item_count;
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
/* Set return values (no error is possible from here). */
buffer_p += *in_out_buffer_offset_p;
JERRY_ASSERT ((*in_out_buffer_offset_p % sizeof (uint32_t)) == 0);
uint8_t *destination_p = (uint8_t *) (buffer_p + (*in_out_buffer_offset_p / sizeof (uint32_t)));
uint32_t literal_offset = 0;
*in_out_buffer_offset_p += lit_table_size;
*out_map_p = map_p;
*out_map_len_p = total_count;
*out_lit_table_size_p = lit_table_size;
/* Write data into the buffer. */
iterator_p = ecma_collection_iterator_init (lit_pool_p);
/* The zero value is reserved for NULL (no literal)
* constant so the first literal must have offset one. */
uint32_t literal_offset = JERRY_SNAPSHOT_LITERAL_ALIGNMENT;
((uint32_t *) buffer_p)[0] = string_count;
((uint32_t *) buffer_p)[1] = number_count;
buffer_p += 2 * sizeof (uint32_t);
string_list_p = JERRY_CONTEXT (string_list_first_p);
while (string_list_p != NULL)
/* Generate literal pool data. */
while (iterator_p != NULL)
{
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
map_p->literal_id = *iterator_p;
map_p->literal_offset = (literal_offset << JERRY_SNAPSHOT_LITERAL_SHIFT) | ECMA_TYPE_SNAPSHOT_OFFSET;
ecma_length_t length;
if (ecma_is_value_float_number (*iterator_p))
{
if (string_list_p->values[i] != JMEM_CP_NULL)
{
map_p->literal_id = string_list_p->values[i];
map_p->literal_offset = (jmem_cpointer_t) (literal_offset >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG);
map_p++;
map_p->literal_offset |= JERRY_SNAPSHOT_LITERAL_IS_NUMBER;
ecma_string_t *string_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
string_list_p->values[i]);
ecma_number_t num = ecma_get_float_from_value (*iterator_p);
memcpy (destination_p, &num, sizeof (ecma_number_t));
ecma_length_t length = ecma_string_get_size (string_p);
length = JERRY_ALIGNUP (sizeof (ecma_number_t), JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
}
else
{
ecma_string_t *string_p = ecma_get_string_from_value (*iterator_p);
length = ecma_string_get_size (string_p);
*((uint16_t *) buffer_p) = (uint16_t) length;
ecma_string_to_utf8_bytes (string_p, buffer_p + sizeof (uint16_t), length);
*(uint16_t *) destination_p = (uint16_t) length;
length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
ecma_string_to_utf8_bytes (string_p, destination_p + sizeof (uint16_t), length);
buffer_p += length;
literal_offset += length;
}
length = JERRY_ALIGNUP (sizeof (uint16_t) + length, JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
}
string_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, string_list_p->next_cp);
}
number_list_p = JERRY_CONTEXT (number_list_first_p);
while (number_list_p != NULL)
{
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
{
if (number_list_p->values[i] != JMEM_CP_NULL)
{
map_p->literal_id = number_list_p->values[i];
map_p->literal_offset = (jmem_cpointer_t) (literal_offset >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG);
map_p++;
ecma_string_t *value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
number_list_p->values[i]);
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
ecma_number_t num = ecma_get_number_from_value (value_p->u.lit_number);
memcpy (buffer_p, &num, sizeof (ecma_number_t));
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
buffer_p += length;
literal_offset += length;
}
}
number_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, number_list_p->next_cp);
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
destination_p += length;
literal_offset += length;
iterator_p = ecma_collection_iterator_next (iterator_p);
map_p++;
}
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
return true;
} /* ecma_save_literals_for_snapshot */
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
#ifdef JERRY_ENABLE_SNAPSHOT_EXEC
#if ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE)
/**
* Helper function for ecma_load_literals_from_snapshot.
* Get the compressed pointer of a given literal.
*
* Note: always inline because it is used only once.
*
* @return true, if load was performed successfully
* false - otherwise (i.e. buffer length is incorrect).
* @return literal compressed pointer
*/
static inline bool __attr_always_inline___
ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with literal table in snapshot */
uint32_t lit_table_size, /**< size of literal table in snapshot */
lit_mem_to_snapshot_id_map_entry_t *map_p, /**< literal map */
uint32_t string_count, /**< number of strings */
uint32_t number_count) /**< number of numbers */
ecma_value_t
ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */
ecma_value_t literal_value) /**< string / number offset */
{
/* The zero value is reserved for NULL (no literal)
* constant so the first literal must have offset one. */
uint32_t literal_offset = JERRY_SNAPSHOT_LITERAL_ALIGNMENT;
JERRY_ASSERT ((literal_value & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET);
/* Load strings first. */
while (string_count > 0)
const uint8_t *literal_p = literal_base_p + (literal_value >> JERRY_SNAPSHOT_LITERAL_SHIFT);
if (literal_value & JERRY_SNAPSHOT_LITERAL_IS_NUMBER)
{
if (lit_table_size < literal_offset + sizeof (uint32_t))
{
/* Buffer is not sufficent. */
return false;
}
lit_utf8_size_t length = *((uint16_t *) buffer_p);
lit_utf8_size_t aligned_length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
if (lit_table_size < literal_offset + aligned_length)
{
/* Buffer is not sufficent. */
return false;
}
map_p->literal_id = ecma_find_or_create_literal_string (buffer_p + sizeof (uint16_t), length);
map_p->literal_offset = (jmem_cpointer_t) (literal_offset >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG);
map_p++;
buffer_p += aligned_length;
literal_offset += aligned_length;
string_count--;
}
/* Load numbers. */
while (number_count > 0)
{
if (lit_table_size < literal_offset + sizeof (ecma_number_t))
{
/* Buffer is not sufficent. */
return false;
}
ecma_number_t num;
memcpy (&num, buffer_p, sizeof (ecma_number_t));
map_p->literal_id = ecma_find_or_create_literal_number (num);
map_p->literal_offset = (jmem_cpointer_t) (literal_offset >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG);
map_p++;
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
buffer_p += length;
literal_offset += length;
number_count--;
memcpy (&num, literal_p, sizeof (ecma_number_t));
return ecma_find_or_create_literal_number (num);
}
return (lit_table_size == (literal_offset + 2 * sizeof (uint32_t) - JERRY_SNAPSHOT_LITERAL_ALIGNMENT));
} /* ecma_load_literals_from_buffer */
uint16_t length = *(const uint16_t *) literal_p;
/**
* Load literals from snapshot.
*
* @return true, if load was performed successfully (i.e. literals saved in the snapshot are consistent),
* false - otherwise (i.e. snapshot is incorrect).
*/
bool
ecma_load_literals_from_snapshot (const uint8_t *buffer_p, /**< buffer with literal table in snapshot */
uint32_t lit_table_size, /**< size of literal table in snapshot */
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal offsets
* in snapshot to identifiers
* of loaded literals in literal
* storage */
uint32_t *out_map_len_p) /**< [out] literals number */
{
*out_map_p = NULL;
return ecma_find_or_create_literal_string (literal_p + sizeof (uint16_t), length);
} /* ecma_snapshot_get_literal */
if (lit_table_size < 2 * sizeof (uint32_t))
{
/* Buffer is not sufficent. */
return false;
}
uint32_t string_count = ((uint32_t *) buffer_p)[0];
uint32_t number_count = ((uint32_t *) buffer_p)[1];
buffer_p += 2 * sizeof (uint32_t);
uint32_t total_count = string_count + number_count;
lit_mem_to_snapshot_id_map_entry_t *map_p;
*out_map_len_p = total_count;
if (total_count == 0)
{
return true;
}
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
*out_map_p = map_p;
if (ecma_load_literals_from_buffer (buffer_p, lit_table_size, map_p, string_count, number_count))
{
return true;
}
jmem_heap_free_block (map_p, total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
*out_map_p = NULL;
return false;
} /* ecma_load_literals_from_snapshot */
#endif /* JERRY_ENABLE_SNAPSHOT_EXEC */
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE) */
/**
* @}
+21 -18
View File
@@ -1,5 +1,4 @@
/* Copyright 2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +17,7 @@
#define ECMA_LIT_STORAGE_H
#include "ecma-globals.h"
#include "jmem-allocator.h"
#include "jmem.h"
#include "lit-globals.h"
/** \addtogroup ecma ECMA
@@ -28,31 +27,35 @@
* @{
*/
#if ENABLED (JERRY_SNAPSHOT_SAVE)
/**
* Snapshot literal - offset map
*/
typedef struct
{
jmem_cpointer_t literal_id; /**< literal id */
jmem_cpointer_t literal_offset; /**< literal offset */
ecma_value_t literal_id; /**< literal id */
ecma_value_t literal_offset; /**< literal offset */
} lit_mem_to_snapshot_id_map_entry_t;
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
extern void ecma_finalize_lit_storage (void);
void ecma_finalize_lit_storage (void);
extern jmem_cpointer_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *, lit_utf8_size_t);
extern jmem_cpointer_t ecma_find_or_create_literal_number (ecma_number_t);
ecma_value_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, lit_utf8_size_t size);
ecma_value_t ecma_find_or_create_literal_number (ecma_number_t number_arg);
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
extern bool
ecma_save_literals_for_snapshot (uint8_t *, size_t, size_t *,
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *, uint32_t *);
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
#if ENABLED (JERRY_SNAPSHOT_SAVE)
void ecma_save_literals_append_value (ecma_value_t value, ecma_collection_header_t *lit_pool_p);
void ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,
ecma_collection_header_t *lit_pool_p);
bool ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, uint32_t *buffer_p, size_t buffer_size,
size_t *in_out_buffer_offset_p, lit_mem_to_snapshot_id_map_entry_t **out_map_p,
uint32_t *out_map_len_p);
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
#ifdef JERRY_ENABLE_SNAPSHOT_EXEC
extern bool
ecma_load_literals_from_snapshot (const uint8_t *, uint32_t,
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *);
#endif /* JERRY_ENABLE_SNAPSHOT_EXEC */
#if ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE)
ecma_value_t
ecma_snapshot_get_literal (const uint8_t *literal_base_p, ecma_value_t literal_value);
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE) */
/**
* @}
+922
View File
@@ -0,0 +1,922 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jcontext.h"
#include "jerryscript.h"
#include "ecma-exceptions.h"
#include "ecma-function-object.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lex-env.h"
#include "ecma-module.h"
#include "ecma-objects.h"
#include "lit-char-helpers.h"
#include "vm.h"
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
/**
* Takes a ModuleSpecifier and applies path normalization to it.
* It's not checked if the ModuleSpecifier is a valid path or not.
* Note: See 15.2.1.17
*
* @return pointer to ecma_string_t containing the normalized and zero terminated path
*/
ecma_string_t *
ecma_module_create_normalized_path (const uint8_t *char_p, /**< module specifier */
prop_length_t size) /**< size of module specifier */
{
JERRY_ASSERT (size > 0);
ecma_string_t *ret_p = NULL;
/* The module specifier is cesu8 encoded, we need to convert is to utf8, and zero terminate it,
* so that OS level functions can handle it. */
lit_utf8_byte_t *path_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (size + 1u);
lit_utf8_size_t utf8_size;
utf8_size = lit_convert_cesu8_string_to_utf8_string (char_p,
size,
path_p,
size);
path_p[utf8_size] = LIT_CHAR_NULL;
lit_utf8_byte_t *module_path_p = NULL;
lit_utf8_size_t module_path_size = 0;
/* Check if we have a current module, and use its path as the base path. */
JERRY_ASSERT (JERRY_CONTEXT (module_top_context_p) != NULL);
if (JERRY_CONTEXT (module_top_context_p)->module_p != NULL)
{
JERRY_ASSERT (JERRY_CONTEXT (module_top_context_p)->module_p->path_p != NULL);
module_path_size = ecma_string_get_size (JERRY_CONTEXT (module_top_context_p)->module_p->path_p);
module_path_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (module_path_size + 1);
lit_utf8_size_t module_utf8_size;
module_utf8_size = ecma_string_copy_to_utf8_buffer (JERRY_CONTEXT (module_top_context_p)->module_p->path_p,
module_path_p,
module_path_size);
module_path_p[module_utf8_size] = LIT_CHAR_NULL;
}
lit_utf8_byte_t *normalized_out_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (ECMA_MODULE_MAX_PATH);
size_t normalized_size = jerry_port_normalize_path ((const char *) path_p,
(char *) normalized_out_p,
ECMA_MODULE_MAX_PATH,
(char *) module_path_p);
if (normalized_size > 0)
{
/* Convert the normalized path to cesu8. */
ret_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (normalized_out_p, (lit_utf8_size_t) (normalized_size));
}
jmem_heap_free_block (path_p, size + 1u);
jmem_heap_free_block (normalized_out_p, ECMA_MODULE_MAX_PATH);
if (module_path_p != NULL)
{
jmem_heap_free_block (module_path_p, module_path_size + 1);
}
return ret_p;
} /* ecma_module_create_normalized_path */
/**
* Checks if we already have a module request in the module list.
*
* @return pointer to found or newly created module structure
*/
ecma_module_t *
ecma_module_find_or_create_module (ecma_string_t * const path_p) /**< module path */
{
ecma_module_t *current_p = JERRY_CONTEXT (ecma_modules_p);
while (current_p != NULL)
{
if (ecma_compare_ecma_strings (path_p, current_p->path_p))
{
return current_p;
}
current_p = current_p->next_p;
}
current_p = (ecma_module_t *) jmem_heap_alloc_block (sizeof (ecma_module_t));
memset (current_p, 0, sizeof (ecma_module_t));
ecma_ref_ecma_string (path_p);
current_p->path_p = path_p;
current_p->next_p = JERRY_CONTEXT (ecma_modules_p);
JERRY_CONTEXT (ecma_modules_p) = current_p;
return current_p;
} /* ecma_module_find_or_create_module */
/**
* Creates a module context.
*
* @return pointer to created module context
*/
static ecma_module_context_t *
ecma_module_create_module_context (void)
{
ecma_module_context_t *context_p = (ecma_module_context_t *) jmem_heap_alloc_block (sizeof (ecma_module_context_t));
memset (context_p, 0, sizeof (ecma_module_context_t));
return context_p;
} /* ecma_module_create_module_context */
/**
* Inserts a {module, export_name} record into a resolve set.
* Note: See 15.2.1.16.3 - resolveSet and exportStarSet
*
* @return true - if the set already contains the record
* false - otherwise
*/
bool
ecma_module_resolve_set_insert (ecma_module_resolve_set_t **set_p, /**< [in, out] resolve set */
ecma_module_t * const module_p, /**< module */
ecma_string_t * const export_name_p) /**< export name */
{
JERRY_ASSERT (set_p != NULL);
ecma_module_resolve_set_t *current_p = *set_p;
while (current_p != NULL)
{
if (current_p->record.module_p == module_p
&& ecma_compare_ecma_strings (current_p->record.name_p, export_name_p))
{
return false;
}
current_p = current_p->next_p;
}
ecma_module_resolve_set_t *new_p;
new_p = (ecma_module_resolve_set_t *) jmem_heap_alloc_block (sizeof (ecma_module_resolve_set_t));
new_p->next_p = *set_p;
new_p->record.module_p = module_p;
ecma_ref_ecma_string (export_name_p);
new_p->record.name_p = export_name_p;
*set_p = new_p;
return true;
} /* ecma_module_resolve_set_insert */
/**
* Cleans up contents of a resolve set.
*/
void
ecma_module_resolve_set_cleanup (ecma_module_resolve_set_t *set_p) /**< resolve set */
{
while (set_p != NULL)
{
ecma_module_resolve_set_t *next_p = set_p->next_p;
ecma_deref_ecma_string (set_p->record.name_p);
jmem_heap_free_block (set_p, sizeof (ecma_module_resolve_set_t));
set_p = next_p;
}
} /* ecma_module_resolve_set_cleanup */
/**
* Pushes a new resolve frame on top of a resolve stack and initializes it
* to begin resolving the specified exported name in the base module.
*/
void
ecma_module_resolve_stack_push (ecma_module_resolve_stack_t **stack_p, /**< [in, out] resolve stack */
ecma_module_t * const module_p, /**< base module */
ecma_string_t * const export_name_p) /**< exported name */
{
JERRY_ASSERT (stack_p != NULL);
ecma_module_resolve_stack_t *new_frame_p;
new_frame_p = (ecma_module_resolve_stack_t *) jmem_heap_alloc_block (sizeof (ecma_module_resolve_stack_t));
ecma_ref_ecma_string (export_name_p);
new_frame_p->export_name_p = export_name_p;
new_frame_p->module_p = module_p;
new_frame_p->resolving = false;
new_frame_p->next_p = *stack_p;
*stack_p = new_frame_p;
} /* ecma_module_resolve_stack_push */
/**
* Pops the topmost frame from a resolve stack.
*/
void
ecma_module_resolve_stack_pop (ecma_module_resolve_stack_t **stack_p) /**< [in, out] resolve stack */
{
JERRY_ASSERT (stack_p != NULL);
ecma_module_resolve_stack_t *current_p = *stack_p;
if (current_p != NULL)
{
*stack_p = current_p->next_p;
ecma_deref_ecma_string (current_p->export_name_p);
jmem_heap_free_block (current_p, sizeof (ecma_module_resolve_stack_t));
}
} /* ecma_module_resolve_stack_pop */
/**
* Resolves which module satisfies an export based from a specific module in the import tree.
* If no error occurs, out_record_p will contain a {module, local_name} record, which satisfies
* the export, or {NULL, NULL} if the export is ambiguous.
* Note: See 15.2.1.16.3
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
static ecma_value_t
ecma_module_resolve_export (ecma_module_t * const module_p, /**< base module */
ecma_string_t * const export_name_p, /**< export name */
ecma_module_record_t *out_record_p) /**< [out] found module record */
{
ecma_module_resolve_set_t *resolve_set_p = NULL;
ecma_module_resolve_stack_t *stack_p = NULL;
bool found = false;
ecma_module_record_t found_record = { NULL, NULL };
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ecma_module_resolve_stack_push (&stack_p, module_p, export_name_p);
while (stack_p != NULL)
{
ecma_module_resolve_stack_t *current_frame_p = stack_p;
ecma_module_t *current_module_p = current_frame_p->module_p;
JERRY_ASSERT (current_module_p->state >= ECMA_MODULE_STATE_PARSED);
ecma_module_context_t *context_p = current_module_p->context_p;
ecma_string_t *current_export_name_p = current_frame_p->export_name_p;
if (!current_frame_p->resolving)
{
current_frame_p->resolving = true;
/* 15.2.1.16.3 / 2-3 */
if (!ecma_module_resolve_set_insert (&resolve_set_p, current_module_p, current_export_name_p))
{
/* This is a circular import request. */
ecma_module_resolve_stack_pop (&stack_p);
continue;
}
if (context_p->local_exports_p != NULL)
{
/* 15.2.1.16.3 / 4 */
JERRY_ASSERT (context_p->local_exports_p->next_p == NULL);
ecma_module_names_t *export_names_p = context_p->local_exports_p->module_names_p;
while (export_names_p != NULL)
{
if (ecma_compare_ecma_strings (current_export_name_p, export_names_p->imex_name_p))
{
if (found)
{
/* This is an ambigous export. */
found_record.module_p = NULL;
found_record.name_p = NULL;
break;
}
/* The current module provides a direct binding for this export. */
found = true;
found_record.module_p = current_module_p;
found_record.name_p = export_names_p->local_name_p;
break;
}
export_names_p = export_names_p->next_p;
}
}
if (found)
{
/* We found a resolution for the current frame, return to the previous. */
ecma_module_resolve_stack_pop (&stack_p);
continue;
}
/* 15.2.1.16.3 / 5 */
ecma_module_node_t *indirect_export_p = context_p->indirect_exports_p;
while (indirect_export_p != NULL)
{
ecma_module_names_t *export_names_p = indirect_export_p->module_names_p;
while (export_names_p != NULL)
{
if (ecma_compare_ecma_strings (current_export_name_p, export_names_p->imex_name_p))
{
/* 5.2.1.16.3 / 5.a.iv */
ecma_module_resolve_stack_push (&stack_p,
indirect_export_p->module_request_p,
export_names_p->local_name_p);
}
export_names_p = export_names_p->next_p;
}
indirect_export_p = indirect_export_p->next_p;
}
/* We need to check whether the newly pushed indirect exports resolve to anything.
* Keep current frame in the stack, and continue from the topmost frame. */
continue;
} /* if (!current_frame_p->resolving) */
/* By the time we return to the current frame, the indirect exports will have finished resolving. */
if (found)
{
/* We found at least one export that satisfies the current request.
* Pop current frame, and return to the previous. */
ecma_module_resolve_stack_pop (&stack_p);
continue;
}
/* 15.2.1.16.3 / 6 */
if (ecma_compare_ecma_string_to_magic_id (current_export_name_p, LIT_MAGIC_STRING_DEFAULT))
{
ret_value = ecma_raise_syntax_error (ECMA_ERR_MSG ("No explicitly defined default export in module."));
break;
}
/* 15.2.1.16.3 / 7-8 */
if (!ecma_module_resolve_set_insert (&resolve_set_p,
current_module_p,
ecma_get_magic_string (LIT_MAGIC_STRING_ASTERIX_CHAR)))
{
/* This is a circular import request. */
ecma_module_resolve_stack_pop (&stack_p);
continue;
}
/* Pop the current frame, we have nothing else to do here after the star export resolutions are queued. */
ecma_module_resolve_stack_pop (&stack_p);
/* 15.2.1.16.3 / 10 */
ecma_module_node_t *star_export_p = context_p->star_exports_p;
while (star_export_p != NULL)
{
JERRY_ASSERT (star_export_p->module_names_p == NULL);
/* 15.2.1.16.3 / 10.c */
ecma_module_resolve_stack_push (&stack_p, star_export_p->module_request_p, export_name_p);
star_export_p = star_export_p->next_p;
}
}
/* Clean up. */
ecma_module_resolve_set_cleanup (resolve_set_p);
while (stack_p)
{
ecma_module_resolve_stack_pop (&stack_p);
}
if (ECMA_IS_VALUE_ERROR (ret_value))
{
/* No default export was found */
return ret_value;
}
if (found)
{
*out_record_p = found_record;
}
else
{
ret_value = ecma_raise_syntax_error (ECMA_ERR_MSG ("Unexported or circular import request."));
}
return ret_value;
} /* ecma_module_resolve_export */
/**
* Resolves an export and adds it to the modules namespace object, if the export name is not yet handled.
* Note: See 15.2.1.16.2 and 15.2.1.18
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
static ecma_value_t
ecma_module_namespace_object_add_export_if_needed (ecma_module_t *module_p, /**< module */
ecma_string_t *export_name_p) /**< export name */
{
JERRY_ASSERT (module_p->namespace_object_p != NULL);
ecma_value_t result = ECMA_VALUE_EMPTY;
if (ecma_find_named_property (module_p->namespace_object_p, export_name_p) != NULL)
{
/* This export name has already been handled. */
return result;
}
ecma_module_record_t record;
result = ecma_module_resolve_export (module_p, export_name_p, &record);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
if (record.module_p == NULL)
{
/* 15.2.1.18 / 3.d.iv Skip ambiguous names. */
return result;
}
ecma_object_t *ref_base_lex_env_p;
ecma_value_t prop_value = ecma_op_get_value_lex_env_base (record.module_p->scope_p,
&ref_base_lex_env_p,
record.name_p);
ecma_property_t *new_property_p;
ecma_create_named_data_property (module_p->namespace_object_p,
export_name_p,
ECMA_PROPERTY_FIXED,
&new_property_p);
ecma_named_data_property_assign_value (module_p->namespace_object_p,
ECMA_PROPERTY_VALUE_PTR (new_property_p),
prop_value);
ecma_free_value (prop_value);
return result;
} /* ecma_module_namespace_object_add_export_if_needed */
/**
* Creates a namespace object for a module.
* Note: See 15.2.1.18
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
static ecma_value_t
ecma_module_create_namespace_object (ecma_module_t *module_p) /**< module */
{
ecma_value_t result = ECMA_VALUE_EMPTY;
if (module_p->namespace_object_p != NULL)
{
return result;
}
JERRY_ASSERT (module_p->state == ECMA_MODULE_STATE_EVALUATED);
ecma_module_resolve_set_t *resolve_set_p = NULL;
ecma_module_resolve_stack_t *stack_p = NULL;
module_p->namespace_object_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE),
0,
ECMA_OBJECT_TYPE_GENERAL);
ecma_module_resolve_stack_push (&stack_p, module_p, ecma_get_magic_string (LIT_MAGIC_STRING_ASTERIX_CHAR));
while (stack_p != NULL)
{
ecma_module_resolve_stack_t *current_frame_p = stack_p;
ecma_module_t *current_module_p = current_frame_p->module_p;
ecma_module_context_t *context_p = current_module_p->context_p;
ecma_module_resolve_stack_pop (&stack_p);
/* 15.2.1.16.2 / 2-3 */
if (!ecma_module_resolve_set_insert (&resolve_set_p,
current_module_p,
ecma_get_magic_string (LIT_MAGIC_STRING_ASTERIX_CHAR)))
{
/* Circular import. */
continue;
}
if (context_p->local_exports_p != NULL)
{
/* 15.2.1.16.2 / 5 */
JERRY_ASSERT (context_p->local_exports_p->next_p == NULL);
ecma_module_names_t *export_names_p = context_p->local_exports_p->module_names_p;
while (export_names_p != NULL && ecma_is_value_empty (result))
{
result = ecma_module_namespace_object_add_export_if_needed (module_p,
export_names_p->imex_name_p);
export_names_p = export_names_p->next_p;
}
}
/* 15.2.1.16.2 / 6 */
ecma_module_node_t *indirect_export_p = context_p->indirect_exports_p;
while (indirect_export_p != NULL && ecma_is_value_empty (result))
{
ecma_module_names_t *export_names_p = indirect_export_p->module_names_p;
while (export_names_p != NULL && ecma_is_value_empty (result))
{
result = ecma_module_namespace_object_add_export_if_needed (module_p,
export_names_p->imex_name_p);
export_names_p = export_names_p->next_p;
}
indirect_export_p = indirect_export_p->next_p;
}
/* 15.2.1.16.2 / 7 */
ecma_module_node_t *star_export_p = context_p->star_exports_p;
while (star_export_p != NULL && ecma_is_value_empty (result))
{
JERRY_ASSERT (star_export_p->module_names_p == NULL);
/* 15.2.1.16.3/10.c */
ecma_module_resolve_stack_push (&stack_p,
star_export_p->module_request_p,
ecma_get_magic_string (LIT_MAGIC_STRING_ASTERIX_CHAR));
star_export_p = star_export_p->next_p;
}
}
/* Clean up. */
ecma_module_resolve_set_cleanup (resolve_set_p);
while (stack_p)
{
ecma_module_resolve_stack_pop (&stack_p);
}
return result;
} /* ecma_module_create_namespace_object */
/**
* Evaluates an EcmaScript module.
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
static ecma_value_t
ecma_module_evaluate (ecma_module_t *module_p) /**< module */
{
JERRY_ASSERT (module_p->state >= ECMA_MODULE_STATE_PARSED);
if (module_p->state >= ECMA_MODULE_STATE_EVALUATING)
{
return ECMA_VALUE_EMPTY;
}
module_p->state = ECMA_MODULE_STATE_EVALUATING;
module_p->scope_p = ecma_create_decl_lex_env (ecma_get_global_environment ());
module_p->context_p->parent_p = JERRY_CONTEXT (module_top_context_p);
JERRY_CONTEXT (module_top_context_p) = module_p->context_p;
ecma_value_t ret_value;
ret_value = vm_run_module (module_p->compiled_code_p,
module_p->scope_p);
if (!ECMA_IS_VALUE_ERROR (ret_value))
{
jerry_release_value (ret_value);
ret_value = ECMA_VALUE_EMPTY;
}
JERRY_CONTEXT (module_top_context_p) = module_p->context_p->parent_p;
ecma_bytecode_deref (module_p->compiled_code_p);
module_p->state = ECMA_MODULE_STATE_EVALUATED;
return ret_value;
} /* ecma_module_evaluate */
/**
* Connects imported values to the current context.
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
ecma_value_t
ecma_module_connect_imports (void)
{
ecma_module_context_t *current_context_p = JERRY_CONTEXT (module_top_context_p);
ecma_object_t *local_env_p = current_context_p->module_p->scope_p;
JERRY_ASSERT (ecma_is_lexical_environment (local_env_p));
ecma_module_node_t *import_node_p = current_context_p->imports_p;
while (import_node_p != NULL)
{
ecma_value_t result = ecma_module_evaluate (import_node_p->module_request_p);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
ecma_module_names_t *import_names_p = import_node_p->module_names_p;
while (import_names_p != NULL)
{
const bool is_namespace_import = ecma_compare_ecma_string_to_magic_id (import_names_p->imex_name_p,
LIT_MAGIC_STRING_ASTERIX_CHAR);
if (is_namespace_import)
{
result = ecma_module_create_namespace_object (import_node_p->module_request_p);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
ecma_op_create_mutable_binding (local_env_p, import_names_p->local_name_p, true /* is_deletable */);
ecma_op_set_mutable_binding (local_env_p,
import_names_p->local_name_p,
ecma_make_object_value (import_node_p->module_request_p->namespace_object_p),
false /* is_strict */);
}
else /* !is_namespace_import */
{
ecma_module_record_t record;
result = ecma_module_resolve_export (import_node_p->module_request_p, import_names_p->imex_name_p, &record);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
if (record.module_p == NULL)
{
return ecma_raise_syntax_error (ECMA_ERR_MSG ("Ambiguous import request."));
}
result = ecma_module_evaluate (record.module_p);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
ecma_object_t *ref_base_lex_env_p;
ecma_value_t prop_value = ecma_op_get_value_lex_env_base (record.module_p->scope_p,
&ref_base_lex_env_p,
record.name_p);
ecma_op_create_mutable_binding (local_env_p, import_names_p->local_name_p, true /* is_deletable */);
ecma_op_set_mutable_binding (local_env_p,
import_names_p->local_name_p,
prop_value,
false /* is_strict */);
ecma_free_value (prop_value);
}
import_names_p = import_names_p->next_p;
}
import_node_p = import_node_p->next_p;
}
return ECMA_VALUE_EMPTY;
} /* ecma_module_connect_imports */
/**
* Parses an EcmaScript module.
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
static jerry_value_t
ecma_module_parse (ecma_module_t *module_p) /**< module */
{
if (module_p->state >= ECMA_MODULE_STATE_PARSING)
{
return ECMA_VALUE_EMPTY;
}
module_p->state = ECMA_MODULE_STATE_PARSING;
module_p->context_p = ecma_module_create_module_context ();
lit_utf8_size_t module_path_size = ecma_string_get_size (module_p->path_p);
lit_utf8_byte_t *module_path_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (module_path_size + 1);
lit_utf8_size_t module_path_utf8_size;
module_path_utf8_size = ecma_string_copy_to_utf8_buffer (module_p->path_p,
module_path_p,
module_path_size);
module_path_p[module_path_utf8_size] = LIT_CHAR_NULL;
size_t source_size = 0;
uint8_t *source_p = jerry_port_read_source ((const char *) module_path_p, &source_size);
jmem_heap_free_block (module_path_p, module_path_size + 1);
if (source_p == NULL)
{
return ecma_raise_syntax_error (ECMA_ERR_MSG ("File not found."));
}
module_p->context_p->module_p = module_p;
module_p->context_p->parent_p = JERRY_CONTEXT (module_top_context_p);
JERRY_CONTEXT (module_top_context_p) = module_p->context_p;
#if ENABLED (JERRY_DEBUGGER) && ENABLED (JERRY_PARSER)
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
JERRY_DEBUGGER_NO_SUBTYPE,
module_path_p,
module_path_size - 1);
}
#endif /* ENABLED (JERRY_DEBUGGER) && ENABLED (JERRY_PARSER) */
JERRY_CONTEXT (resource_name) = ecma_make_string_value (module_p->path_p);
ecma_compiled_code_t *bytecode_data_p;
ecma_value_t ret_value = parser_parse_script (NULL,
0,
(jerry_char_t *) source_p,
source_size,
JERRY_PARSE_STRICT_MODE,
&bytecode_data_p);
JERRY_CONTEXT (module_top_context_p) = module_p->context_p->parent_p;
jerry_port_release_source (source_p);
if (ECMA_IS_VALUE_ERROR (ret_value))
{
return ret_value;
}
ecma_free_value (ret_value);
module_p->compiled_code_p = bytecode_data_p;
module_p->state = ECMA_MODULE_STATE_PARSED;
return ECMA_VALUE_EMPTY;
} /* ecma_module_parse */
/**
* Parses all referenced modules.
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
ecma_value_t
ecma_module_parse_modules (void)
{
ecma_module_t *current_p = JERRY_CONTEXT (ecma_modules_p);
while (current_p != NULL)
{
ecma_value_t ret_value = ecma_module_parse (current_p);
if (ECMA_IS_VALUE_ERROR (ret_value))
{
return ret_value;
}
JERRY_ASSERT (ecma_is_value_empty (ret_value));
current_p = current_p->next_p;
}
return ECMA_VALUE_EMPTY;
} /* ecma_module_parse_modules */
/**
* Checks if indirect exports in the current context are resolvable.
* Note: See 15.2.1.16.4 / 9.
*
* @return ECMA_VALUE_ERROR - if an error occured
* ECMA_VALUE_EMPTY - otherwise
*/
ecma_value_t
ecma_module_check_indirect_exports (void)
{
ecma_module_node_t *indirect_export_p = JERRY_CONTEXT (module_top_context_p)->indirect_exports_p;
while (indirect_export_p != NULL)
{
ecma_module_names_t *name_p = indirect_export_p->module_names_p;
while (name_p != NULL)
{
ecma_module_record_t record;
ecma_value_t result = ecma_module_resolve_export (indirect_export_p->module_request_p,
name_p->local_name_p,
&record);
if (ECMA_IS_VALUE_ERROR (result))
{
return result;
}
if (record.module_p == NULL)
{
return ecma_raise_syntax_error (ECMA_ERR_MSG ("Ambiguous indirect export request."));
}
name_p = name_p->next_p;
}
indirect_export_p = indirect_export_p->next_p;
}
return ECMA_VALUE_EMPTY;
} /* ecma_module_check_indirect_exports */
/**
* Cleans up a list of module names.
*/
void
ecma_module_release_module_names (ecma_module_names_t *module_name_p) /**< first module name */
{
while (module_name_p != NULL)
{
ecma_module_names_t *next_p = module_name_p->next_p;
ecma_deref_ecma_string (module_name_p->imex_name_p);
ecma_deref_ecma_string (module_name_p->local_name_p);
jmem_heap_free_block (module_name_p, sizeof (ecma_module_names_t));
module_name_p = next_p;
}
} /* ecma_module_release_module_names */
/**
* Cleans up a list of module nodes.
*/
static void
ecma_module_release_module_nodes (ecma_module_node_t *module_node_p) /**< first module node */
{
while (module_node_p != NULL)
{
ecma_module_node_t *next_p = module_node_p->next_p;
ecma_module_release_module_names (module_node_p->module_names_p);
jmem_heap_free_block (module_node_p, sizeof (ecma_module_node_t));
module_node_p = next_p;
}
} /* ecma_module_release_module_nodes */
/**
* Cleans up a module context.
*/
static void
ecma_module_release_module_context (ecma_module_context_t *module_context_p) /**< modle context */
{
ecma_module_release_module_nodes (module_context_p->imports_p);
ecma_module_release_module_nodes (module_context_p->local_exports_p);
ecma_module_release_module_nodes (module_context_p->indirect_exports_p);
ecma_module_release_module_nodes (module_context_p->star_exports_p);
jmem_heap_free_block (module_context_p, sizeof (ecma_module_context_t));
} /* ecma_module_release_module_context */
/**
* Cleans up a module structure.
*/
static void
ecma_module_release_module (ecma_module_t *module_p) /**< module */
{
ecma_deref_ecma_string (module_p->path_p);
if (module_p->state >= ECMA_MODULE_STATE_PARSING)
{
ecma_module_release_module_context (module_p->context_p);
}
if (module_p->state >= ECMA_MODULE_STATE_EVALUATING)
{
ecma_deref_object (module_p->scope_p);
}
if (module_p->state >= ECMA_MODULE_STATE_PARSED
&& module_p->state < ECMA_MODULE_STATE_EVALUATED)
{
ecma_bytecode_deref (module_p->compiled_code_p);
}
if (module_p->namespace_object_p != NULL)
{
ecma_deref_object (module_p->namespace_object_p);
}
jmem_heap_free_block (module_p, sizeof (ecma_module_t));
} /* ecma_module_release_module */
/**
* Cleans up all modules if the current context is the root context.
*/
void
ecma_module_cleanup (void)
{
if (JERRY_CONTEXT (module_top_context_p)->parent_p != NULL)
{
return;
}
ecma_module_t *current_p = JERRY_CONTEXT (ecma_modules_p);
while (current_p != NULL)
{
ecma_module_t *next_p = current_p->next_p;
ecma_module_release_module (current_p);
current_p = next_p;
}
JERRY_CONTEXT (module_top_context_p) = NULL;
} /* ecma_module_cleanup */
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
+140
View File
@@ -0,0 +1,140 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMA_MODULE_H
#define ECMA_MODULE_H
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
#include "common.h"
#include "ecma-globals.h"
#define ECMA_MODULE_MAX_PATH 255u
/**
* Imported or exported names, such as "a as b"
* Note: See https://www.ecma-international.org/ecma-262/6.0/#table-39
* and https://www.ecma-international.org/ecma-262/6.0/#table-41
*/
typedef struct ecma_module_names
{
struct ecma_module_names *next_p; /**< next linked list node */
ecma_string_t *imex_name_p; /**< Import/export name of the item */
ecma_string_t *local_name_p; /**< Local name of the item */
} ecma_module_names_t;
typedef struct ecma_module ecma_module_t;
/**
* Module node to store imports / exports.
*/
typedef struct ecma_module_node
{
struct ecma_module_node *next_p; /**< next linked list node */
ecma_module_names_t *module_names_p; /**< names of the requested import/export node */
ecma_module_t *module_request_p; /**< module structure of the requested module */
} ecma_module_node_t;
/**
* Module context containing all import and export nodes.
*/
typedef struct ecma_module_context
{
struct ecma_module_context *parent_p; /**< parent context */
ecma_module_node_t *imports_p; /**< import item of the current context */
ecma_module_node_t *local_exports_p; /**< export item of the current context */
ecma_module_node_t *indirect_exports_p; /**< export item of the current context */
ecma_module_node_t *star_exports_p; /**< export item of the current context */
ecma_module_t *module_p; /**< module request */
} ecma_module_context_t;
/**
* An enum identifing the current state of the module
*/
typedef enum
{
ECMA_MODULE_STATE_INIT = 0, /**< module is initialized */
ECMA_MODULE_STATE_PARSING = 1, /**< module is currently being parsed */
ECMA_MODULE_STATE_PARSED = 2, /**< module has been parsed */
ECMA_MODULE_STATE_EVALUATING = 3, /**< module is currently being evaluated */
ECMA_MODULE_STATE_EVALUATED = 4, /**< module has been evaluated */
} ecma_module_state_t;
/**
* Module structure storing an instance of a module
*/
struct ecma_module
{
struct ecma_module *next_p; /**< next linked list node */
ecma_module_state_t state; /**< state of the mode */
ecma_string_t *path_p; /**< path of the module */
ecma_module_context_t *context_p; /**< module context of the module */
ecma_compiled_code_t *compiled_code_p; /**< compiled code of the module */
ecma_object_t *scope_p; /**< lexica lenvironment of the module */
ecma_object_t *namespace_object_p; /**< namespace import object of the module */
};
/**
* A record that can be used to store {module, identifier} pairs
*/
typedef struct ecma_module_record
{
ecma_module_t *module_p; /**< module */
ecma_string_t *name_p; /**< identifier name */
} ecma_module_record_t;
/**
* A list of module records that can be used to identify circular imports during resolution
*/
typedef struct ecma_module_resolve_set
{
struct ecma_module_resolve_set *next_p; /**< next in linked list */
ecma_module_record_t record; /**< module record */
} ecma_module_resolve_set_t;
/**
* A list that is used like a stack to drive the resolution process, instead of recursion.
*/
typedef struct ecma_module_resolve_stack
{
struct ecma_module_resolve_stack *next_p; /**< next in linked list */
ecma_module_t *module_p; /**< module request */
ecma_string_t *export_name_p; /**< export identifier name */
bool resolving; /**< flag storing wether the current frame started resolving */
} ecma_module_resolve_stack_t;
bool ecma_module_resolve_set_insert (ecma_module_resolve_set_t **set_p,
ecma_module_t * const module_p,
ecma_string_t * const export_name_p);
void ecma_module_resolve_set_cleanup (ecma_module_resolve_set_t *set_p);
void ecma_module_resolve_stack_push (ecma_module_resolve_stack_t **stack_p,
ecma_module_t * const module_p,
ecma_string_t * const export_name_p);
void ecma_module_resolve_stack_pop (ecma_module_resolve_stack_t **stack_p);
ecma_string_t *ecma_module_create_normalized_path (const uint8_t *char_p,
prop_length_t size);
ecma_module_t *ecma_module_find_or_create_module (ecma_string_t * const path_p);
ecma_value_t ecma_module_connect_imports (void);
ecma_value_t ecma_module_parse_modules (void);
ecma_value_t ecma_module_check_indirect_exports (void);
void ecma_module_release_module_names (ecma_module_names_t *module_name_p);
void ecma_module_cleanup (void);
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
#endif /* !ECMA_MODULE_H */
+155 -72
View File
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +17,7 @@
#include "ecma-helpers.h"
#include "ecma-property-hashmap.h"
#include "jrt-libc-includes.h"
#include "jcontext.h"
/** \addtogroup ecma ECMA
* @{
@@ -26,7 +26,7 @@
* @{
*/
#ifndef CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
#if ENABLED (JERRY_PROPRETY_HASHMAP)
/**
* Compute the total size of the property hashmap.
@@ -42,7 +42,7 @@
/**
* Stepping values for searching items in the hashmap.
*/
static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS] JERRY_CONST_DATA =
static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS] JERRY_ATTR_CONST_DATA =
{
3, 5, 7, 11, 13, 17, 19, 23
};
@@ -65,7 +65,7 @@ static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF
#define ECMA_PROPERTY_HASHMAP_SET_BIT(byte_p, index) \
((byte_p)[(index) >> 3] = (uint8_t) ((byte_p)[(index) >> 3] | (1 << ((index) & 0x7))))
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
/**
* Create a new property hashmap for the object.
@@ -74,23 +74,32 @@ static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF
void
ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
{
#ifndef CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
JERRY_ASSERT (ecma_get_property_list (object_p) != NULL);
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (ecma_get_property_list (object_p)));
uint32_t named_property_count = 0;
#if ENABLED (JERRY_PROPRETY_HASHMAP)
if (JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) != ECMA_PROP_HASHMAP_ALLOC_ON)
{
return;
}
ecma_property_header_t *prop_iter_p = ecma_get_property_list (object_p);
if (prop_iter_p == NULL)
{
return;
}
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
uint32_t named_property_count = 0;
while (prop_iter_p != NULL)
{
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
{
ecma_property_types_t type = ECMA_PROPERTY_GET_TYPE (prop_iter_p->types + i);
ecma_property_types_t type = ECMA_PROPERTY_GET_TYPE (prop_iter_p->types[i]);
if (type == ECMA_PROPERTY_TYPE_NAMEDDATA || type == ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
if (type != ECMA_PROPERTY_TYPE_SPECIAL)
{
named_property_count++;
}
@@ -99,6 +108,11 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
prop_iter_p->next_property_cp);
}
if (named_property_count < (ECMA_PROPERTY_HASMAP_MINIMUM_SIZE / 2))
{
return;
}
/* The max_property_count must be power of 2. */
uint32_t max_property_count = ECMA_PROPERTY_HASMAP_MINIMUM_SIZE;
@@ -119,10 +133,12 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
memset (hashmap_p, 0, total_size);
hashmap_p->header.types[0].type_and_flags = ECMA_PROPERTY_TYPE_HASHMAP;
hashmap_p->header.types[0] = ECMA_PROPERTY_TYPE_HASHMAP;
hashmap_p->header.types[1] = 0;
hashmap_p->header.next_property_cp = object_p->property_list_or_bound_object_cp;
hashmap_p->max_property_count = max_property_count;
hashmap_p->null_count = max_property_count - named_property_count;
hashmap_p->unused_count = max_property_count - named_property_count;
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
uint8_t *bits_p = (uint8_t *) (pair_list_p + max_property_count);
@@ -130,20 +146,13 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
uint8_t shift_counter = 0;
if (max_property_count <= LIT_STRING_HASH_LIMIT)
while (max_property_count > LIT_STRING_HASH_LIMIT)
{
hashmap_p->header.types[1].type_and_flags = 0;
}
else
{
while (max_property_count > LIT_STRING_HASH_LIMIT)
{
shift_counter++;
max_property_count >>= 1;
}
shift_counter++;
max_property_count >>= 1;
}
hashmap_p->header.types[1].type_and_flags = shift_counter;
hashmap_p->header.types[1] = shift_counter;
prop_iter_p = ecma_get_property_list (object_p);
ECMA_SET_POINTER (object_p->property_list_or_bound_object_cp, hashmap_p);
@@ -154,18 +163,15 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
{
ecma_property_types_t type = ECMA_PROPERTY_GET_TYPE (prop_iter_p->types + i);
if (!(type == ECMA_PROPERTY_TYPE_NAMEDDATA || type == ECMA_PROPERTY_TYPE_NAMEDACCESSOR))
if (!ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i]))
{
continue;
}
ecma_property_pair_t *property_pair_p = (ecma_property_pair_t *) prop_iter_p;
ecma_string_t *name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
property_pair_p->names_cp[i]);
uint32_t entry_index = name_p->hash;
uint32_t entry_index = ecma_string_get_property_name_hash (prop_iter_p->types[i],
property_pair_p->names_cp[i]);
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
if (mask < LIT_STRING_HASH_LIMIT)
@@ -208,9 +214,9 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t,
prop_iter_p->next_property_cp);
}
#else /* CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
JERRY_UNUSED (object_p);
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
} /* ecma_property_hashmap_create */
/**
@@ -220,12 +226,11 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
void
ecma_property_hashmap_free (ecma_object_t *object_p) /**< object */
{
#ifndef CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
#if ENABLED (JERRY_PROPRETY_HASHMAP)
/* Property hash must be exists and must be the first property. */
ecma_property_header_t *property_p = ecma_get_property_list (object_p);
JERRY_ASSERT (property_p != NULL
&& ECMA_PROPERTY_GET_TYPE (property_p->types + 0) == ECMA_PROPERTY_TYPE_HASHMAP);
JERRY_ASSERT (property_p != NULL && property_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) property_p;
@@ -233,9 +238,9 @@ ecma_property_hashmap_free (ecma_object_t *object_p) /**< object */
jmem_heap_free_block (hashmap_p,
ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (hashmap_p->max_property_count));
#else /* CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
JERRY_UNUSED (object_p);
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
} /* ecma_property_hashmap_free */
/**
@@ -247,11 +252,11 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
ecma_property_pair_t *property_pair_p, /**< property pair */
int property_index) /**< property index in the pair (0 or 1) */
{
#ifndef CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
#if ENABLED (JERRY_PROPRETY_HASHMAP)
ecma_property_hashmap_t *hashmap_p = ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t,
object_p->property_list_or_bound_object_cp);
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (hashmap_p->header.types + 0) == ECMA_PROPERTY_TYPE_HASHMAP);
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
/* The NULLs are reduced below 1/8 of the hashmap. */
if (hashmap_p->null_count < (hashmap_p->max_property_count >> 3))
@@ -263,7 +268,7 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
JERRY_ASSERT (property_index < ECMA_PROPERTY_PAIR_ITEM_COUNT);
uint32_t entry_index = name_p->hash;
uint32_t entry_index = ecma_string_hash (name_p);
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
uint32_t mask = hashmap_p->max_property_count - 1;
@@ -273,7 +278,7 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
}
else
{
entry_index <<= hashmap_p->header.types[1].type_and_flags;
entry_index <<= hashmap_p->header.types[1];
}
#ifndef JERRY_NDEBUG
@@ -306,6 +311,9 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
JERRY_ASSERT (hashmap_p->null_count > 0);
}
hashmap_p->unused_count--;
JERRY_ASSERT (hashmap_p->unused_count > 0);
if (property_index == 0)
{
*bits_p = (uint8_t) ((*bits_p) & ~mask);
@@ -314,29 +322,40 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
{
*bits_p = (uint8_t) ((*bits_p) | mask);
}
#else /* CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
JERRY_UNUSED (object_p);
JERRY_UNUSED (name_p);
JERRY_UNUSED (property_pair_p);
JERRY_UNUSED (property_index);
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
} /* ecma_property_hashmap_insert */
/**
* Delete named property from the hashmap.
*
* @return ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP if hashmap should be recreated
* ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP otherwise
*/
void
ecma_property_hashmap_delete_status
ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
ecma_string_t *name_p, /**< name of the property */
jmem_cpointer_t name_cp, /**< property name */
ecma_property_t *property_p) /**< property */
{
#ifndef CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
#if ENABLED (JERRY_PROPRETY_HASHMAP)
ecma_property_hashmap_t *hashmap_p = ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t,
object_p->property_list_or_bound_object_cp);
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (hashmap_p->header.types + 0) == ECMA_PROPERTY_TYPE_HASHMAP);
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
uint32_t entry_index = name_p->hash;
hashmap_p->unused_count++;
/* The NULLs are above 3/4 of the hashmap. */
if (hashmap_p->unused_count > ((hashmap_p->max_property_count * 3) >> 2))
{
return ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP;
}
uint32_t entry_index = ecma_string_get_property_name_hash (*property_p, name_cp);
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
uint32_t mask = hashmap_p->max_property_count - 1;
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
@@ -348,7 +367,7 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
}
else
{
entry_index <<= hashmap_p->header.types[1].type_and_flags;
entry_index <<= hashmap_p->header.types[1];
JERRY_ASSERT (entry_index <= mask);
}
@@ -362,6 +381,7 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
if (pair_list_p[entry_index] != ECMA_NULL_POINTER)
{
size_t offset = 0;
if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
{
offset = 1;
@@ -372,13 +392,11 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
if ((property_pair_p->header.types + offset) == property_p)
{
JERRY_ASSERT (ecma_compare_ecma_strings (ECMA_GET_NON_NULL_POINTER (ecma_string_t,
property_pair_p->names_cp[offset]),
name_p));
JERRY_ASSERT (property_pair_p->names_cp[offset] == name_cp);
pair_list_p[entry_index] = ECMA_NULL_POINTER;
ECMA_PROPERTY_HASHMAP_SET_BIT (bits_p, entry_index);
return;
return ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP;
}
}
else
@@ -393,14 +411,16 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
JERRY_ASSERT (entry_index != start_entry_index);
#endif /* !JERRY_NDEBUG */
}
#else /* CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
JERRY_UNUSED (object_p);
JERRY_UNUSED (name_p);
JERRY_UNUSED (name_cp);
JERRY_UNUSED (property_p);
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
return ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP;
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
} /* ecma_property_hashmap_delete */
#ifndef CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
#if ENABLED (JERRY_PROPRETY_HASHMAP)
/**
* Find a named property.
*
@@ -409,7 +429,7 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
ecma_property_t *
ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
ecma_string_t *name_p, /**< property name */
ecma_string_t **property_real_name_p) /**< [out] property real name */
jmem_cpointer_t *property_real_name_cp) /**< [out] property real name */
{
#ifndef JERRY_NDEBUG
/* A sanity check in debug mode: a named property must be present
@@ -428,12 +448,11 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
{
if (prop_pair_p->names_cp[i] != ECMA_NULL_POINTER)
if (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i]))
{
ecma_string_t *property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
prop_pair_p->names_cp[i]);
if (ecma_compare_ecma_strings (name_p, property_name_p))
if (ecma_string_compare_to_property_name (prop_iter_p->types[i],
prop_pair_p->names_cp[i],
name_p))
{
property_found = true;
break;
@@ -446,7 +465,7 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
}
#endif /* !JERRY_NDEBUG */
uint32_t entry_index = name_p->hash;
uint32_t entry_index = ecma_string_hash (name_p);
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
uint32_t mask = hashmap_p->max_property_count - 1;
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
@@ -458,7 +477,7 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
}
else
{
entry_index <<= hashmap_p->header.types[1].type_and_flags;
entry_index <<= hashmap_p->header.types[1];
JERRY_ASSERT (entry_index <= mask);
}
@@ -467,6 +486,62 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
uint32_t start_entry_index = entry_index;
#endif /* !JERRY_NDEBUG */
if (ECMA_IS_DIRECT_STRING (name_p))
{
ecma_property_t prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (name_p);
jmem_cpointer_t property_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (name_p);
JERRY_ASSERT (prop_name_type > 0);
while (true)
{
if (pair_list_p[entry_index] != ECMA_NULL_POINTER)
{
size_t offset = 0;
if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
{
offset = 1;
}
ecma_property_pair_t *property_pair_p = ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t,
pair_list_p[entry_index]);
ecma_property_t *property_p = property_pair_p->header.types + offset;
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p));
if (property_pair_p->names_cp[offset] == property_name_cp
&& ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == prop_name_type)
{
#ifndef JERRY_NDEBUG
JERRY_ASSERT (property_found);
#endif /* !JERRY_NDEBUG */
*property_real_name_cp = property_name_cp;
return property_p;
}
}
else
{
if (!ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
{
#ifndef JERRY_NDEBUG
JERRY_ASSERT (!property_found);
#endif /* !JERRY_NDEBUG */
return NULL;
}
/* Otherwise it is a deleted entry. */
}
entry_index = (entry_index + step) & mask;
#ifndef JERRY_NDEBUG
JERRY_ASSERT (entry_index != start_entry_index);
#endif /* !JERRY_NDEBUG */
}
}
while (true)
{
if (pair_list_p[entry_index] != ECMA_NULL_POINTER)
@@ -480,16 +555,23 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
ecma_property_pair_t *property_pair_p = ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t,
pair_list_p[entry_index]);
ecma_string_t *property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
property_pair_p->names_cp[offset]);
ecma_property_t *property_p = property_pair_p->header.types + offset;
if (ecma_compare_ecma_strings (name_p, property_name_p))
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p));
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_PTR)
{
ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, property_pair_p->names_cp[offset]);
if (ecma_compare_ecma_non_direct_strings (prop_name_p, name_p))
{
#ifndef JERRY_NDEBUG
JERRY_ASSERT (property_found);
JERRY_ASSERT (property_found);
#endif /* !JERRY_NDEBUG */
*property_real_name_p = property_name_p;
return property_pair_p->header.types + offset;
*property_real_name_cp = property_pair_p->names_cp[offset];
return property_p;
}
}
}
else
@@ -499,6 +581,7 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
#ifndef JERRY_NDEBUG
JERRY_ASSERT (!property_found);
#endif /* !JERRY_NDEBUG */
return NULL;
}
/* Otherwise it is a deleted entry. */
@@ -511,7 +594,7 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
#endif /* !JERRY_NDEBUG */
}
} /* ecma_property_hashmap_find */
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
/**
* @}
+22 -9
View File
@@ -1,5 +1,4 @@
/* Copyright 2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +36,7 @@ typedef struct
ecma_property_header_t header; /**< header of the property */
uint32_t max_property_count; /**< maximum property count (power of 2) */
uint32_t null_count; /**< number of NULLs in the map */
uint32_t unused_count; /**< number of unused entires in the map */
/*
* The hash is followed by max_property_count ecma_cpointer_t
@@ -53,14 +53,27 @@ typedef struct
*/
} ecma_property_hashmap_t;
extern void ecma_property_hashmap_create (ecma_object_t *);
extern void ecma_property_hashmap_free (ecma_object_t *);
extern void ecma_property_hashmap_insert (ecma_object_t *, ecma_string_t *, ecma_property_pair_t *, int);
extern void ecma_property_hashmap_delete (ecma_object_t *, ecma_string_t *, ecma_property_t *);
/**
* Simple ecma values
*/
typedef enum
{
ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP, /**< object has no hashmap */
ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP, /**< object has hashmap */
ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP, /**< hashmap should be recreated */
} ecma_property_hashmap_delete_status;
#ifndef CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE
extern ecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *, ecma_string_t *, ecma_string_t **);
#endif /* !CONFIG_ECMA_PROPERTY_HASHMAP_DISABLE */
void ecma_property_hashmap_create (ecma_object_t *object_p);
void ecma_property_hashmap_free (ecma_object_t *object_p);
void ecma_property_hashmap_insert (ecma_object_t *object_p, ecma_string_t *name_p,
ecma_property_pair_t *property_pair_p, int property_index);
ecma_property_hashmap_delete_status ecma_property_hashmap_delete (ecma_object_t *object_p, jmem_cpointer_t name_cp,
ecma_property_t *property_p);
#if ENABLED (JERRY_PROPRETY_HASHMAP)
ecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, ecma_string_t *name_p,
jmem_cpointer_t *property_real_name_cp);
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
/**
* @}
@@ -0,0 +1,209 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-builtin-helpers.h"
#include "ecma-builtins.h"
#include "ecma-iterator-object.h"
#include "ecma-typedarray-object.h"
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
#if !ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
#error "Iterator builtin requires ES2015 symbol builtin"
#endif /* !ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array-iterator-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID array_iterator_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup %arrayiteratorprototype% ECMA %ArrayIteratorPrototype% object built-in
* @{
*/
/**
* The %ArrayIteratorPrototype% object's 'next' routine
*
* See also:
* ECMA-262 v6, 22.1.5.2.1
*
* Note:
* Returned value must be freed with ecma_free_value.
*
* @return iterator result object, if success
* error - otherwise
*/
static ecma_value_t
ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< this argument */
{
/* 1 - 2. */
if (!ecma_is_value_object (this_val))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an object."));
}
ecma_object_t *obj_p = ecma_get_object_from_value (this_val);
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
/* 3. */
if (ecma_get_object_type (obj_p) != ECMA_OBJECT_TYPE_PSEUDO_ARRAY
|| ext_obj_p->u.pseudo_array.type != ECMA_PSEUDO_ARRAY_ITERATOR)
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an iterator."));
}
ecma_value_t iterated_value = ext_obj_p->u.pseudo_array.u2.iterated_value;
/* 4 - 5 */
if (ecma_is_value_empty (iterated_value))
{
return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE);
}
ecma_object_t *array_object_p = ecma_get_object_from_value (iterated_value);
uint32_t length;
/* 8 - 9. */
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
if (ecma_is_typedarray (ecma_make_object_value (array_object_p)))
{
length = ecma_typedarray_get_length (array_object_p);
}
else
{
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
ecma_value_t len_value = ecma_op_object_get (array_object_p,
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH));
if (ECMA_IS_VALUE_ERROR (len_value))
{
return len_value;
}
ecma_number_t length_number;
ecma_value_t length_value = ecma_get_number (len_value, &length_number);
if (ECMA_IS_VALUE_ERROR (length_value))
{
ecma_free_value (len_value);
return length_value;
}
length = ecma_number_to_uint32 (length_number);
ecma_free_value (len_value);
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
uint32_t index = ext_obj_p->u.pseudo_array.u1.iterator_index;
if (JERRY_UNLIKELY (index == ECMA_ITERATOR_INDEX_LIMIT))
{
/* After the ECMA_ITERATOR_INDEX_LIMIT limit is reached the [[%Iterator%NextIndex]]
property is stored as an internal property */
ecma_string_t *prop_name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX);
ecma_value_t index_value = ecma_op_object_get (obj_p, prop_name_p);
if (!ecma_is_value_undefined (index_value))
{
index = (uint32_t) (ecma_get_number_from_value (index_value) + 1);
}
ecma_value_t put_result = ecma_op_object_put (obj_p,
prop_name_p,
ecma_make_uint32_value (index),
true);
JERRY_ASSERT (ecma_is_value_true (put_result));
ecma_free_value (index_value);
}
else
{
/* 11. */
ext_obj_p->u.pseudo_array.u1.iterator_index++;
}
if (index >= length)
{
ext_obj_p->u.pseudo_array.u2.iterated_value = ECMA_VALUE_EMPTY;
return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE);
}
/* 7. */
uint8_t iterator_type = ext_obj_p->u.pseudo_array.extra_info;
if (iterator_type == ECMA_ITERATOR_KEYS)
{
/* 12. */
return ecma_create_iter_result_object (ecma_make_uint32_value (index), ECMA_VALUE_FALSE);
}
/* 13. */
ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index);
/* 14. */
ecma_value_t get_value = ecma_op_object_get (array_object_p, index_string_p);
ecma_deref_ecma_string (index_string_p);
/* 15. */
if (ECMA_IS_VALUE_ERROR (get_value))
{
return get_value;
}
ecma_value_t result;
/* 16. */
if (iterator_type == ECMA_ITERATOR_VALUES)
{
result = ecma_create_iter_result_object (get_value, ECMA_VALUE_FALSE);
}
else
{
/* 17.a */
JERRY_ASSERT (iterator_type == ECMA_ITERATOR_KEYS_VALUES);
/* 17.b */
ecma_value_t entry_array_value;
entry_array_value = ecma_create_array_from_iter_element (get_value,
ecma_make_uint32_value (index));
result = ecma_create_iter_result_object (entry_array_value, ECMA_VALUE_FALSE);
ecma_free_value (entry_array_value);
}
ecma_free_value (get_value);
return result;
} /* ecma_builtin_array_iterator_prototype_object_next */
/**
* @}
* @}
* @}
*/
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
@@ -0,0 +1,34 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* %ArrayIteratorPrototype% built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
LIT_MAGIC_STRING_ARRAY_ITERATOR_UL,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_NEXT, ecma_builtin_array_iterator_prototype_object_next, 0, 0)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
* Copyright 2015 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,29 +17,14 @@
* Array.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#include "ecma-builtin-helpers-macro-defines.inc.h"
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_attributes)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE)
#if ENABLED (JERRY_BUILTIN_ARRAY)
/* Object properties:
* (property name, object pointer getter) */
// 15.4.4.1
/* ECMA-262 v5, 15.4.4.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
@@ -48,39 +32,47 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
/* Number properties:
* (property name, object pointer getter) */
// 15.4.4
/* ECMA-262 v5, 15.4.4 */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
0,
ECMA_PROPERTY_FLAG_WRITABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_array_prototype_object_to_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_array_prototype_object_to_locale_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_CONCAT, ecma_builtin_array_prototype_object_concat, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_JOIN, ecma_builtin_array_prototype_join, 1, 1)
ROUTINE (LIT_MAGIC_STRING_POP, ecma_builtin_array_prototype_object_pop, 0, 0)
ROUTINE (LIT_MAGIC_STRING_PUSH, ecma_builtin_array_prototype_object_push, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_REVERSE, ecma_builtin_array_prototype_object_reverse, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SHIFT, ecma_builtin_array_prototype_object_shift, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_array_prototype_object_slice, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SORT, ecma_builtin_array_prototype_object_sort, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SPLICE, ecma_builtin_array_prototype_object_splice, NON_FIXED, 2)
ROUTINE (LIT_MAGIC_STRING_UNSHIFT, ecma_builtin_array_prototype_object_unshift, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ecma_builtin_array_prototype_object_index_of, 2, 1)
ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ecma_builtin_array_prototype_object_last_index_of, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_EVERY, ecma_builtin_array_prototype_object_every, 2, 1)
ROUTINE (LIT_MAGIC_STRING_SOME, ecma_builtin_array_prototype_object_some, 2, 1)
ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ecma_builtin_array_prototype_object_for_each, 2, 1)
ROUTINE (LIT_MAGIC_STRING_MAP, ecma_builtin_array_prototype_object_map, 2, 1)
ROUTINE (LIT_MAGIC_STRING_FILTER, ecma_builtin_array_prototype_object_filter, 2, 1)
ROUTINE (LIT_MAGIC_STRING_REDUCE, ecma_builtin_array_prototype_object_reduce, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ecma_builtin_array_prototype_object_reduce_right, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_ARRAY_PROTOTYPE_TO_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_ARRAY_PROTOTYPE_TO_LOCALE_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_CONCAT, ECMA_ARRAY_PROTOTYPE_CONCAT, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_JOIN, ECMA_ARRAY_PROTOTYPE_JOIN, 1, 1)
ROUTINE (LIT_MAGIC_STRING_POP, ECMA_ARRAY_PROTOTYPE_POP, 0, 0)
ROUTINE (LIT_MAGIC_STRING_PUSH, ECMA_ARRAY_PROTOTYPE_PUSH, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_REVERSE, ECMA_ARRAY_PROTOTYPE_REVERSE, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SHIFT, ECMA_ARRAY_PROTOTYPE_SHIFT, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SLICE, ECMA_ARRAY_PROTOTYPE_SLICE, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SORT, ECMA_ARRAY_PROTOTYPE_SORT, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SPLICE, ECMA_ARRAY_PROTOTYPE_SPLICE, NON_FIXED, 2)
ROUTINE (LIT_MAGIC_STRING_UNSHIFT, ECMA_ARRAY_PROTOTYPE_UNSHIFT, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ECMA_ARRAY_PROTOTYPE_INDEX_OF, 2, 1)
ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ECMA_ARRAY_PROTOTYPE_LAST_INDEX_OF, NON_FIXED, 1)
/* Note these 3 routines must be in this order */
ROUTINE (LIT_MAGIC_STRING_EVERY, ECMA_ARRAY_PROTOTYPE_EVERY, 2, 1)
ROUTINE (LIT_MAGIC_STRING_SOME, ECMA_ARRAY_PROTOTYPE_SOME, 2, 1)
ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ECMA_ARRAY_PROTOTYPE_FOR_EACH, 2, 1)
ROUTINE (LIT_MAGIC_STRING_MAP, ECMA_ARRAY_PROTOTYPE_MAP, 2, 1)
ROUTINE (LIT_MAGIC_STRING_FILTER, ECMA_ARRAY_PROTOTYPE_FILTER, 2, 1)
/* Note these 2 routines must be in this order */
ROUTINE (LIT_MAGIC_STRING_REDUCE, ECMA_ARRAY_PROTOTYPE_REDUCE, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ECMA_ARRAY_PROTOTYPE_REDUCE_RIGHT, NON_FIXED, 1)
#if ENABLED (JERRY_ES2015_BUILTIN)
ROUTINE (LIT_MAGIC_STRING_FIND, ECMA_ARRAY_PROTOTYPE_FIND, 2, 1)
ROUTINE (LIT_MAGIC_STRING_FIND_INDEX, ECMA_ARRAY_PROTOTYPE_FIND_INDEX, 2, 1)
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
ROUTINE (LIT_MAGIC_STRING_ENTRIES, ECMA_ARRAY_PROTOTYPE_ENTRIES, 0, 0)
ROUTINE (LIT_MAGIC_STRING_VALUES, ECMA_ARRAY_PROTOTYPE_VALUES, 0, 0)
ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_ARRAY_PROTOTYPE_KEYS, 0, 0)
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ECMA_ARRAY_PROTOTYPE_SYMBOL_ITERATOR, 0, 0)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -1,4 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
#if ENABLED (JERRY_BUILTIN_ARRAY)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
@@ -58,7 +58,7 @@ ecma_builtin_array_object_is_array (ecma_value_t this_arg, /**< 'this' argument
ecma_value_t arg) /**< first argument */
{
JERRY_UNUSED (this_arg);
ecma_simple_value_t is_array = ECMA_SIMPLE_VALUE_FALSE;
ecma_value_t is_array = ECMA_VALUE_FALSE;
if (ecma_is_value_object (arg))
{
@@ -66,11 +66,11 @@ ecma_builtin_array_object_is_array (ecma_value_t this_arg, /**< 'this' argument
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_ARRAY_UL)
{
is_array = ECMA_SIMPLE_VALUE_TRUE;
is_array = ECMA_VALUE_TRUE;
}
}
return ecma_make_simple_value (is_array);
return is_array;
} /* ecma_builtin_array_object_is_array */
/**
@@ -107,4 +107,4 @@ ecma_builtin_array_dispatch_construct (const ecma_value_t *arguments_list_p, /**
* @}
*/
#endif /* !CONFIG_DISABLE_ARRAY_BUILTIN */
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,29 +17,14 @@
* Array description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#include "ecma-builtin-helpers-macro-defines.inc.h"
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_attributes)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY)
#if ENABLED (JERRY_BUILTIN_ARRAY)
/* Object properties:
* (property name, object pointer getter) */
// 15.4.3.1
/* ECMA-262 v5, 15.4.3.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_BUILTIN_ID_ARRAY_PROTOTYPE,
ECMA_PROPERTY_FIXED)
@@ -47,7 +32,7 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
/* Number properties:
* (property name, object pointer getter) */
// 15.4.3
/* ECMA-262 v5, 15.4.3 */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_FIXED)
@@ -56,10 +41,6 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#endif /* !(ENABLED (JERRY_BUILTIN_ARRAY)) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -0,0 +1,146 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-builtin-helpers.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-arraybuffer-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#include "jrt-libc-includes.h"
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID arraybuffer_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup arraybufferprototype ECMA ArrayBuffer.prototype object built-in
* @{
*/
/**
* The ArrayBuffer.prototype.bytelength accessor
*
* See also:
* ES2015, 24.1.4.1
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */
{
if (ecma_is_value_object (this_arg))
{
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL))
{
ecma_length_t len = ecma_arraybuffer_get_length (object_p);
return ecma_make_uint32_value (len);
}
}
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a ArrayBuffer object."));
} /* ecma_builtin_arraybuffer_prototype_bytelength_getter */
/**
* The ArrayBuffer.prototype object's 'slice' routine
*
* See also:
* ES2015, 24.1.4.3
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< this argument */
ecma_value_t arg1, /**< routine's first argument */
ecma_value_t arg2) /**< routine's second argument */
{
if (!ecma_is_value_object (this_arg))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not object."));
}
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
if (!ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an ArrayBuffer object."));
}
ecma_length_t len = ecma_arraybuffer_get_length (object_p);
ecma_length_t start = 0, end = len;
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ECMA_OP_TO_NUMBER_TRY_CATCH (start_num,
arg1,
ret_value);
start = ecma_builtin_helper_array_index_normalize (start_num, len);
if (!ecma_is_value_undefined (arg2))
{
ECMA_OP_TO_NUMBER_TRY_CATCH (end_num,
arg2,
ret_value);
end = ecma_builtin_helper_array_index_normalize (end_num, len);
ECMA_OP_TO_NUMBER_FINALIZE (end_num);
}
ECMA_OP_TO_NUMBER_FINALIZE (start_num);
if (ret_value != ECMA_VALUE_EMPTY)
{
return ret_value;
}
JERRY_ASSERT (start <= len && end <= len);
ecma_length_t new_len = (end >= start) ? (end - start) : 0;
ecma_object_t *new_arraybuffer_p = ecma_arraybuffer_new_object (new_len);
lit_utf8_byte_t *old_buf = ecma_arraybuffer_get_buffer (object_p);
lit_utf8_byte_t *new_buf = ecma_arraybuffer_get_buffer (new_arraybuffer_p);
memcpy (new_buf, old_buf + start, new_len);
return ecma_make_object_value (new_arraybuffer_p);
} /* ecma_builtin_arraybuffer_prototype_object_slice */
/**
* @}
* @}
* @}
*/
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
@@ -0,0 +1,49 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* ArrayBuffer.prototype built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
/* Object properties:
* (property name, object pointer getter) */
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_ARRAYBUFFER,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
/* Readonly accessor properties */
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
ecma_builtin_arraybuffer_prototype_bytelength_getter,
ECMA_PROPERTY_FIXED)
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
/* ECMA-262 v6, 24.1.4.4 */
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, 2, 2)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -0,0 +1,103 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-arraybuffer-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer.inc.h"
#define BUILTIN_UNDERSCORED_ID arraybuffer
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup arraybuffer ECMA ArrayBuffer object built-in
* @{
*/
/**
* The ArrayBuffer object's 'isView' routine
*
* See also:
* ES2015 24.1.3.1
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argument */
ecma_value_t arg) /**< argument 1 */
{
JERRY_UNUSED (this_arg);
JERRY_UNUSED (arg);
/* TODO: if arg has [[ViewArrayBuffer]], return true */
return ECMA_VALUE_FALSE;
} /* ecma_builtin_arraybuffer_object_is_view */
/**
* Handle calling [[Call]] of built-in ArrayBuffer object
*
* ES2015 24.1.2 ArrayBuffer is not intended to be called as
* a function and will throw an exception when called in
* that manner.
*
* @return ecma value
*/
ecma_value_t
ecma_builtin_arraybuffer_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor ArrayBuffer requires 'new'"));
} /* ecma_builtin_arraybuffer_dispatch_call */
/**
* Handle calling [[Construct]] of built-in ArrayBuffer object
*
* @return ecma value
*/
ecma_value_t
ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_op_create_arraybuffer_object (arguments_list_p, arguments_list_len);
} /* ecma_builtin_arraybuffer_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
@@ -0,0 +1,46 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* ArrayBuffer built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_FIXED)
/* Object properties:
* (property name, object pointer getter) */
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE,
ECMA_PROPERTY_FIXED)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
/* ES2015 24.1.3.1 */
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
#if ENABLED (JERRY_BUILTIN_BOOLEAN)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
@@ -56,27 +56,23 @@
static ecma_value_t
ecma_builtin_boolean_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ECMA_TRY_CATCH (value_of_ret,
ecma_builtin_boolean_prototype_object_value_of (this_arg),
ret_value);
ecma_string_t *ret_str_p;
if (ecma_is_value_true (value_of_ret))
{
ret_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_TRUE);
ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING_TRUE);
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (value_of_ret));
ret_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_FALSE);
ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING_FALSE);
}
ret_value = ecma_make_string_value (ret_str_p);
ECMA_FINALIZE (value_of_ret);
return ret_value;
@@ -100,20 +96,19 @@ ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this_arg) /**< this
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_BOOLEAN_UL)
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_BOOLEAN_UL))
{
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
JERRY_ASSERT (ecma_is_value_boolean (ecma_get_internal_property_value (prim_value_prop_p)));
JERRY_ASSERT (ecma_is_value_boolean (ext_object_p->u.class_prop.u.value));
return ecma_get_internal_property_value (prim_value_prop_p);
return ext_object_p->u.class_prop.u.value;
}
}
return ecma_raise_type_error (ECMA_ERR_MSG (""));
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a Boolean object."));
} /* ecma_builtin_boolean_prototype_object_value_of */
/**
@@ -122,4 +117,4 @@ ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this_arg) /**< this
* @}
*/
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +17,14 @@
* Boolean.prototype description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_id)
#endif /* !OBJECT_ID */
#include "ecma-builtin-helpers-macro-defines.inc.h"
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE)
#if ENABLED (JERRY_BUILTIN_BOOLEAN)
/* Object properties:
* (property name, object pointer getter) */
// 15.6.4.1
/* ECMA-262 v5, 15.6.4.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_BOOLEAN,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
@@ -45,9 +34,6 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_boolean_prototype_object_to_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_boolean_prototype_object_value_of, 0, 0)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
#if ENABLED (JERRY_BUILTIN_BOOLEAN)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
@@ -59,15 +59,14 @@ ecma_builtin_boolean_dispatch_call (const ecma_value_t *arguments_list_p, /**< a
if (arguments_list_len == 0)
{
arg_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
arg_value = ECMA_VALUE_UNDEFINED;
}
else
{
arg_value = arguments_list_p[0];
}
return ecma_make_simple_value (ecma_op_to_boolean (arg_value) ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE);
return ecma_make_boolean_value (ecma_op_to_boolean (arg_value));
} /* ecma_builtin_boolean_dispatch_call */
/**
@@ -83,7 +82,7 @@ ecma_builtin_boolean_dispatch_construct (const ecma_value_t *arguments_list_p, /
if (arguments_list_len == 0)
{
return ecma_op_create_boolean_object (ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE));
return ecma_op_create_boolean_object (ECMA_VALUE_FALSE);
}
else
{
@@ -97,4 +96,4 @@ ecma_builtin_boolean_dispatch_construct (const ecma_value_t *arguments_list_p, /
* @}
*/
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,29 +17,14 @@
* Boolean description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#include "ecma-builtin-helpers-macro-defines.inc.h"
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_attributes)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN)
#if ENABLED (JERRY_BUILTIN_BOOLEAN)
/* Object properties:
* (property name, object pointer getter) */
// 15.6.3.1
/* ECMA-262 v5, 15.6.3.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
ECMA_PROPERTY_FIXED)
@@ -47,14 +32,11 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
/* Number properties:
* (property name, object pointer getter) */
// 15.6.3
/* ECMA-262 v5, 15.6.3 */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_FIXED)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -0,0 +1,215 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-dataview-object.h"
#include "ecma-gc.h"
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
#ifdef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
#error "DataView builtin requires ES2015 TypedArray builtin"
#endif /* !CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
/**
* This object has a custom dispatch function.
*/
#define BUILTIN_CUSTOM_DISPATCH
/**
* List of built-in routine identifiers.
*/
enum
{
ECMA_DATAVIEW_PROTOTYPE_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1,
ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER,
ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER,
ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER,
ECMA_DATAVIEW_PROTOTYPE_GET_INT8,
ECMA_DATAVIEW_PROTOTYPE_GET_UINT8,
ECMA_DATAVIEW_PROTOTYPE_GET_INT16,
ECMA_DATAVIEW_PROTOTYPE_GET_UINT16,
ECMA_DATAVIEW_PROTOTYPE_GET_INT32,
ECMA_DATAVIEW_PROTOTYPE_GET_UINT32,
ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT32,
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT64,
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
ECMA_DATAVIEW_PROTOTYPE_SET_INT8,
ECMA_DATAVIEW_PROTOTYPE_SET_UINT8,
ECMA_DATAVIEW_PROTOTYPE_SET_INT16,
ECMA_DATAVIEW_PROTOTYPE_SET_UINT16,
ECMA_DATAVIEW_PROTOTYPE_SET_INT32,
ECMA_DATAVIEW_PROTOTYPE_SET_UINT32,
ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32,
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT64,
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
};
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-dataview-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID dataview_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup dataviewprototype ECMA DataView.prototype object built-in
* @{
*/
/**
* Corresponding typedarray mappings for the {get,set}{[U]int, Float}{8, 16, 32, 64} routines
*/
static const uint8_t ecma_dataview_type_mapping[] =
{
ECMA_BUILTIN_ID_INT8ARRAY,
ECMA_BUILTIN_ID_UINT8ARRAY,
ECMA_BUILTIN_ID_INT16ARRAY,
ECMA_BUILTIN_ID_UINT16ARRAY,
ECMA_BUILTIN_ID_INT32ARRAY,
ECMA_BUILTIN_ID_UINT32ARRAY,
ECMA_BUILTIN_ID_FLOAT32ARRAY,
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
ECMA_BUILTIN_ID_FLOAT64ARRAY,
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
};
/**
* The DataView.prototype object's {buffer, byteOffset, byteLength} getters
*
* See also:
* ECMA-262 v6, 24.2.4.1
* ECMA-262 v6, 24.2.4.2
* ECMA-262 v6, 24.2.4.3
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_dataview_prototype_object_getters (ecma_value_t this_arg, /**< this argument */
uint16_t builtin_routine_id) /**< built-in wide routine identifier */
{
ecma_dataview_object_t *obj_p = ecma_op_dataview_get_object (this_arg);
if (JERRY_UNLIKELY (obj_p == NULL))
{
return ECMA_VALUE_ERROR;
}
switch (builtin_routine_id)
{
case ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER:
{
ecma_object_t *buffer_p = obj_p->buffer_p;
ecma_ref_object (buffer_p);
return ecma_make_object_value (buffer_p);
}
case ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER:
{
return ecma_make_uint32_value (obj_p->header.u.class_prop.u.length);
}
default:
{
JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER);
return ecma_make_uint32_value (obj_p->byte_offset);
}
}
} /* ecma_builtin_dataview_prototype_object_getters */
/**
* Dispatcher of the built-in's routines
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
ecma_value_t
ecma_builtin_dataview_prototype_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine identifier */
ecma_value_t this_arg, /**< 'this' argument value */
const ecma_value_t arguments_list_p[], /**< list of arguments
* passed to routine */
ecma_length_t arguments_number) /**< length of arguments' list */
{
ecma_value_t byte_offset = arguments_number > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
switch (builtin_routine_id)
{
case ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER:
case ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER:
case ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER:
{
return ecma_builtin_dataview_prototype_object_getters (this_arg, builtin_routine_id);
}
case ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT32:
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
case ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT64:
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
case ECMA_DATAVIEW_PROTOTYPE_GET_INT16:
case ECMA_DATAVIEW_PROTOTYPE_GET_INT32:
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT16:
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT32:
{
ecma_value_t little_endian = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_FALSE;
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8];
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, ECMA_VALUE_EMPTY, type);
}
case ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32:
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
case ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT64:
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
case ECMA_DATAVIEW_PROTOTYPE_SET_INT16:
case ECMA_DATAVIEW_PROTOTYPE_SET_INT32:
case ECMA_DATAVIEW_PROTOTYPE_SET_UINT16:
case ECMA_DATAVIEW_PROTOTYPE_SET_UINT32:
{
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
ecma_value_t little_endian = arguments_number > 2 ? arguments_list_p[2] : ECMA_VALUE_FALSE;
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8];
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, value_to_set, type);
}
case ECMA_DATAVIEW_PROTOTYPE_GET_INT8:
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT8:
{
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8];
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, ECMA_VALUE_EMPTY, type);
}
default:
{
JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_INT8
|| builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_UINT8);
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8];
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, value_to_set, type);
}
}
} /* ecma_builtin_dataview_prototype_dispatch_routine */
/**
* @}
* @}
* @}
*/
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
@@ -0,0 +1,79 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* DataView.prototype built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
/* Object properties:
* (property name, object pointer getter) */
/* ECMA-262 v6, 24.2.3 */
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_DATAVIEW,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
/* ECMA-262 v6, 23.2.4.21 */
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
LIT_MAGIC_STRING_DATAVIEW_UL,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_GET_FLOAT_32_UL, ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT32, 2, 1)
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
ROUTINE (LIT_MAGIC_STRING_GET_FLOAT_64_UL, ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT64, 2, 1)
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
ROUTINE (LIT_MAGIC_STRING_GET_INT8_UL, ECMA_DATAVIEW_PROTOTYPE_GET_INT8, 1, 1)
ROUTINE (LIT_MAGIC_STRING_GET_INT16_UL, ECMA_DATAVIEW_PROTOTYPE_GET_INT16, 2, 1)
ROUTINE (LIT_MAGIC_STRING_GET_INT32_UL, ECMA_DATAVIEW_PROTOTYPE_GET_INT32, 2, 1)
ROUTINE (LIT_MAGIC_STRING_GET_UINT8_UL, ECMA_DATAVIEW_PROTOTYPE_GET_UINT8, 2, 1)
ROUTINE (LIT_MAGIC_STRING_GET_UINT16_UL, ECMA_DATAVIEW_PROTOTYPE_GET_UINT16, 2, 1)
ROUTINE (LIT_MAGIC_STRING_GET_UINT32_UL, ECMA_DATAVIEW_PROTOTYPE_GET_UINT32, 2, 1)
ROUTINE (LIT_MAGIC_STRING_SET_FLOAT_32_UL, ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32, 2, 1)
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
ROUTINE (LIT_MAGIC_STRING_SET_FLOAT_64_UL, ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT64, 2, 1)
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
ROUTINE (LIT_MAGIC_STRING_SET_INT8_UL, ECMA_DATAVIEW_PROTOTYPE_SET_INT8, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_INT16_UL, ECMA_DATAVIEW_PROTOTYPE_SET_INT16, 2, 1)
ROUTINE (LIT_MAGIC_STRING_SET_INT32_UL, ECMA_DATAVIEW_PROTOTYPE_SET_INT32, 2, 1)
ROUTINE (LIT_MAGIC_STRING_SET_UINT8_UL, ECMA_DATAVIEW_PROTOTYPE_SET_UINT8, 2, 1)
ROUTINE (LIT_MAGIC_STRING_SET_UINT16_UL, ECMA_DATAVIEW_PROTOTYPE_SET_UINT16, 2, 1)
ROUTINE (LIT_MAGIC_STRING_SET_UINT32_UL, ECMA_DATAVIEW_PROTOTYPE_SET_UINT32, 2, 1)
/* ECMA-262 v6, 24.2.4.1 */
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BUFFER,
ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER,
ECMA_PROPERTY_FIXED)
/* ECMA-262 v6, 24.2.4.2 */
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER,
ECMA_PROPERTY_FIXED)
/* ECMA-262 v6, 24.2.4.3 */
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_OFFSET_UL,
ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER,
ECMA_PROPERTY_FIXED)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -0,0 +1,71 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-dataview-object.h"
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-dataview.inc.h"
#define BUILTIN_UNDERSCORED_ID dataview
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup dataview ECMA DataView object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in DataView object
*
* @return ecma value
*/
ecma_value_t
ecma_builtin_dataview_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor DataView requires 'new'."));
} /* ecma_builtin_dataview_dispatch_call */
/**
* Handle calling [[Construct]] of built-in DataView object
*
* @return ecma value
*/
ecma_value_t
ecma_builtin_dataview_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_op_dataview_create (arguments_list_p, arguments_list_len);
} /* ecma_builtin_dataview_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
@@ -0,0 +1,47 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* DataView built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
/* ECMA-262 v6, 23.1.2 */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
3,
ECMA_PROPERTY_FIXED)
/* ECMA-262 v6, 23.1 */
STRING_VALUE (LIT_MAGIC_STRING_NAME,
LIT_MAGIC_STRING_DATAVIEW_UL,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
/* ECMA-262 v6, 23.1.2.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_BUILTIN_ID_DATAVIEW_PROTOTYPE,
ECMA_PROPERTY_FIXED)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,4 @@
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
* Copyright 2015-2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,80 +17,66 @@
* Date.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#include "ecma-builtin-helpers-macro-defines.inc.h"
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_DATE_PROTOTYPE)
#if ENABLED (JERRY_BUILTIN_DATE)
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_DATE,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_date_prototype_to_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_DATE_STRING_UL, ecma_builtin_date_prototype_to_date_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_TIME_STRING_UL, ecma_builtin_date_prototype_to_time_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_date_prototype_to_locale_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_DATE_STRING_UL, ecma_builtin_date_prototype_to_locale_date_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_TIME_STRING_UL, ecma_builtin_date_prototype_to_locale_time_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_date_prototype_value_of, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_TIME_UL, ecma_builtin_date_prototype_get_time, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_FULL_YEAR_UL, ecma_builtin_date_prototype_get_full_year, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_FULL_YEAR_UL, ecma_builtin_date_prototype_get_utc_full_year, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_MONTH_UL, ecma_builtin_date_prototype_get_month, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MONTH_UL, ecma_builtin_date_prototype_get_utc_month, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_DATE_UL, ecma_builtin_date_prototype_get_date, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_DATE_UL, ecma_builtin_date_prototype_get_utc_date, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_DAY_UL, ecma_builtin_date_prototype_get_day, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_DAY_UL, ecma_builtin_date_prototype_get_utc_day, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_HOURS_UL, ecma_builtin_date_prototype_get_hours, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_HOURS_UL, ecma_builtin_date_prototype_get_utc_hours, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_MINUTES_UL, ecma_builtin_date_prototype_get_minutes, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MINUTES_UL, ecma_builtin_date_prototype_get_utc_minutes, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_SECONDS_UL, ecma_builtin_date_prototype_get_seconds, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_SECONDS_UL, ecma_builtin_date_prototype_get_utc_seconds, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_MILLISECONDS_UL, ecma_builtin_date_prototype_get_milliseconds, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MILLISECONDS_UL, ecma_builtin_date_prototype_get_utc_milliseconds, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL, ecma_builtin_date_prototype_get_timezone_offset, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SET_TIME_UL, ecma_builtin_date_prototype_set_time, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_MILLISECONDS_UL, ecma_builtin_date_prototype_set_milliseconds, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MILLISECONDS_UL, ecma_builtin_date_prototype_set_utc_milliseconds, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_SECONDS_UL, ecma_builtin_date_prototype_set_seconds, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_SECONDS_UL, ecma_builtin_date_prototype_set_utc_seconds, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_MINUTES_UL, ecma_builtin_date_prototype_set_minutes, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MINUTES_UL, ecma_builtin_date_prototype_set_utc_minutes, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_SET_HOURS_UL, ecma_builtin_date_prototype_set_hours, NON_FIXED, 4)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_HOURS_UL, ecma_builtin_date_prototype_set_utc_hours, NON_FIXED, 4)
ROUTINE (LIT_MAGIC_STRING_SET_DATE_UL, ecma_builtin_date_prototype_set_date, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_DATE_UL, ecma_builtin_date_prototype_set_utc_date, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_MONTH_UL, ecma_builtin_date_prototype_set_month, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MONTH_UL, ecma_builtin_date_prototype_set_utc_month, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_FULL_YEAR_UL, ecma_builtin_date_prototype_set_full_year, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_FULL_YEAR_UL, ecma_builtin_date_prototype_set_utc_full_year, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_TO_UTC_STRING_UL, ecma_builtin_date_prototype_to_utc_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_ISO_STRING_UL, ecma_builtin_date_prototype_to_iso_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_JSON_UL, ecma_builtin_date_prototype_to_json, 1, 1)
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_DATE_PROTOTYPE_TO_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_DATE_STRING_UL, ECMA_DATE_PROTOTYPE_TO_DATE_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_TIME_STRING_UL, ECMA_DATE_PROTOTYPE_TO_TIME_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_DATE_PROTOTYPE_TO_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_DATE_STRING_UL, ECMA_DATE_PROTOTYPE_TO_DATE_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_TIME_STRING_UL, ECMA_DATE_PROTOTYPE_TO_TIME_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_DATE_PROTOTYPE_GET_TIME, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_TIME_UL, ECMA_DATE_PROTOTYPE_GET_TIME, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_GET_FULL_YEAR, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_GET_UTC_FULL_YEAR, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_MONTH_UL, ECMA_DATE_PROTOTYPE_GET_MONTH, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MONTH_UL, ECMA_DATE_PROTOTYPE_GET_UTC_MONTH, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_DATE_UL, ECMA_DATE_PROTOTYPE_GET_DATE, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_DATE_UL, ECMA_DATE_PROTOTYPE_GET_UTC_DATE, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_DAY_UL, ECMA_DATE_PROTOTYPE_GET_DAY, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_DAY_UL, ECMA_DATE_PROTOTYPE_GET_UTC_DAY, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_HOURS_UL, ECMA_DATE_PROTOTYPE_GET_HOURS, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_HOURS_UL, ECMA_DATE_PROTOTYPE_GET_UTC_HOURS, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_MINUTES_UL, ECMA_DATE_PROTOTYPE_GET_MINUTES, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MINUTES_UL, ECMA_DATE_PROTOTYPE_GET_UTC_MINUTES, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_SECONDS_UL, ECMA_DATE_PROTOTYPE_GET_SECONDS, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_SECONDS_UL, ECMA_DATE_PROTOTYPE_GET_UTC_SECONDS, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_GET_MILLISECONDS, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_GET_UTC_MILLISECONDS, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL, ECMA_DATE_PROTOTYPE_GET_UTC_TIMEZONE_OFFSET, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SET_TIME_UL, ECMA_DATE_PROTOTYPE_SET_TIME, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_SET_MILLISECONDS, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_SET_UTC_MILLISECONDS, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_SECONDS_UL, ECMA_DATE_PROTOTYPE_SET_SECONDS, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_SECONDS_UL, ECMA_DATE_PROTOTYPE_SET_UTC_SECONDS, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_MINUTES_UL, ECMA_DATE_PROTOTYPE_SET_MINUTES, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MINUTES_UL, ECMA_DATE_PROTOTYPE_SET_UTC_MINUTES, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_SET_HOURS_UL, ECMA_DATE_PROTOTYPE_SET_HOURS, NON_FIXED, 4)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_HOURS_UL, ECMA_DATE_PROTOTYPE_SET_UTC_HOURS, NON_FIXED, 4)
ROUTINE (LIT_MAGIC_STRING_SET_DATE_UL, ECMA_DATE_PROTOTYPE_SET_DATE, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_DATE_UL, ECMA_DATE_PROTOTYPE_SET_UTC_DATE, 1, 1)
ROUTINE (LIT_MAGIC_STRING_SET_MONTH_UL, ECMA_DATE_PROTOTYPE_SET_MONTH, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MONTH_UL, ECMA_DATE_PROTOTYPE_SET_UTC_MONTH, 2, 2)
ROUTINE (LIT_MAGIC_STRING_SET_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_SET_FULL_YEAR, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_SET_UTC_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_SET_UTC_FULL_YEAR, NON_FIXED, 3)
ROUTINE (LIT_MAGIC_STRING_TO_UTC_STRING_UL, ECMA_DATE_PROTOTYPE_TO_UTC_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_ISO_STRING_UL, ECMA_DATE_PROTOTYPE_TO_ISO_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_JSON_UL, ECMA_DATE_PROTOTYPE_TO_JSON, 1, 1)
#ifndef CONFIG_DISABLE_ANNEXB_BUILTIN
#if ENABLED (JERRY_BUILTIN_ANNEXB)
ROUTINE (LIT_MAGIC_STRING_GET_YEAR_UL, ecma_builtin_date_prototype_get_year, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SET_YEAR_UL, ecma_builtin_date_prototype_set_year, 1, 1)
ROUTINE (LIT_MAGIC_STRING_TO_GMT_STRING_UL, ecma_builtin_date_prototype_to_utc_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_GET_YEAR_UL, ECMA_DATE_PROTOTYPE_GET_YEAR, 0, 0)
ROUTINE (LIT_MAGIC_STRING_SET_YEAR_UL, ECMA_DATE_PROTOTYPE_SET_YEAR, 1, 1)
ROUTINE (LIT_MAGIC_STRING_TO_GMT_STRING_UL, ECMA_DATE_PROTOTYPE_TO_UTC_STRING, 0, 0)
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
#endif /* ENABLED (JERRY_BUILTIN_ANNEXB) */
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -1,5 +1,4 @@
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
* Copyright 2015-2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,6 +13,8 @@
* limitations under the License.
*/
#include <math.h>
#include "ecma-alloc.h"
#include "ecma-builtin-helpers.h"
#include "ecma-conversion.h"
@@ -24,7 +25,7 @@
#include "ecma-try-catch-macro.h"
#include "lit-char-helpers.h"
#ifndef CONFIG_DISABLE_DATE_BUILTIN
#if ENABLED (JERRY_BUILTIN_DATE)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
@@ -80,7 +81,7 @@ static ecma_value_t
ecma_date_construct_helper (const ecma_value_t *args, /**< arguments passed to the Date constructor */
ecma_length_t args_len) /**< number of arguments */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ecma_number_t prim_value = ecma_number_make_nan ();
ECMA_TRY_CATCH (year_value, ecma_op_to_number (args[0]), ret_value);
@@ -182,7 +183,7 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
ecma_value_t arg) /**< string */
{
JERRY_UNUSED (this_arg);
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ecma_number_t date_num = ecma_number_make_nan ();
/* Date Time String fromat (ECMA-262 v5, 15.9.1.15) */
@@ -264,40 +265,44 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
hours = ECMA_NUMBER_ZERO;
}
/* eat up ':' */
date_str_curr_p++;
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
if (minutes < 0 || minutes > 59)
{
minutes = ecma_number_make_nan ();
}
/* 4.2 read seconds if any */
if (date_str_curr_p < date_str_end_p
&& *date_str_curr_p == ':')
{
/* eat up ':' */
date_str_curr_p++;
seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
if (seconds < 0 || seconds > 59)
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
if (minutes < 0 || minutes > 59)
{
seconds = ecma_number_make_nan ();
minutes = ecma_number_make_nan ();
}
/* 4.3 read milliseconds if any */
/* 4.2 read seconds if any */
if (date_str_curr_p < date_str_end_p
&& *date_str_curr_p == '.')
&& *date_str_curr_p == ':')
{
/* eat up '.' */
/* eat up ':' */
date_str_curr_p++;
milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 3);
seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
if (milliseconds < 0)
if (seconds < 0 || seconds > 59)
{
milliseconds = ecma_number_make_nan ();
seconds = ecma_number_make_nan ();
}
/* 4.3 read milliseconds if any */
if (date_str_curr_p < date_str_end_p
&& *date_str_curr_p == '.')
{
/* eat up '.' */
date_str_curr_p++;
milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 3);
if (milliseconds < 0)
{
milliseconds = ecma_number_make_nan ();
}
}
}
}
@@ -320,11 +325,11 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
else if (date_str_curr_p < date_str_end_p
&& (*date_str_curr_p == '+' || *date_str_curr_p == '-'))
{
ecma_length_t remaining_length;
remaining_length = lit_utf8_string_length (date_str_curr_p,
(lit_utf8_size_t) (date_str_end_p - date_str_curr_p)) - 1;
ecma_length_t remaining_date_length;
remaining_date_length = lit_utf8_string_length (date_str_curr_p,
(lit_utf8_size_t) (date_str_end_p - date_str_curr_p)) - 1;
if (remaining_length == 5)
if (remaining_date_length == 5)
{
bool is_negative = false;
@@ -400,7 +405,7 @@ ecma_builtin_date_utc (ecma_value_t this_arg, /**< this argument */
ecma_length_t args_number) /**< number of arguments */
{
JERRY_UNUSED (this_arg);
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
if (args_number < 2)
{
@@ -434,7 +439,7 @@ static ecma_value_t
ecma_builtin_date_now (ecma_value_t this_arg) /**< this argument */
{
JERRY_UNUSED (this_arg);
return ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (jerry_port_get_current_time ()));
return ecma_make_number_value (floor (DOUBLE_TO_ECMA_NUMBER_T (jerry_port_get_current_time ())));
} /* ecma_builtin_date_now */
/**
@@ -451,10 +456,10 @@ ecma_builtin_date_dispatch_call (const ecma_value_t *arguments_list_p, /**< argu
{
JERRY_UNUSED (arguments_list_p);
JERRY_UNUSED (arguments_list_len);
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ECMA_TRY_CATCH (now_val,
ecma_builtin_date_now (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED)),
ecma_builtin_date_now (ECMA_VALUE_UNDEFINED),
ret_value);
ret_value = ecma_date_value_to_string (ecma_get_number_from_value (now_val));
@@ -476,15 +481,16 @@ ecma_value_t
ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ecma_number_t prim_value_num = ECMA_NUMBER_ZERO;
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_DATE_PROTOTYPE);
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
false,
true,
ECMA_OBJECT_TYPE_GENERAL);
ecma_deref_object (prototype_obj_p);
sizeof (ecma_extended_object_t),
ECMA_OBJECT_TYPE_CLASS);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_UNDEFINED;
if (arguments_list_len == 0)
{
@@ -523,7 +529,7 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
ECMA_FINALIZE (prim_comp_value);
}
else if (arguments_list_len >= 2)
else
{
ECMA_TRY_CATCH (time_value,
ecma_date_construct_helper (arguments_list_p, arguments_list_len),
@@ -534,10 +540,6 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
ECMA_FINALIZE (time_value);
}
else
{
prim_value_num = ecma_number_make_nan ();
}
if (ecma_is_value_empty (ret_value))
{
@@ -546,16 +548,11 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
prim_value_num = ecma_number_make_nan ();
}
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
ecma_set_internal_property_value (class_prop_p, LIT_MAGIC_STRING_DATE_UL);
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_DATE_UL;
ecma_property_t *prim_value_prop_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ecma_number_t *prim_value_num_p = ecma_alloc_number ();
*prim_value_num_p = prim_value_num;
ECMA_SET_INTERNAL_VALUE_POINTER (ECMA_PROPERTY_VALUE_PTR (prim_value_prop_p)->value, prim_value_num_p);
ecma_number_t *date_num_p = ecma_alloc_number ();
*date_num_p = prim_value_num;
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, date_num_p);
ret_value = ecma_make_object_value (obj_p);
}
@@ -574,4 +571,4 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
* @}
*/
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
@@ -1,5 +1,4 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
* Copyright 2015 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,26 +17,11 @@
* Date built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#include "ecma-builtin-helpers-macro-defines.inc.h"
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
#if ENABLED (JERRY_BUILTIN_DATE)
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_attributes)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_DATE)
// ECMA-262 v5, 15.9.4.1
/* ECMA-262 v5, 15.9.4.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_BUILTIN_ID_DATE_PROTOTYPE,
ECMA_PROPERTY_FIXED)
@@ -50,9 +34,6 @@ ROUTINE (LIT_MAGIC_STRING_PARSE, ecma_builtin_date_parse, 1, 1)
ROUTINE (LIT_MAGIC_STRING_UTC_U, ecma_builtin_date_utc, NON_FIXED, 7)
ROUTINE (LIT_MAGIC_STRING_NOW, ecma_builtin_date_now, 0, 0)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -1,5 +1,4 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,61 +55,54 @@
static ecma_value_t
ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
// 2.
/* 2. */
if (!ecma_is_value_object (this_arg))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an object."));
}
else
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_string_t *name_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_NAME);
ECMA_TRY_CATCH (name_get_ret_value,
ecma_op_object_get (obj_p, name_magic_string_p),
ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_NAME),
ret_value);
ecma_value_t name_to_str_completion;
if (ecma_is_value_undefined (name_get_ret_value))
{
ecma_string_t *error_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_ERROR_UL);
name_to_str_completion = ecma_make_string_value (error_magic_string_p);
name_to_str_completion = ecma_make_magic_string_value (LIT_MAGIC_STRING_ERROR_UL);
}
else
{
name_to_str_completion = ecma_op_to_string (name_get_ret_value);
}
if (unlikely (ECMA_IS_VALUE_ERROR (name_to_str_completion)))
if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (name_to_str_completion)))
{
ret_value = ecma_copy_value (name_to_str_completion);
}
else
{
ecma_string_t *message_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE);
ECMA_TRY_CATCH (msg_get_ret_value,
ecma_op_object_get (obj_p, message_magic_string_p),
ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_MESSAGE),
ret_value);
ecma_value_t msg_to_str_completion;
if (ecma_is_value_undefined (msg_get_ret_value))
{
ecma_string_t *empty_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
msg_to_str_completion = ecma_make_string_value (empty_magic_string_p);
msg_to_str_completion = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
}
else
{
msg_to_str_completion = ecma_op_to_string (msg_get_ret_value);
}
if (unlikely (ECMA_IS_VALUE_ERROR (msg_to_str_completion)))
if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (msg_to_str_completion)))
{
ret_value = ecma_copy_value (msg_to_str_completion);
}
@@ -142,7 +134,7 @@ ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this
JMEM_DEFINE_LOCAL_ARRAY (ret_str_buffer, size, lit_utf8_byte_t);
lit_utf8_byte_t *ret_str_buffer_p = ret_str_buffer;
lit_utf8_size_t bytes = ecma_string_copy_to_utf8_buffer (name_string_p, ret_str_buffer_p, name_size);
lit_utf8_size_t bytes = ecma_string_copy_to_cesu8_buffer (name_string_p, ret_str_buffer_p, name_size);
JERRY_ASSERT (bytes == name_size);
ret_str_buffer_p = ret_str_buffer_p + bytes;
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
@@ -157,7 +149,7 @@ ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this
space_size);
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
bytes = ecma_string_copy_to_utf8_buffer (msg_string_p, ret_str_buffer_p, msg_size);
bytes = ecma_string_copy_to_cesu8_buffer (msg_string_p, ret_str_buffer_p, msg_size);
JERRY_ASSERT (bytes == msg_size);
ret_str_buffer_p = ret_str_buffer_p + bytes;
JERRY_ASSERT (ret_str_buffer_p == ret_str_buffer + size);
@@ -174,15 +166,11 @@ ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this
ecma_free_value (msg_to_str_completion);
ECMA_FINALIZE (msg_get_ret_value);
ecma_deref_ecma_string (message_magic_string_p);
}
ecma_free_value (name_to_str_completion);
ECMA_FINALIZE (name_get_ret_value);
ecma_deref_ecma_string (name_magic_string_p);
}
return ret_value;
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,39 +17,22 @@
* Error.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_attributes)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ERROR_PROTOTYPE)
#include "ecma-builtin-helpers-macro-defines.inc.h"
/* Object properties:
* (property name, object pointer getter) */
// 15.11.4.1
/* ECMA-262 v5, 15.11.4.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_ERROR,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
// 15.11.4.2
/* ECMA-262 v5, 15.11.4.2 */
STRING_VALUE (LIT_MAGIC_STRING_NAME,
LIT_MAGIC_STRING_ERROR_UL,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
// 15.11.4.3
/* ECMA-262 v5, 15.11.4.3 */
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
LIT_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
@@ -58,9 +41,4 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_error_prototype_object_to_string, 0, 0)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,29 +17,12 @@
* Error built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_attributes)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_attributes)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ERROR)
#include "ecma-builtin-helpers-macro-defines.inc.h"
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
/* ECMA-262 v5, 15.11.3 */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_FIXED)
@@ -47,14 +30,9 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
/* Object properties:
* (property name, object pointer getter) */
// 15.7.3.1
/* ECMA-262 v5, 15.7.3.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
ECMA_PROPERTY_FIXED)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
#if ENABLED (JERRY_BUILTIN_ERRORS)
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
@@ -34,4 +34,4 @@
#define BUILTIN_UNDERSCORED_ID eval_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */

Some files were not shown because too many files have changed in this diff Show More