65 Commits

Author SHA1 Message Date
Zoltan Herczeg
ae1118293f Add two new API functions: jerry_create_number_infinity and jerry_create_number_nan
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-08-14 23:20:50 -07:00
Akos Kiss
a2d5acb43c Follow-up refactoring of logging-related parts
This patch:
* Ensures that all calls to `jerry_port_log` in jerry-core happen
  via macros defined in jrt.h. Also, it unifies the names of those
  macros: as `JERRY_ERROR_MSG` and `JERRY_WARNING_MSG` gave a good
  pattern that was well aligned with the naming scheme of the log
  level enum, `JERRY_DLOG` and `JERRY_DDLOG` were rewritten to
  `JERRY_DEBUG_MSG` and `JERRY_TRACE_MSG`.
* Ensures that all debug logging code parts of jerry-core (i.e.,
  memory statistics, JS byte-code dumps, and RegExp byte-code
  dumps) are guarded by macros: `JMEM_STATS`,
  `PARSER_DUMP_BYTE_CODE`, and `REGEXP_DUMP_BYTE_CODE`, which in
  turn are controled by cmake build system feature flags
  `FEATURE_MEM_STATS`, `FEATURE_PARSER_DUMP`, and
  `FEATURE_REGEXP_DUMP`.
* Ensures that all debug logging functionalities can be controled
  during run time (provided that they were enabled during build
  time): the engine has `JERRY_INIT_MEM_STATS[_SEPARATE]`,
  `JERRY_INIT_SHOW_OPCODES`, `JERRY_INIT_SHOW_REGEXP_OPCODES` init
  flags, and the default unix/linux command line app has
  corresponding command line switches.`
* Drops `FEATURE_LOG`, `JERRY_ENABLE_LOG`, and
  `JERRY_INIT_ENABLE_LOG`, as their name was misleadingly general,
  even though they mostly controled the regexp engine only. The
  above-mentioned `*REGEXP*` things mostly act as their
  replacements.
* Updates build, test, and measurement tool scripts, and
  documentation.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-08-11 22:00:12 +02:00
Akos Kiss
e9a23c4235 Refactor jrt buffer operations
`jrt_read_from_buffer_by_offset` is not used anywhere in the code
while `jrt_write_to_buffer_by_offset` is only used by snapshot
saving functions. Thus, this patch removes the read variant
completely and moves the write variant as a static function to
jerry.c. This empties out jrt.c, thus deleting.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-08-05 11:28:15 +02:00
Akos Kiss
697442434d Cleanup jerry's assert-like routines and macros
Until now, jerry had 3 different assert-like routines:
`jerry_assert_fail`, `jerry_unreachable`, and `jerry_unimplemented`,
and 3 corresponding macros (`JERRY_ASSERT`, `JERRY_UNREACHABLE`,
and `JERRY_UNIMPLEMENTED`). They had some irregularities, namely:

* All of them had a string parameter, although `jerry_unreachable`
  never got anything there but NULL.
* Both `jerry_unreachable` and `jerry_unimplemented` checked its
  string parameter for NULL, although it was always NULL for the
  first one and never NULL for the second.
* `jerry_unreachable` is just a regular assert with a fixed error
  message (i.e., control should not have got here), however, the
  expansion of its corresponding macro in debug and release modes
  differs from the behaviour of `JERRY_ASSERT`: `JERRY_ASSERT` is
  a no-op in release, however, `JERRY_UNREACHABLE` was triggering
  a crash even there.
* Moreover, `JERRY_UNIMPLEMENTED` was almost never used anymore but
  in a few places (where often an `#ifdef` selected between
  `JERRY_UNIMPLEMENTED` and `JERRY_UNREACHABLE`).

Because of the above, this patch makes the following changes:

* Drops `JERRY_UNIMPLEMENTED` completely and whereever it was still
  used, replaces it with `JERRY_UNREACHABLE`. As a consequence, the
  `jerry_unimplemented` function and the `ERR_UNIMPLEMENTED_CASE`
  fatal error code are also removed.
* Makes `JERRY_UNREACHABLE` expand to no-op in release builds.
  (Actually, to `__builtin_unreachable ()` to avoid warnings.) As
  a consequence, makes both `jerry_assert_fail` and
  `jerry_unreachable` be guarded by `#ifndef JERRY_NDEBUG`. Also,
  changes `jerry_unreachable` not to expect a string parameter.
