102 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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