* Rewrites `TEST_ASSERT` not to rely on `jerry_assert_fail` as
  `TEST_ASSERT` has to work in release builds as well. This also
  allows changing the error message not to mention "ICE", which
  would misleadingly suggest an assert within the engine, but
  "TEST" instead.

As a side-effect of the cleanup, some refactorings happened in
jrt.h:

* Removed the definition of the unnecessary `__extension__` macro.
* Re-used `JERRY_UNUSED` and `unlikely` where possible.
* Moved some parts of the file around.
* Fixed some comments (`/**` should only be used for the docstring
  of a single entity, for groups header comments, the regular `/*`
  should be used).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-08-05 10:09:32 +02:00
Robert Sipka
f15e7beadc Remove compact profile.
The standard doesn't defines ECMAScript Compact Profile as a subset of Ecma-262 Edition 5.1.
Profile modes can be added easily like the minimal profile if required.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-08-05 09:11:33 +02:00
Zoltan Herczeg
d1b0b58729 Move all remaining globals to the global context.
Zero out all globals (and remove unnecessary init() functions).
Move snapshot globals to a temporary stack variable.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-08-01 04:25:32 -07:00
Robert Sipka
e70c89e39e Comment fixes which are left behind after the API update.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-08-01 12:57:00 +02:00
Robert Sipka
ddab1d8152 Re-thinking the build system to bring it more into line with the conventions.
We removed that implementation where the build directory isn't set up to build with exactly one
configuration of the project but potentially several variants: the same build directory
can/must be used for debug and release builds, for full or compact profile versions, etc.
So we reworked the CMakeLists, and now one build dir deal with exactly one configuration
of the project's libraries and tools.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
2016-07-28 12:29:55 +02:00
István Kádár
e7ec053362 More gc-friendly property hashmap allocation.
- New allocator is added that returns null on out of memory, property hasmap create uses this allocator for now.
- Property hashmaps of objects are removed durring a high severity gc.

Follow up patch is in progress.

JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
2016-07-20 17:31:24 +02:00
Zoltan Herczeg
12916c6c55 Fix minor implementation issues found in the JerryScript API.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-07-20 01:54:00 -07:00
Zidong Jiang
ca39875690 fix bug of "deref bytecode twice" in jerry_exec_snapshot
Enable the snapshot related test code in test-api.c

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-07-19 18:56:06 +08:00
Zidong Jiang
6084f0845c Fix bug in jerry_string_to_char_buffer.
str_len can smaller than buffer_size.

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
2016-07-15 21:06:47 +08:00
László Langó
f0fd939d87 Move log level to default port
Setting the log level should be specified by the actual port.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-07-15 09:13:16 +02:00
László Langó
fa94c67ee7 Implement IO port API
Related issue: #964

Implemented the IO API of Jerry ports. Removed log file from API level.
The port implementation should define the destination of log messages.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-07-14 13:15:30 +02:00
Zoltan Herczeg
6f1ce8d6bb Improve the construction of "length" built-in strings.
The "length" property name is the most frequently used built-in string
and also frequently created by various hot-paths. New functions are
added to improve the speed of the "length" string creation.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-07-13 23:36:27 -07:00
László Langó
b4bba2ef70 Update API reference to the new API
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-07-12 14:08:59 +02:00
László Langó
9bce5b09a9 Update Jerry API
* Removed jerry_string_t and jerry_object_t
* Updated function names
* Updated return values
* Updated function descriptions
* Added new functions
* Added new unittests

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-07-11 09:01:29 +02:00
István Kádár
a81c7c83d7 ecma_make_boolean_value(bool) function is added in order to make ecma_value form a raw bool.
JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
2016-07-01 16:00:56 +02:00
László Langó
c3541c3ab7 Check error values in API functions
Internal functions cannot handle error values, so it must be avoided to
pass error values to the engine.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-29 14:26:55 +02:00
Zoltan Herczeg
0a32c97755 Rework literal storage.
The new literal storage keeps ecma strings rather than having a
custom string implementation which duplicates the string management
routines. Conversions between string implementations are eliminated
which improved the performance by 4%.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-06-27 00:25:09 -07:00
László Langó
cfa0c94697 Add new API function
Implemented 'jerry_is_array' and 'jerry_get_array_length' API functions.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-24 10:08:17 +02:00
László Langó
65542549af Add conversion API functions
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-16 14:13:06 +02:00
László Langó
8e8504244b Update jerry API
* Fix error handling (related issue: #1141)
 * Move output paramters to the end of the arguments lists

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-16 13:43:33 +02:00
László Langó
8453a9ade8 Change return value of 'ecma_ref_ecma_string' to void
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-16 12:44:27 +02:00
László Langó
0daeb2f942 Remove string copy
Changed 'ecma_copy_or_ref_ecma_string' to 'ecma_ref_ecma_string'. It does
not copy the string if the maximum number of reference counter is reached,
but bails out with an error like the 'ecma_ref_object' function does.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-16 12:44:27 +02:00
László Langó
a816ab8bb0 Use 'ecma_value_t' in API too
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-14 14:44:02 +02:00
Zoltan Herczeg
b828d4a463 Rename ecma_is_value_error to ECMA_IS_VALUE_ERROR.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-06-14 02:31:34 -07:00
Zsolt Borbély
c557a0a047 Modify the usage of ecma_string_to_utf8_string()
Parts:
 * Rename ecma_string_to_utf8_string() to ecma_string_copy_to_utf8_buffer.

 * Introduce ecma_string_to_utf8_bytes(), which wraps the usual 'function call-assertion' pair,
   and check strict equality of size of the string and the buffer.

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-06-13 15:21:30 +02:00
László Langó
824d39c2a2 Update API functions
* Rename 'jerry_api_' prefix to 'jerry_'
 * Fix minor style issues
 * Group the API functions and add comment to each group
 * Move engine behaviour related funtions to 'jerry.h'

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-06-08 12:48:47 +02:00
Zoltan Herczeg
8c92972b2f Passing less number of arguments to a function is generally faster. So
the three boolean arguments of ecma_create_named_data_property and the
two boolean arguments of ecma_create_named_accessor_property are combined
into one uint8_t argument. On ARM-32 it is preferred to have less than
four arguments, since these arguments can be passed in registers.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-05-29 23:47:46 -07:00
László Langó
92bb551d45 Change 'mem' namspace to 'jmem'
The 'mem_' prefix is too general, so it might clash with
symbols in other libraries. Renamed the directory, file,
funtion and type names.

Related issue: #1052

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-05-20 16:01:33 +02:00
Akos Kiss
c7d33e9887 Don't concatenate multiple JS scripts in jerry
Jerry (the command line tool) has been supporting the execution of
multiple script files for long. However, until now, it simply
concatenated all sources into a single source buffer and
parsed/executed them as one unit. Other JS execution tools (e.g.,
jsc, v8) load and execute separate files as separate units -- but
still in the same execution environment. The most significant
effect of this approach is that the `"use strict;"` directive (or
the absence of it) at the beginning of each JS script file takes
effect as expected (i.e., as if the script was executed alone).
Contrarily, the concatenation-based approach forces the strictness
of the first script on all the rest (i.e., if the first script
starts with `"use strict";` the rest is also executed in a strict
environment even if they did not contain the directive, and vice
versa).

This patch makes the jerry command line tool to load/parse/run one
unit at a time.

Side effects:
- As there is no need for separate file read routines that load one
  file (a snapshot) or concat multiple (JS sources) anymore, those
  routines got merged.
- Both previous read routines used multiple stdio functions
  (`fseek`, `ftell`, and `rewind`). This has been simplified to
  rely on `fread` only to find out the length of the input.
- This simplification made the above mentioned functions
  superfluous in jerry-libc.
- As some error messages had to be touched in this patch, several
  more have been beautified to make them more consistent.
- One small change was needed in `jerry_parse` in jerry-core to
  allow subsequent parsing of multiple sources (without that, an
  assertion was triggered).

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-05-19 12:07:54 +02:00
Zoltan Herczeg
00f759e275 Introduce integer ecma-value representation to reduce the double allocations.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-05-17 00:11:19 -07:00
Zoltan Herczeg
7cf8b79429 Argument literal names were not stored in the snapshot, because the
names were replaced by empty strings before that. The snapshot form
of tests/jerry/arguments.js fails because of this issue.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-05-16 23:49:41 -07:00
László Langó
fe3c269e99 Fix return value of 'jerry_api_get_object_field_value'
Fixed the return value to return false when the field does
not exist as the documentation says.

Related issue: #1041

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-05-06 21:07:19 +02:00
Zsolt Borbély
7813801cd3 Fix wrong indentations of function parameters
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
2016-05-02 13:38:28 +02:00
László Langó
80bfb61b13 Remove unnecessary error bit negation
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-04-21 09:36:42 +02:00
Akos Kiss
02ba19f24d Introduce the Termination Port API
* Moved the error codes to jerry-port.h and declared port function
  `jerry_port_fatal`.

* Moved "exit or abort on fail" functionality to the newly added
  jerry-port-default-fatal.c.

* This implied that a default port-specific API had to be introduced:
  functions `jerry_port_default_set_abort_on_fail` and
  `jerry_port_default_is_abort_on_fail` declared in jerry-port-default.h
  control the fatal exit behaviour.

* For the sake of clarity, renamed jerry-port.c to
  jerry-port-default-io.c.

* Adapted CMakeLists to deal with port implementations consisting of
  more then one source file and exposing headers. This also required
  the renaming of `EXTERNAL_PORT_FILE` cmake option to
  `EXTERNAL_PORT_DIR`.

* Adapted main sources to use the default port header for the
  abort-on-fail functionality, as that is not part of the core jerry
  API anymore.

* Added default port implementation to the static source code checker
  tools.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-04-19 14:10:18 +02:00
Akos Kiss
3a8d3b3bcc Unifiy the comments of preprocessor conditionals
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-04-18 19:20:49 +02:00
Zoltan Herczeg
e92ecd44e7 Refactor ecma value to store pointers directly in ecma values rather than compressing them.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-04-15 11:35:51 -07:00
Dániel Bátyai
e191794118 Print unhandled errors in REPL mode
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2016-04-14 14:01:47 +02:00
László Langó
9dad7dbfba Introduce ECMA_STRING_TO_UTF8_STRING and ECMA_FINALIZE_UTF8_STRING
Benefits:
 * Better readability and maintenance
 * Better heap consumption on 'date-format-xparb.js' test of SunSpider

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-04-12 12:52:59 +02:00
László Langó
b78f5a55bb Fix assertion on unhandled exceptions
Follow up fix after #815 ('a187e6d'). Fixed the following
assertion on unhandled exceptions:
  * ICE: Assertion 'ecma_get_value_type_field (value) == ECMA_TYPE_OBJECT'
    failed at ecma-helpers-value.c(ecma_get_object_from_value):375.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-04-11 10:53:15 +02:00
Akos Kiss
920a9ee244 Remove jerry_reg_err_callback API function
Discussions on Termination Port API point in a different direction
than what's already in the API. Moreover, since the function has
been throwing unimplemented assert error since its introduction,
we should remove it from the code base.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-04-08 16:54:07 +02:00
Akos Kiss
d501c92f96 Eliminate TODO and FIXME macros
Those macros are legacy and are not used consitently throughout the
code base. This patch eliminates their definitions and rewrites
their remaining occurrences to TODO comments.

All occurrences have been checked and made sure that the comments
used a consistent style.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-04-06 14:40:43 +02:00
Zoltan Herczeg
cc23c225ea Fix snapshot saving issue.
Snapshot save algorithm should not resolve uninitialized literals.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-03-24 02:57:31 -07:00
László Langó
2027caeda5 Performance optimizations
* inline some hot function
 * add 'ecma_copy_value_if_not_object' similer to 'ecma_value_free_if_not_object'
 * remove unnecessary helpers
 * improve 'do_number_bitwise_logic'

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
2016-03-22 08:05:00 +01:00
Akos Kiss
ea2f0e44fb Fix terminology of snapshot saving in literals and main
In case of literals and in main, snapshot saving is incorrectly
named dumping. Elsewhere in the code, 'dump' functions output debug
data (even literals have a `lit_dump_literals` debug function). To
help distinction and to align terminologies, snapshot saving
functions of literals and command line options of main are also
re-named 'save'.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2016-03-16 11:26:46 +01:00
Zoltan Herczeg
d190ca44ae Storing byte code size in the byte code header. This reduces the
memory consumption, because the new allocator uses less memory if
the size as available when a block is freed. Snapshot generation
is also simplified.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
2016-03-16 02:58:10 -07:00
François Baldassari
7b047d4b20 Add acquire_value API to simplify caller code
JerryScript-DCO-1.0-Signed-off-by: François Baldassari francois@pebble.com
2016-03-11 09:57:40 -08:00