Compare commits
209 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23bba1c6d9 | |||
| 38111c0889 | |||
| 01e9670365 | |||
| 049a0c43f6 | |||
| 1bf52f5847 | |||
| 6d9d2328e9 | |||
| dba9533af1 | |||
| 70383255fc | |||
| 585332f072 | |||
| 36bf1ec09d | |||
| a885664220 | |||
| 2058ea1286 | |||
| fed1b0c827 | |||
| b7a641c124 | |||
| 4c53c94341 | |||
| 90fd881fda | |||
| 1230d4532c | |||
| ab2e821777 | |||
| c2c623df79 | |||
| 358101f27f | |||
| ba4e3a402f | |||
| cae6cd08fb | |||
| 10e78a4eef | |||
| 1770ccaecd | |||
| 0d4116933f | |||
| 252cfb0876 | |||
| c09c2c5dd7 | |||
| e6ebc2be78 | |||
| 1414e9bb00 | |||
| 1322e08ac2 | |||
| fe09200d61 | |||
| 4660bab16b | |||
| a56e31f194 | |||
| dc837d232d | |||
| 9ceece8eb4 | |||
| d06c3a7f50 | |||
| 3b4c259281 | |||
| 5895b96bdb | |||
| e76a1381e6 | |||
| ab3461b63d | |||
| d4fe48fae4 | |||
| 104001df68 | |||
| 562dcc8630 | |||
| c2b6621702 | |||
| 7a20150ae7 | |||
| 69f8e78c2f | |||
| 8f76a1f382 | |||
| 908240ba62 | |||
| dd6d148c3b | |||
| 15629e8ba5 | |||
| 3060656562 | |||
| edaf4ef30f | |||
| 843c542053 | |||
| e50e2719df | |||
| ecf159795a | |||
| 1105b43c22 | |||
| 1774cca47c | |||
| 589af6dc90 | |||
| 6fe6dab9cc | |||
| b2a2022d0a | |||
| f06c533a29 | |||
| b9258da7d0 | |||
| 6cd309b525 | |||
| 876622a061 | |||
| 5d6069176b | |||
| 87b1d1eeb0 | |||
| 08222992dc | |||
| e1960621f3 | |||
| a4659a888b | |||
| bbb5c9180e | |||
| 378244942f | |||
| 7274fa4dd4 | |||
| f0d443daec | |||
| e01cfda0b8 | |||
| c4d5c2c9e1 | |||
| 2570f8e745 | |||
| 09ac2ffa67 | |||
| 0aad9cb431 | |||
| bd1c4df9a6 | |||
| 4aa27371b6 | |||
| 1f00d750b7 | |||
| a6f6bce6f0 | |||
| f13e8b602e | |||
| b51157d3c5 | |||
| 95aa827635 | |||
| aaf0442611 | |||
| 9ad9d574fe | |||
| 4dc2cb3328 | |||
| df7e303145 | |||
| 050fbfc130 | |||
| 094ba2f30a | |||
| 97a35b0f10 | |||
| aa1777b1a0 | |||
| 18fe546802 | |||
| 90c7eccb42 | |||
| 99859fb221 | |||
| 5af751263b | |||
| 8d08cec349 | |||
| 409e1fec5f | |||
| 8ccb95c31c | |||
| 132a2008c9 | |||
| 40a9f27314 | |||
| 14cea9c1ec | |||
| b5d9699788 | |||
| 1a72e070c8 | |||
| 48e7b01fe9 | |||
| 6ff299c831 | |||
| 4b780507e1 | |||
| 9e6c44be4f | |||
| 85401db547 | |||
| 2bdd0f5008 | |||
| 62730f2ae1 | |||
| f254b1a8b7 | |||
| 4e8dac8ce1 | |||
| daeee77d63 | |||
| e2807c28fa | |||
| dcf8ccfd03 | |||
| 1b1460e61f | |||
| bcd5ff3f40 | |||
| d1bf9635c7 | |||
| 3900152631 | |||
| 0269b6c25d | |||
| 52f1476061 | |||
| b209e95daa | |||
| 9c7a699d10 | |||
| 453da11398 | |||
| 1b01171a60 | |||
| 4be9ffda84 | |||
| 895973ca82 | |||
| 58257040dc | |||
| e5702edab4 | |||
| b5977de99c | |||
| d82bbb1c77 | |||
| 4342c9ea6f | |||
| 60db840cf4 | |||
| 901e57c7d0 | |||
| 48fa2ec01b | |||
| 73a78bd223 | |||
| e470b13096 | |||
| c74256ccba | |||
| 28f2772d9c | |||
| 1bd1a36a81 | |||
| c237ba6097 | |||
| d63936f371 | |||
| 4240b740aa | |||
| 94b8b4bb7b | |||
| 3c7a776cae | |||
| 2ed742a9e7 | |||
| 76b8555210 | |||
| 14bcc98089 | |||
| 43a36c9673 | |||
| 6a022eb265 | |||
| f29e6f9020 | |||
| 18a4cba062 | |||
| d539d30bf9 | |||
| 56832d772e | |||
| 655110ad7b | |||
| 5b6d4f39b1 | |||
| b2e54e915b | |||
| 85fced2632 | |||
| 51a9575fd0 | |||
| 1cfda262bd | |||
| 7ea93aff4c | |||
| c305aee80f | |||
| 7f67795326 | |||
| bc7c39d893 | |||
| 1a8276c493 | |||
| bfd2639634 | |||
| 56b9f098ab | |||
| ccca998f43 | |||
| 47d85a12e2 | |||
| 6ef0a0e07e | |||
| 57b8599581 | |||
| 055f753d02 | |||
| 64fd37d1db | |||
| 38862c39a6 | |||
| 9509c3da85 | |||
| 72f8ef344c | |||
| 6c3a42ec48 | |||
| 651b62584a | |||
| 23974e2389 | |||
| 76bbb088e9 | |||
| 3c8a6ca71d | |||
| 34edf53753 | |||
| 19c61e14c0 | |||
| aa17a4fa5d | |||
| ec39d08d67 | |||
| f31931267a | |||
| a6acf2d417 | |||
| 4e136c8973 | |||
| 9b393ee2ea | |||
| 20300189cb | |||
| 6430d1a3a3 | |||
| bd2696f7c7 | |||
| cdbabc8c30 | |||
| acbdb4184f | |||
| 73daeb19c9 | |||
| 68909fc5de | |||
| b0a575b049 | |||
| f8da3d5e9d | |||
| 98b90ba697 | |||
| 0ff664cab6 | |||
| 181570ff41 | |||
| fda02d4b2a | |||
| 44e63e038d | |||
| 54e4de39ab | |||
| 4d67ac3225 | |||
| 4b325ea9e3 | |||
| 8cd5d06620 |
+18
-10
@@ -1,8 +1,8 @@
|
||||
language: c
|
||||
|
||||
# Default environment: Ubuntu Trusty 14.04.
|
||||
# Default environment: Ubuntu Bionic 18.04.
|
||||
os: linux
|
||||
dist: trusty
|
||||
dist: bionic
|
||||
|
||||
# Default job task: run tests as defined in the $OPT environment variable.
|
||||
# Jobs can redefine the 'script' stage in the matrix below.
|
||||
@@ -12,13 +12,12 @@ script: tools/run-tests.py $OPTS
|
||||
matrix:
|
||||
include:
|
||||
- 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++]
|
||||
packages: [doxygen, cppcheck, vera++, pylint]
|
||||
|
||||
- name: "Linux/x86-64 Build, Correctness & Debugger Tests"
|
||||
env:
|
||||
@@ -40,10 +39,17 @@ matrix:
|
||||
apt:
|
||||
packages: [gcc-arm-linux-gnueabihf, libc6-dev-armhf-cross, qemu-user-static]
|
||||
|
||||
- name: "Linux/AArch64 Native Build & Correctness Tests"
|
||||
arch: arm64
|
||||
env:
|
||||
- OPTS="--quiet --jerry-tests --jerry-test-suite --buildoptions=--linker-flag=-static"
|
||||
- TIMEOUT=300
|
||||
|
||||
- name: "OSX/x86-64 Build, Correctness & Unit Tests"
|
||||
env:
|
||||
- OPTS="--quiet --jerry-tests --jerry-test-suite --unittests"
|
||||
os: osx
|
||||
osx_image: xcode11.4
|
||||
addons:
|
||||
homebrew:
|
||||
packages: [cmake, cppcheck, vera++]
|
||||
@@ -55,10 +61,14 @@ matrix:
|
||||
apt:
|
||||
packages: [gcc-multilib]
|
||||
|
||||
- name: "Conformance Tests"
|
||||
- name: "Conformance Tests - ES5.1"
|
||||
env:
|
||||
- OPTS="--test262"
|
||||
|
||||
- name: "Conformance Tests - ES2015"
|
||||
env:
|
||||
- OPTS="--test262-es2015"
|
||||
|
||||
- name: "Unit Tests"
|
||||
env:
|
||||
- OPTS="--unittests"
|
||||
@@ -67,25 +77,23 @@ matrix:
|
||||
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"
|
||||
- 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,regression-test-issue-3785.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]
|
||||
packages: [gcc-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]
|
||||
packages: [gcc-multilib]
|
||||
|
||||
- name: "Coverity Scan & SonarQube"
|
||||
env:
|
||||
|
||||
@@ -798,7 +798,6 @@ RECURSIVE = YES
|
||||
# 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 \
|
||||
|
||||
@@ -22,11 +22,10 @@ Additional information can be found on our [project page](http://jerryscript.net
|
||||
|
||||
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:
|
||||
The latest results on **Raspberry Pi 2**:
|
||||
|
||||
| STM32F4-Discovery | [](https://jerryscript-project.github.io/jerryscript-test-results/?view=stm32f4dis) |
|
||||
| :---: | :---: |
|
||||
| **Raspberry Pi 2** | [](https://jerryscript-project.github.io/jerryscript-test-results/?view=rpi2) |
|
||||
|
||||
[](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).
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# 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 Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
|
||||
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
|
||||
@@ -1,6 +1,6 @@
|
||||
## Setting up prerequisites
|
||||
|
||||
Currently, only Ubuntu 14.04+ is officially supported as primary development environment.
|
||||
Currently, only Ubuntu 18.04+ is officially supported as primary development environment.
|
||||
|
||||
There are several dependencies, that should be installed manually. The following list is the absolute minimum for building:
|
||||
|
||||
|
||||
+256
-6
@@ -70,8 +70,26 @@ Possible compile time enabled feature types:
|
||||
- JERRY_FEATURE_LOGGING - logging
|
||||
- JERRY_FEATURE_SYMBOL - symbol support
|
||||
- JERRY_FEATURE_DATAVIEW - DataView support
|
||||
- JERRY_FEATURE_PROXY - Proxy support
|
||||
- JERRY_FEATURE_MAP - Map support
|
||||
- JERRY_FEATURE_SET - Set support
|
||||
- JERRY_FEATURE_WEAKMAP - WeakMap support
|
||||
- JERRY_FEATURE_WEAKSET - WeakSet support
|
||||
|
||||
*New in version 2.0*.
|
||||
*Changed in version 2.3* : Added `JERRY_FEATURE_WEAKMAP`, `JERRY_FEATURE_WEAKSET` values.
|
||||
|
||||
## jerry_container_type_t
|
||||
|
||||
Container object types:
|
||||
|
||||
- JERRY_CONTAINER_TYPE_INVALID - Invalid container
|
||||
- JERRY_CONTAINER_TYPE_MAP - Map type
|
||||
- JERRY_CONTAINER_TYPE_SET - Set type
|
||||
- JERRY_CONTAINER_TYPE_WEAKMAP - WeakMap type
|
||||
- JERRY_CONTAINER_TYPE_WEAKSET - WeakSet type
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
## jerry_regexp_flags_t
|
||||
|
||||
@@ -1865,6 +1883,55 @@ jerry_value_is_promise (const jerry_value_t value)
|
||||
- [jerry_create_promise](#jerry_create_promise)
|
||||
|
||||
|
||||
## jerry_value_is_proxy
|
||||
|
||||
**Summary**
|
||||
|
||||
Returns whether the given `jerry_value_t` is a proxy value.
|
||||
|
||||
*Notes*:
|
||||
- This API depends on a build option (`JERRY_ES2015_BUILTIN_PROXY`) and can be checked
|
||||
in runtime with the `JERRY_FEATURE_PROXY` feature enum value,
|
||||
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||
- The ES2015-subset profile enables this by default.
|
||||
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
bool
|
||||
jerry_value_is_proxy (const jerry_value_t value)
|
||||
```
|
||||
|
||||
- `value` - api value
|
||||
- return value
|
||||
- true, if the given `jerry_value_t` is a proxy object
|
||||
- false, otherwise
|
||||
|
||||
**Example**
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
```c
|
||||
{
|
||||
jerry_value_t value;
|
||||
... // create or acquire value
|
||||
|
||||
if (jerry_value_is_proxy (value))
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
jerry_release_value (value);
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_release_value](#jerry_release_value)
|
||||
- [jerry_create_proxy](#jerry_create_proxy)
|
||||
|
||||
|
||||
## jerry_value_is_string
|
||||
|
||||
**Summary**
|
||||
@@ -2022,6 +2089,64 @@ main (void)
|
||||
- [jerry_create_typedarray](#jerry_create_typedarray)
|
||||
|
||||
|
||||
## jerry_get_container_type
|
||||
|
||||
**Summary**
|
||||
|
||||
Checks whether the given `jerry_value_t` is the given `jerry_container_type_t` type container object.
|
||||
|
||||
*Notes*
|
||||
- This API function depends on a build option (`JERRY_ES2015_BUILTIN_CONTAINER`) and can be checked
|
||||
runtime with the `JERRY_FEATURE_MAP, JERRY_FEATURE_SET, JERRY_FEATURE_WEAKMAP, JERRY_FEATURE_WEAKSET`
|
||||
feature enum values.
|
||||
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||
- The ES2015-subset profile enables this by default.
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_container_type_t
|
||||
jerry_get_container_type (const jerry_value_t value)
|
||||
```
|
||||
|
||||
- `value` - Container object
|
||||
- return value
|
||||
- The corresponding enum value of `jerry_container_type_t`, or `JERRY_CONTAINER_TYPE_INVALID` if the container
|
||||
was not a valid container object.
|
||||
**Example**
|
||||
|
||||
[doctest]: # ()
|
||||
|
||||
```c
|
||||
#include "jerryscript.h"
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
jerry_value_t value = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0);
|
||||
|
||||
if (jerry_get_container_type (value) == JERRY_CONTAINER_TYPE_MAP)
|
||||
{
|
||||
/* "value" is a map. */
|
||||
}
|
||||
|
||||
jerry_release_value (value);
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_create_container](#jerry_create_container)
|
||||
- [jerry_container_type_t](#jerry_container_type_t)
|
||||
|
||||
|
||||
## jerry_value_is_undefined
|
||||
|
||||
**Summary**
|
||||
@@ -4212,6 +4337,65 @@ jerry_create_promise (void)
|
||||
- [jerry_release_value](#jerry_release_value)
|
||||
|
||||
|
||||
## jerry_create_proxy
|
||||
|
||||
**Summary**
|
||||
|
||||
Create a new Proxy object with the given target and handler.
|
||||
|
||||
*Note*:
|
||||
- This API depends on the ES2015-subset profile.
|
||||
- Returned value must be freed with [jerry_release_value](#jerry_release_value)
|
||||
when it is no longer needed.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_value_t
|
||||
jerry_create_proxy (const jerry_value_t target,
|
||||
const jerry_value_t handler)
|
||||
```
|
||||
|
||||
- `target` - proxy target
|
||||
- `handler` - proxy handler
|
||||
- return thrown error - if the Proxy construction fails
|
||||
value of the newly created proxy object - otherwise
|
||||
|
||||
**Example**
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
[doctest]: # ()
|
||||
|
||||
```c
|
||||
#include "jerryscript.h"
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
jerry_value_t target = jerry_create_object ();
|
||||
jerry_value_t handler = jerry_create_object ();
|
||||
jerry_value_t proxy = jerry_create_proxy (target, handler);
|
||||
|
||||
jerry_release_value (target);
|
||||
jerry_release_value (handler);
|
||||
|
||||
// usage of the proxy
|
||||
|
||||
jerry_release_value (proxy);
|
||||
|
||||
jerry_cleanup ();
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_value_is_proxy](#jerry_value_is_proxy)
|
||||
- [jerry_release_value](#jerry_release_value)
|
||||
|
||||
|
||||
## jerry_create_string
|
||||
|
||||
**Summary**
|
||||
@@ -4693,6 +4877,70 @@ jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name,
|
||||
- [jerry_release_value](#jerry_release_value)
|
||||
|
||||
|
||||
## jerry_create_container
|
||||
|
||||
**Summary**
|
||||
|
||||
Create a jerry_value_t representing a given type container object.
|
||||
|
||||
*Notes*:
|
||||
- This method is expected to work the same way as the JavaScript Map constructor.
|
||||
- Returned value must be freed with [jerry_release_value](#jerry_release_value)
|
||||
when it is no longer needed.
|
||||
- This API depends on a build option (`JERRY_ES2015_BUILTIN_CONTAINER`) and can be checked
|
||||
in runtime with the `JERRY_FEATURE_MAP, JERRY_FEATURE_SET, JERRY_FEATURE_WEAKMAP, JERRY_FEATURE_WEAKSET`
|
||||
feature enum values.
|
||||
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||
- The ES2015-subset profile enables this by default.
|
||||
|
||||
*New in version 2.3*.
|
||||
|
||||
**Prototype**
|
||||
|
||||
```c
|
||||
jerry_value_t
|
||||
jerry_create_container (jerry_container_type_t container_type,
|
||||
const jerry_value_t *arguments_list_p,
|
||||
jerry_length_t arguments_list_len);
|
||||
```
|
||||
|
||||
- `container_type` - Type of the container to be created, see `jerry_container_type_t`.
|
||||
- `arguments_list_p` - The arguments passed to the container constructor to be inserted to the container.
|
||||
- `arguments_list_len` - The length of the above arguments.
|
||||
- return value - the new container object as a `jerry_value_t`
|
||||
|
||||
**Example**
|
||||
|
||||
[doctest]: # ()
|
||||
|
||||
```c
|
||||
#include "jerryscript.h"
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
jerry_char_t src[] = "[1,2,3,4].entries()";
|
||||
jerry_value_t iterable = jerry_eval (src, sizeof (src) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
jerry_value_t map = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, &iterable, 1);
|
||||
jerry_release_value (iterable);
|
||||
|
||||
// use the Map
|
||||
|
||||
jerry_release_value (map);
|
||||
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
**See also**
|
||||
|
||||
- [jerry_container_type_t](#jerry_container_type_t)
|
||||
- [jerry_get_container_type](#jerry_get_container_type)
|
||||
|
||||
|
||||
## jerry_create_undefined
|
||||
|
||||
**Summary**
|
||||
@@ -4746,11 +4994,12 @@ jerry_has_property (const jerry_value_t obj_val,
|
||||
|
||||
- `obj_val` - object value
|
||||
- `prop_name_val` - property name
|
||||
- return value - JavaScript boolean value that evaluates to
|
||||
- true, if the property exists
|
||||
- false, otherwise
|
||||
- return value - JavaScript value that evaluates to
|
||||
- raised error - if the operation fail
|
||||
- true/false API value - depend on whether the property exists
|
||||
|
||||
*Changed in version 2.0*: The return value type is now a JavaScript value and not a primitive boolean value.
|
||||
*Changed in version 2.3*: The return value can be an error value.
|
||||
|
||||
**Example**
|
||||
|
||||
@@ -4805,11 +5054,12 @@ jerry_has_own_property (const jerry_value_t obj_val,
|
||||
|
||||
- `obj_val` - object value
|
||||
- `prop_name_val` - property name
|
||||
- return value - JavaScript boolean value that evaluates to
|
||||
- true, if the property exists
|
||||
- false, otherwise
|
||||
- return value - JavaScript value that evaluates to
|
||||
- raised error - if the operation fails
|
||||
- true/false API value - depend on whether the property exists
|
||||
|
||||
*Changed in version 2.0*: The return value type is now a JavaScript value and not a primitive boolean value.
|
||||
*Changed in version 2.3*: The return value can be an error value.
|
||||
|
||||
**Example**
|
||||
|
||||
|
||||
@@ -1084,7 +1084,8 @@ int
|
||||
main (void)
|
||||
{
|
||||
/* Initialize srand value */
|
||||
srand ((unsigned) jerry_port_get_current_time ());
|
||||
union { double d; unsigned u; } now = { .d = jerry_port_get_current_time () };
|
||||
srand (now.u);
|
||||
|
||||
/* Generate a random number, and print it */
|
||||
const jerry_char_t script[] = "var a = Math.random (); print(a)";
|
||||
|
||||
+119
-111
@@ -168,7 +168,7 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
globals_p->class_found = true;
|
||||
}
|
||||
@@ -295,20 +295,20 @@ static void
|
||||
static_snapshot_error_unsupported_literal (snapshot_globals_t *globals_p, /**< snapshot globals */
|
||||
ecma_value_t literal) /**< literal form the literal pool */
|
||||
{
|
||||
const lit_utf8_byte_t error_prefix[] = "Unsupported static snapshot literal: ";
|
||||
|
||||
ecma_string_t *error_message_p = ecma_new_ecma_string_from_utf8 (error_prefix, sizeof (error_prefix) - 1);
|
||||
lit_utf8_byte_t *str_p = (lit_utf8_byte_t *) "Unsupported static snapshot literal: ";
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw (str_p, 37);
|
||||
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (literal));
|
||||
|
||||
ecma_string_t *literal_string_p = ecma_op_to_string (literal);
|
||||
JERRY_ASSERT (literal_string_p != NULL);
|
||||
|
||||
error_message_p = ecma_concat_ecma_strings (error_message_p, literal_string_p);
|
||||
ecma_stringbuilder_append (&builder, literal_string_p);
|
||||
|
||||
ecma_deref_ecma_string (literal_string_p);
|
||||
|
||||
ecma_object_t *error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_RANGE, error_message_p);
|
||||
ecma_deref_ecma_string (error_message_p);
|
||||
ecma_object_t *error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_RANGE,
|
||||
ecma_stringbuilder_finalize (&builder));
|
||||
|
||||
globals_p->snapshot_error = ecma_create_error_object_reference (error_object_p);
|
||||
} /* static_snapshot_error_unsupported_literal */
|
||||
@@ -367,7 +367,6 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
|
||||
/* Sub-functions and regular expressions are stored recursively. */
|
||||
uint8_t *buffer_p = (uint8_t *) copied_code_p;
|
||||
ecma_value_t *literal_start_p;
|
||||
uint32_t argument_end;
|
||||
uint32_t const_literal_end;
|
||||
uint32_t literal_end;
|
||||
|
||||
@@ -378,7 +377,6 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
|
||||
literal_start_p = (ecma_value_t *) (buffer_p + sizeof (cbc_uint16_arguments_t));
|
||||
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
@@ -387,7 +385,6 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
|
||||
literal_start_p = (ecma_value_t *) (buffer_p + sizeof (cbc_uint8_arguments_t));
|
||||
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
@@ -424,19 +421,19 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
|
||||
}
|
||||
}
|
||||
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
buffer_p += ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
literal_start_p = ((ecma_value_t *) buffer_p) - argument_end;
|
||||
buffer_p += ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
literal_start_p = ecma_snapshot_resolve_serializable_values (compiled_code_p, buffer_p);
|
||||
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
while (literal_start_p < (ecma_value_t *) buffer_p)
|
||||
{
|
||||
if (!ecma_is_value_direct_string (*literal_start_p)
|
||||
&& !ecma_is_value_empty (*literal_start_p))
|
||||
{
|
||||
if (!ecma_is_value_direct_string (literal_start_p[i]))
|
||||
{
|
||||
static_snapshot_error_unsupported_literal (globals_p, literal_start_p[i]);
|
||||
return 0;
|
||||
}
|
||||
static_snapshot_error_unsupported_literal (globals_p, *literal_start_p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
literal_start_p++;
|
||||
}
|
||||
|
||||
return start_offset;
|
||||
@@ -460,7 +457,6 @@ jerry_snapshot_set_offsets (uint32_t *buffer_p, /**< buffer */
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_FUNCTION)
|
||||
{
|
||||
ecma_value_t *literal_start_p;
|
||||
uint32_t argument_end;
|
||||
uint32_t const_literal_end;
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
@@ -468,7 +464,6 @@ jerry_snapshot_set_offsets (uint32_t *buffer_p, /**< buffer */
|
||||
literal_start_p = (ecma_value_t *) (((uint8_t *) buffer_p) + sizeof (cbc_uint16_arguments_t));
|
||||
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
else
|
||||
@@ -476,7 +471,6 @@ jerry_snapshot_set_offsets (uint32_t *buffer_p, /**< buffer */
|
||||
literal_start_p = (ecma_value_t *) (((uint8_t *) buffer_p) + sizeof (cbc_uint8_arguments_t));
|
||||
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
|
||||
@@ -496,28 +490,26 @@ jerry_snapshot_set_offsets (uint32_t *buffer_p, /**< buffer */
|
||||
}
|
||||
}
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p + (((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG);
|
||||
literal_start_p = ecma_snapshot_resolve_serializable_values (bytecode_p, byte_p);
|
||||
|
||||
while (literal_start_p < (ecma_value_t *) byte_p)
|
||||
{
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
literal_start_p = ((ecma_value_t *) byte_p) - argument_end;
|
||||
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
if (*literal_start_p != ECMA_VALUE_EMPTY)
|
||||
{
|
||||
if (literal_start_p[i] != ECMA_VALUE_EMPTY)
|
||||
JERRY_ASSERT (ecma_is_value_string (*literal_start_p));
|
||||
|
||||
lit_mem_to_snapshot_id_map_entry_t *current_p = lit_map_p;
|
||||
|
||||
while (current_p->literal_id != *literal_start_p)
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_string (literal_start_p[i]));
|
||||
|
||||
lit_mem_to_snapshot_id_map_entry_t *current_p = lit_map_p;
|
||||
|
||||
while (current_p->literal_id != literal_start_p[i])
|
||||
{
|
||||
current_p++;
|
||||
}
|
||||
|
||||
literal_start_p[i] = current_p->literal_offset;
|
||||
current_p++;
|
||||
}
|
||||
|
||||
*literal_start_p = current_p->literal_offset;
|
||||
}
|
||||
|
||||
literal_start_p++;
|
||||
}
|
||||
|
||||
/* Set reference counter to 1. */
|
||||
@@ -559,7 +551,6 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
if (!(bytecode_p->status_flags & CBC_CODE_FLAGS_FUNCTION))
|
||||
{
|
||||
const re_compiled_code_t *re_bytecode_p = NULL;
|
||||
|
||||
const uint8_t *regex_start_p = ((const uint8_t *) bytecode_p) + sizeof (ecma_compiled_code_t);
|
||||
|
||||
@@ -567,10 +558,8 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
ecma_string_t *pattern_str_p = ecma_new_ecma_string_from_utf8 (regex_start_p,
|
||||
bytecode_p->refs);
|
||||
|
||||
re_compile_bytecode (&re_bytecode_p,
|
||||
pattern_str_p,
|
||||
bytecode_p->status_flags);
|
||||
|
||||
const re_compiled_code_t *re_bytecode_p = re_compile_bytecode (pattern_str_p,
|
||||
bytecode_p->status_flags);
|
||||
ecma_deref_ecma_string (pattern_str_p);
|
||||
|
||||
return (ecma_compiled_code_t *) re_bytecode_p;
|
||||
@@ -580,7 +569,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
JERRY_ASSERT (bytecode_p->status_flags & CBC_CODE_FLAGS_FUNCTION);
|
||||
|
||||
size_t header_size;
|
||||
uint32_t argument_end = 0;
|
||||
uint32_t argument_end;
|
||||
uint32_t const_literal_end;
|
||||
uint32_t literal_end;
|
||||
|
||||
@@ -589,11 +578,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) byte_p;
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
header_size = sizeof (cbc_uint16_arguments_t);
|
||||
@@ -603,11 +588,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) byte_p;
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
header_size = sizeof (cbc_uint8_arguments_t);
|
||||
@@ -630,13 +611,33 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
|
||||
uint8_t *real_bytecode_p = ((uint8_t *) bytecode_p) + start_offset;
|
||||
uint32_t new_code_size = (uint32_t) (start_offset + 1 + sizeof (uint8_t *));
|
||||
uint32_t extra_bytes = 0;
|
||||
|
||||
if (argument_end != 0)
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
new_code_size += (uint32_t) (argument_end * sizeof (ecma_value_t));
|
||||
extra_bytes += (uint32_t) (argument_end * sizeof (ecma_value_t));
|
||||
}
|
||||
|
||||
new_code_size = JERRY_ALIGNUP (new_code_size, JMEM_ALIGNMENT);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* function name */
|
||||
if (!(bytecode_p->status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR))
|
||||
{
|
||||
extra_bytes += (uint32_t) sizeof (ecma_value_t);
|
||||
}
|
||||
|
||||
/* tagged template literals */
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS)
|
||||
{
|
||||
extra_bytes += (uint32_t) sizeof (ecma_value_t);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
/* resource name */
|
||||
extra_bytes += (uint32_t) sizeof (ecma_value_t);
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
new_code_size = JERRY_ALIGNUP (new_code_size + extra_bytes, JMEM_ALIGNMENT);
|
||||
|
||||
bytecode_p = (ecma_compiled_code_t *) jmem_heap_alloc_block (new_code_size);
|
||||
|
||||
@@ -650,12 +651,12 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
|
||||
if (argument_end != 0)
|
||||
uint8_t *new_base_p = byte_p + new_code_size - extra_bytes;
|
||||
const uint8_t *base_p = base_addr_p + code_size - extra_bytes;
|
||||
|
||||
if (extra_bytes != 0)
|
||||
{
|
||||
uint32_t argument_size = (uint32_t) (argument_end * sizeof (ecma_value_t));
|
||||
memcpy (byte_p + new_code_size - argument_size,
|
||||
base_addr_p + code_size - argument_size,
|
||||
argument_size);
|
||||
memcpy (new_base_p, base_p, extra_bytes);
|
||||
}
|
||||
|
||||
byte_p[start_offset] = CBC_SET_BYTECODE_PTR;
|
||||
@@ -702,18 +703,17 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
}
|
||||
}
|
||||
|
||||
if (argument_end != 0)
|
||||
{
|
||||
literal_start_p = (ecma_value_t *) (((uint8_t *) bytecode_p) + code_size);
|
||||
literal_start_p -= argument_end;
|
||||
uint8_t *byte_p = ((uint8_t *) bytecode_p) + code_size;
|
||||
literal_start_p = ecma_snapshot_resolve_serializable_values (bytecode_p, byte_p);
|
||||
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
while (literal_start_p < (ecma_value_t *) byte_p)
|
||||
{
|
||||
if ((*literal_start_p & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET)
|
||||
{
|
||||
if ((literal_start_p[i] & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET)
|
||||
{
|
||||
literal_start_p[i] = ecma_snapshot_get_literal (literal_base_p, literal_start_p[i]);
|
||||
}
|
||||
*literal_start_p = ecma_snapshot_get_literal (literal_base_p, *literal_start_p);
|
||||
}
|
||||
|
||||
literal_start_p++;
|
||||
}
|
||||
|
||||
return bytecode_p;
|
||||
@@ -746,9 +746,17 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
||||
JERRY_UNUSED (resource_name_p);
|
||||
JERRY_UNUSED (resource_name_length);
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
JERRY_CONTEXT (resource_name) = ECMA_VALUE_UNDEFINED;
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
if (resource_name_length == 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
snapshot_globals_t globals;
|
||||
ecma_value_t parse_status;
|
||||
@@ -761,11 +769,14 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
||||
globals.regex_found = false;
|
||||
globals.class_found = false;
|
||||
|
||||
uint32_t status_flags = ((generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STRICT) ? ECMA_PARSE_STRICT_MODE
|
||||
: ECMA_PARSE_NO_OPTS);
|
||||
|
||||
parse_status = parser_parse_script (args_p,
|
||||
args_size,
|
||||
source_p,
|
||||
source_size,
|
||||
(generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STRICT) != 0,
|
||||
status_flags,
|
||||
&bytecode_data_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (parse_status))
|
||||
@@ -989,7 +1000,14 @@ jerry_snapshot_result (const uint32_t *snapshot_p, /**< snapshot */
|
||||
|
||||
if (as_function)
|
||||
{
|
||||
ecma_object_t *lex_env_p = ecma_get_global_environment ();
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED)
|
||||
{
|
||||
ecma_create_global_lexical_block ();
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_object_t *lex_env_p = ecma_get_global_scope ();
|
||||
ecma_object_t *func_obj_p = ecma_op_create_simple_function_object (lex_env_p, bytecode_p);
|
||||
|
||||
if (!(bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
||||
@@ -1069,7 +1087,6 @@ scan_snapshot_functions (const uint8_t *buffer_p, /**< snapshot buffer start */
|
||||
&& !(bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
||||
{
|
||||
const ecma_value_t *literal_start_p;
|
||||
uint32_t argument_end;
|
||||
uint32_t const_literal_end;
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
@@ -1077,7 +1094,6 @@ scan_snapshot_functions (const uint8_t *buffer_p, /**< snapshot buffer start */
|
||||
literal_start_p = (ecma_value_t *) (buffer_p + sizeof (cbc_uint16_arguments_t));
|
||||
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
else
|
||||
@@ -1085,7 +1101,6 @@ scan_snapshot_functions (const uint8_t *buffer_p, /**< snapshot buffer start */
|
||||
literal_start_p = (ecma_value_t *) (buffer_p + sizeof (cbc_uint8_arguments_t));
|
||||
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
|
||||
@@ -1098,20 +1113,18 @@ scan_snapshot_functions (const uint8_t *buffer_p, /**< snapshot buffer start */
|
||||
}
|
||||
}
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
literal_start_p = ((ecma_value_t *) byte_p) - argument_end;
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p + (((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG);
|
||||
literal_start_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t *) bytecode_p, byte_p);
|
||||
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
while (literal_start_p < (ecma_value_t *) byte_p)
|
||||
{
|
||||
if ((*literal_start_p & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET)
|
||||
{
|
||||
if ((literal_start_p[i] & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET)
|
||||
{
|
||||
ecma_value_t lit_value = ecma_snapshot_get_literal (literal_base_p, literal_start_p[i]);
|
||||
ecma_save_literals_append_value (lit_value, lit_pool_p);
|
||||
}
|
||||
ecma_value_t lit_value = ecma_snapshot_get_literal (literal_base_p, *literal_start_p);
|
||||
ecma_save_literals_append_value (lit_value, lit_pool_p);
|
||||
}
|
||||
|
||||
literal_start_p++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1140,7 +1153,6 @@ update_literal_offsets (uint8_t *buffer_p, /**< [in,out] snapshot buffer start *
|
||||
&& !(bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
||||
{
|
||||
ecma_value_t *literal_start_p;
|
||||
uint32_t argument_end;
|
||||
uint32_t const_literal_end;
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
@@ -1148,7 +1160,6 @@ update_literal_offsets (uint8_t *buffer_p, /**< [in,out] snapshot buffer start *
|
||||
literal_start_p = (ecma_value_t *) (buffer_p + sizeof (cbc_uint16_arguments_t));
|
||||
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
else
|
||||
@@ -1156,7 +1167,6 @@ update_literal_offsets (uint8_t *buffer_p, /**< [in,out] snapshot buffer start *
|
||||
literal_start_p = (ecma_value_t *) (buffer_p + sizeof (cbc_uint8_arguments_t));
|
||||
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) buffer_p;
|
||||
argument_end = args_p->argument_end;
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
}
|
||||
|
||||
@@ -1176,27 +1186,25 @@ update_literal_offsets (uint8_t *buffer_p, /**< [in,out] snapshot buffer start *
|
||||
}
|
||||
}
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p + (((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG);
|
||||
literal_start_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t *) bytecode_p, byte_p);
|
||||
|
||||
while (literal_start_p < (ecma_value_t *) byte_p)
|
||||
{
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
literal_start_p = ((ecma_value_t *) byte_p) - argument_end;
|
||||
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
if ((*literal_start_p & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET)
|
||||
{
|
||||
if ((literal_start_p[i] & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET)
|
||||
ecma_value_t lit_value = ecma_snapshot_get_literal (literal_base_p, *literal_start_p);
|
||||
const lit_mem_to_snapshot_id_map_entry_t *current_p = lit_map_p;
|
||||
|
||||
while (current_p->literal_id != lit_value)
|
||||
{
|
||||
ecma_value_t lit_value = ecma_snapshot_get_literal (literal_base_p, literal_start_p[i]);
|
||||
const lit_mem_to_snapshot_id_map_entry_t *current_p = lit_map_p;
|
||||
|
||||
while (current_p->literal_id != lit_value)
|
||||
{
|
||||
current_p++;
|
||||
}
|
||||
|
||||
literal_start_p[i] = current_p->literal_offset;
|
||||
current_p++;
|
||||
}
|
||||
|
||||
*literal_start_p = current_p->literal_offset;
|
||||
}
|
||||
|
||||
literal_start_p++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+335
-47
@@ -22,6 +22,7 @@
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-comparison.h"
|
||||
#include "ecma-container-object.h"
|
||||
#include "ecma-dataview-object.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-eval.h"
|
||||
@@ -30,11 +31,13 @@
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-init-finalize.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "lit-char-helpers.h"
|
||||
#include "ecma-literal-storage.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-regexp-object.h"
|
||||
#include "ecma-promise-object.h"
|
||||
#include "ecma-proxy-object.h"
|
||||
#include "ecma-symbol-object.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "opcodes.h"
|
||||
@@ -73,9 +76,8 @@ JERRY_STATIC_ASSERT ((int) RE_FLAG_GLOBAL == (int) JERRY_REGEXP_FLAG_GLOBAL
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
||||
/* The internal ECMA_PROMISE_STATE_* values are "one byte away" from the API values */
|
||||
JERRY_STATIC_ASSERT (((ECMA_PROMISE_STATE_PENDING + 1) == JERRY_PROMISE_STATE_PENDING)
|
||||
&& ((ECMA_PROMISE_STATE_FULFILLED + 1) == JERRY_PROMISE_STATE_FULFILLED)
|
||||
&& ((ECMA_PROMISE_STATE_REJECTED + 1) == JERRY_PROMISE_STATE_REJECTED),
|
||||
JERRY_STATIC_ASSERT ((int) ECMA_PROMISE_IS_PENDING == (int) JERRY_PROMISE_STATE_PENDING
|
||||
&& (int) ECMA_PROMISE_IS_FULFILLED == (int) JERRY_PROMISE_STATE_FULFILLED,
|
||||
promise_internal_state_matches_external);
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
|
||||
@@ -427,7 +429,7 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
if (resource_name_length == 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
@@ -437,7 +439,7 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
ecma_value_t parse_status;
|
||||
@@ -505,7 +507,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
ecma_value_t parse_status;
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
if (resource_name_length == 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
@@ -515,7 +517,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
if (arg_list_p == NULL)
|
||||
{
|
||||
@@ -582,8 +584,8 @@ jerry_run (const jerry_value_t func_val) /**< function to run */
|
||||
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) func_obj_p;
|
||||
|
||||
ecma_object_t *scope_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_func_p->u.function.scope_cp);
|
||||
ecma_object_t *scope_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
|
||||
ext_func_p->u.function.scope_cp);
|
||||
|
||||
if (scope_p != ecma_get_global_environment ())
|
||||
{
|
||||
@@ -803,6 +805,25 @@ jerry_value_is_promise (const jerry_value_t value) /**< api value */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
} /* jerry_value_is_promise */
|
||||
|
||||
/**
|
||||
* Check if the specified value is a proxy object.
|
||||
*
|
||||
* @return true - if the specified value is a proxy object,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_value_is_proxy (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
return (ecma_is_value_object (value)
|
||||
&& ECMA_OBJECT_IS_PROXY (ecma_get_object_from_value (value)));
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
JERRY_UNUSED (value);
|
||||
return false;
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
} /* jerry_value_is_proxy */
|
||||
|
||||
/**
|
||||
* Check if the specified value is string.
|
||||
*
|
||||
@@ -966,6 +987,9 @@ jerry_is_feature_enabled (const jerry_feature_t feature) /**< feature to check *
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
|
||||
|| feature == JERRY_FEATURE_DATAVIEW
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
|| feature == JERRY_FEATURE_PROXY
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
#if ENABLED (JERRY_BUILTIN_DATE)
|
||||
|| feature == JERRY_FEATURE_DATE
|
||||
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
|
||||
@@ -978,6 +1002,18 @@ jerry_is_feature_enabled (const jerry_feature_t feature) /**< feature to check *
|
||||
#if ENABLED (JERRY_LOGGING)
|
||||
|| feature == JERRY_FEATURE_LOGGING
|
||||
#endif /* ENABLED (JERRY_LOGGING) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
|| feature == JERRY_FEATURE_MAP
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
|| feature == JERRY_FEATURE_SET
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP)
|
||||
|| feature == JERRY_FEATURE_WEAKMAP
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||
|| feature == JERRY_FEATURE_WEAKSET
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
);
|
||||
} /* jerry_is_feature_enabled */
|
||||
|
||||
@@ -1579,12 +1615,50 @@ jerry_create_promise (void)
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
||||
return ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_PROMISE_EXECUTOR_EMPTY);
|
||||
ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target);
|
||||
|
||||
if (old_new_target_p == NULL)
|
||||
{
|
||||
JERRY_CONTEXT (current_new_target) = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE);
|
||||
}
|
||||
|
||||
ecma_value_t promise_value = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_PROMISE_EXECUTOR_EMPTY);
|
||||
|
||||
JERRY_CONTEXT (current_new_target) = old_new_target_p;
|
||||
return promise_value;
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Promise not supported.")));
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
} /* jerry_create_promise */
|
||||
|
||||
/**
|
||||
* Create a new Proxy object with the given target and handler
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_release_value, when it is no longer needed.
|
||||
*
|
||||
* @return value of the created Proxy object
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_create_proxy (const jerry_value_t target, /**< target argument */
|
||||
const jerry_value_t handler) /**< handler argument */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
if (ecma_is_value_error_reference (target)
|
||||
|| ecma_is_value_error_reference (handler))
|
||||
{
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
ecma_object_t *proxy_p = ecma_proxy_create (target, handler);
|
||||
return jerry_return (proxy_p == NULL ? ECMA_VALUE_ERROR : ecma_make_object_value (proxy_p));
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Proxy is not supported.")));
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
} /* jerry_create_proxy */
|
||||
|
||||
/**
|
||||
* Create string from a valid UTF-8 string
|
||||
*
|
||||
@@ -1709,11 +1783,20 @@ jerry_create_regexp_sz (const jerry_char_t *pattern_p, /**< zero-terminated UTF-
|
||||
return jerry_throw (ecma_raise_common_error (ECMA_ERR_MSG ("Input must be a valid utf8 string")));
|
||||
}
|
||||
|
||||
ecma_object_t *regexp_obj_p = ecma_op_regexp_alloc (NULL);
|
||||
|
||||
if (JERRY_UNLIKELY (regexp_obj_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_string_t *ecma_pattern = ecma_new_ecma_string_from_utf8 (pattern_p, pattern_size);
|
||||
|
||||
jerry_value_t ret_val = ecma_op_create_regexp_object (ecma_pattern, flags);
|
||||
|
||||
jerry_value_t ret_val = ecma_op_create_regexp_with_flags (regexp_obj_p,
|
||||
ecma_make_string_value (ecma_pattern),
|
||||
flags);
|
||||
ecma_deref_ecma_string (ecma_pattern);
|
||||
|
||||
return ret_val;
|
||||
|
||||
#else /* !ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
@@ -1986,8 +2069,8 @@ jerry_substring_to_utf8_char_buffer (const jerry_value_t value, /**< input strin
|
||||
/**
|
||||
* Checks whether the object or it's prototype objects have the given property.
|
||||
*
|
||||
* @return true - if the property exists
|
||||
* false - otherwise
|
||||
* @return raised error - if the operation fail
|
||||
* true/false API value - depend on whether the property exists
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_has_property (const jerry_value_t obj_val, /**< object value */
|
||||
@@ -2001,17 +2084,15 @@ jerry_has_property (const jerry_value_t obj_val, /**< object value */
|
||||
return ECMA_VALUE_FALSE;
|
||||
}
|
||||
|
||||
bool has_property = ecma_op_object_has_property (ecma_get_object_from_value (obj_val),
|
||||
ecma_get_prop_name_from_value (prop_name_val));
|
||||
|
||||
return ecma_make_boolean_value (has_property);
|
||||
return ecma_op_object_has_property (ecma_get_object_from_value (obj_val),
|
||||
ecma_get_prop_name_from_value (prop_name_val));
|
||||
} /* jerry_has_property */
|
||||
|
||||
/**
|
||||
* Checks whether the object has the given property.
|
||||
*
|
||||
* @return true - if the property exists
|
||||
* false - otherwise
|
||||
* @return ECMA_VALUE_ERROR - if the operation raises error
|
||||
* ECMA_VALUE_{TRUE, FALSE} - based on whether the property exists
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_has_own_property (const jerry_value_t obj_val, /**< object value */
|
||||
@@ -2025,10 +2106,26 @@ jerry_has_own_property (const jerry_value_t obj_val, /**< object value */
|
||||
return ECMA_VALUE_FALSE;
|
||||
}
|
||||
|
||||
bool has_property = ecma_op_object_has_own_property (ecma_get_object_from_value (obj_val),
|
||||
ecma_get_prop_name_from_value (prop_name_val));
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);
|
||||
ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (prop_name_val);
|
||||
|
||||
return ecma_make_boolean_value (has_property);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
ecma_value_t status = ecma_proxy_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc);
|
||||
|
||||
if (ecma_is_value_true (status))
|
||||
{
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
}
|
||||
|
||||
return jerry_return (status);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
return ecma_make_boolean_value (ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p));
|
||||
} /* jerry_has_own_property */
|
||||
|
||||
/**
|
||||
@@ -2092,6 +2189,15 @@ jerry_delete_property (const jerry_value_t obj_val, /**< object value */
|
||||
ecma_value_t ret_value = ecma_op_object_delete (ecma_get_object_from_value (obj_val),
|
||||
ecma_get_prop_name_from_value (prop_name_val),
|
||||
false);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
// TODO: Due to Proxies the return value must be changed to jerry_value_t on next release
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
return ecma_is_value_true (ret_value);
|
||||
} /* jerry_delete_property */
|
||||
|
||||
@@ -2118,6 +2224,14 @@ jerry_delete_property_by_index (const jerry_value_t obj_val, /**< object value *
|
||||
false);
|
||||
ecma_deref_ecma_string (str_idx_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
// TODO: Due to Proxies the return value must be changed to jerry_value_t on next release
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
return ecma_is_value_true (ret_value);
|
||||
} /* jerry_delete_property_by_index */
|
||||
|
||||
@@ -2468,8 +2582,8 @@ jerry_define_own_property (const jerry_value_t obj_val, /**< object value */
|
||||
|
||||
if (prop_desc_p->is_configurable_defined)
|
||||
{
|
||||
flags |= (uint32_t) (ECMA_PROP_IS_CONFIGURABLE_DEFINED | (prop_desc_p->is_enumerable ? ECMA_PROP_IS_CONFIGURABLE
|
||||
: ECMA_PROP_NO_OPTS));
|
||||
flags |= (uint32_t) (ECMA_PROP_IS_CONFIGURABLE_DEFINED | (prop_desc_p->is_configurable ? ECMA_PROP_IS_CONFIGURABLE
|
||||
: ECMA_PROP_NO_OPTS));
|
||||
}
|
||||
|
||||
/* Copy data property info. */
|
||||
@@ -2560,9 +2674,19 @@ jerry_get_own_property_descriptor (const jerry_value_t obj_val, /**< object val
|
||||
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
if (!ecma_op_object_get_own_property_descriptor (ecma_get_object_from_value (obj_val),
|
||||
ecma_get_prop_name_from_value (prop_name_val),
|
||||
&prop_desc))
|
||||
ecma_value_t status = ecma_op_object_get_own_property_descriptor (ecma_get_object_from_value (obj_val),
|
||||
ecma_get_prop_name_from_value (prop_name_val),
|
||||
&prop_desc);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
// TODO: Due to Proxies the return value must be changed to jerry_value_t on next release
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (!ecma_is_value_true (status))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -2677,7 +2801,7 @@ jerry_invoke_function (bool is_invoke_as_constructor, /**< true - invoke functio
|
||||
JERRY_ASSERT (jerry_value_is_constructor (func_obj_val));
|
||||
|
||||
return jerry_return (ecma_op_function_construct (ecma_get_object_from_value (func_obj_val),
|
||||
ECMA_VALUE_UNDEFINED,
|
||||
ecma_get_object_from_value (func_obj_val),
|
||||
args_p,
|
||||
args_count));
|
||||
}
|
||||
@@ -2803,6 +2927,13 @@ jerry_get_prototype (const jerry_value_t obj_val) /**< object value */
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
return jerry_return (ecma_proxy_object_get_prototype_of (obj_p));
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (obj_p->u2.prototype_cp == JMEM_CP_NULL)
|
||||
{
|
||||
return ECMA_VALUE_NULL;
|
||||
@@ -2834,16 +2965,14 @@ jerry_set_prototype (const jerry_value_t obj_val, /**< object value */
|
||||
}
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);
|
||||
|
||||
if (ecma_is_value_null (proto_obj_val))
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
obj_p->u2.prototype_cp = JMEM_CP_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_SET_NON_NULL_POINTER (obj_p->u2.prototype_cp, ecma_get_object_from_value (proto_obj_val));
|
||||
return jerry_return (ecma_proxy_object_set_prototype_of (obj_p, proto_obj_val));
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
return ECMA_VALUE_TRUE;
|
||||
return ecma_op_ordinary_object_set_prototype_of (obj_p, proto_obj_val);
|
||||
} /* jerry_set_prototype */
|
||||
|
||||
/**
|
||||
@@ -2871,9 +3000,7 @@ bool jerry_object_is_valid_foreach (ecma_object_t *object_p) /**< object to test
|
||||
switch (ext_object_p->u.class_prop.class_id)
|
||||
{
|
||||
/* An object's internal property object should not be iterable by foreach. */
|
||||
case LIT_INTERNAL_MAGIC_STRING_INTERNAL_OBJECT:
|
||||
/* Containers are internal data, do not iterate on them. */
|
||||
case LIT_INTERNAL_MAGIC_STRING_CONTAINER: return false;
|
||||
case LIT_INTERNAL_MAGIC_STRING_INTERNAL_OBJECT: return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3073,6 +3200,16 @@ jerry_foreach_object_property (const jerry_value_t obj_val, /**< object value */
|
||||
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (obj_val);
|
||||
ecma_collection_t *names_p = ecma_op_object_get_property_names (object_p, ECMA_LIST_ENUMERABLE_PROTOTYPE);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (names_p == NULL)
|
||||
{
|
||||
// TODO: Due to Proxies the return value must be changed to jerry_value_t on next release
|
||||
jcontext_release_exception ();
|
||||
return false;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t *buffer_p = names_p->buffer_p;
|
||||
|
||||
ecma_value_t property_value = ECMA_VALUE_EMPTY;
|
||||
@@ -3193,12 +3330,10 @@ jerry_get_promise_state (const jerry_value_t promise) /**< promise object to get
|
||||
return JERRY_PROMISE_STATE_NONE;
|
||||
}
|
||||
|
||||
uint8_t state = ecma_promise_get_state (ecma_get_object_from_value (promise));
|
||||
uint16_t flags = ecma_promise_get_flags (ecma_get_object_from_value (promise));
|
||||
flags &= (ECMA_PROMISE_IS_PENDING | ECMA_PROMISE_IS_FULFILLED);
|
||||
|
||||
JERRY_ASSERT (state < ECMA_PROMISE_STATE__COUNT);
|
||||
|
||||
/* Static assert above guarantees the mapping from internal type to external type. */
|
||||
return (jerry_promise_state_t) (state + 1);
|
||||
return (flags ? flags : JERRY_PROMISE_STATE_REJECTED);
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
JERRY_UNUSED (promise);
|
||||
return JERRY_PROMISE_STATE_NONE;
|
||||
@@ -3411,7 +3546,7 @@ jerry_get_backtrace (uint32_t max_depth) /**< depth limit of the backtrace */
|
||||
jerry_value_t
|
||||
jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
|
||||
{
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
if (ecma_is_value_undefined (value))
|
||||
{
|
||||
if (JERRY_CONTEXT (vm_top_context_p) != NULL)
|
||||
@@ -3419,7 +3554,7 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
|
||||
return ecma_copy_value (JERRY_CONTEXT (vm_top_context_p)->resource_name);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
#if ENABLED (JERRY_LINE_INFO)
|
||||
else if (ecma_is_value_object (value))
|
||||
{
|
||||
@@ -3457,7 +3592,7 @@ jerry_get_new_target (void)
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_object_t *current_new_target = JERRY_CONTEXT (current_new_target);
|
||||
|
||||
if (current_new_target == NULL || current_new_target == JERRY_CONTEXT_INVALID_NEW_TARGET)
|
||||
if (current_new_target == NULL)
|
||||
{
|
||||
return jerry_create_undefined ();
|
||||
}
|
||||
@@ -4269,6 +4404,159 @@ jerry_json_stringify (const jerry_value_t object_to_stringify) /**< a jerry_obje
|
||||
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
||||
} /* jerry_json_stringify */
|
||||
|
||||
/**
|
||||
* Create a container type specified in jerry_container_type_t.
|
||||
* The container can be created with a list of arguments, which will be passed to the container constructor to be
|
||||
* inserted to the container.
|
||||
*
|
||||
* Note:
|
||||
* The returned value must be freed with jerry_release_value
|
||||
* @return jerry_value_t representing a container with the given type.
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_create_container (jerry_container_type_t container_type, /**< Type of the container */
|
||||
const jerry_value_t *arguments_list_p, /**< arguments list */
|
||||
jerry_length_t arguments_list_len) /**< Length of arguments list */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_CONTAINER)
|
||||
for (jerry_length_t i = 0; i < arguments_list_len; i++)
|
||||
{
|
||||
if (ecma_is_value_error_reference (arguments_list_p[i]))
|
||||
{
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (error_value_msg_p)));
|
||||
}
|
||||
}
|
||||
|
||||
lit_magic_string_id_t lit_id;
|
||||
ecma_builtin_id_t proto_id;
|
||||
ecma_builtin_id_t ctor_id;
|
||||
|
||||
switch (container_type)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
case JERRY_CONTAINER_TYPE_MAP:
|
||||
{
|
||||
lit_id = LIT_MAGIC_STRING_MAP_UL;
|
||||
proto_id = ECMA_BUILTIN_ID_MAP_PROTOTYPE;
|
||||
ctor_id = ECMA_BUILTIN_ID_MAP;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
case JERRY_CONTAINER_TYPE_SET:
|
||||
{
|
||||
lit_id = LIT_MAGIC_STRING_SET_UL;
|
||||
proto_id = ECMA_BUILTIN_ID_SET_PROTOTYPE;
|
||||
ctor_id = ECMA_BUILTIN_ID_SET;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP)
|
||||
case JERRY_CONTAINER_TYPE_WEAKMAP:
|
||||
{
|
||||
lit_id = LIT_MAGIC_STRING_WEAKMAP_UL;
|
||||
proto_id = ECMA_BUILTIN_ID_WEAKMAP_PROTOTYPE;
|
||||
ctor_id = ECMA_BUILTIN_ID_WEAKMAP;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||
case JERRY_CONTAINER_TYPE_WEAKSET:
|
||||
{
|
||||
lit_id = LIT_MAGIC_STRING_WEAKSET_UL;
|
||||
proto_id = ECMA_BUILTIN_ID_WEAKSET_PROTOTYPE;
|
||||
ctor_id = ECMA_BUILTIN_ID_WEAKSET;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
default:
|
||||
{
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Invalid container type.")));
|
||||
}
|
||||
}
|
||||
ecma_object_t * old_new_target_p = JERRY_CONTEXT (current_new_target);
|
||||
|
||||
if (old_new_target_p == NULL)
|
||||
{
|
||||
JERRY_CONTEXT (current_new_target) = ecma_builtin_get (ctor_id);
|
||||
}
|
||||
|
||||
ecma_value_t container_value = ecma_op_container_create (arguments_list_p,
|
||||
arguments_list_len,
|
||||
lit_id,
|
||||
proto_id);
|
||||
|
||||
JERRY_CONTEXT (current_new_target) = old_new_target_p;
|
||||
return container_value;
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
JERRY_UNUSED (arguments_list_p);
|
||||
JERRY_UNUSED (arguments_list_len);
|
||||
JERRY_UNUSED (container_type);
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Containers are disabled.")));
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
} /* jerry_create_container */
|
||||
|
||||
/**
|
||||
* Get the type of the given container object.
|
||||
*
|
||||
* @return Corresponding type to the given container object.
|
||||
*/
|
||||
jerry_container_type_t
|
||||
jerry_get_container_type (const jerry_value_t value) /**< the container object */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_CONTAINER)
|
||||
if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_CLASS)
|
||||
{
|
||||
uint16_t type = ((ecma_extended_object_t *) obj_p)->u.class_prop.class_id;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
case LIT_MAGIC_STRING_MAP_UL:
|
||||
{
|
||||
return JERRY_CONTAINER_TYPE_MAP;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
case LIT_MAGIC_STRING_SET_UL:
|
||||
{
|
||||
return JERRY_CONTAINER_TYPE_SET;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP)
|
||||
case LIT_MAGIC_STRING_WEAKMAP_UL:
|
||||
{
|
||||
return JERRY_CONTAINER_TYPE_WEAKMAP;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||
case LIT_MAGIC_STRING_WEAKSET_UL:
|
||||
{
|
||||
return JERRY_CONTAINER_TYPE_WEAKSET;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
default:
|
||||
{
|
||||
return JERRY_CONTAINER_TYPE_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
JERRY_UNUSED (value);
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
return JERRY_CONTAINER_TYPE_INVALID;
|
||||
} /* jerry_get_container_type */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -103,6 +103,10 @@
|
||||
# define JERRY_ES2015_BUILTIN_PROMISE JERRY_ES2015
|
||||
#endif /* !defined (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
|
||||
#ifndef JERRY_ES2015_BUILTIN_PROXY
|
||||
# define JERRY_ES2015_BUILTIN_PROXY JERRY_ES2015
|
||||
#endif /* !defined (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
#ifndef JERRY_ES2015_BUILTIN_REFLECT
|
||||
# define JERRY_ES2015_BUILTIN_REFLECT JERRY_ES2015
|
||||
#endif /* !defined (JERRY_ES2015_BUILTIN_REFLECT) */
|
||||
@@ -543,6 +547,10 @@
|
||||
|| ((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_PROXY) \
|
||||
|| ((JERRY_ES2015_BUILTIN_PROXY != 0) && (JERRY_ES2015_BUILTIN_PROXY != 1))
|
||||
# error "Invalid value for JERRY_ES2015_BUILTIN_PROXY 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."
|
||||
@@ -676,4 +684,13 @@
|
||||
# define JERRY_ES2015_BUILTIN_CONTAINER 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Resource name relatey types into a single guard
|
||||
*/
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
# define JERRY_RESOURCE_NAME 1
|
||||
#else
|
||||
# define JERRY_RESOURCE_NAME 0
|
||||
#endif
|
||||
|
||||
#endif /* !JERRYSCRIPT_CONFIG_H */
|
||||
|
||||
@@ -1474,11 +1474,9 @@ jerry_debugger_exception_object_to_string (ecma_value_t exception_obj_value) /**
|
||||
}
|
||||
}
|
||||
|
||||
lit_utf8_size_t size = lit_get_magic_string_size (string_id);
|
||||
JERRY_ASSERT (size <= 14);
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
|
||||
|
||||
lit_utf8_byte_t data[16];
|
||||
memcpy (data, lit_get_magic_string_utf8 (string_id), size);
|
||||
ecma_stringbuilder_append_magic (&builder, string_id);
|
||||
|
||||
ecma_property_t *property_p;
|
||||
property_p = ecma_find_named_property (ecma_get_object_from_value (exception_obj_value),
|
||||
@@ -1487,21 +1485,21 @@ jerry_debugger_exception_object_to_string (ecma_value_t exception_obj_value) /**
|
||||
if (property_p == NULL
|
||||
|| ECMA_PROPERTY_GET_TYPE (*property_p) != ECMA_PROPERTY_TYPE_NAMEDDATA)
|
||||
{
|
||||
return ecma_new_ecma_string_from_utf8 (data, size);
|
||||
return ecma_stringbuilder_finalize (&builder);
|
||||
}
|
||||
|
||||
ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
|
||||
if (!ecma_is_value_string (prop_value_p->value))
|
||||
{
|
||||
return ecma_new_ecma_string_from_utf8 (data, size);
|
||||
return ecma_stringbuilder_finalize (&builder);
|
||||
}
|
||||
|
||||
data[size] = LIT_CHAR_COLON;
|
||||
data[size + 1] = LIT_CHAR_SP;
|
||||
ecma_stringbuilder_append_byte (&builder, LIT_CHAR_COLON);
|
||||
ecma_stringbuilder_append_byte (&builder, LIT_CHAR_SP);
|
||||
ecma_stringbuilder_append (&builder, ecma_get_string_from_value (prop_value_p->value));
|
||||
|
||||
return ecma_concat_ecma_strings (ecma_new_ecma_string_from_utf8 (data, size + 2),
|
||||
ecma_get_string_from_value (prop_value_p->value));
|
||||
return ecma_stringbuilder_finalize (&builder);
|
||||
} /* jerry_debugger_exception_object_to_string */
|
||||
|
||||
/**
|
||||
|
||||
+229
-202
@@ -24,7 +24,9 @@
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-property-hashmap.h"
|
||||
#include "ecma-proxy-object.h"
|
||||
#include "jcontext.h"
|
||||
#include "jrt.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
@@ -113,8 +115,6 @@ ecma_init_gc_info (ecma_object_t *object_p) /**< object */
|
||||
JERRY_CONTEXT (ecma_gc_objects_number)++;
|
||||
JERRY_CONTEXT (ecma_gc_new_objects)++;
|
||||
|
||||
JERRY_ASSERT (JERRY_CONTEXT (ecma_gc_new_objects) <= JERRY_CONTEXT (ecma_gc_objects_number));
|
||||
|
||||
JERRY_ASSERT (object_p->type_flags_refs < ECMA_OBJECT_REF_ONE);
|
||||
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs | ECMA_OBJECT_REF_ONE);
|
||||
|
||||
@@ -215,15 +215,15 @@ ecma_gc_mark_bound_function_object (ecma_object_t *object_p) /**< bound function
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
|
||||
ecma_extended_object_t *ext_function_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p;
|
||||
|
||||
ecma_object_t *target_func_obj_p;
|
||||
target_func_obj_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_function_p->u.bound_function.target_function);
|
||||
ecma_object_t *target_func_p;
|
||||
target_func_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
|
||||
bound_func_p->header.u.bound_function.target_function);
|
||||
|
||||
ecma_gc_set_object_visited (target_func_obj_p);
|
||||
ecma_gc_set_object_visited (target_func_p);
|
||||
|
||||
ecma_value_t args_len_or_this = ext_function_p->u.bound_function.args_len_or_this;
|
||||
ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this;
|
||||
|
||||
if (!ecma_is_value_integer_number (args_len_or_this))
|
||||
{
|
||||
@@ -236,7 +236,7 @@ ecma_gc_mark_bound_function_object (ecma_object_t *object_p) /**< bound function
|
||||
}
|
||||
|
||||
ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this);
|
||||
ecma_value_t *args_p = (ecma_value_t *) (ext_function_p + 1);
|
||||
ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1);
|
||||
|
||||
JERRY_ASSERT (args_length > 0);
|
||||
|
||||
@@ -266,119 +266,136 @@ ecma_gc_mark_promise_object (ecma_extended_object_t *ext_object_p) /**< extended
|
||||
|
||||
/* Mark all reactions. */
|
||||
ecma_promise_object_t *promise_object_p = (ecma_promise_object_t *) ext_object_p;
|
||||
ecma_collection_t *collection_p = promise_object_p->fulfill_reactions;
|
||||
ecma_collection_t *collection_p = promise_object_p->reactions;
|
||||
|
||||
if (collection_p != NULL)
|
||||
{
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
ecma_value_t *buffer_end_p = buffer_p + collection_p->item_count;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
while (buffer_p < buffer_end_p)
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (buffer_p[i]));
|
||||
}
|
||||
}
|
||||
ecma_value_t value = *buffer_p++;
|
||||
|
||||
collection_p = promise_object_p->reject_reactions;
|
||||
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, value));
|
||||
|
||||
if (collection_p != NULL)
|
||||
{
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
if (JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (value))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (*buffer_p++));
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (buffer_p[i]));
|
||||
if (JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (value))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (*buffer_p++));
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* ecma_gc_mark_promise_object */
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_CONTAINER)
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
/**
|
||||
* Mark objects referenced by Map/Set built-in.
|
||||
* Mark objects referenced by Map built-in.
|
||||
*/
|
||||
static void
|
||||
ecma_gc_mark_container_object (ecma_object_t *object_p) /**< object */
|
||||
ecma_gc_mark_map_object (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
|
||||
ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_object_t *internal_obj_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
map_object_p->u.class_prop.u.value);
|
||||
ecma_extended_object_t *internal_ext_p = (ecma_extended_object_t *) internal_obj_p;
|
||||
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
|
||||
map_object_p->u.class_prop.u.value);
|
||||
ecma_value_t *start_p = ECMA_CONTAINER_START (container_p);
|
||||
uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
|
||||
|
||||
ecma_gc_set_object_visited (internal_obj_p);
|
||||
|
||||
jmem_cpointer_t prop_iter_cp = internal_obj_p->u1.property_list_cp;
|
||||
|
||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
||||
if (prop_iter_cp != JMEM_CP_NULL)
|
||||
for (uint32_t i = 0; i < entry_count; i+= ECMA_CONTAINER_PAIR_SIZE)
|
||||
{
|
||||
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t,
|
||||
prop_iter_cp);
|
||||
if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP)
|
||||
ecma_container_pair_t *entry_p = (ecma_container_pair_t *) (start_p + i);
|
||||
|
||||
if (ecma_is_value_empty (entry_p->key))
|
||||
{
|
||||
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
||||
|
||||
while (prop_iter_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||
|
||||
ecma_gc_mark_properties ((ecma_property_pair_t *) prop_iter_p);
|
||||
|
||||
if ((internal_ext_p->u.class_prop.extra_info & ECMA_CONTAINER_FLAGS_WEAK) == 0)
|
||||
{
|
||||
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
||||
|
||||
for (uint32_t i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
||||
{
|
||||
ecma_property_t *property_p = (ecma_property_t *) (prop_iter_p->types + i);
|
||||
|
||||
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_PTR)
|
||||
{
|
||||
jmem_cpointer_t name_cp = prop_pair_p->names_cp[i];
|
||||
ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, name_cp);
|
||||
|
||||
if (ECMA_STRING_GET_CONTAINER (prop_name_p) == ECMA_STRING_CONTAINER_MAP_KEY)
|
||||
{
|
||||
ecma_value_t key_arg = ((ecma_extended_string_t *) prop_name_p)->u.value;
|
||||
|
||||
if (ecma_is_value_object (key_arg))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (key_arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||
}
|
||||
} /* ecma_gc_mark_container_object */
|
||||
if (ecma_is_value_object (entry_p->key))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (entry_p->key));
|
||||
}
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
if (ecma_is_value_object (entry_p->value))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (entry_p->value));
|
||||
}
|
||||
}
|
||||
} /* ecma_gc_mark_map_object */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP)
|
||||
/**
|
||||
* Mark objects referenced by WeakMap built-in.
|
||||
*/
|
||||
static void
|
||||
ecma_gc_mark_weakmap_object (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
|
||||
ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
|
||||
map_object_p->u.class_prop.u.value);
|
||||
ecma_value_t *start_p = ECMA_CONTAINER_START (container_p);
|
||||
uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
|
||||
|
||||
for (uint32_t i = 0; i < entry_count; i+= ECMA_CONTAINER_PAIR_SIZE)
|
||||
{
|
||||
ecma_container_pair_t *entry_p = (ecma_container_pair_t *) (start_p + i);
|
||||
|
||||
if (ecma_is_value_empty (entry_p->key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ecma_is_value_object (entry_p->value))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (entry_p->value));
|
||||
}
|
||||
}
|
||||
} /* ecma_gc_mark_weakmap_object */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
/**
|
||||
* Mark objects referenced by Set built-in.
|
||||
*/
|
||||
static void
|
||||
ecma_gc_mark_set_object (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
|
||||
ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
|
||||
map_object_p->u.class_prop.u.value);
|
||||
ecma_value_t *start_p = ECMA_CONTAINER_START (container_p);
|
||||
uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
|
||||
|
||||
for (uint32_t i = 0; i < entry_count; i+= ECMA_CONTAINER_VALUE_SIZE)
|
||||
{
|
||||
ecma_value_t *entry_p = start_p + i;
|
||||
|
||||
if (ecma_is_value_empty (*entry_p))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ecma_is_value_object (*entry_p))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (*entry_p));
|
||||
}
|
||||
}
|
||||
} /* ecma_gc_mark_set_object */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
|
||||
/**
|
||||
* Mark tagged template literals of the compiled code.
|
||||
*/
|
||||
static void
|
||||
ecma_gc_mark_tagged_template_literals (const ecma_compiled_code_t *byte_code_p)
|
||||
{
|
||||
JERRY_ASSERT (byte_code_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS);
|
||||
|
||||
ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (byte_code_p);
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (collection_p->buffer_p[i]));
|
||||
}
|
||||
} /* ecma_gc_mark_tagged_template_literals */
|
||||
|
||||
/**
|
||||
* Mark objects referenced by inactive generator functions, async functions, etc.
|
||||
*/
|
||||
@@ -450,6 +467,29 @@ ecma_gc_mark_executable_object (ecma_object_t *object_p) /**< object */
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
/**
|
||||
* Mark the objects referenced by a proxy object
|
||||
*/
|
||||
static void
|
||||
ecma_gc_mark_proxy_object (ecma_object_t *object_p) /**< proxy object */
|
||||
{
|
||||
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (object_p));
|
||||
|
||||
ecma_proxy_object_t *proxy_p = (ecma_proxy_object_t *) object_p;
|
||||
|
||||
if (!ecma_is_value_null (proxy_p->target))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (proxy_p->target));
|
||||
}
|
||||
|
||||
if (!ecma_is_value_null (proxy_p->handler))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (proxy_p->handler));
|
||||
}
|
||||
} /* ecma_gc_mark_proxy_object */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
/**
|
||||
* Mark objects as visited starting from specified object as root
|
||||
*/
|
||||
@@ -509,22 +549,33 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_CONTAINER)
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
case LIT_MAGIC_STRING_MAP_UL:
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||
case LIT_MAGIC_STRING_WEAKSET_UL:
|
||||
{
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
case LIT_MAGIC_STRING_SET_UL:
|
||||
{
|
||||
ecma_gc_mark_set_object (object_p);
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP)
|
||||
case LIT_MAGIC_STRING_WEAKMAP_UL:
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||
case LIT_MAGIC_STRING_WEAKSET_UL:
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
{
|
||||
ecma_gc_mark_container_object (object_p);
|
||||
ecma_gc_mark_weakmap_object (object_p);
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
case LIT_MAGIC_STRING_MAP_UL:
|
||||
{
|
||||
ecma_gc_mark_map_object (object_p);
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case LIT_MAGIC_STRING_GENERATOR_UL:
|
||||
@@ -609,6 +660,13 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
}
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
case ECMA_OBJECT_TYPE_PROXY:
|
||||
{
|
||||
ecma_gc_mark_proxy_object (object_p);
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
{
|
||||
ecma_gc_mark_bound_function_object (object_p);
|
||||
@@ -619,38 +677,43 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
if (!ecma_get_object_is_builtin (object_p))
|
||||
{
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_func_p->u.function.scope_cp));
|
||||
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
|
||||
ext_func_p->u.function.scope_cp));
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
const ecma_compiled_code_t *byte_code_p = ecma_op_function_get_compiled_code (ext_func_p);
|
||||
|
||||
if (byte_code_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS)
|
||||
if (byte_code_p->status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION)
|
||||
{
|
||||
ecma_gc_mark_tagged_template_literals (byte_code_p);
|
||||
ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) object_p;
|
||||
|
||||
if (ecma_is_value_object (arrow_func_p->this_binding))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (arrow_func_p->this_binding));
|
||||
}
|
||||
|
||||
if (ecma_is_value_object (arrow_func_p->new_target))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (arrow_func_p->new_target));
|
||||
}
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case ECMA_OBJECT_TYPE_ARROW_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
|
||||
{
|
||||
ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) object_p;
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
arrow_func_p->scope_cp));
|
||||
|
||||
if (ecma_is_value_object (arrow_func_p->this_binding))
|
||||
if (ext_func_p->u.external_handler_cb == ecma_proxy_revoke_cb)
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (arrow_func_p->this_binding));
|
||||
}
|
||||
ecma_revocable_proxy_object_t *rev_proxy_p = (ecma_revocable_proxy_object_t *) object_p;
|
||||
|
||||
const ecma_compiled_code_t *byte_code_p = ecma_op_arrow_function_get_compiled_code (arrow_func_p);
|
||||
|
||||
if (byte_code_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS)
|
||||
{
|
||||
ecma_gc_mark_tagged_template_literals (byte_code_p);
|
||||
if (!ecma_is_value_null (rev_proxy_p->proxy))
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (rev_proxy_p->proxy));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -843,7 +906,7 @@ ecma_gc_free_executable_object (ecma_object_t *object_p) /**< object */
|
||||
/**
|
||||
* Free properties of an object
|
||||
*/
|
||||
static void
|
||||
void
|
||||
ecma_gc_free_properties (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp;
|
||||
@@ -987,6 +1050,14 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (ext_func_p->u.external_handler_cb == ecma_proxy_revoke_cb)
|
||||
{
|
||||
ext_object_size = sizeof (ecma_revocable_proxy_object_t);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_CLASS:
|
||||
@@ -1012,17 +1083,13 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
ecma_dealloc_number (num_p);
|
||||
break;
|
||||
}
|
||||
|
||||
case LIT_MAGIC_STRING_REGEXP_UL:
|
||||
{
|
||||
ecma_compiled_code_t *bytecode_p;
|
||||
bytecode_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_compiled_code_t,
|
||||
ext_object_p->u.class_prop.u.value);
|
||||
ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_compiled_code_t,
|
||||
ext_object_p->u.class_prop.u.value);
|
||||
|
||||
ecma_bytecode_deref (bytecode_p);
|
||||
|
||||
if (bytecode_p != NULL)
|
||||
{
|
||||
ecma_bytecode_deref (bytecode_p);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
||||
@@ -1055,8 +1122,10 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
case LIT_MAGIC_STRING_PROMISE_UL:
|
||||
{
|
||||
ecma_free_value_if_not_object (ext_object_p->u.class_prop.u.value);
|
||||
ecma_collection_free_if_not_object (((ecma_promise_object_t *) object_p)->fulfill_reactions);
|
||||
ecma_collection_free_if_not_object (((ecma_promise_object_t *) object_p)->reject_reactions);
|
||||
|
||||
/* Reactions only contains objects. */
|
||||
ecma_collection_destroy (((ecma_promise_object_t *) object_p)->reactions);
|
||||
|
||||
ext_object_size = sizeof (ecma_promise_object_t);
|
||||
break;
|
||||
}
|
||||
@@ -1075,50 +1144,12 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
case LIT_MAGIC_STRING_WEAKSET_UL:
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
{
|
||||
break;
|
||||
}
|
||||
case LIT_INTERNAL_MAGIC_STRING_CONTAINER:
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) || ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||
ecma_extended_object_t *container_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
|
||||
map_object_p->u.class_prop.u.value);
|
||||
ecma_op_container_free_entries (object_p);
|
||||
ecma_collection_destroy (container_p);
|
||||
|
||||
if (container_p->u.class_prop.extra_info & ECMA_CONTAINER_FLAGS_WEAK)
|
||||
{
|
||||
jmem_cpointer_t prop_iter_cp = container_p->object.u1.property_list_cp;
|
||||
while (prop_iter_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||
|
||||
/* Both cannot be deleted. */
|
||||
JERRY_ASSERT (prop_iter_p->types[0] != ECMA_PROPERTY_TYPE_DELETED
|
||||
|| prop_iter_p->types[1] != ECMA_PROPERTY_TYPE_DELETED);
|
||||
|
||||
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
||||
|
||||
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
||||
{
|
||||
ecma_property_t *property_p = (ecma_property_t *) (prop_iter_p->types + i);
|
||||
|
||||
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_PTR)
|
||||
{
|
||||
jmem_cpointer_t name_cp = prop_pair_p->names_cp[i];
|
||||
ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, name_cp);
|
||||
|
||||
if (JERRY_LIKELY (ECMA_STRING_GET_CONTAINER (prop_name_p) == ECMA_STRING_CONTAINER_MAP_KEY))
|
||||
{
|
||||
ecma_value_t key_arg = ((ecma_extended_string_t *) prop_name_p)->u.value;
|
||||
ecma_object_t *key_object_p = ecma_get_object_from_value (key_arg);
|
||||
|
||||
ecma_op_container_unref_weak (key_object_p, ecma_make_object_value (object_p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) || ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
@@ -1150,6 +1181,13 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
case ECMA_OBJECT_TYPE_PROXY:
|
||||
{
|
||||
ext_object_size = sizeof (ecma_proxy_object_t);
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
{
|
||||
/* Function with byte-code (not a built-in function). */
|
||||
@@ -1159,8 +1197,19 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
if (ext_func_p->u.function.bytecode_cp != ECMA_NULL_POINTER)
|
||||
{
|
||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
||||
ecma_bytecode_deref (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
|
||||
ext_func_p->u.function.bytecode_cp));
|
||||
ecma_compiled_code_t *byte_code_p = (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
|
||||
ext_func_p->u.function.bytecode_cp));
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (byte_code_p->status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION)
|
||||
{
|
||||
ecma_free_value_if_not_object (((ecma_arrow_function_t *) object_p)->this_binding);
|
||||
ecma_free_value_if_not_object (((ecma_arrow_function_t *) object_p)->new_target);
|
||||
ext_object_size = sizeof (ecma_arrow_function_t);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_bytecode_deref (byte_code_p);
|
||||
#if ENABLED (JERRY_SNAPSHOT_EXEC)
|
||||
}
|
||||
else
|
||||
@@ -1170,29 +1219,6 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case ECMA_OBJECT_TYPE_ARROW_FUNCTION:
|
||||
{
|
||||
ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) object_p;
|
||||
|
||||
ecma_free_value_if_not_object (arrow_func_p->this_binding);
|
||||
|
||||
#if ENABLED (JERRY_SNAPSHOT_EXEC)
|
||||
if (arrow_func_p->bytecode_cp != ECMA_NULL_POINTER)
|
||||
{
|
||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
||||
ecma_bytecode_deref (ECMA_GET_NON_NULL_POINTER (ecma_compiled_code_t, arrow_func_p->bytecode_cp));
|
||||
ext_object_size = sizeof (ecma_arrow_function_t);
|
||||
#if ENABLED (JERRY_SNAPSHOT_EXEC)
|
||||
}
|
||||
else
|
||||
{
|
||||
ext_object_size = sizeof (ecma_static_arrow_function_t);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
@@ -1253,9 +1279,10 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
{
|
||||
ecma_extended_object_t *ext_function_p = (ecma_extended_object_t *) object_p;
|
||||
ext_object_size = sizeof (ecma_bound_function_t);
|
||||
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p;
|
||||
|
||||
ecma_value_t args_len_or_this = ext_function_p->u.bound_function.args_len_or_this;
|
||||
ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this;
|
||||
|
||||
if (!ecma_is_value_integer_number (args_len_or_this))
|
||||
{
|
||||
@@ -1264,7 +1291,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
|
||||
}
|
||||
|
||||
ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this);
|
||||
ecma_value_t *args_p = (ecma_value_t *) (ext_function_p + 1);
|
||||
ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1);
|
||||
|
||||
for (ecma_integer_value_t i = 0; i < args_length; i++)
|
||||
{
|
||||
@@ -1416,7 +1443,7 @@ ecma_gc_run (void)
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
/* Free RegExp bytecodes stored in cache */
|
||||
re_cache_gc_run ();
|
||||
re_cache_gc ();
|
||||
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
} /* ecma_gc_run */
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
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_free_properties (ecma_object_t *object_p);
|
||||
void ecma_gc_run (void);
|
||||
void ecma_free_unused_memory (jmem_pressure_t pressure);
|
||||
|
||||
|
||||
@@ -36,6 +36,15 @@
|
||||
*/
|
||||
#define ECMA_NULL_POINTER JMEM_CP_NULL
|
||||
|
||||
#if defined (JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY)
|
||||
|
||||
/**
|
||||
* JMEM_ALIGNMENT_LOG aligned pointers can be stored directly in ecma_value_t
|
||||
*/
|
||||
#define ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
|
||||
|
||||
#endif /* JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -89,26 +98,37 @@ typedef enum
|
||||
#endif /* ENABLED (JERRY_DEBUGGER) */
|
||||
|
||||
/**
|
||||
* Option flags for script parsing.
|
||||
* Option flags for parser_parse_script and internal flags for global_status_flags in parser context.
|
||||
* Note:
|
||||
* The enum members must be kept in sync with parser_general_flags_t
|
||||
* The last 16 bits are reserved for scope chain index
|
||||
* the last 16 bits is reserved for internal parser flags, because the debugger uses these
|
||||
* 16 bits to encode the scope chain skip index as well (see ECMA_PARSE_CHAIN_INDEX_SHIFT)
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_PARSE_NO_OPTS = 0, /**< no options passed */
|
||||
ECMA_PARSE_STRICT_MODE = (1u << 0), /**< enable strict mode */
|
||||
ECMA_PARSE_DIRECT_EVAL = (1u << 1), /**< eval is called directly (ECMA-262 v5, 15.1.2.1.1) */
|
||||
/* These four status flags must be in this order. See PARSER_CLASS_PARSE_OPTS_OFFSET. */
|
||||
ECMA_PARSE_CLASS_CONSTRUCTOR = (1u << 2), /**< a class constructor is being parsed (this value must be kept in
|
||||
* in sync with PARSER_CLASS_CONSTRUCTOR) */
|
||||
ECMA_PARSE_HAS_SUPER = (1u << 3), /**< the current context has super reference */
|
||||
ECMA_PARSE_HAS_IMPL_SUPER = (1u << 4), /**< the current context has implicit parent class */
|
||||
ECMA_PARSE_HAS_STATIC_SUPER = (1u << 5), /**< the current context is a static class method */
|
||||
ECMA_PARSE_EVAL = (1u << 6), /**< eval is called */
|
||||
ECMA_PARSE_MODULE = (1u << 7), /**< module is parsed */
|
||||
ECMA_PARSE_FUNCTION = (1u << 8), /**< a function body is parsed or the code is inside a function */
|
||||
ECMA_PARSE_STRICT_MODE = (1u << 0), /**< enable strict mode, must be same as PARSER_IS_STRICT */
|
||||
ECMA_PARSE_MODULE = (1u << 1), /**< module is parsed */
|
||||
ECMA_PARSE_EVAL = (1u << 2), /**< eval is called */
|
||||
ECMA_PARSE_DIRECT_EVAL = (1u << 3), /**< eval is called directly (ECMA-262 v5, 15.1.2.1.1) */
|
||||
ECMA_PARSE_CLASS_CONSTRUCTOR = (1u << 4), /**< a class constructor is being parsed */
|
||||
|
||||
/* These four status flags must be in this order. The first three are also parser status flags.
|
||||
* See PARSER_SAVE_STATUS_FLAGS / PARSER_RESTORE_STATUS_FLAGS. */
|
||||
ECMA_PARSE_ALLOW_SUPER = (1u << 5), /**< allow super property access */
|
||||
ECMA_PARSE_ALLOW_SUPER_CALL = (1u << 6), /**< allow super constructor call */
|
||||
ECMA_PARSE_ALLOW_NEW_TARGET = (1u << 7), /**< allow new.target access */
|
||||
ECMA_PARSE_FUNCTION_CONTEXT = (1u << 8), /**< function context is present (ECMA_PARSE_DIRECT_EVAL must be set) */
|
||||
|
||||
ECMA_PARSE_GENERATOR_FUNCTION = (1u << 9), /**< generator function is parsed */
|
||||
|
||||
/* These flags are internally used by the parser. */
|
||||
#ifndef JERRY_NDEBUG
|
||||
/**
|
||||
* This flag represents an error in for in/of statements, which cannot be set
|
||||
* if the parsing is completed successfully.
|
||||
*/
|
||||
ECMA_PARSE_INTERNAL_FOR_IN_OFF_CONTEXT_ERROR = (1u << 30),
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
} ecma_parse_opts_t;
|
||||
|
||||
/**
|
||||
@@ -123,15 +143,6 @@ typedef uint32_t ecma_value_t;
|
||||
*/
|
||||
typedef int32_t ecma_integer_value_t;
|
||||
|
||||
#if UINTPTR_MAX <= UINT32_MAX
|
||||
|
||||
/**
|
||||
* JMEM_ALIGNMENT_LOG aligned pointers can be stored directly in ecma_value_t
|
||||
*/
|
||||
#define ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
|
||||
|
||||
#endif /* UINTPTR_MAX <= UINT32_MAX */
|
||||
|
||||
/**
|
||||
* Mask for ecma types in ecma_value_t
|
||||
*/
|
||||
@@ -191,7 +202,8 @@ enum
|
||||
* ecma_op_object_find */
|
||||
ECMA_VALUE_REGISTER_REF = ECMA_MAKE_VALUE (8), /**< register reference,
|
||||
* a special "base" value for vm */
|
||||
ECMA_VALUE_IMPLICIT_CONSTRUCTOR = ECMA_MAKE_VALUE (9), /**< special value for bound class constructors */
|
||||
ECMA_VALUE_RELEASE_LEX_ENV = ECMA_MAKE_VALUE (9), /**< if this error remains on the stack when an exception occours
|
||||
the top lexical environment of the VM frame should be popped */
|
||||
ECMA_VALUE_UNINITIALIZED = ECMA_MAKE_VALUE (10), /**< a special value for uninitialized let/const declarations */
|
||||
ECMA_VALUE_SPREAD_ELEMENT = ECMA_MAKE_VALUE (11), /**< a special value for spread elements in array initialization
|
||||
* or function call argument list */
|
||||
@@ -398,6 +410,15 @@ typedef enum
|
||||
*/
|
||||
#define ECMA_PROPERTY_FIXED 0
|
||||
|
||||
/**
|
||||
* Default flag of length property.
|
||||
*/
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
#define ECMA_PROPERTY_FLAG_DEFAULT_LENGTH ECMA_PROPERTY_FLAG_CONFIGURABLE
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
#define ECMA_PROPERTY_FLAG_DEFAULT_LENGTH ECMA_PROPERTY_FIXED
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
* Shift for property name part.
|
||||
*/
|
||||
@@ -601,6 +622,7 @@ typedef enum
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS = 0, /**< no option flags for ecma_op_object_get_property */
|
||||
ECMA_PROPERTY_GET_VALUE = 1u << 0, /**< fill virtual_value field for virtual properties */
|
||||
ECMA_PROPERTY_GET_EXT_REFERENCE = 1u << 1, /**< get extended reference to the property */
|
||||
ECMA_PROPERTY_GET_HAS_OWN_PROP = 1u << 2, /**< internal [[HasOwnProperty]] method */
|
||||
} ecma_property_get_option_bits_t;
|
||||
|
||||
/**
|
||||
@@ -612,11 +634,9 @@ typedef enum
|
||||
ECMA_OBJECT_TYPE_CLASS = 1, /**< Objects with class property */
|
||||
ECMA_OBJECT_TYPE_ARRAY = 2, /**< Array object (15.4) */
|
||||
ECMA_OBJECT_TYPE_PSEUDO_ARRAY = 3, /**< Array-like object, such as Arguments object (10.6) */
|
||||
ECMA_OBJECT_TYPE_PROXY = 4, /**< Proxy object ECMAScript v6 26.2 */
|
||||
/* Note: these 4 types must be in this order. See IsCallable operation. */
|
||||
ECMA_OBJECT_TYPE_FUNCTION = 4, /**< Function objects (15.3), created through 13.2 routine */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ECMA_OBJECT_TYPE_ARROW_FUNCTION = 5, /**< arrow function objects */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
ECMA_OBJECT_TYPE_FUNCTION = 5, /**< Function objects (15.3), created through 13.2 routine */
|
||||
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 6, /**< Function objects (15.3), created through 15.3.4.5 routine */
|
||||
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION = 7, /**< External (host) function object */
|
||||
/* Types between 13-15 cannot have a built-in flag. See ecma_lexical_environment_type_t. */
|
||||
@@ -649,12 +669,12 @@ typedef enum
|
||||
ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE = 13, /**< declarative lexical environment */
|
||||
ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND = 14, /**< object-bound lexical environment
|
||||
* with provideThis flag */
|
||||
ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND = 15, /**< object-bound lexical environment
|
||||
* with provided super reference */
|
||||
ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND = 15, /**< object-bound lexical environment
|
||||
* with provided home object reference */
|
||||
|
||||
ECMA_LEXICAL_ENVIRONMENT_TYPE_START = ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< first lexical
|
||||
* environment type */
|
||||
ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND /**< maximum value */
|
||||
ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND /**< maximum value */
|
||||
} ecma_lexical_environment_type_t;
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
@@ -674,29 +694,30 @@ typedef enum
|
||||
/**
|
||||
* Offset for JERRY_CONTEXT (status_flags) top 8 bits.
|
||||
*/
|
||||
#define ECMA_SUPER_EVAL_OPTS_OFFSET (32 - 8)
|
||||
#define ECMA_LOCAL_PARSE_OPTS_OFFSET ((sizeof (uint32_t) - sizeof (uint8_t)) * JERRY_BITSINBYTE)
|
||||
|
||||
/**
|
||||
* Set JERRY_CONTEXT (status_flags) top 8 bits to the specified 'opts'.
|
||||
*/
|
||||
#define ECMA_SET_SUPER_EVAL_PARSER_OPTS(opts) \
|
||||
#define ECMA_SET_LOCAL_PARSE_OPTS(opts) \
|
||||
do \
|
||||
{ \
|
||||
JERRY_CONTEXT (status_flags) |= ((uint32_t) opts << ECMA_SUPER_EVAL_OPTS_OFFSET) | ECMA_STATUS_DIRECT_EVAL; \
|
||||
JERRY_CONTEXT (status_flags) |= ((uint32_t) opts << ECMA_LOCAL_PARSE_OPTS_OFFSET) | ECMA_STATUS_DIRECT_EVAL; \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* Get JERRY_CONTEXT (status_flags) top 8 bits.
|
||||
*/
|
||||
#define ECMA_GET_SUPER_EVAL_PARSER_OPTS() (JERRY_CONTEXT (status_flags) >> ECMA_SUPER_EVAL_OPTS_OFFSET)
|
||||
#define ECMA_GET_LOCAL_PARSE_OPTS() \
|
||||
(JERRY_CONTEXT (status_flags) >> (ECMA_LOCAL_PARSE_OPTS_OFFSET - JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)))
|
||||
|
||||
/**
|
||||
* Clear JERRY_CONTEXT (status_flags) top 8 bits.
|
||||
*/
|
||||
#define ECMA_CLEAR_SUPER_EVAL_PARSER_OPTS() \
|
||||
#define ECMA_CLEAR_LOCAL_PARSE_OPTS() \
|
||||
do \
|
||||
{ \
|
||||
JERRY_CONTEXT (status_flags) &= ((1 << ECMA_SUPER_EVAL_OPTS_OFFSET) - 1); \
|
||||
JERRY_CONTEXT (status_flags) &= ((1 << ECMA_LOCAL_PARSE_OPTS_OFFSET) - 1); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
@@ -766,8 +787,9 @@ typedef struct
|
||||
union
|
||||
{
|
||||
jmem_cpointer_t property_list_cp; /**< compressed pointer to object's
|
||||
* or declerative lexical environments's property list */
|
||||
* or declerative lexical environments's property list */
|
||||
jmem_cpointer_t bound_object_cp; /**< compressed pointer to lexical environments's the bound object */
|
||||
jmem_cpointer_t home_object_cp; /**< compressed pointer to lexical environments's the home object */
|
||||
} u1;
|
||||
|
||||
/** object prototype or outer reference */
|
||||
@@ -787,9 +809,29 @@ typedef struct
|
||||
uint8_t length_and_bitset_size; /**< length for built-in functions and
|
||||
* bit set size for all built-ins */
|
||||
uint16_t routine_id; /**< routine id for built-in functions */
|
||||
uint32_t instantiated_bitset[1]; /**< bit set for instantiated properties */
|
||||
union
|
||||
{
|
||||
uint32_t instantiated_bitset[1]; /**< bit set for instantiated properties */
|
||||
struct
|
||||
{
|
||||
uint16_t name; /**< name of the built-in functions */
|
||||
uint16_t bitset; /**< bit set for instantiated properties of builtin functions */
|
||||
} builtin_routine;
|
||||
} u;
|
||||
} ecma_built_in_props_t;
|
||||
|
||||
/**
|
||||
* Builtin routine function object status flags
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_BUILTIN_ROUTINE_NO_OPTS = 0, /**< No options are provided */
|
||||
ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED = (1u << 0), /**< 'length' property has been initialized */
|
||||
ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED = (1u << 1), /**< 'name' property has been initialized */
|
||||
ECMA_BUILTIN_ROUTINE_GETTER = (1u << 2), /**< this routine is getter */
|
||||
ECMA_BUILTIN_ROUTINE_SETTER = (1u << 3), /**< this routine is setter */
|
||||
} ecma_builtin_routine_flags_t;
|
||||
|
||||
/**
|
||||
* Start position of bit set size in length_and_bitset_size field.
|
||||
*/
|
||||
@@ -827,6 +869,7 @@ typedef struct
|
||||
{
|
||||
ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
|
||||
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
|
||||
ecma_value_t target; /**< [[ProxyTarget]] internal property */
|
||||
} u;
|
||||
} class_prop;
|
||||
|
||||
@@ -835,7 +878,7 @@ typedef struct
|
||||
*/
|
||||
struct
|
||||
{
|
||||
ecma_value_t scope_cp; /**< function scope */
|
||||
jmem_cpointer_tag_t scope_cp; /**< function scope */
|
||||
ecma_value_t bytecode_cp; /**< function byte code */
|
||||
} function;
|
||||
|
||||
@@ -883,7 +926,7 @@ typedef struct
|
||||
*/
|
||||
struct
|
||||
{
|
||||
ecma_value_t target_function; /**< target function */
|
||||
jmem_cpointer_tag_t target_function; /**< target function */
|
||||
ecma_value_t args_len_or_this; /**< length of arguments or this value */
|
||||
} bound_function;
|
||||
|
||||
@@ -926,6 +969,17 @@ typedef struct
|
||||
* If regexp, the other flags must be RE_FLAG... */
|
||||
} ecma_compiled_code_t;
|
||||
|
||||
/**
|
||||
* Description of bound function objects.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_extended_object_t header; /**< extended object header */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_integer_value_t target_length; /**< length of target function */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
} ecma_bound_function_t;
|
||||
|
||||
#if ENABLED (JERRY_SNAPSHOT_EXEC)
|
||||
|
||||
/**
|
||||
@@ -946,10 +1000,9 @@ typedef struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_object_t object; /**< object header */
|
||||
ecma_extended_object_t header; /**< extended object header */
|
||||
ecma_value_t this_binding; /**< value of 'this' binding */
|
||||
jmem_cpointer_t scope_cp; /**< function scope */
|
||||
jmem_cpointer_t bytecode_cp; /**< function byte code */
|
||||
ecma_value_t new_target; /**< value of new.target */
|
||||
} ecma_arrow_function_t;
|
||||
|
||||
#if ENABLED (JERRY_SNAPSHOT_EXEC)
|
||||
@@ -976,6 +1029,50 @@ typedef enum
|
||||
ECMA_CONTAINER_FLAGS_EMPTY = (0), /** empty flags */
|
||||
ECMA_CONTAINER_FLAGS_WEAK = (1 << 0) /** container object is weak */
|
||||
} ecma_container_flags_t;
|
||||
|
||||
/**
|
||||
* Description of map collection.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_value_t key; /**< key value */
|
||||
ecma_value_t value; /**< value of the key */
|
||||
} ecma_container_pair_t;
|
||||
|
||||
/**
|
||||
* Size of a single element (in ecma_value_t unit).
|
||||
*/
|
||||
#define ECMA_CONTAINER_VALUE_SIZE 1
|
||||
|
||||
/**
|
||||
* Size of a key - value pair (in ecma_value_t unit).
|
||||
*/
|
||||
#define ECMA_CONTAINER_PAIR_SIZE 2
|
||||
|
||||
/**
|
||||
* Size of the internal buffer.
|
||||
*/
|
||||
#define ECMA_CONTAINER_GET_SIZE(container_p) \
|
||||
(container_p->buffer_p[0])
|
||||
|
||||
/**
|
||||
* Remove the size field of the internal buffer.
|
||||
*/
|
||||
#define ECMA_CONTAINER_SET_SIZE(container_p, size) \
|
||||
(container_p->buffer_p[0] = (ecma_value_t) (size))
|
||||
|
||||
/**
|
||||
* Number of entries of the internal buffer.
|
||||
*/
|
||||
#define ECMA_CONTAINER_ENTRY_COUNT(collection_p) \
|
||||
(collection_p->item_count - 1)
|
||||
|
||||
/**
|
||||
* Pointer to the first entry of the internal buffer.
|
||||
*/
|
||||
#define ECMA_CONTAINER_START(collection_p) \
|
||||
(collection_p->buffer_p + 1)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||
|
||||
typedef enum
|
||||
@@ -1416,9 +1513,7 @@ typedef enum
|
||||
|
||||
ECMA_STRING_CONTAINER_SYMBOL, /**< the ecma-string is a symbol */
|
||||
|
||||
ECMA_STRING_CONTAINER_MAP_KEY, /**< the ecma-string is a map key string */
|
||||
|
||||
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_MAP_KEY /**< maximum value */
|
||||
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_SYMBOL /**< maximum value */
|
||||
} ecma_string_container_t;
|
||||
|
||||
/**
|
||||
@@ -1675,12 +1770,12 @@ typedef struct
|
||||
/**
|
||||
* Function callback descriptor of a %TypedArray% object getter
|
||||
*/
|
||||
typedef ecma_number_t (*ecma_typedarray_getter_fn_t)(lit_utf8_byte_t *src);
|
||||
typedef ecma_number_t (*ecma_typedarray_getter_fn_t) (lit_utf8_byte_t *src);
|
||||
|
||||
/**
|
||||
* Function callback descriptor of a %TypedArray% object setter
|
||||
*/
|
||||
typedef void (*ecma_typedarray_setter_fn_t)(lit_utf8_byte_t *src, ecma_number_t value);
|
||||
typedef void (*ecma_typedarray_setter_fn_t) (lit_utf8_byte_t *src, ecma_number_t value);
|
||||
|
||||
/**
|
||||
* Builtin id for the different types of TypedArray's
|
||||
@@ -1827,6 +1922,32 @@ do \
|
||||
#define ECMA_CHECK_STACK_USAGE()
|
||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||
|
||||
/**
|
||||
* Invalid object pointer which represents abrupt completion
|
||||
*/
|
||||
#define ECMA_OBJECT_POINTER_ERROR ((ecma_object_t *) 0x01)
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
/**
|
||||
* Description of Proxy objects.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_object_t header; /**< header part */
|
||||
ecma_value_t target; /**< [[ProxyTarget]] internal slot */
|
||||
ecma_value_t handler; /**< [[ProxyHandler]] internal slot */
|
||||
} ecma_proxy_object_t;
|
||||
|
||||
/**
|
||||
* Description of Proxy objects.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_extended_object_t header; /**< header part */
|
||||
ecma_value_t proxy; /**< [[RevocableProxy]] internal slot */
|
||||
} ecma_revocable_proxy_object_t;
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@@ -144,6 +144,49 @@ ecma_collection_push_back (ecma_collection_t *collection_p, /**< value collectio
|
||||
collection_p->buffer_p = buffer_p;
|
||||
} /* ecma_collection_push_back */
|
||||
|
||||
/**
|
||||
* Reserve space for the given amount of ecma_values in the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_reserve (ecma_collection_t *collection_p, /**< value collection */
|
||||
uint32_t count) /**< number of ecma values to reserve */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
JERRY_ASSERT (UINT32_MAX - count > collection_p->capacity);
|
||||
|
||||
const uint32_t new_capacity = collection_p->capacity + count;
|
||||
const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity);
|
||||
const uint32_t new_size = ECMA_COLLECTION_ALLOCATED_SIZE (new_capacity);
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
buffer_p = jmem_heap_realloc_block (buffer_p, old_size, new_size);
|
||||
|
||||
collection_p->capacity = new_capacity;
|
||||
collection_p->buffer_p = buffer_p;
|
||||
} /* ecma_collection_reserve */
|
||||
|
||||
/**
|
||||
* Append a list of values to the end of the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_append (ecma_collection_t *collection_p, /**< value collection */
|
||||
const ecma_value_t *buffer_p, /**< values to append */
|
||||
uint32_t count) /**< number of ecma values to append */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
JERRY_ASSERT (collection_p->capacity >= collection_p->item_count);
|
||||
|
||||
uint32_t free_count = collection_p->capacity - collection_p->item_count;
|
||||
|
||||
if (free_count < count)
|
||||
{
|
||||
ecma_collection_reserve (collection_p, count - free_count);
|
||||
}
|
||||
|
||||
memcpy (collection_p->buffer_p + collection_p->item_count, buffer_p, count * sizeof (ecma_value_t));
|
||||
collection_p->item_count += count;
|
||||
} /* ecma_collection_append */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
@@ -193,7 +194,8 @@ ecma_delete_native_pointer_property (ecma_object_t *obj_p, /**< object to delete
|
||||
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);
|
||||
ecma_op_general_object_delete (obj_p, name_p, false);
|
||||
|
||||
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "ecma-conversion.h"
|
||||
#include "lit-char-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
@@ -656,6 +658,31 @@ ecma_number_calc_remainder (ecma_number_t left_num, /**< left operand */
|
||||
return r;
|
||||
} /* ecma_number_calc_remainder */
|
||||
|
||||
/**
|
||||
* Compute power operation according to the ES standard.
|
||||
*
|
||||
* @return x ** y
|
||||
*/
|
||||
ecma_number_t
|
||||
ecma_number_pow (ecma_number_t x, /**< left operand */
|
||||
ecma_number_t y) /**< right operand */
|
||||
{
|
||||
if (ecma_number_is_nan (y) ||
|
||||
(ecma_number_is_infinity (y) && (x == 1.0 || x == -1.0)))
|
||||
{
|
||||
/* Handle differences between ES5.1 and ISO C standards for pow. */
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
if (ecma_number_is_zero (y))
|
||||
{
|
||||
/* Handle differences between ES5.1 and ISO C standards for pow. */
|
||||
return (ecma_number_t) 1.0;
|
||||
}
|
||||
|
||||
return DOUBLE_TO_ECMA_NUMBER_T (pow (x, y));
|
||||
} /* ecma_number_pow */
|
||||
|
||||
/**
|
||||
* ECMA-integer number multiplication.
|
||||
*
|
||||
@@ -681,6 +708,371 @@ ecma_integer_multiply (ecma_integer_value_t left_integer, /**< left operand */
|
||||
return ecma_make_integer_value (left_integer * right_integer);
|
||||
} /* ecma_integer_multiply */
|
||||
|
||||
/**
|
||||
* The Number object's 'parseInt' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_number_parse_int (const lit_utf8_byte_t *string_buff, /**< routine's first argument's
|
||||
* string buffer */
|
||||
lit_utf8_size_t string_buff_size, /**< routine's first argument's
|
||||
* string buffer's size */
|
||||
ecma_value_t radix) /**< routine's second argument */
|
||||
{
|
||||
if (string_buff_size == 0)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *string_curr_p = string_buff;
|
||||
|
||||
/* 2. Remove leading whitespace. */
|
||||
ecma_string_trim_helper (&string_curr_p, &string_buff_size);
|
||||
|
||||
const lit_utf8_byte_t *string_end_p = string_curr_p + string_buff_size;
|
||||
const lit_utf8_byte_t *start_p = string_curr_p;
|
||||
const lit_utf8_byte_t *end_p = string_end_p;
|
||||
|
||||
if (string_curr_p >= string_end_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* 3. */
|
||||
int sign = 1;
|
||||
|
||||
/* 4. */
|
||||
ecma_char_t current = lit_cesu8_read_next (&string_curr_p);
|
||||
if (current == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
|
||||
{
|
||||
start_p = string_curr_p;
|
||||
if (string_curr_p < string_end_p)
|
||||
{
|
||||
current = lit_cesu8_read_next (&string_curr_p);
|
||||
}
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
ecma_number_t radix_num;
|
||||
radix = ecma_get_number (radix, &radix_num);
|
||||
|
||||
if (!ecma_is_value_empty (radix))
|
||||
{
|
||||
return radix;
|
||||
}
|
||||
|
||||
int32_t rad = ecma_number_to_int32 (radix_num);
|
||||
|
||||
/* 7.*/
|
||||
bool strip_prefix = true;
|
||||
|
||||
/* 8. */
|
||||
if (rad != 0)
|
||||
{
|
||||
/* 8.a */
|
||||
if (rad < 2 || rad > 36)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
/* 8.b */
|
||||
else if (rad != 16)
|
||||
{
|
||||
strip_prefix = false;
|
||||
}
|
||||
}
|
||||
/* 9. */
|
||||
else
|
||||
{
|
||||
rad = 10;
|
||||
}
|
||||
|
||||
/* 10. */
|
||||
if (strip_prefix
|
||||
&& ((end_p - start_p) >= 2)
|
||||
&& (current == LIT_CHAR_0))
|
||||
{
|
||||
ecma_char_t next = *string_curr_p;
|
||||
if (next == LIT_CHAR_LOWERCASE_X || next == LIT_CHAR_UPPERCASE_X)
|
||||
{
|
||||
/* Skip the 'x' or 'X' characters. */
|
||||
start_p = ++string_curr_p;
|
||||
rad = 16;
|
||||
}
|
||||
}
|
||||
|
||||
/* 11. Check if characters are in [0, Radix - 1]. We also convert them to number values in the process. */
|
||||
string_curr_p = start_p;
|
||||
while (string_curr_p < string_end_p)
|
||||
{
|
||||
ecma_char_t current_char = *string_curr_p++;
|
||||
int32_t current_number;
|
||||
|
||||
if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
|
||||
{
|
||||
current_number = current_char - LIT_CHAR_LOWERCASE_A + 10;
|
||||
}
|
||||
else if ((current_char >= LIT_CHAR_UPPERCASE_A && current_char <= LIT_CHAR_UPPERCASE_Z))
|
||||
{
|
||||
current_number = current_char - LIT_CHAR_UPPERCASE_A + 10;
|
||||
}
|
||||
else if (lit_char_is_decimal_digit (current_char))
|
||||
{
|
||||
current_number = current_char - LIT_CHAR_0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not a valid number char, set value to radix so it fails to pass as a valid character. */
|
||||
current_number = rad;
|
||||
}
|
||||
|
||||
if (!(current_number < rad))
|
||||
{
|
||||
end_p = --string_curr_p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 12. */
|
||||
if (end_p == start_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
ecma_number_t value = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t multiplier = 1.0f;
|
||||
|
||||
/* 13. and 14. */
|
||||
string_curr_p = end_p;
|
||||
|
||||
while (string_curr_p > start_p)
|
||||
{
|
||||
ecma_char_t current_char = *(--string_curr_p);
|
||||
ecma_number_t current_number = ECMA_NUMBER_MINUS_ONE;
|
||||
|
||||
if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
|
||||
{
|
||||
current_number = (ecma_number_t) current_char - LIT_CHAR_LOWERCASE_A + 10;
|
||||
}
|
||||
else if ((current_char >= LIT_CHAR_UPPERCASE_A && current_char <= LIT_CHAR_UPPERCASE_Z))
|
||||
{
|
||||
current_number = (ecma_number_t) current_char - LIT_CHAR_UPPERCASE_A + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (lit_char_is_decimal_digit (current_char));
|
||||
current_number = (ecma_number_t) current_char - LIT_CHAR_0;
|
||||
}
|
||||
|
||||
value += current_number * multiplier;
|
||||
multiplier *= (ecma_number_t) rad;
|
||||
}
|
||||
|
||||
/* 15. */
|
||||
if (sign < 0)
|
||||
{
|
||||
value *= (ecma_number_t) sign;
|
||||
}
|
||||
return ecma_make_number_value (value);
|
||||
} /* ecma_number_parse_int */
|
||||
|
||||
/**
|
||||
* The Number object's 'parseFloat' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_number_parse_float (const lit_utf8_byte_t *string_buff, /**< routine's first argument's
|
||||
* string buffer */
|
||||
lit_utf8_size_t string_buff_size) /**< routine's first argument's
|
||||
* string buffer's size */
|
||||
{
|
||||
if (string_buff_size == 0)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *str_curr_p = string_buff;
|
||||
|
||||
/* 2. Remove leading whitespace. */
|
||||
ecma_string_trim_helper (&str_curr_p, &string_buff_size);
|
||||
|
||||
const lit_utf8_byte_t *str_end_p = str_curr_p + string_buff_size;
|
||||
const lit_utf8_byte_t *start_p = str_curr_p;
|
||||
const lit_utf8_byte_t *end_p = str_end_p;
|
||||
|
||||
bool sign = false;
|
||||
ecma_char_t current;
|
||||
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
/* Check if sign is present. */
|
||||
current = *str_curr_p;
|
||||
if (current == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = true;
|
||||
}
|
||||
|
||||
if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
|
||||
{
|
||||
/* Set starting position to be after the sign character. */
|
||||
start_p = ++str_curr_p;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if string is equal to "Infinity". */
|
||||
const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
const lit_utf8_size_t infinity_length = lit_get_magic_string_size (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
|
||||
/* The input string should be at least the length of "Infinity" to be correctly processed as
|
||||
* the infinity value.
|
||||
*/
|
||||
if ((str_end_p - str_curr_p) >= (int) infinity_length
|
||||
&& memcmp (infinity_str_p, str_curr_p, infinity_length) == 0)
|
||||
{
|
||||
/* String matched Infinity. */
|
||||
return ecma_make_number_value (ecma_number_make_infinity (sign));
|
||||
}
|
||||
|
||||
/* Reset to starting position. */
|
||||
str_curr_p = start_p;
|
||||
|
||||
/* String ended after sign character, or was empty after removing leading whitespace. */
|
||||
if (str_curr_p >= str_end_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* Reset to starting position. */
|
||||
str_curr_p = start_p;
|
||||
|
||||
current = *str_curr_p;
|
||||
|
||||
bool has_whole_part = false;
|
||||
bool has_fraction_part = false;
|
||||
|
||||
/* Check digits of whole part. */
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
has_whole_part = true;
|
||||
str_curr_p++;
|
||||
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to the end of whole part. */
|
||||
end_p = str_curr_p;
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p;
|
||||
|
||||
/* Check decimal point. */
|
||||
if (current == LIT_CHAR_DOT)
|
||||
{
|
||||
str_curr_p++;
|
||||
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p;
|
||||
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
has_fraction_part = true;
|
||||
|
||||
/* Check digits of fractional part. */
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to end of fraction part. */
|
||||
end_p = str_curr_p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
}
|
||||
|
||||
/* Check exponent. */
|
||||
if ((current == LIT_CHAR_LOWERCASE_E || current == LIT_CHAR_UPPERCASE_E)
|
||||
&& (has_whole_part || has_fraction_part)
|
||||
&& str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
|
||||
/* Check sign of exponent. */
|
||||
if ((current == LIT_CHAR_PLUS || current == LIT_CHAR_MINUS)
|
||||
&& str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
}
|
||||
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
/* Check digits of exponent part. */
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to end of exponent part. */
|
||||
end_p = str_curr_p;
|
||||
}
|
||||
}
|
||||
|
||||
/* String did not contain a valid number. */
|
||||
if (start_p == end_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
ecma_number_t ret_num = ecma_utf8_string_to_number (start_p, (lit_utf8_size_t) (end_p - start_p));
|
||||
|
||||
if (sign)
|
||||
{
|
||||
ret_num *= ECMA_NUMBER_MINUS_ONE;
|
||||
}
|
||||
|
||||
return ecma_make_number_value (ret_num);
|
||||
} /* ecma_number_parse_float */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@@ -240,41 +240,6 @@ ecma_prop_name_is_symbol (ecma_string_t *string_p) /**< ecma-string */
|
||||
} /* ecma_prop_name_is_symbol */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with reference to the map key descriptor
|
||||
*
|
||||
* @return pointer to ecma-string descriptor
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_new_map_key_string (ecma_value_t value) /**< non prop-name ecma-value */
|
||||
{
|
||||
JERRY_ASSERT (!ecma_is_value_prop_name (value));
|
||||
|
||||
ecma_extended_string_t *string_p = ecma_alloc_extended_string ();
|
||||
string_p->header.refs_and_container = ECMA_STRING_REF_ONE | ECMA_STRING_CONTAINER_MAP_KEY;
|
||||
string_p->u.value = ecma_copy_value_if_not_object (value);
|
||||
string_p->header.u.hash = (lit_string_hash_t) (ecma_is_value_simple (value) ? value : 0);
|
||||
|
||||
return (ecma_string_t *) string_p;
|
||||
} /* ecma_new_map_key_string */
|
||||
|
||||
/**
|
||||
* Check whether an ecma-string contains a map key string
|
||||
*
|
||||
* @return true - if the ecma-string contains a map key string
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_prop_name_is_map_key (ecma_string_t *string_p) /**< ecma-string */
|
||||
{
|
||||
JERRY_ASSERT (string_p != NULL);
|
||||
|
||||
return (!ECMA_IS_DIRECT_STRING (string_p)
|
||||
&& ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAP_KEY);
|
||||
} /* ecma_prop_name_is_map_key */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
|
||||
/**
|
||||
* Allocate new UTF8 ecma-string and fill it with characters from the given utf8 buffer
|
||||
*
|
||||
@@ -784,30 +749,6 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
|
||||
return result_p;
|
||||
} /* ecma_concat_ecma_strings */
|
||||
|
||||
/**
|
||||
* Append a magic string after an ecma-string
|
||||
*
|
||||
* Note:
|
||||
* The string1_p argument is freed. If it needs to be preserved,
|
||||
* call ecma_ref_ecma_string with string1_p before the call.
|
||||
*
|
||||
* @return concatenation of an ecma-string and a magic string
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_append_magic_string_to_string (ecma_string_t *string1_p, /**< string descriptor */
|
||||
lit_magic_string_id_t string2_id) /**< magic string ID */
|
||||
{
|
||||
if (JERRY_UNLIKELY (ecma_string_is_empty (string1_p)))
|
||||
{
|
||||
return ecma_get_magic_string (string2_id);
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *cesu8_string2_p = lit_get_magic_string_utf8 (string2_id);
|
||||
lit_utf8_size_t cesu8_string2_size = lit_get_magic_string_size (string2_id);
|
||||
|
||||
return ecma_append_chars_to_string (string1_p, cesu8_string2_p, cesu8_string2_size, cesu8_string2_size);
|
||||
} /* ecma_append_magic_string_to_string */
|
||||
|
||||
/**
|
||||
* Increase reference counter of ecma-string.
|
||||
*/
|
||||
@@ -913,15 +854,6 @@ ecma_destroy_ecma_string (ecma_string_t *string_p) /**< ecma-string */
|
||||
return;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||
case ECMA_STRING_CONTAINER_MAP_KEY:
|
||||
{
|
||||
ecma_extended_string_t *key_p = (ecma_extended_string_t *) string_p;
|
||||
ecma_free_value_if_not_object (key_p->u.value);
|
||||
ecma_dealloc_extended_string (key_p);
|
||||
return;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC
|
||||
@@ -1810,14 +1742,6 @@ ecma_compare_ecma_strings (const ecma_string_t *string1_p, /**< ecma-string */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
if (string1_container == ECMA_STRING_CONTAINER_MAP_KEY)
|
||||
{
|
||||
return ecma_op_same_value_zero (((ecma_extended_string_t *) string1_p)->u.value,
|
||||
((ecma_extended_string_t *) string2_p)->u.value);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
|
||||
return ecma_compare_ecma_strings_longpath (string1_p, string2_p);
|
||||
} /* ecma_compare_ecma_strings */
|
||||
|
||||
@@ -1864,14 +1788,6 @@ ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, /**< ecma-
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||
if (string1_container == ECMA_STRING_CONTAINER_MAP_KEY)
|
||||
{
|
||||
return ecma_op_same_value_zero (((ecma_extended_string_t *) string1_p)->u.value,
|
||||
((ecma_extended_string_t *) string2_p)->u.value);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
|
||||
return ecma_compare_ecma_strings_longpath (string1_p, string2_p);
|
||||
} /* ecma_compare_ecma_non_direct_strings */
|
||||
|
||||
@@ -2446,8 +2362,7 @@ ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p, /**< [in, out] curr
|
||||
{
|
||||
read_size = lit_read_code_unit_from_utf8 (current_p, &ch);
|
||||
|
||||
if (!lit_char_is_white_space (ch)
|
||||
&& !lit_char_is_line_terminator (ch))
|
||||
if (!lit_char_is_white_space (ch))
|
||||
{
|
||||
nonws_start_p = current_p;
|
||||
break;
|
||||
@@ -2462,8 +2377,7 @@ ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p, /**< [in, out] curr
|
||||
{
|
||||
read_size = lit_read_prev_code_unit_from_utf8 (current_p, &ch);
|
||||
|
||||
if (!lit_char_is_white_space (ch)
|
||||
&& !lit_char_is_line_terminator (ch))
|
||||
if (!lit_char_is_white_space (ch))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -2552,6 +2466,29 @@ ecma_stringbuilder_create_from (ecma_string_t *string_p) /**< ecma string */
|
||||
return ret;
|
||||
} /* ecma_stringbuilder_create_from */
|
||||
|
||||
/**
|
||||
* Create a string builder from a raw string
|
||||
*
|
||||
* @return new string builder
|
||||
*/
|
||||
ecma_stringbuilder_t
|
||||
ecma_stringbuilder_create_raw (const lit_utf8_byte_t *data_p, /**< pointer to data */
|
||||
const lit_utf8_size_t data_size) /**< size of the data */
|
||||
{
|
||||
const lit_utf8_size_t initial_size = data_size + (lit_utf8_size_t) sizeof (ecma_ascii_string_t);
|
||||
|
||||
ecma_stringbuilder_header_t *header_p = (ecma_stringbuilder_header_t *) jmem_heap_alloc_block (initial_size);
|
||||
header_p->current_size = initial_size;
|
||||
#if ENABLED (JERRY_MEM_STATS)
|
||||
jmem_stats_allocate_string_bytes (initial_size);
|
||||
#endif /* ENABLED (JERRY_MEM_STATS) */
|
||||
|
||||
memcpy (ECMA_STRINGBUILDER_STRING_PTR (header_p), data_p, data_size);
|
||||
|
||||
ecma_stringbuilder_t ret = {.header_p = header_p};
|
||||
return ret;
|
||||
} /* ecma_stringbuilder_create_raw */
|
||||
|
||||
/**
|
||||
* Grow the underlying buffer of a string builder
|
||||
*
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
@@ -35,8 +36,12 @@ JERRY_STATIC_ASSERT (ECMA_VALUE_SHIFT <= JMEM_ALIGNMENT_LOG,
|
||||
JERRY_STATIC_ASSERT (sizeof (jmem_cpointer_t) <= sizeof (ecma_value_t),
|
||||
size_of_jmem_cpointer_t_must_be_less_or_equal_to_the_size_of_ecma_value_t);
|
||||
|
||||
JERRY_STATIC_ASSERT (sizeof (jmem_cpointer_t) <= sizeof (jmem_cpointer_tag_t),
|
||||
size_of_jmem_cpointer_t_must_be_less_or_equal_to_the_size_of_jmem_cpointer_tag_t);
|
||||
|
||||
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
|
||||
|
||||
/* cppcheck-suppress zerodiv */
|
||||
JERRY_STATIC_ASSERT (sizeof (uintptr_t) <= sizeof (ecma_value_t),
|
||||
uintptr_t_must_fit_in_ecma_value_t);
|
||||
|
||||
@@ -408,14 +413,40 @@ ecma_check_value_type_is_spec_defined (ecma_value_t value) /**< ecma value */
|
||||
/**
|
||||
* Checks if the given argument is an array or not.
|
||||
*
|
||||
* @return true - if the given argument is an array object
|
||||
* false - otherwise
|
||||
* @return ECMA_VALUE_ERROR- if the operation fails
|
||||
* ECMA_VALUE_{TRUE/FALSE} - depends on whether 'arg' is an array object
|
||||
*/
|
||||
inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_value_t
|
||||
ecma_is_value_array (ecma_value_t arg) /**< argument */
|
||||
{
|
||||
return (ecma_is_value_object (arg)
|
||||
&& ecma_get_object_type (ecma_get_object_from_value (arg)) == ECMA_OBJECT_TYPE_ARRAY);
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
return ECMA_VALUE_FALSE;
|
||||
}
|
||||
|
||||
ecma_object_t *arg_obj_p = ecma_get_object_from_value (arg);
|
||||
|
||||
if (ecma_get_object_type (arg_obj_p) == ECMA_OBJECT_TYPE_ARRAY)
|
||||
{
|
||||
return ECMA_VALUE_TRUE;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (arg_obj_p))
|
||||
{
|
||||
ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) arg_obj_p;
|
||||
|
||||
if (proxy_obj_p->handler == ECMA_VALUE_NULL)
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot perform 'IsArray' on the given proxy "
|
||||
"because handler is null"));
|
||||
}
|
||||
|
||||
return ecma_is_value_array (proxy_obj_p->target);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
return ECMA_VALUE_FALSE;
|
||||
} /* ecma_is_value_array */
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,7 +141,7 @@ ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, /**< out
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
JERRY_ASSERT (type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND
|
||||
|| type == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND);
|
||||
|| type == ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
JERRY_ASSERT (type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
@@ -179,40 +179,17 @@ ecma_is_lexical_environment (const ecma_object_t *object_p) /**< object or lexic
|
||||
return full_type >= (ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV | ECMA_LEXICAL_ENVIRONMENT_TYPE_START);
|
||||
} /* ecma_is_lexical_environment */
|
||||
|
||||
/**
|
||||
* Get value of [[Extensible]] object's internal property.
|
||||
*
|
||||
* @return true - if object is extensible
|
||||
* false - otherwise
|
||||
*/
|
||||
inline bool JERRY_ATTR_PURE
|
||||
ecma_get_object_extensible (const ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
JERRY_ASSERT (!ecma_is_lexical_environment (object_p));
|
||||
|
||||
return (object_p->type_flags_refs & ECMA_OBJECT_FLAG_EXTENSIBLE) != 0;
|
||||
} /* ecma_get_object_extensible */
|
||||
|
||||
/**
|
||||
* Set value of [[Extensible]] object's internal property.
|
||||
*/
|
||||
inline void
|
||||
ecma_set_object_extensible (ecma_object_t *object_p, /**< object */
|
||||
bool is_extensible) /**< value of [[Extensible]] */
|
||||
ecma_op_ordinary_object_set_extensible (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
JERRY_ASSERT (!ecma_is_lexical_environment (object_p));
|
||||
|
||||
if (is_extensible)
|
||||
{
|
||||
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs | ECMA_OBJECT_FLAG_EXTENSIBLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs & ~ECMA_OBJECT_FLAG_EXTENSIBLE);
|
||||
}
|
||||
} /* ecma_set_object_extensible */
|
||||
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs | ECMA_OBJECT_FLAG_EXTENSIBLE);
|
||||
} /* ecma_op_ordinary_object_set_extensible */
|
||||
|
||||
/**
|
||||
* Get object's internal implementation-defined type.
|
||||
@@ -311,7 +288,7 @@ ecma_get_lex_env_binding_object (const ecma_object_t *object_p) /**< object-boun
|
||||
JERRY_ASSERT (ecma_is_lexical_environment (object_p));
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND
|
||||
|| ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND);
|
||||
|| ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
@@ -1464,17 +1441,12 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS)
|
||||
{
|
||||
ecma_length_t formal_params_number = ecma_compiled_code_get_formal_params (bytecode_p);
|
||||
ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (bytecode_p);
|
||||
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
|
||||
ecma_value_t *tagged_base_p = (ecma_value_t *) byte_p;
|
||||
tagged_base_p -= formal_params_number;
|
||||
|
||||
ecma_collection_t *coll_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, tagged_base_p[-1]);
|
||||
|
||||
ecma_collection_destroy (coll_p);
|
||||
/* Since the objects in the tagged template collection are not strong referenced anymore by the compiled code
|
||||
we can treat them as 'new' objects. */
|
||||
JERRY_CONTEXT (ecma_gc_new_objects) += collection_p->item_count;
|
||||
ecma_collection_free (collection_p);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
@@ -1507,17 +1479,17 @@ ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *b
|
||||
JERRY_ASSERT (bytecode_header_p != NULL);
|
||||
JERRY_ASSERT (bytecode_header_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS);
|
||||
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_header_p;
|
||||
byte_p += ((size_t) bytecode_header_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
ecma_value_t *base_p = ecma_compiled_code_resolve_function_name (bytecode_header_p);
|
||||
|
||||
ecma_value_t *tagged_base_p = (ecma_value_t *) byte_p;
|
||||
tagged_base_p -= ecma_compiled_code_get_formal_params (bytecode_header_p);
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
base_p--;
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, tagged_base_p[-1]);
|
||||
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, base_p[-1]);
|
||||
} /* ecma_compiled_code_get_tagged_template_collection */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015)
|
||||
#if ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ES2015)
|
||||
/**
|
||||
* Get the number of formal parameters of the compiled code
|
||||
*
|
||||
@@ -1538,7 +1510,44 @@ ecma_compiled_code_get_formal_params (const ecma_compiled_code_t *bytecode_heade
|
||||
|
||||
return ((cbc_uint8_arguments_t *) bytecode_header_p)->argument_end;
|
||||
} /* ecma_compiled_code_get_formal_params */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
* Resolve the position of the arguments list start of the compiled code
|
||||
*
|
||||
* @return start position of the arguments list start of the compiled code
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p)
|
||||
{
|
||||
JERRY_ASSERT (bytecode_header_p != NULL);
|
||||
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_header_p;
|
||||
byte_p += ((size_t) bytecode_header_p->size) << JMEM_ALIGNMENT_LOG;
|
||||
|
||||
return ((ecma_value_t *) byte_p) - ecma_compiled_code_get_formal_params (bytecode_header_p);
|
||||
} /* ecma_compiled_code_resolve_arguments_start */
|
||||
|
||||
/**
|
||||
* Resolve the position of the function name of the compiled code
|
||||
*
|
||||
* @return position of the function name of the compiled code
|
||||
*/
|
||||
inline ecma_value_t * JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p)
|
||||
{
|
||||
JERRY_ASSERT (bytecode_header_p != NULL);
|
||||
ecma_value_t *base_p = ecma_compiled_code_resolve_arguments_start (bytecode_header_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR))
|
||||
{
|
||||
base_p--;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
return base_p;
|
||||
} /* ecma_compiled_code_resolve_function_name */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if (JERRY_STACK_LIMIT != 0)
|
||||
/**
|
||||
@@ -1550,7 +1559,7 @@ uintptr_t JERRY_ATTR_NOINLINE
|
||||
ecma_get_current_stack_usage (void)
|
||||
{
|
||||
volatile int __sp;
|
||||
return (uintptr_t) (JERRY_CONTEXT (stack_base) - (uintptr_t)&__sp);
|
||||
return (uintptr_t) (JERRY_CONTEXT (stack_base) - (uintptr_t) &__sp);
|
||||
} /* ecma_get_current_stack_usage */
|
||||
|
||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
*/
|
||||
#define ECMA_GET_NON_NULL_POINTER(type, field) JMEM_CP_GET_NON_NULL_POINTER (type, field)
|
||||
|
||||
/**
|
||||
* Extract value of pointer from specified pointer-tag value
|
||||
*/
|
||||
#define ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG(type, field) \
|
||||
JMEM_CP_GET_NON_NULL_POINTER_FROM_POINTER_TAG (type, field)
|
||||
|
||||
/**
|
||||
* Get value of pointer from specified compressed pointer.
|
||||
*/
|
||||
@@ -44,12 +50,39 @@
|
||||
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) JMEM_CP_SET_NON_NULL_POINTER (field, \
|
||||
non_compressed_pointer)
|
||||
|
||||
/**
|
||||
* Set value of pointer-tag value so that it will correspond
|
||||
* to specified non_compressed_pointer along with tag
|
||||
*/
|
||||
#define ECMA_SET_NON_NULL_POINTER_TAG(field, non_compressed_pointer, tag) \
|
||||
JMEM_CP_SET_NON_NULL_POINTER_TAG (field, non_compressed_pointer, tag)
|
||||
|
||||
/**
|
||||
* Set value of compressed pointer so that it will correspond
|
||||
* to specified non_compressed_pointer.
|
||||
*/
|
||||
#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer)
|
||||
|
||||
/**
|
||||
* Get value of each tag bit from specified pointer-tag value
|
||||
*/
|
||||
#define ECMA_GET_FIRST_BIT_FROM_POINTER_TAG(field) \
|
||||
JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (field) /**< get first tag bit from jmem_cpointer_tag_t **/
|
||||
#define ECMA_GET_SECOND_BIT_FROM_POINTER_TAG(field) \
|
||||
JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (field) /**< get second tag bit from jmem_cpointer_tag_t **/
|
||||
#define ECMA_GET_THIRD_BIT_FROM_POINTER_TAG(field) \
|
||||
JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG (field) /**< get third tag bit from jmem_cpointer_tag_t **/
|
||||
|
||||
/**
|
||||
* Set value of each tag bit to specified pointer-tag value
|
||||
*/
|
||||
#define ECMA_SET_FIRST_BIT_TO_POINTER_TAG(field) \
|
||||
JMEM_CP_SET_FIRST_BIT_TO_POINTER_TAG (field) /**< set first tag bit to jmem_cpointer_tag_t **/
|
||||
#define ECMA_SET_SECOND_BIT_TO_POINTER_TAG(field) \
|
||||
JMEM_CP_SET_SECOND_BIT_TO_POINTER_TAG (field) /**< set second tag bit to jmem_cpointer_tag_t **/
|
||||
#define ECMA_SET_THIRD_BIT_TO_POINTER_TAG(field) \
|
||||
JMEM_CP_SET_THIRD_BIT_TO_POINTER_TAG (field) /**< set third tag bit to jmem_cpointer_tag_t **/
|
||||
|
||||
/**
|
||||
* Status flags for ecma_string_get_chars function
|
||||
*/
|
||||
@@ -159,6 +192,24 @@ typedef enum
|
||||
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (false)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
* Check whether the given type is ECMA_OBJECT_TYPE_PROXY
|
||||
*
|
||||
* @param type object type
|
||||
*/
|
||||
#define ECMA_OBJECT_TYPE_IS_PROXY(type) (JERRY_UNLIKELY ((type) == ECMA_OBJECT_TYPE_PROXY))
|
||||
|
||||
/**
|
||||
* Check whether the given object has [[ProxyHandler]] and [[ProxyTarger]] internal slots
|
||||
*
|
||||
* @param obj_p ecma-object
|
||||
*/
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
#define ECMA_OBJECT_IS_PROXY(obj_p) (ECMA_OBJECT_TYPE_IS_PROXY (ecma_get_object_type ((obj_p))))
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
#define ECMA_OBJECT_IS_PROXY(obj_p) (false)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
/* ecma-helpers-value.c */
|
||||
ecma_type_t JERRY_ATTR_CONST ecma_get_value_type_field (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_direct (ecma_value_t value);
|
||||
@@ -185,7 +236,7 @@ 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_array (ecma_value_t arg);
|
||||
ecma_value_t ecma_is_value_array (ecma_value_t arg);
|
||||
|
||||
void ecma_check_value_type_is_spec_defined (ecma_value_t value);
|
||||
|
||||
@@ -257,7 +308,6 @@ ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_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);
|
||||
void ecma_destroy_ecma_string (ecma_string_t *string_p);
|
||||
@@ -321,6 +371,8 @@ ecma_string_t *ecma_string_trim (const ecma_string_t *string_p);
|
||||
|
||||
ecma_stringbuilder_t ecma_stringbuilder_create (void);
|
||||
ecma_stringbuilder_t ecma_stringbuilder_create_from (ecma_string_t *string_p);
|
||||
ecma_stringbuilder_t ecma_stringbuilder_create_raw (const lit_utf8_byte_t *data_p,
|
||||
const lit_utf8_size_t data_size);
|
||||
lit_utf8_size_t ecma_stringbuilder_get_size (ecma_stringbuilder_t *builder_p);
|
||||
lit_utf8_byte_t *ecma_stringbuilder_get_data (ecma_stringbuilder_t *builder_p);
|
||||
void ecma_stringbuilder_revert (ecma_stringbuilder_t *builder_p, const lit_utf8_size_t size);
|
||||
@@ -348,6 +400,12 @@ 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_number_t ecma_number_pow (ecma_number_t x, ecma_number_t y);
|
||||
ecma_value_t ecma_number_parse_int (const lit_utf8_byte_t *string_buff,
|
||||
lit_utf8_size_t string_buff_size,
|
||||
ecma_value_t radix);
|
||||
ecma_value_t ecma_number_parse_float (const lit_utf8_byte_t *string_buff,
|
||||
lit_utf8_size_t string_buff_size);
|
||||
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,
|
||||
@@ -357,6 +415,8 @@ lit_utf8_size_t ecma_number_to_binary_floating_point_number (ecma_number_t num,
|
||||
/* ecma-helpers-collection.c */
|
||||
ecma_collection_t *ecma_new_collection (void);
|
||||
void ecma_collection_push_back (ecma_collection_t *collection_p, ecma_value_t value);
|
||||
void ecma_collection_reserve (ecma_collection_t *collection_p, uint32_t count);
|
||||
void ecma_collection_append (ecma_collection_t *collection_p, const ecma_value_t *buffer_p, uint32_t count);
|
||||
void ecma_collection_destroy (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free_if_not_object (ecma_collection_t *collection_p);
|
||||
@@ -368,14 +428,12 @@ ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environmen
|
||||
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);
|
||||
void ecma_op_ordinary_object_set_extensible (ecma_object_t *object_p);
|
||||
ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (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_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p);
|
||||
ecma_object_t *ecma_clone_decl_lexical_environment (ecma_object_t *lex_env_p, bool copy_values);
|
||||
|
||||
@@ -430,9 +488,11 @@ void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_collection_t *ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *bytecode_header_p);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015)
|
||||
#if ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ES2015)
|
||||
ecma_length_t ecma_compiled_code_get_formal_params (const ecma_compiled_code_t *bytecode_p);
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015) */
|
||||
ecma_value_t *ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p);
|
||||
ecma_value_t *ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p);
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ES2015) */
|
||||
#if (JERRY_STACK_LIMIT != 0)
|
||||
uintptr_t ecma_get_current_stack_usage (void);
|
||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||
|
||||
@@ -44,7 +44,7 @@ ecma_init (void)
|
||||
JERRY_CONTEXT (ecma_gc_mark_recursion_limit) = JERRY_GC_MARK_LIMIT;
|
||||
#endif /* (JERRY_GC_MARK_LIMIT != 0) */
|
||||
|
||||
ecma_init_global_lex_env ();
|
||||
ecma_init_global_environment ();
|
||||
|
||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
||||
JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) = ECMA_PROP_HASHMAP_ALLOC_ON;
|
||||
@@ -53,7 +53,7 @@ ecma_init (void)
|
||||
|
||||
#if (JERRY_STACK_LIMIT != 0)
|
||||
volatile int sp;
|
||||
JERRY_CONTEXT (stack_base) = (uintptr_t)&sp;
|
||||
JERRY_CONTEXT (stack_base) = (uintptr_t) &sp;
|
||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
||||
@@ -61,7 +61,7 @@ ecma_init (void)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
JERRY_CONTEXT (current_new_target) = JERRY_CONTEXT_INVALID_NEW_TARGET;
|
||||
JERRY_CONTEXT (current_new_target) = NULL;
|
||||
JERRY_CONTEXT (current_function_obj_p) = NULL;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
} /* ecma_init */
|
||||
@@ -73,11 +73,11 @@ void
|
||||
ecma_finalize (void)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
JERRY_ASSERT (JERRY_CONTEXT (current_new_target) == JERRY_CONTEXT_INVALID_NEW_TARGET);
|
||||
JERRY_ASSERT (JERRY_CONTEXT (current_new_target) == NULL);
|
||||
JERRY_ASSERT (JERRY_CONTEXT (current_function_obj_p) == NULL);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_finalize_global_lex_env ();
|
||||
ecma_finalize_global_environment ();
|
||||
uint8_t runs = 0;
|
||||
do
|
||||
{
|
||||
|
||||
@@ -329,7 +329,7 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
|
||||
ecma_collection_t *lit_pool_p) /**< list of known values */
|
||||
{
|
||||
ecma_value_t *literal_p;
|
||||
uint32_t argument_end = 0;
|
||||
uint32_t argument_end;
|
||||
uint32_t register_end;
|
||||
uint32_t const_literal_end;
|
||||
uint32_t literal_end;
|
||||
@@ -345,11 +345,7 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
|
||||
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 (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -360,16 +356,15 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
|
||||
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 (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
ecma_save_literals_append_value (literal_p[i], lit_pool_p);
|
||||
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++)
|
||||
@@ -389,16 +384,13 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
uint8_t *byte_p = ((uint8_t *) compiled_code_p) + (((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG);
|
||||
literal_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t *) compiled_code_p, byte_p);
|
||||
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
{
|
||||
ecma_save_literals_append_value (literal_p[i], lit_pool_p);
|
||||
}
|
||||
while (literal_p < (ecma_value_t *) byte_p)
|
||||
{
|
||||
ecma_save_literals_append_value (*literal_p, lit_pool_p);
|
||||
literal_p++;
|
||||
}
|
||||
} /* ecma_save_literals_add_compiled_code */
|
||||
|
||||
@@ -546,6 +538,51 @@ ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */
|
||||
return ecma_find_or_create_literal_string (literal_p + sizeof (uint16_t), length);
|
||||
} /* ecma_snapshot_get_literal */
|
||||
|
||||
/**
|
||||
* Compute the start of the serializable ecma-values of the bytecode
|
||||
* Related values:
|
||||
* - function argument names, if CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED is present
|
||||
* - function name, if CBC_CODE_FLAGS_CLASS_CONSTRUCTOR is not present and ES2015 profile is enabled
|
||||
* - resource name, if JERRY_RESOURCE_NAME is enabled
|
||||
*
|
||||
* @return pointer to the beginning of the serializable ecma-values
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_snapshot_resolve_serializable_values (ecma_compiled_code_t *compiled_code_p, /**< compiled code */
|
||||
uint8_t *bytecode_end_p) /**< end of the bytecode */
|
||||
{
|
||||
ecma_value_t *base_p = (ecma_value_t *) bytecode_end_p;
|
||||
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
uint32_t argument_end;
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
{
|
||||
argument_end = ((cbc_uint16_arguments_t *) compiled_code_p)->argument_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
argument_end = ((cbc_uint8_arguments_t *) compiled_code_p)->argument_end;
|
||||
}
|
||||
|
||||
base_p -= argument_end;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* function name */
|
||||
if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR))
|
||||
{
|
||||
base_p--;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
/* resource name */
|
||||
base_p--;
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
return base_p;
|
||||
} /* ecma_snapshot_resolve_serializable_values */
|
||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,6 +55,8 @@ bool ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, uint32_t *b
|
||||
#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);
|
||||
ecma_value_t *
|
||||
ecma_snapshot_resolve_serializable_values (ecma_compiled_code_t *compiled_code_p, uint8_t *byte_code_end_p);
|
||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -660,7 +660,7 @@ ecma_module_evaluate (ecma_module_t *module_p) /**< module */
|
||||
* @return ECMA_VALUE_ERROR - if an error occured
|
||||
* ECMA_VALUE_EMPTY - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
static ecma_value_t
|
||||
ecma_module_connect_imports (void)
|
||||
{
|
||||
ecma_module_context_t *current_context_p = JERRY_CONTEXT (module_top_context_p);
|
||||
@@ -669,6 +669,53 @@ ecma_module_connect_imports (void)
|
||||
JERRY_ASSERT (ecma_is_lexical_environment (local_env_p));
|
||||
|
||||
ecma_module_node_t *import_node_p = current_context_p->imports_p;
|
||||
|
||||
/* Check that the imported bindings don't exist yet. */
|
||||
while (import_node_p != NULL)
|
||||
{
|
||||
ecma_module_names_t *import_names_p = import_node_p->module_names_p;
|
||||
|
||||
while (import_names_p != NULL)
|
||||
{
|
||||
ecma_object_t *lex_env_p = local_env_p;
|
||||
ecma_property_t *binding_p = NULL;
|
||||
|
||||
if (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK)
|
||||
{
|
||||
binding_p = ecma_find_named_property (lex_env_p, import_names_p->local_name_p);
|
||||
|
||||
JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL);
|
||||
lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp);
|
||||
}
|
||||
|
||||
if (binding_p != NULL)
|
||||
{
|
||||
return ecma_raise_syntax_error (ECMA_ERR_MSG ("Imported binding shadows local variable."));
|
||||
}
|
||||
|
||||
ecma_value_t status = ecma_op_has_binding (lex_env_p, import_names_p->local_name_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_true (status))
|
||||
{
|
||||
return ecma_raise_syntax_error (ECMA_ERR_MSG ("Imported binding shadows local variable."));
|
||||
}
|
||||
|
||||
import_names_p = import_names_p->next_p;
|
||||
}
|
||||
|
||||
import_node_p = import_node_p->next_p;
|
||||
}
|
||||
|
||||
import_node_p = current_context_p->imports_p;
|
||||
|
||||
/* Resolve imports and create local bindings. */
|
||||
while (import_node_p != NULL)
|
||||
{
|
||||
ecma_value_t result = ecma_module_evaluate (import_node_p->module_request_p);
|
||||
@@ -761,6 +808,26 @@ ecma_module_connect_imports (void)
|
||||
return ECMA_VALUE_EMPTY;
|
||||
} /* ecma_module_connect_imports */
|
||||
|
||||
/**
|
||||
* Initialize the current module by creating the local binding for the imported variables
|
||||
* and verifying indirect exports.
|
||||
*
|
||||
* @return ECMA_VALUE_ERROR - if an error occured
|
||||
* ECMA_VALUE_EMPTY - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_module_initialize_current (void)
|
||||
{
|
||||
ecma_value_t ret_value = ecma_module_connect_imports ();
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_module_check_indirect_exports ();
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_module_initialize_current */
|
||||
|
||||
/**
|
||||
* Parses an EcmaScript module.
|
||||
*
|
||||
@@ -975,7 +1042,8 @@ ecma_module_release_module (ecma_module_t *module_p) /**< module */
|
||||
ecma_module_release_module_context (module_p->context_p);
|
||||
}
|
||||
|
||||
if (module_p->state >= ECMA_MODULE_STATE_EVALUATING)
|
||||
if (module_p->state >= ECMA_MODULE_STATE_EVALUATING
|
||||
&& module_p->scope_p != NULL)
|
||||
{
|
||||
ecma_deref_object (module_p->scope_p);
|
||||
}
|
||||
@@ -996,11 +1064,6 @@ finished:
|
||||
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)
|
||||
{
|
||||
@@ -1009,6 +1072,7 @@ ecma_module_cleanup (void)
|
||||
current_p = next_p;
|
||||
}
|
||||
|
||||
JERRY_CONTEXT (ecma_modules_p) = NULL;
|
||||
JERRY_CONTEXT (module_top_context_p) = NULL;
|
||||
} /* ecma_module_cleanup */
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ ecma_module_t *ecma_module_create_native_module (ecma_string_t *const path_p,
|
||||
ecma_object_t *const namespace_p);
|
||||
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_initialize_current (void);
|
||||
ecma_value_t ecma_module_parse_modules (void);
|
||||
ecma_value_t ecma_module_check_indirect_exports (void);
|
||||
|
||||
|
||||
@@ -426,7 +426,7 @@ ecma_builtin_array_prototype_object_pop (ecma_object_t *obj_p, /**< array object
|
||||
|
||||
if (ecma_op_object_is_fast_array (obj_p))
|
||||
{
|
||||
if (!ecma_get_object_extensible (obj_p))
|
||||
if (!ecma_op_ordinary_object_is_extensible (obj_p))
|
||||
{
|
||||
ecma_free_value (get_value);
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));
|
||||
@@ -479,7 +479,7 @@ ecma_builtin_array_prototype_object_push (const ecma_value_t *argument_list_p, /
|
||||
|
||||
if (ecma_op_object_is_fast_array (obj_p))
|
||||
{
|
||||
if (!ecma_get_object_extensible (obj_p))
|
||||
if (!ecma_op_ordinary_object_is_extensible (obj_p))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));
|
||||
}
|
||||
@@ -545,7 +545,6 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this ar
|
||||
ecma_object_t *obj_p, /**< array object */
|
||||
uint32_t len) /**< array object's length */
|
||||
{
|
||||
/* 4. */
|
||||
uint32_t middle = len / 2;
|
||||
|
||||
if (ecma_op_object_is_fast_array (obj_p))
|
||||
@@ -554,7 +553,7 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this ar
|
||||
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
|
||||
&& len != 0
|
||||
&& ecma_get_object_extensible (obj_p))
|
||||
&& ecma_op_ordinary_object_is_extensible (obj_p))
|
||||
{
|
||||
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
|
||||
|
||||
@@ -571,36 +570,81 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this ar
|
||||
|
||||
for (uint32_t lower = 0; lower < middle; lower++)
|
||||
{
|
||||
uint32_t upper = len - lower - 1;
|
||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||
ecma_string_t *lower_str_p = ecma_new_ecma_string_from_uint32 (lower);
|
||||
|
||||
/* 6.d and 6.e */
|
||||
ecma_string_t *lower_str_p = ecma_new_ecma_string_from_uint32 (lower);
|
||||
ecma_string_t *upper_str_p = ecma_new_ecma_string_from_uint32 (upper);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_value_t lower_value = ECMA_VALUE_EMPTY;
|
||||
ecma_value_t upper_value = ECMA_VALUE_EMPTY;
|
||||
|
||||
ecma_value_t has_lower = ecma_op_object_has_property (obj_p, lower_str_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (has_lower))
|
||||
{
|
||||
goto clean_up;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
bool lower_exist = ecma_is_value_true (has_lower);
|
||||
|
||||
if (lower_exist)
|
||||
{
|
||||
lower_value = ecma_op_object_get (obj_p, lower_str_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (lower_value))
|
||||
{
|
||||
goto clean_up;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_value_t has_upper = ecma_op_object_has_property (obj_p, upper_str_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (has_upper))
|
||||
{
|
||||
goto clean_up;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
bool upper_exist = ecma_is_value_true (has_upper);
|
||||
|
||||
if (upper_exist)
|
||||
{
|
||||
upper_value = ecma_op_object_get (obj_p, upper_str_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (upper_value))
|
||||
{
|
||||
goto clean_up;
|
||||
}
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
ecma_value_t lower_value = ecma_op_object_get (obj_p, lower_str_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (lower_value))
|
||||
{
|
||||
ecma_deref_ecma_string (lower_str_p);
|
||||
return lower_value;
|
||||
ecma_deref_ecma_string (upper_str_p);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/* 6.a */
|
||||
uint32_t upper = len - lower - 1;
|
||||
/* 6.b and 6.c */
|
||||
ecma_string_t *upper_str_p = ecma_new_ecma_string_from_uint32 (upper);
|
||||
|
||||
ecma_value_t upper_value = ecma_op_object_get (obj_p, upper_str_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (upper_value))
|
||||
{
|
||||
upper_value = ECMA_VALUE_EMPTY;
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
/* 6.f and 6.g */
|
||||
bool lower_exist = ecma_op_object_has_property (obj_p, lower_str_p);
|
||||
bool upper_exist = ecma_op_object_has_property (obj_p, upper_str_p);
|
||||
ecma_value_t has_lower = ecma_op_object_has_property (obj_p, lower_str_p);
|
||||
ecma_value_t has_upper = ecma_op_object_has_property (obj_p, upper_str_p);
|
||||
|
||||
bool lower_exist = ecma_is_value_true (has_lower);
|
||||
bool upper_exist = ecma_is_value_true (has_upper);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* 6.h */
|
||||
if (lower_exist && upper_exist)
|
||||
{
|
||||
ecma_value_t outer_put_value = ecma_op_object_put (obj_p, lower_str_p, upper_value, true);
|
||||
@@ -617,7 +661,6 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this ar
|
||||
goto clean_up;
|
||||
}
|
||||
}
|
||||
/* 6.i */
|
||||
else if (!lower_exist && upper_exist)
|
||||
{
|
||||
ecma_value_t put_value = ecma_op_object_put (obj_p, lower_str_p, upper_value, true);
|
||||
@@ -629,14 +672,11 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this ar
|
||||
|
||||
ecma_value_t del_value = ecma_op_object_delete (obj_p, upper_str_p, true);
|
||||
|
||||
JERRY_ASSERT (ECMA_IS_VALUE_ERROR (del_value) || ecma_is_value_boolean (del_value));
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (del_value))
|
||||
{
|
||||
goto clean_up;
|
||||
}
|
||||
}
|
||||
/* 6.j */
|
||||
else if (lower_exist)
|
||||
{
|
||||
ecma_value_t del_value = ecma_op_object_delete (obj_p, lower_str_p, true);
|
||||
@@ -668,7 +708,6 @@ clean_up:
|
||||
}
|
||||
}
|
||||
|
||||
/* 7. */
|
||||
return ecma_copy_value (this_arg);
|
||||
} /* ecma_builtin_array_prototype_object_reverse */
|
||||
|
||||
@@ -699,7 +738,7 @@ ecma_builtin_array_prototype_object_shift (ecma_object_t *obj_p, /**< array obje
|
||||
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
|
||||
&& len != 0
|
||||
&& ecma_get_object_extensible (obj_p))
|
||||
&& ecma_op_ordinary_object_is_extensible (obj_p))
|
||||
{
|
||||
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
|
||||
ecma_value_t ret_value = buffer_p[0];
|
||||
@@ -852,6 +891,15 @@ ecma_builtin_array_prototype_object_slice (ecma_value_t arg1, /**< start */
|
||||
|
||||
if (ext_from_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE)
|
||||
{
|
||||
if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL))
|
||||
{
|
||||
/**
|
||||
* Very unlikely case: the buffer copied from is a fast buffer and the property list was deleted.
|
||||
* There is no need to do any copy.
|
||||
*/
|
||||
return new_array;
|
||||
}
|
||||
|
||||
ecma_extended_object_t *ext_to_obj_p = (ecma_extended_object_t *) new_array_p;
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
@@ -1069,6 +1117,13 @@ ecma_builtin_array_prototype_object_sort (ecma_value_t this_arg, /**< this argum
|
||||
|
||||
ecma_collection_t *array_index_props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ARRAY_INDICES);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (array_index_props_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
uint32_t defined_prop_count = 0;
|
||||
|
||||
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
|
||||
@@ -1482,7 +1537,7 @@ ecma_builtin_array_prototype_object_unshift (const ecma_value_t args[], /**< arg
|
||||
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
|
||||
&& len != 0
|
||||
&& ecma_get_object_extensible (obj_p))
|
||||
&& ecma_op_ordinary_object_is_extensible (obj_p))
|
||||
{
|
||||
if ((ecma_number_t) (len + args_number) > UINT32_MAX)
|
||||
{
|
||||
@@ -1621,9 +1676,15 @@ ecma_builtin_array_prototype_object_index_of (const ecma_value_t args[], /**< ar
|
||||
{
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
|
||||
&& len != 0)
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE)
|
||||
{
|
||||
if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL))
|
||||
{
|
||||
return ecma_make_integer_value (-1);
|
||||
}
|
||||
|
||||
len = JERRY_MIN (ext_obj_p->u.array.length, len);
|
||||
|
||||
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
|
||||
|
||||
while (from_idx < len)
|
||||
@@ -1721,9 +1782,15 @@ ecma_builtin_array_prototype_object_last_index_of (const ecma_value_t args[], /*
|
||||
{
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
|
||||
&& len != 0)
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE)
|
||||
{
|
||||
if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL))
|
||||
{
|
||||
return ecma_make_integer_value (-1);
|
||||
}
|
||||
|
||||
len = JERRY_MIN (ext_obj_p->u.array.length, len);
|
||||
|
||||
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
|
||||
|
||||
while (from_idx < len)
|
||||
@@ -2073,15 +2140,14 @@ ecma_builtin_array_prototype_object_filter (ecma_value_t arg1, /**< callbackfn *
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_array_reduce_from (ecma_value_t callbackfn, /**< routine's 1st argument */
|
||||
ecma_value_t initial_value, /**< routine's 2nd argument */
|
||||
ecma_builtin_array_reduce_from (const ecma_value_t args_p[], /**< routine's arguments */
|
||||
ecma_length_t args_number, /**< arguments list length */
|
||||
bool start_from_left, /**< whether the reduce starts from left or right */
|
||||
ecma_object_t *obj_p, /**< array object */
|
||||
uint32_t len) /**< array object's length */
|
||||
{
|
||||
/* 4. */
|
||||
if (!ecma_op_is_callable (callbackfn))
|
||||
if (!ecma_op_is_callable (args_p[0]))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Callback function is not callable."));
|
||||
}
|
||||
@@ -2092,8 +2158,8 @@ ecma_builtin_array_reduce_from (ecma_value_t callbackfn, /**< routine's 1st argu
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Reduce of empty array with no initial value."));
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_object (callbackfn));
|
||||
ecma_object_t *func_object_p = ecma_get_object_from_value (callbackfn);
|
||||
JERRY_ASSERT (ecma_is_value_object (args_p[0]));
|
||||
ecma_object_t *func_object_p = ecma_get_object_from_value (args_p[0]);
|
||||
|
||||
ecma_value_t accumulator = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
@@ -2104,7 +2170,7 @@ ecma_builtin_array_reduce_from (ecma_value_t callbackfn, /**< routine's 1st argu
|
||||
/* 7.a */
|
||||
if (args_number > 1)
|
||||
{
|
||||
accumulator = ecma_copy_value (initial_value);
|
||||
accumulator = ecma_copy_value (args_p[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2233,15 +2299,38 @@ ecma_builtin_array_prototype_fill (ecma_value_t value, /**< value */
|
||||
}
|
||||
}
|
||||
|
||||
if (ecma_op_object_is_fast_array (obj_p))
|
||||
{
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
|
||||
&& ecma_op_ordinary_object_is_extensible (obj_p))
|
||||
{
|
||||
if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL))
|
||||
{
|
||||
ecma_ref_object (obj_p);
|
||||
return ecma_make_object_value (obj_p);
|
||||
}
|
||||
|
||||
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
|
||||
|
||||
while (k < final)
|
||||
{
|
||||
ecma_free_value_if_not_object (buffer_p[k]);
|
||||
buffer_p[k] = ecma_copy_value_if_not_object (value);
|
||||
k++;
|
||||
}
|
||||
|
||||
ecma_ref_object (obj_p);
|
||||
return ecma_make_object_value (obj_p);
|
||||
}
|
||||
}
|
||||
|
||||
/* 11. */
|
||||
while (k < final)
|
||||
{
|
||||
/* 11.a */
|
||||
ecma_string_t *pk = ecma_new_ecma_string_from_number (k);
|
||||
|
||||
/* 11.b */
|
||||
ecma_value_t put_val = ecma_op_object_put (obj_p, pk, value, true);
|
||||
ecma_deref_ecma_string (pk);
|
||||
/* 11.a - 11.b */
|
||||
ecma_value_t put_val = ecma_op_object_put_by_number_index (obj_p, k, value, true);
|
||||
|
||||
/* 11. c */
|
||||
if (ECMA_IS_VALUE_ERROR (put_val))
|
||||
@@ -2290,48 +2379,45 @@ ecma_builtin_array_prototype_object_find (ecma_value_t predicate, /**< callback
|
||||
for (uint32_t index = 0; index < len; index++)
|
||||
{
|
||||
/* 8.a - 8.c */
|
||||
ecma_value_t get_value = ecma_op_object_find_by_uint32_index (obj_p, index);
|
||||
ecma_value_t get_value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||
{
|
||||
return get_value;
|
||||
}
|
||||
|
||||
if (ecma_is_value_found (get_value))
|
||||
/* 8.d - 8.e */
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
|
||||
ecma_value_t call_args[] = { get_value, current_index, ecma_make_object_value (obj_p) };
|
||||
|
||||
ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (call_value))
|
||||
{
|
||||
/* 8.d - 8.e */
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
ecma_free_value (get_value);
|
||||
return call_value;
|
||||
}
|
||||
|
||||
ecma_value_t call_args[] = { get_value, current_index, ecma_make_object_value (obj_p) };
|
||||
bool call_value_to_bool = ecma_op_to_boolean (call_value);
|
||||
|
||||
ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3);
|
||||
ecma_free_value (call_value);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (call_value))
|
||||
if (call_value_to_bool)
|
||||
{
|
||||
/* 8.f */
|
||||
if (is_find)
|
||||
{
|
||||
ecma_free_value (get_value);
|
||||
return call_value;
|
||||
}
|
||||
|
||||
bool call_value_to_bool = ecma_op_to_boolean (call_value);
|
||||
|
||||
ecma_free_value (call_value);
|
||||
|
||||
if (call_value_to_bool)
|
||||
{
|
||||
/* 8.f */
|
||||
if (is_find)
|
||||
{
|
||||
ecma_free_value (current_index);
|
||||
return get_value;
|
||||
}
|
||||
|
||||
ecma_free_value (get_value);
|
||||
return current_index;
|
||||
ecma_free_value (current_index);
|
||||
return get_value;
|
||||
}
|
||||
|
||||
ecma_free_value (get_value);
|
||||
ecma_free_value (current_index);
|
||||
return current_index;
|
||||
}
|
||||
|
||||
ecma_free_value (get_value);
|
||||
ecma_free_value (current_index);
|
||||
}
|
||||
|
||||
/* 9. */
|
||||
@@ -2424,8 +2510,11 @@ ecma_builtin_array_prototype_object_copy_within (const ecma_value_t args[], /**<
|
||||
|
||||
for (; count > 0; count--)
|
||||
{
|
||||
ecma_value_t copy_value = ecma_copy_value_if_not_object (buffer_p[start]);
|
||||
|
||||
ecma_free_value_if_not_object (buffer_p[target]);
|
||||
buffer_p[target] = ecma_copy_value_if_not_object (buffer_p[start]);
|
||||
|
||||
buffer_p[target] = copy_value;
|
||||
|
||||
if (forward)
|
||||
{
|
||||
@@ -2674,8 +2763,7 @@ ecma_builtin_array_prototype_dispatch_routine (uint16_t builtin_routine_id, /**<
|
||||
case ECMA_ARRAY_PROTOTYPE_REDUCE:
|
||||
case ECMA_ARRAY_PROTOTYPE_REDUCE_RIGHT:
|
||||
{
|
||||
ret_value = ecma_builtin_array_reduce_from (routine_arg_1,
|
||||
routine_arg_2,
|
||||
ret_value = ecma_builtin_array_reduce_from (arguments_list_p,
|
||||
arguments_number,
|
||||
builtin_routine_id == ECMA_ARRAY_PROTOTYPE_REDUCE,
|
||||
obj_p,
|
||||
|
||||
@@ -76,8 +76,10 @@ ROUTINE (LIT_MAGIC_STRING_FILL, ECMA_ARRAY_PROTOTYPE_FILL, 3, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_COPY_WITHIN, ECMA_ARRAY_PROTOTYPE_COPY_WITHIN, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_ENTRIES, ECMA_ARRAY_PROTOTYPE_ENTRIES, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_ARRAY_PROTOTYPE_KEYS, 0, 0)
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_VALUES, LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES)
|
||||
INTRINSIC_PROPERTY (LIT_GLOBAL_SYMBOL_ITERATOR, LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES)
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_VALUES, LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
INTRINSIC_PROPERTY (LIT_GLOBAL_SYMBOL_ITERATOR, LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "ecma-iterator-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "jcontext.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_ARRAY)
|
||||
@@ -61,7 +62,7 @@ ecma_builtin_array_object_is_array (ecma_value_t this_arg, /**< 'this' argument
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
|
||||
return ecma_make_boolean_value (ecma_is_value_array (arg));
|
||||
return ecma_is_value_array (arg);
|
||||
} /* ecma_builtin_array_object_is_array */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
@@ -128,7 +129,7 @@ ecma_builtin_array_object_from (ecma_value_t this_arg, /**< 'this' argument */
|
||||
{
|
||||
ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor);
|
||||
|
||||
array = ecma_op_function_construct (constructor_obj_p, ECMA_VALUE_UNDEFINED, NULL, 0);
|
||||
array = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, NULL, 0);
|
||||
|
||||
if (ecma_is_value_undefined (array) || ecma_is_value_null (array))
|
||||
{
|
||||
@@ -289,7 +290,7 @@ iterator_cleanup:
|
||||
{
|
||||
ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor);
|
||||
|
||||
array = ecma_op_function_construct (constructor_obj_p, ECMA_VALUE_UNDEFINED, &len_value, 1);
|
||||
array = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, &len_value, 1);
|
||||
|
||||
if (ecma_is_value_undefined (array) || ecma_is_value_null (array))
|
||||
{
|
||||
@@ -414,7 +415,7 @@ ecma_builtin_array_object_of (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t len = ecma_make_uint32_value (arguments_list_len);
|
||||
|
||||
ecma_value_t ret_val = ecma_op_function_construct (ecma_get_object_from_value (this_arg),
|
||||
ECMA_VALUE_UNDEFINED,
|
||||
ecma_get_object_from_value (this_arg),
|
||||
&len,
|
||||
1);
|
||||
|
||||
@@ -485,7 +486,7 @@ ecma_builtin_array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arg
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_builtin_array_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
return ecma_op_create_array_object (arguments_list_p, arguments_list_len, true);
|
||||
} /* ecma_builtin_array_dispatch_call */
|
||||
|
||||
/**
|
||||
@@ -499,7 +500,30 @@ ecma_builtin_array_dispatch_construct (const ecma_value_t *arguments_list_p, /**
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
#if !ENABLED (JERRY_ES2015)
|
||||
return ecma_op_create_array_object (arguments_list_p, arguments_list_len, true);
|
||||
#else /* ENABLED (JERRY_ES2015) */
|
||||
ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target),
|
||||
ECMA_BUILTIN_ID_ARRAY_PROTOTYPE);
|
||||
|
||||
if (proto_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t result = ecma_op_create_array_object (arguments_list_p, arguments_list_len, true);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
ecma_deref_object (proto_p);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (result);
|
||||
ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p);
|
||||
ecma_deref_object (proto_p);
|
||||
return result;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
} /* ecma_builtin_array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,10 +32,15 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v5, 15.4.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_ARRAY_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
|
||||
@@ -31,7 +31,7 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
/* Readonly accessor properties */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
|
||||
ecma_builtin_arraybuffer_prototype_bytelength_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* ECMA-262 v6, 24.1.4.4 */
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -35,6 +35,10 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
|
||||
|
||||
@@ -32,10 +32,15 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v5, 15.6.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_BOOLEAN_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
|
||||
@@ -62,17 +62,17 @@ ROUTINE (LIT_MAGIC_STRING_SET_UINT32_UL, ECMA_DATAVIEW_PROTOTYPE_SET_UINT32, 2,
|
||||
/* ECMA-262 v6, 24.2.4.1 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BUFFER,
|
||||
ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* 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_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* 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)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/* ECMA-262 v6, 23.1.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
3,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ECMA-262 v6, 23.1 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
|
||||
@@ -237,7 +237,7 @@ ecma_builtin_date_prototype_dispatch_get (uint16_t builtin_routine_id, /**< buil
|
||||
{
|
||||
if (ecma_number_is_nan (date_num))
|
||||
{
|
||||
return ecma_make_magic_string_value (LIT_MAGIC_STRING_NAN);
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
switch (builtin_routine_id)
|
||||
@@ -616,12 +616,10 @@ ecma_builtin_date_prototype_dispatch_routine (uint16_t builtin_routine_id, /**<
|
||||
if (!ecma_is_value_object (this_arg)
|
||||
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Date object expected"));
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a Date object"));
|
||||
}
|
||||
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) ecma_get_object_from_value (this_arg);
|
||||
ecma_number_t *prim_value_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
|
||||
ext_object_p->u.class_prop.u.value);
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "jcontext.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-conversion.h"
|
||||
@@ -734,6 +736,17 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
|
||||
ecma_number_t prim_value_num = ECMA_NUMBER_ZERO;
|
||||
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_DATE_PROTOTYPE);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (JERRY_CONTEXT (current_new_target))
|
||||
{
|
||||
prototype_obj_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target),
|
||||
ECMA_BUILTIN_ID_DATE_PROTOTYPE);
|
||||
if (JERRY_UNLIKELY (prototype_obj_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
}
|
||||
#endif /* !(ENABLED (JERRY_ES2015) */
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
|
||||
sizeof (ecma_extended_object_t),
|
||||
ECMA_OBJECT_TYPE_CLASS);
|
||||
@@ -810,7 +823,12 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
|
||||
JERRY_ASSERT (ECMA_IS_VALUE_ERROR (ret_value));
|
||||
ecma_deref_object (obj_p);
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (JERRY_CONTEXT (current_new_target))
|
||||
{
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
}
|
||||
#endif /* !(ENABLED (JERRY_ES2015) */
|
||||
return ret_value;
|
||||
} /* ecma_builtin_date_dispatch_construct */
|
||||
|
||||
|
||||
@@ -28,12 +28,18 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
7,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
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)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_DATE_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -22,10 +22,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -35,4 +34,10 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_ERROR_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -37,6 +36,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_EVAL_ERROR_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-proxy-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
#include "ecma-builtin-function-prototype.h"
|
||||
@@ -210,53 +211,81 @@ ecma_builtin_function_prototype_object_bind (ecma_object_t *this_arg_obj_p , /**
|
||||
/* 4. 11. 18. */
|
||||
ecma_object_t *prototype_obj_p;
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
prototype_obj_p = ECMA_GET_POINTER (ecma_object_t, this_arg_obj_p->u2.prototype_cp);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
#if !ENABLED (JERRY_ES2015)
|
||||
prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#else /* ENABLED (JERRY_ES2015) */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (this_arg_obj_p))
|
||||
{
|
||||
ecma_value_t proto = ecma_proxy_object_get_prototype_of (this_arg_obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (proto))
|
||||
{
|
||||
return proto;
|
||||
}
|
||||
prototype_obj_p = ecma_is_value_null (proto) ? NULL : ecma_get_object_from_value (proto);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (this_arg_obj_p);
|
||||
if (proto_cp != JMEM_CP_NULL)
|
||||
{
|
||||
prototype_obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
|
||||
ecma_ref_object (prototype_obj_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
prototype_obj_p = NULL;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
#endif /* !ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_object_t *function_p;
|
||||
ecma_extended_object_t *ext_function_p;
|
||||
ecma_bound_function_t *bound_func_p;
|
||||
|
||||
if (arguments_number == 0
|
||||
|| (arguments_number == 1 && !ecma_is_value_integer_number (arguments_list_p[0])))
|
||||
{
|
||||
function_p = ecma_create_object (prototype_obj_p,
|
||||
sizeof (ecma_extended_object_t),
|
||||
sizeof (ecma_bound_function_t),
|
||||
ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
|
||||
/* 8. */
|
||||
ext_function_p = (ecma_extended_object_t *) function_p;
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (ext_function_p->u.bound_function.target_function,
|
||||
this_arg_obj_p);
|
||||
bound_func_p = (ecma_bound_function_t *) function_p;
|
||||
ECMA_SET_NON_NULL_POINTER_TAG (bound_func_p->header.u.bound_function.target_function,
|
||||
this_arg_obj_p,
|
||||
0);
|
||||
|
||||
ext_function_p->u.bound_function.args_len_or_this = ECMA_VALUE_UNDEFINED;
|
||||
bound_func_p->header.u.bound_function.args_len_or_this = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
if (arguments_number != 0)
|
||||
{
|
||||
ext_function_p->u.bound_function.args_len_or_this = ecma_copy_value_if_not_object (arguments_list_p[0]);
|
||||
bound_func_p->header.u.bound_function.args_len_or_this = ecma_copy_value_if_not_object (arguments_list_p[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (arguments_number > 0);
|
||||
|
||||
size_t obj_size = sizeof (ecma_extended_object_t) + (arguments_number * sizeof (ecma_value_t));
|
||||
size_t obj_size = sizeof (ecma_bound_function_t) + (arguments_number * sizeof (ecma_value_t));
|
||||
|
||||
function_p = ecma_create_object (prototype_obj_p,
|
||||
obj_size,
|
||||
ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
|
||||
/* 8. */
|
||||
ext_function_p = (ecma_extended_object_t *) function_p;
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (ext_function_p->u.bound_function.target_function,
|
||||
this_arg_obj_p);
|
||||
bound_func_p = (ecma_bound_function_t *) function_p;
|
||||
ECMA_SET_NON_NULL_POINTER_TAG (bound_func_p->header.u.bound_function.target_function,
|
||||
this_arg_obj_p,
|
||||
0);
|
||||
|
||||
/* NOTE: This solution provides temporary false data about the object's size
|
||||
but prevents GC from freeing it until it's not fully initialized. */
|
||||
ext_function_p->u.bound_function.args_len_or_this = ECMA_VALUE_UNDEFINED;
|
||||
ecma_value_t *args_p = (ecma_value_t *) (ext_function_p + 1);
|
||||
bound_func_p->header.u.bound_function.args_len_or_this = ECMA_VALUE_UNDEFINED;
|
||||
ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1);
|
||||
|
||||
for (ecma_length_t i = 0; i < arguments_number; i++)
|
||||
{
|
||||
@@ -264,9 +293,86 @@ ecma_builtin_function_prototype_object_bind (ecma_object_t *this_arg_obj_p , /**
|
||||
}
|
||||
|
||||
ecma_value_t args_len_or_this = ecma_make_integer_value ((ecma_integer_value_t) arguments_number);
|
||||
ext_function_p->u.bound_function.args_len_or_this = args_len_or_this;
|
||||
bound_func_p->header.u.bound_function.args_len_or_this = args_len_or_this;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (prototype_obj_p != NULL)
|
||||
{
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
}
|
||||
|
||||
ecma_integer_value_t len = 0;
|
||||
ecma_string_t *len_string = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t status = ecma_op_object_get_own_property_descriptor (this_arg_obj_p,
|
||||
len_string,
|
||||
&prop_desc);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
ecma_deref_object (function_p);
|
||||
return status;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_true (status))
|
||||
{
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
ecma_value_t len_value = ecma_op_object_get (this_arg_obj_p,
|
||||
len_string);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (len_value))
|
||||
{
|
||||
ecma_deref_object (function_p);
|
||||
return len_value;
|
||||
}
|
||||
|
||||
if (ecma_is_value_number (len_value))
|
||||
{
|
||||
ecma_number_t len_num;
|
||||
ecma_op_to_integer (len_value, &len_num);
|
||||
len = (ecma_integer_value_t) len_num;
|
||||
}
|
||||
ecma_free_value (len_value);
|
||||
}
|
||||
|
||||
bound_func_p->target_length = len;
|
||||
|
||||
/* 12. */
|
||||
ecma_value_t name_value = ecma_op_object_get_by_magic_id (this_arg_obj_p, LIT_MAGIC_STRING_NAME);
|
||||
if (ECMA_IS_VALUE_ERROR (name_value))
|
||||
{
|
||||
ecma_deref_object (function_p);
|
||||
return name_value;
|
||||
}
|
||||
|
||||
ecma_string_t *name_p;
|
||||
|
||||
if (ecma_is_value_string (name_value))
|
||||
{
|
||||
name_p = ecma_get_string_from_value (name_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_free_value (name_value);
|
||||
name_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
}
|
||||
|
||||
ecma_value_t bound_function_name = ecma_op_function_form_name (name_p, "bound ", 6);
|
||||
|
||||
ecma_deref_ecma_string (name_p);
|
||||
|
||||
ecma_property_value_t *name_prop_value_p;
|
||||
name_prop_value_p = ecma_create_named_data_property (function_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_NAME),
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE,
|
||||
NULL);
|
||||
|
||||
name_prop_value_p->value = bound_function_name;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/*
|
||||
* [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_FUNCTION type.
|
||||
*
|
||||
@@ -321,6 +427,13 @@ ecma_builtin_function_prototype_dispatch_routine (uint16_t builtin_routine_id, /
|
||||
{
|
||||
if (!ecma_op_is_callable (this_arg))
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (JERRY_UNLIKELY (builtin_routine_id == ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE))
|
||||
{
|
||||
return ECMA_VALUE_FALSE;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a function."));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,15 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v5, 15.3.4 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#include "js-parser.h"
|
||||
#include "lit-magic-strings.h"
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
#include "jcontext.h"
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
@@ -30,9 +30,14 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v5, 15.3.3.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_FUNCTION_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -26,7 +26,7 @@ STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ECMA-262 v6, 25.2.2 */
|
||||
/* ECMA-262 v6, 25.2.2.1 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
@@ -103,7 +103,7 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument *
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (vm_is_direct_eval_form_call ())
|
||||
{
|
||||
parse_opts |= ECMA_GET_SUPER_EVAL_PARSER_OPTS ();
|
||||
parse_opts |= ECMA_GET_LOCAL_PARSE_OPTS ();
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
@@ -111,373 +111,6 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument *
|
||||
return ecma_op_eval (ecma_get_string_from_value (x), parse_opts);
|
||||
} /* ecma_builtin_global_object_eval */
|
||||
|
||||
/**
|
||||
* The Global object's 'parseInt' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_global_object_parse_int (const lit_utf8_byte_t *string_buff, /**< routine's first argument's
|
||||
* string buffer */
|
||||
lit_utf8_size_t string_buff_size, /**< routine's first argument's
|
||||
* string buffer's size */
|
||||
ecma_value_t radix) /**< routine's second argument */
|
||||
{
|
||||
if (string_buff_size <= 0)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *string_curr_p = string_buff;
|
||||
|
||||
/* 2. Remove leading whitespace. */
|
||||
ecma_string_trim_helper (&string_curr_p, &string_buff_size);
|
||||
|
||||
const lit_utf8_byte_t *string_end_p = string_curr_p + string_buff_size;
|
||||
const lit_utf8_byte_t *start_p = string_curr_p;
|
||||
const lit_utf8_byte_t *end_p = string_end_p;
|
||||
|
||||
if (string_curr_p >= string_end_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* 3. */
|
||||
int sign = 1;
|
||||
|
||||
/* 4. */
|
||||
ecma_char_t current = lit_cesu8_read_next (&string_curr_p);
|
||||
if (current == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
|
||||
{
|
||||
start_p = string_curr_p;
|
||||
if (string_curr_p < string_end_p)
|
||||
{
|
||||
current = lit_cesu8_read_next (&string_curr_p);
|
||||
}
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
ecma_number_t radix_num;
|
||||
radix = ecma_get_number (radix, &radix_num);
|
||||
|
||||
if (!ecma_is_value_empty (radix))
|
||||
{
|
||||
return radix;
|
||||
}
|
||||
|
||||
int32_t rad = ecma_number_to_int32 (radix_num);
|
||||
|
||||
/* 7.*/
|
||||
bool strip_prefix = true;
|
||||
|
||||
/* 8. */
|
||||
if (rad != 0)
|
||||
{
|
||||
/* 8.a */
|
||||
if (rad < 2 || rad > 36)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
/* 8.b */
|
||||
else if (rad != 16)
|
||||
{
|
||||
strip_prefix = false;
|
||||
}
|
||||
}
|
||||
/* 9. */
|
||||
else
|
||||
{
|
||||
rad = 10;
|
||||
}
|
||||
|
||||
/* 10. */
|
||||
if (strip_prefix
|
||||
&& ((end_p - start_p) >= 2)
|
||||
&& (current == LIT_CHAR_0))
|
||||
{
|
||||
ecma_char_t next = *string_curr_p;
|
||||
if (next == LIT_CHAR_LOWERCASE_X || next == LIT_CHAR_UPPERCASE_X)
|
||||
{
|
||||
/* Skip the 'x' or 'X' characters. */
|
||||
start_p = ++string_curr_p;
|
||||
rad = 16;
|
||||
}
|
||||
}
|
||||
|
||||
/* 11. Check if characters are in [0, Radix - 1]. We also convert them to number values in the process. */
|
||||
string_curr_p = start_p;
|
||||
while (string_curr_p < string_end_p)
|
||||
{
|
||||
ecma_char_t current_char = *string_curr_p++;
|
||||
int32_t current_number;
|
||||
|
||||
if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
|
||||
{
|
||||
current_number = current_char - LIT_CHAR_LOWERCASE_A + 10;
|
||||
}
|
||||
else if ((current_char >= LIT_CHAR_UPPERCASE_A && current_char <= LIT_CHAR_UPPERCASE_Z))
|
||||
{
|
||||
current_number = current_char - LIT_CHAR_UPPERCASE_A + 10;
|
||||
}
|
||||
else if (lit_char_is_decimal_digit (current_char))
|
||||
{
|
||||
current_number = current_char - LIT_CHAR_0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not a valid number char, set value to radix so it fails to pass as a valid character. */
|
||||
current_number = rad;
|
||||
}
|
||||
|
||||
if (!(current_number < rad))
|
||||
{
|
||||
end_p = --string_curr_p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 12. */
|
||||
if (end_p == start_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
ecma_number_t value = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t multiplier = 1.0f;
|
||||
|
||||
/* 13. and 14. */
|
||||
string_curr_p = end_p;
|
||||
|
||||
while (string_curr_p > start_p)
|
||||
{
|
||||
ecma_char_t current_char = *(--string_curr_p);
|
||||
ecma_number_t current_number = ECMA_NUMBER_MINUS_ONE;
|
||||
|
||||
if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
|
||||
{
|
||||
current_number = (ecma_number_t) current_char - LIT_CHAR_LOWERCASE_A + 10;
|
||||
}
|
||||
else if ((current_char >= LIT_CHAR_UPPERCASE_A && current_char <= LIT_CHAR_UPPERCASE_Z))
|
||||
{
|
||||
current_number = (ecma_number_t) current_char - LIT_CHAR_UPPERCASE_A + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (lit_char_is_decimal_digit (current_char));
|
||||
current_number = (ecma_number_t) current_char - LIT_CHAR_0;
|
||||
}
|
||||
|
||||
value += current_number * multiplier;
|
||||
multiplier *= (ecma_number_t) rad;
|
||||
}
|
||||
|
||||
/* 15. */
|
||||
if (sign < 0)
|
||||
{
|
||||
value *= (ecma_number_t) sign;
|
||||
}
|
||||
|
||||
return ecma_make_number_value (value);
|
||||
} /* ecma_builtin_global_object_parse_int */
|
||||
|
||||
/**
|
||||
* The Global object's 'parseFloat' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_global_object_parse_float (const lit_utf8_byte_t *string_buff, /**< routine's first argument's
|
||||
* string buffer */
|
||||
lit_utf8_size_t string_buff_size) /**< routine's first argument's
|
||||
* string buffer's size */
|
||||
{
|
||||
if (string_buff_size <= 0)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *str_curr_p = string_buff;
|
||||
|
||||
/* 2. Remove leading whitespace. */
|
||||
ecma_string_trim_helper (&str_curr_p, &string_buff_size);
|
||||
|
||||
const lit_utf8_byte_t *str_end_p = str_curr_p + string_buff_size;
|
||||
const lit_utf8_byte_t *start_p = str_curr_p;
|
||||
const lit_utf8_byte_t *end_p = str_end_p;
|
||||
|
||||
bool sign = false;
|
||||
ecma_char_t current;
|
||||
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
/* Check if sign is present. */
|
||||
current = *str_curr_p;
|
||||
if (current == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = true;
|
||||
}
|
||||
|
||||
if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
|
||||
{
|
||||
/* Set starting position to be after the sign character. */
|
||||
start_p = ++str_curr_p;
|
||||
}
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
lit_utf8_byte_t *infinity_str_curr_p = (lit_utf8_byte_t *) infinity_str_p;
|
||||
lit_utf8_byte_t *infinity_str_end_p = infinity_str_curr_p + sizeof (*infinity_str_p);
|
||||
|
||||
/* Check if string is equal to "Infinity". */
|
||||
while (str_curr_p < str_end_p
|
||||
&& *str_curr_p++ == *infinity_str_curr_p++)
|
||||
{
|
||||
if (infinity_str_curr_p == infinity_str_end_p)
|
||||
{
|
||||
/* String matched Infinity. */
|
||||
return ecma_make_number_value (ecma_number_make_infinity (sign));
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset to starting position. */
|
||||
str_curr_p = start_p;
|
||||
|
||||
/* String ended after sign character, or was empty after removing leading whitespace. */
|
||||
if (str_curr_p >= str_end_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* Reset to starting position. */
|
||||
str_curr_p = start_p;
|
||||
|
||||
current = *str_curr_p;
|
||||
|
||||
bool has_whole_part = false;
|
||||
bool has_fraction_part = false;
|
||||
|
||||
/* Check digits of whole part. */
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
has_whole_part = true;
|
||||
str_curr_p++;
|
||||
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to the end of whole part. */
|
||||
end_p = str_curr_p;
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p;
|
||||
|
||||
/* Check decimal point. */
|
||||
if (current == LIT_CHAR_DOT)
|
||||
{
|
||||
str_curr_p++;
|
||||
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p;
|
||||
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
has_fraction_part = true;
|
||||
|
||||
/* Check digits of fractional part. */
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to end of fraction part. */
|
||||
end_p = str_curr_p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
}
|
||||
|
||||
/* Check exponent. */
|
||||
if ((current == LIT_CHAR_LOWERCASE_E || current == LIT_CHAR_UPPERCASE_E)
|
||||
&& (has_whole_part || has_fraction_part)
|
||||
&& str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
|
||||
/* Check sign of exponent. */
|
||||
if ((current == LIT_CHAR_PLUS || current == LIT_CHAR_MINUS)
|
||||
&& str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
}
|
||||
|
||||
if (lit_char_is_decimal_digit (current))
|
||||
{
|
||||
/* Check digits of exponent part. */
|
||||
while (str_curr_p < str_end_p)
|
||||
{
|
||||
current = *str_curr_p++;
|
||||
if (!lit_char_is_decimal_digit (current))
|
||||
{
|
||||
str_curr_p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set end position to end of exponent part. */
|
||||
end_p = str_curr_p;
|
||||
}
|
||||
}
|
||||
|
||||
/* String did not contain a valid number. */
|
||||
if (start_p == end_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
ecma_number_t ret_num = ecma_utf8_string_to_number (start_p, (lit_utf8_size_t) (end_p - start_p));
|
||||
|
||||
if (sign)
|
||||
{
|
||||
ret_num *= ECMA_NUMBER_MINUS_ONE;
|
||||
}
|
||||
|
||||
return ecma_make_number_value (ret_num);
|
||||
} /* ecma_builtin_global_object_parse_float */
|
||||
|
||||
/**
|
||||
* The Global object's 'isNaN' routine
|
||||
*
|
||||
@@ -590,13 +223,13 @@ ecma_builtin_global_object_decode_uri_helper (lit_utf8_byte_t *input_start_p, /*
|
||||
continue;
|
||||
}
|
||||
|
||||
ecma_char_t decoded_byte;
|
||||
|
||||
if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &decoded_byte))
|
||||
uint32_t hex_value = lit_char_hex_lookup (input_char_p + 1, input_end_p, 2);
|
||||
if (hex_value == UINT32_MAX)
|
||||
{
|
||||
return ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid hexadecimal value."));
|
||||
}
|
||||
|
||||
ecma_char_t decoded_byte = (ecma_char_t) hex_value;
|
||||
input_char_p += URI_ENCODED_BYTE_SIZE;
|
||||
|
||||
if (decoded_byte <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
||||
@@ -639,20 +272,18 @@ ecma_builtin_global_object_decode_uri_helper (lit_utf8_byte_t *input_start_p, /*
|
||||
/* Input decode. */
|
||||
if (*input_char_p != '%')
|
||||
{
|
||||
*output_char_p = *input_char_p;
|
||||
output_char_p++;
|
||||
input_char_p++;
|
||||
*output_char_p++ = *input_char_p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
ecma_char_t decoded_byte;
|
||||
|
||||
if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &decoded_byte))
|
||||
uint32_t hex_value = lit_char_hex_lookup (input_char_p + 1, input_end_p, 2);
|
||||
if (hex_value == UINT32_MAX)
|
||||
{
|
||||
ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid hexadecimal value."));
|
||||
break;
|
||||
}
|
||||
|
||||
ecma_char_t decoded_byte = (ecma_char_t) hex_value;
|
||||
input_char_p += URI_ENCODED_BYTE_SIZE;
|
||||
|
||||
if (decoded_byte <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
||||
@@ -704,17 +335,16 @@ ecma_builtin_global_object_decode_uri_helper (lit_utf8_byte_t *input_start_p, /*
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_char_t chr;
|
||||
hex_value = lit_char_hex_lookup (input_char_p + 1, input_end_p, 2);
|
||||
|
||||
if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &chr)
|
||||
|| ((chr & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER))
|
||||
if (hex_value == UINT32_MAX || (hex_value & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER)
|
||||
{
|
||||
is_valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
octets[i] = (lit_utf8_byte_t) chr;
|
||||
input_char_p += URI_ENCODED_BYTE_SIZE;
|
||||
octets[i] = (lit_utf8_byte_t) hex_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1198,15 +828,15 @@ ecma_builtin_global_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
|
||||
|
||||
if (builtin_routine_id == ECMA_GLOBAL_PARSE_INT)
|
||||
{
|
||||
ret_value = ecma_builtin_global_object_parse_int (string_buff,
|
||||
string_buff_size,
|
||||
arguments_list_p[1]);
|
||||
ret_value = ecma_number_parse_int (string_buff,
|
||||
string_buff_size,
|
||||
arguments_list_p[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (builtin_routine_id == ECMA_GLOBAL_PARSE_FLOAT);
|
||||
ret_value = ecma_builtin_global_object_parse_float (string_buff,
|
||||
string_buff_size);
|
||||
ret_value = ecma_number_parse_float (string_buff,
|
||||
string_buff_size);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size);
|
||||
|
||||
@@ -246,19 +246,31 @@ OBJECT_VALUE (LIT_MAGIC_STRING_DATAVIEW_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
/* ECMA-262 v6, 26.2.1 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROXY_UL,
|
||||
ECMA_BUILTIN_ID_PROXY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
|
||||
ROUTINE (LIT_MAGIC_STRING_EVAL, ECMA_GLOBAL_EVAL, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_GLOBAL_PARSE_FLOAT, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_NAN, ECMA_GLOBAL_IS_NAN, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_FINITE, ECMA_GLOBAL_IS_FINITE, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_DECODE_URI, ECMA_GLOBAL_DECODE_URI, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_DECODE_URI_COMPONENT, ECMA_GLOBAL_DECODE_URI_COMPONENT, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ENCODE_URI, ECMA_GLOBAL_ENCODE_URI, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ENCODE_URI_COMPONENT, ECMA_GLOBAL_ENCODE_URI_COMPONENT, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_INT, ECMA_GLOBAL_PARSE_INT, 2, 2)
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_FLOAT, LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_INT, LIT_MAGIC_STRING_PARSE_INT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_GLOBAL_PARSE_FLOAT, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_INT, ECMA_GLOBAL_PARSE_INT, 2, 2)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#if ENABLED (JERRY_BUILTIN_ANNEXB)
|
||||
ROUTINE (LIT_MAGIC_STRING_ESCAPE, ECMA_GLOBAL_ESCAPE, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_UNESCAPE, ECMA_GLOBAL_UNESCAPE, 1, 1)
|
||||
|
||||
@@ -60,12 +60,10 @@ ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**<
|
||||
ecma_deref_ecma_string (message_string_p);
|
||||
return ecma_make_object_value (new_error_object_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type);
|
||||
|
||||
return ecma_make_object_value (new_error_object_p);
|
||||
}
|
||||
ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type);
|
||||
|
||||
return ecma_make_object_value (new_error_object_p);
|
||||
} /* ecma_builtin_helper_error_dispatch_call */
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#endif /* !SYMBOL_VALUE */
|
||||
|
||||
#ifndef INTRINSIC_PROPERTY
|
||||
#define INTRINSIC_PROPERTY(name, magic_string_id)
|
||||
#define INTRINSIC_PROPERTY(name, magic_string_id, prop_attributes)
|
||||
#endif /* !INTRINSIC_PROPERTY */
|
||||
|
||||
#ifndef ACCESSOR_BUILTIN_FUNCTION_OBJECT
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-builtin-object.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-exceptions.h"
|
||||
@@ -280,26 +281,23 @@ ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
|
||||
{
|
||||
JERRY_ASSERT (obj_p != NULL);
|
||||
|
||||
ecma_value_t new_array = ecma_op_create_array_object (NULL, 0, false);
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array));
|
||||
ecma_object_t *new_array_p = ecma_get_object_from_value (new_array);
|
||||
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (props_p->item_count == 0)
|
||||
{
|
||||
ecma_collection_destroy (props_p);
|
||||
return new_array;
|
||||
return ecma_op_create_array_object (NULL, 0, false);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_op_object_is_fast_array (new_array_p));
|
||||
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
ecma_value_t *values_p = ecma_fast_array_extend (new_array_p, props_p->item_count);
|
||||
|
||||
memcpy (values_p, buffer_p, props_p->item_count * sizeof (ecma_value_t));
|
||||
|
||||
ecma_collection_free_objects (props_p);
|
||||
ecma_value_t new_array = ecma_op_create_array_object (props_p->buffer_p, props_p->item_count, false);
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
return new_array;
|
||||
} /* ecma_builtin_helper_object_get_properties */
|
||||
@@ -380,7 +378,7 @@ ecma_builtin_helper_array_concat_value (ecma_object_t *array_obj_p, /**< array *
|
||||
|
||||
bool spread_object = is_spreadable == ECMA_VALUE_TRUE;
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
bool spread_object = ecma_is_value_array (value);
|
||||
bool spread_object = ecma_is_value_true (ecma_is_value_array (value));
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if (spread_object)
|
||||
@@ -587,7 +585,9 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_st
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case ECMA_STRING_STARTS_WITH:
|
||||
{
|
||||
if (pos_num + start > original_len)
|
||||
const ecma_length_t search_len = ecma_string_get_length (search_str_p);
|
||||
|
||||
if (search_len + start > original_len)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -689,7 +689,7 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
|
||||
if (!search_len)
|
||||
{
|
||||
match_found = true;
|
||||
*ret_index_p = first_index ? 0 : original_len;
|
||||
*ret_index_p = first_index ? start_pos : original_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -817,7 +817,7 @@ ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, /**< object */
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *index_p, /**< index string */
|
||||
ecma_string_t *name_p, /**< name string */
|
||||
ecma_value_t value, /**< value */
|
||||
uint32_t opts) /**< any combination of ecma_property_flag_t bits
|
||||
* with the optional ECMA_IS_THROW flag */
|
||||
@@ -829,7 +829,7 @@ ecma_builtin_helper_def_prop (ecma_object_t *obj_p, /**< object */
|
||||
prop_desc.value = value;
|
||||
|
||||
return ecma_op_object_define_own_property (obj_p,
|
||||
index_p,
|
||||
name_p,
|
||||
&prop_desc);
|
||||
} /* ecma_builtin_helper_def_prop */
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ bool
|
||||
ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, ecma_string_t *search_str_p, bool first_index,
|
||||
ecma_length_t start_pos, ecma_length_t *ret_index_p);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, ecma_string_t *index_p, ecma_value_t value, uint32_t opts);
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, ecma_string_t *name_p, ecma_value_t value, uint32_t opts);
|
||||
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, uint32_t index, ecma_value_t value, uint32_t opts);
|
||||
@@ -234,9 +234,9 @@ ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, const
|
||||
/**
|
||||
* Comparison callback function header for sorting helper routines.
|
||||
*/
|
||||
typedef ecma_value_t (*ecma_builtin_helper_sort_compare_fn_t)(ecma_value_t lhs, /**< left value */
|
||||
ecma_value_t rhs, /**< right value */
|
||||
ecma_value_t compare_func); /**< compare function */
|
||||
typedef ecma_value_t (*ecma_builtin_helper_sort_compare_fn_t) (ecma_value_t lhs, /**< left value */
|
||||
ecma_value_t rhs, /**< right value */
|
||||
ecma_value_t compare_func); /**< compare function */
|
||||
|
||||
ecma_value_t ecma_builtin_helper_array_heap_sort_helper (ecma_value_t *array_p,
|
||||
uint32_t right,
|
||||
|
||||
@@ -116,6 +116,14 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
||||
prop_attributes, \
|
||||
ECMA_ACCESSOR_ ## name ## c_getter_func_name \
|
||||
},
|
||||
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, \
|
||||
prop_attributes, \
|
||||
ECMA_ACCESSOR_READ_WRITE (ECMA_ACCESSOR_ ## name ## c_getter_func_name, \
|
||||
ECMA_ACCESSOR_ ## name ## c_setter_func_name) \
|
||||
},
|
||||
#else /* BUILTIN_CUSTOM_DISPATCH */
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
{ \
|
||||
@@ -145,6 +153,13 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
||||
prop_attributes, \
|
||||
c_getter_func_name \
|
||||
},
|
||||
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, \
|
||||
prop_attributes, \
|
||||
ECMA_ACCESSOR_READ_WRITE (c_getter_func_name, c_setter_func_name) \
|
||||
},
|
||||
#endif /* !BUILTIN_CUSTOM_DISPATCH */
|
||||
#define OBJECT_VALUE(name, obj_builtin_id, prop_attributes) \
|
||||
{ \
|
||||
@@ -182,11 +197,11 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
||||
ECMA_PROPERTY_FIXED, \
|
||||
desc_magic_string_id \
|
||||
},
|
||||
#define INTRINSIC_PROPERTY(name, magic_string_id) \
|
||||
#define INTRINSIC_PROPERTY(name, magic_string_id, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_INTRINSIC_PROPERTY, \
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE, \
|
||||
prop_attributes, \
|
||||
magic_string_id \
|
||||
},
|
||||
#define ACCESSOR_BUILTIN_FUNCTION(name, getter_builtin_id, setter_builtin_id, prop_attributes) \
|
||||
@@ -197,13 +212,6 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
||||
ECMA_ACCESSOR_READ_WRITE (getter_builtin_id, setter_builtin_id) \
|
||||
},
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#define ACCESSOR_READ_WRITE(name, c_getter_name, c_setter_name, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, \
|
||||
prop_attributes, \
|
||||
ECMA_ACCESSOR_READ_WRITE (ECMA_ACCESSOR_ ## name ## c_getter_name, ECMA_ACCESSOR_ ## name ## c_setter_name) \
|
||||
},
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
{
|
||||
LIT_MAGIC_STRING__COUNT,
|
||||
|
||||
@@ -16,12 +16,29 @@
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "lit-char-helpers.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
|
||||
#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_INTRINSIC_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1,
|
||||
ECMA_INTRINSIC_PARSE_FLOAT,
|
||||
ECMA_INTRINSIC_PARSE_INT,
|
||||
ECMA_INTRINSIC_ARRAY_PROTOTYPE_VALUES
|
||||
};
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-intrinsic.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID intrinsic
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
@@ -64,6 +81,59 @@ ecma_builtin_intrinsic_array_prototype_values (ecma_value_t this_value) /**< thi
|
||||
return ret_value;
|
||||
} /* ecma_builtin_intrinsic_array_prototype_values */
|
||||
|
||||
/**
|
||||
* Dispatcher of the built-in's routines
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_intrinsic_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 */
|
||||
{
|
||||
JERRY_UNUSED (arguments_number);
|
||||
|
||||
ecma_value_t routine_arg_1 = arguments_list_p[0];
|
||||
ecma_value_t routine_arg_2 = arguments_list_p[1];
|
||||
|
||||
if (builtin_routine_id == ECMA_INTRINSIC_ARRAY_PROTOTYPE_VALUES)
|
||||
{
|
||||
return ecma_builtin_intrinsic_array_prototype_values (this_arg);
|
||||
}
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
if (builtin_routine_id <= ECMA_INTRINSIC_PARSE_INT)
|
||||
{
|
||||
ecma_string_t *str_p = ecma_op_to_string (routine_arg_1);
|
||||
|
||||
if (JERRY_UNLIKELY (str_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ECMA_STRING_TO_UTF8_STRING (str_p, string_buff, string_buff_size);
|
||||
|
||||
if (builtin_routine_id == ECMA_INTRINSIC_PARSE_INT)
|
||||
{
|
||||
ret_value = ecma_number_parse_int (string_buff,
|
||||
string_buff_size,
|
||||
routine_arg_2);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (builtin_routine_id == ECMA_INTRINSIC_PARSE_FLOAT);
|
||||
ret_value = ecma_number_parse_float (string_buff,
|
||||
string_buff_size);
|
||||
}
|
||||
ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size);
|
||||
ecma_deref_ecma_string (str_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_intrinsic_dispatch_routine */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@@ -64,8 +64,10 @@ SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||
/* ECMA-262 v6, 19.4.2.14 */
|
||||
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_UNSCOPABLES,
|
||||
LIT_MAGIC_STRING_UNSCOPABLES)
|
||||
|
||||
ROUTINE (LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, ecma_builtin_intrinsic_array_prototype_values, 0, 0)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_INTRINSIC_PARSE_FLOAT, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_INT, ECMA_INTRINSIC_PARSE_INT, 2, 2)
|
||||
ROUTINE (LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, ECMA_INTRINSIC_ARRAY_PROTOTYPE_VALUES, 0, 0)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -174,18 +174,13 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument
|
||||
}
|
||||
case LIT_CHAR_LOWERCASE_U:
|
||||
{
|
||||
if ((end_p - current_p <= ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH))
|
||||
uint32_t hex_value = lit_char_hex_lookup (current_p + 1, end_p, ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH);
|
||||
if (hex_value == UINT32_MAX)
|
||||
{
|
||||
goto invalid_string;
|
||||
}
|
||||
|
||||
ecma_char_t code_unit;
|
||||
if (!(lit_read_code_unit_from_hex (current_p + 1, ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH, &code_unit)))
|
||||
{
|
||||
goto invalid_string;
|
||||
}
|
||||
|
||||
ecma_stringbuilder_append_char (&result_builder, code_unit);
|
||||
ecma_stringbuilder_append_char (&result_builder, (ecma_char_t) hex_value);
|
||||
current_p += ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH + 1;
|
||||
break;
|
||||
}
|
||||
@@ -204,7 +199,7 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument
|
||||
|
||||
ecma_stringbuilder_append_raw (&result_builder,
|
||||
unappended_p,
|
||||
(lit_utf8_size_t)(current_p - unappended_p));
|
||||
(lit_utf8_size_t) (current_p - unappended_p));
|
||||
token_p->u.string_p = ecma_stringbuilder_finalize (&result_builder);
|
||||
token_p->current_p = current_p + 1;
|
||||
token_p->type = TOKEN_STRING;
|
||||
@@ -904,6 +899,13 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
|
||||
else
|
||||
{
|
||||
property_keys_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (property_keys_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
}
|
||||
|
||||
/* 8. */
|
||||
@@ -998,7 +1000,12 @@ static ecma_value_t
|
||||
ecma_builtin_json_serialize_array (ecma_json_stringify_context_t *context_p, /**< context*/
|
||||
ecma_object_t *obj_p) /**< the array object*/
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
|
||||
#ifndef JERRY_NDEBUG
|
||||
ecma_value_t obj_value = ecma_make_object_value (obj_p);
|
||||
ecma_value_t is_array = ecma_is_value_array (obj_value);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (is_array));
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
/* 1. */
|
||||
if (ecma_json_has_object_in_stack (context_p->occurence_stack_last_p, obj_p))
|
||||
@@ -1020,7 +1027,23 @@ ecma_builtin_json_serialize_array (ecma_json_stringify_context_t *context_p, /**
|
||||
const bool has_gap = !ecma_compare_ecma_string_to_magic_id (context_p->gap_str_p, LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
/* 6. */
|
||||
uint32_t array_length = ((ecma_extended_object_t *) obj_p)->u.array.length;
|
||||
uint32_t array_length;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_value_t length_value = ecma_op_object_get_length (obj_p, &array_length);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (length_value))
|
||||
{
|
||||
return length_value;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
{
|
||||
array_length = ((ecma_extended_object_t *) obj_p)->u.array.length;
|
||||
}
|
||||
|
||||
ecma_stringbuilder_append_byte (&context_p->result_builder, LIT_CHAR_LEFT_SQUARE);
|
||||
|
||||
@@ -1163,36 +1186,36 @@ ecma_builtin_json_serialize_property (ecma_json_stringify_context_t *context_p,
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
lit_magic_string_id_t class_name = ecma_object_get_class_name (obj_p);
|
||||
|
||||
ecma_value_t result = ECMA_VALUE_EMPTY;
|
||||
|
||||
/* 5.a */
|
||||
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
result = ecma_op_to_number (value);
|
||||
value = ecma_op_to_number (value);
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
/* 5.b */
|
||||
else if (class_name == LIT_MAGIC_STRING_STRING_UL)
|
||||
{
|
||||
ecma_string_t *str_p = ecma_op_to_string (value);
|
||||
result = ecma_make_string_value (str_p);
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (JERRY_UNLIKELY (str_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
value = ecma_make_string_value (str_p);
|
||||
}
|
||||
/* 5.c */
|
||||
else if (class_name == LIT_MAGIC_STRING_BOOLEAN_UL)
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
result = ext_object_p->u.class_prop.u.value;
|
||||
}
|
||||
|
||||
if (!ecma_is_value_empty (result))
|
||||
{
|
||||
value = ext_object_p->u.class_prop.u.value;
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
value = result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1253,11 +1276,21 @@ ecma_builtin_json_serialize_property (ecma_json_stringify_context_t *context_p,
|
||||
/* 11. */
|
||||
if (ecma_is_value_object (value) && !ecma_op_is_callable (value))
|
||||
{
|
||||
ecma_value_t is_array = ecma_is_value_array (value);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (ECMA_IS_VALUE_ERROR (is_array))
|
||||
{
|
||||
ecma_free_value (value);
|
||||
return is_array;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
ecma_value_t ret_value;
|
||||
/* 10.a */
|
||||
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY)
|
||||
if (ecma_is_value_true (is_array))
|
||||
{
|
||||
ret_value = ecma_builtin_json_serialize_array (context_p, obj_p);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ecma_builtin_map_prototype_object_entries,
|
||||
/* ECMA-262 v6, 23.1.3.10 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE,
|
||||
ecma_builtin_map_prototype_object_size_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/* ECMA-262 v6, 23.1.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ECMA-262 v6, 23.1 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
#include "jrt.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
|
||||
#if defined (WIN32)
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_MATH)
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
@@ -55,21 +59,37 @@ enum
|
||||
ECMA_MATH_OBJECT_EXP, /* ECMA-262 v5, 15.8.2.8 */
|
||||
ECMA_MATH_OBJECT_FLOOR, /* ECMA-262 v5, 15.8.2.9 */
|
||||
ECMA_MATH_OBJECT_LOG, /* ECMA-262 v5, 15.8.2.10 */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ECMA_MATH_OBJECT_TRUNC, /* ECMA-262 v6, 20.2.2.35 */
|
||||
ECMA_MATH_OBJECT_SIGN, /* ECMA-262 v6, 20.2.2.29 */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
ECMA_MATH_OBJECT_ROUND, /* ECMA-262 v5, 15.8.2.15 */
|
||||
ECMA_MATH_OBJECT_SIN, /* ECMA-262 v5, 15.8.2.16 */
|
||||
ECMA_MATH_OBJECT_SQRT, /* ECMA-262 v5, 15.8.2.17 */
|
||||
ECMA_MATH_OBJECT_TAN, /* ECMA-262 v5, 15.8.2.18 */
|
||||
|
||||
ECMA_MATH_OBJECT_ATAN2, /* ECMA-262 v5, 15.8.2.5 */
|
||||
ECMA_MATH_OBJECT_POW, /* ECMA-262 v5, 15.8.2.13 */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ECMA_MATH_OBJECT_ACOSH, /* ECMA-262 v6, 20.2.2.3 */
|
||||
ECMA_MATH_OBJECT_ASINH, /* ECMA-262 v6, 20.2.2.5 */
|
||||
ECMA_MATH_OBJECT_ATANH, /* ECMA-262 v6, 20.2.2.7 */
|
||||
ECMA_MATH_OBJECT_CBRT, /* ECMA-262 v6, 20.2.2.9 */
|
||||
ECMA_MATH_OBJECT_CLZ32, /* ECMA-262 v6, 20.2.2.11 */
|
||||
ECMA_MATH_OBJECT_COSH, /* ECMA-262 v6, 20.2.2.13 */
|
||||
ECMA_MATH_OBJECT_EXPM1, /* ECMA-262 v6, 20.2.2.15 */
|
||||
ECMA_MATH_OBJECT_FROUND, /* ECMA-262 v6, 20.2.2.17 */
|
||||
ECMA_MATH_OBJECT_LOG1P, /* ECMA-262 v6, 20.2.2.21 */
|
||||
ECMA_MATH_OBJECT_LOG10, /* ECMA-262 v6, 20.2.2.22 */
|
||||
ECMA_MATH_OBJECT_LOG2, /* ECMA-262 v6, 20.2.2.23 */
|
||||
ECMA_MATH_OBJECT_SIGN, /* ECMA-262 v6, 20.2.2.29 */
|
||||
ECMA_MATH_OBJECT_SINH, /* ECMA-262 v6, 20.2.2.31 */
|
||||
ECMA_MATH_OBJECT_TANH, /* ECMA-262 v6, 20.2.2.34 */
|
||||
ECMA_MATH_OBJECT_TRUNC, /* ECMA-262 v6, 20.2.2.35 */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
ECMA_MATH_OBJECT_ATAN2, /* ECMA-262 v5, 15.8.2.5 */ /* first routine with 2 arguments */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ECMA_MATH_OBJECT_IMUL, /* ECMA-262 v6, 20.2.2.19 */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
ECMA_MATH_OBJECT_POW, /* ECMA-262 v5, 15.8.2.13 */ /* last routine with 1 or 2 arguments*/
|
||||
ECMA_MATH_OBJECT_MAX, /* ECMA-262 v5, 15.8.2.11 */
|
||||
ECMA_MATH_OBJECT_MIN, /* ECMA-262 v5, 15.8.2.12 */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ECMA_MATH_OBJECT_HYPOT, /* ECMA-262 v6, 20.2.2.18 */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
ECMA_MATH_OBJECT_RANDOM, /* ECMA-262 v5, 15.8.2.14 */
|
||||
};
|
||||
|
||||
@@ -164,6 +184,76 @@ ecma_builtin_math_object_max_min (bool is_max, /**< 'max' or 'min' operation */
|
||||
} /* ecma_builtin_math_object_max_min */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/**
|
||||
* The Math object's 'hypot' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 20.2.2.18
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_hypot (const ecma_value_t *arg, /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
if (args_number == 0)
|
||||
{
|
||||
return ecma_make_number_value (0.0);
|
||||
}
|
||||
|
||||
bool nan_found = false;
|
||||
bool inf_found = false;
|
||||
ecma_number_t result_num = 0;
|
||||
|
||||
while (args_number > 0)
|
||||
{
|
||||
ecma_number_t arg_num;
|
||||
if (ecma_is_value_number (*arg))
|
||||
{
|
||||
arg_num = ecma_get_number_from_value (*arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t value = ecma_op_to_number (*arg);
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
arg_num = ecma_get_number_from_value (value);
|
||||
ecma_fast_free_value (value);
|
||||
}
|
||||
|
||||
arg++;
|
||||
args_number--;
|
||||
|
||||
if (JERRY_UNLIKELY (inf_found || ecma_number_is_infinity (arg_num)))
|
||||
{
|
||||
inf_found = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY (nan_found || ecma_number_is_nan (arg_num)))
|
||||
{
|
||||
nan_found = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
result_num += arg_num * arg_num;
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY (inf_found))
|
||||
{
|
||||
return ecma_make_number_value (ecma_number_make_infinity (false));
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY (nan_found))
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
return ecma_make_number_value (sqrt (result_num));
|
||||
} /* ecma_builtin_math_object_hypot */
|
||||
|
||||
/**
|
||||
* The Math object's 'trunc' routine
|
||||
@@ -415,27 +505,100 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
||||
}
|
||||
case ECMA_MATH_OBJECT_POW:
|
||||
{
|
||||
if (ecma_number_is_nan (y) ||
|
||||
(ecma_number_is_infinity (y) && (x == 1.0 || x == -1.0)))
|
||||
{
|
||||
/* Handle differences between ES5.1 and ISO C standards for pow. */
|
||||
x = ecma_number_make_nan ();
|
||||
}
|
||||
else if (ecma_number_is_zero (y))
|
||||
{
|
||||
/* Handle differences between ES5.1 and ISO C standards for pow. */
|
||||
x = (ecma_number_t) 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (pow (x, y));
|
||||
}
|
||||
x = ecma_number_pow (x, y);
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case ECMA_MATH_OBJECT_ACOSH:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (acosh (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_ASINH:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (asinh (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_ATANH:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (atanh (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_CBRT:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (cbrt (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_COSH:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (cosh (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_EXPM1:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (expm1 (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_LOG1P:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (log1p (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_LOG10:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (log10 (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_LOG2:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (log2 (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_SINH:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (sinh (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_TANH:
|
||||
{
|
||||
x = DOUBLE_TO_ECMA_NUMBER_T (tanh (x));
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_CLZ32:
|
||||
{
|
||||
uint32_t n = ecma_number_to_uint32 (x);
|
||||
#if defined (__GNUC__) || defined (__clang__)
|
||||
x = n ? __builtin_clz (n) : 32;
|
||||
#elif defined (WIN32)
|
||||
unsigned long ret;
|
||||
x = _BitScanReverse (&ret, n) ? 31 - ret : 32;
|
||||
#else
|
||||
x = 32;
|
||||
for (int i = 31; i >= 0; i--)
|
||||
{
|
||||
if (n >> i)
|
||||
{
|
||||
x = 31 - i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_FROUND:
|
||||
{
|
||||
x = (float) x;
|
||||
break;
|
||||
}
|
||||
case ECMA_MATH_OBJECT_IMUL:
|
||||
{
|
||||
x = (int32_t) (ecma_number_to_uint32 (x) * ecma_number_to_uint32 (y));
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
}
|
||||
|
||||
return ecma_make_number_value (x);
|
||||
}
|
||||
} /* if (builtin_routine_id <= ECMA_MATH_OBJECT_POW) */
|
||||
|
||||
if (builtin_routine_id <= ECMA_MATH_OBJECT_MIN)
|
||||
{
|
||||
@@ -444,6 +607,13 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
||||
arguments_number);
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (builtin_routine_id == ECMA_MATH_OBJECT_HYPOT)
|
||||
{
|
||||
return ecma_builtin_math_object_hypot (arguments_list, arguments_number);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
JERRY_ASSERT (builtin_routine_id == ECMA_MATH_OBJECT_RANDOM);
|
||||
|
||||
return ecma_builtin_math_object_random ();
|
||||
|
||||
@@ -92,7 +92,22 @@ ROUTINE (LIT_MAGIC_STRING_SIN, ECMA_MATH_OBJECT_SIN, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SQRT, ECMA_MATH_OBJECT_SQRT, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TAN, ECMA_MATH_OBJECT_TAN, 1, 1)
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ROUTINE (LIT_MAGIC_STRING_ACOSH, ECMA_MATH_OBJECT_ACOSH, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ASINH, ECMA_MATH_OBJECT_ASINH, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ATANH, ECMA_MATH_OBJECT_ATANH, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_CBRT, ECMA_MATH_OBJECT_CBRT, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_CLZ32, ECMA_MATH_OBJECT_CLZ32, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_COSH, ECMA_MATH_OBJECT_COSH, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_EXPM1, ECMA_MATH_OBJECT_EXPM1, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_FROUND, ECMA_MATH_OBJECT_FROUND, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_HYPOT, ECMA_MATH_OBJECT_HYPOT, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_IMUL, ECMA_MATH_OBJECT_IMUL, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_LOG1P, ECMA_MATH_OBJECT_LOG1P, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LOG10, ECMA_MATH_OBJECT_LOG10, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LOG2, ECMA_MATH_OBJECT_LOG2, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SIGN, ECMA_MATH_OBJECT_SIGN, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SINH, ECMA_MATH_OBJECT_SINH, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TANH, ECMA_MATH_OBJECT_TANH, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TRUNC, ECMA_MATH_OBJECT_TRUNC, 1, 1)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
|
||||
@@ -673,6 +673,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_number_t this_num, /**< this
|
||||
if (!ecma_number_is_zero (this_num))
|
||||
{
|
||||
num_digits = ecma_number_to_binary_floating_point_number (this_num, digits, &exponent);
|
||||
JERRY_ASSERT (exponent >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -692,7 +693,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_number_t this_num, /**< this
|
||||
|
||||
/* 8. */
|
||||
num_digits = ecma_builtin_number_prototype_helper_round (digits,
|
||||
num_digits + 1,
|
||||
num_digits + (lit_utf8_size_t) exponent,
|
||||
exponent + frac_digits,
|
||||
&exponent,
|
||||
ecma_number_is_zero (this_num));
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.7.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* ECMA-262 v5, 15.7.3.4 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_NAN,
|
||||
@@ -71,6 +70,9 @@ NUMBER_VALUE (LIT_MAGIC_STRING_MIN_SAFE_INTEGER_U,
|
||||
ECMA_BUILTIN_NUMBER_MIN_SAFE_INTEGER,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_NUMBER_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* Object properties:
|
||||
@@ -90,5 +92,7 @@ ROUTINE (LIT_MAGIC_STRING_IS_FINITE, ecma_builtin_number_object_is_finite, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_NAN, ecma_builtin_number_object_is_nan, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_INTEGER, ecma_builtin_number_object_is_integer, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_SAFE_INTEGER, ecma_builtin_number_object_is_safe_integer, 1, 1)
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_FLOAT, LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_INT, LIT_MAGIC_STRING_PARSE_INT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-builtin-object.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-function-object.h"
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-proxy-object.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
@@ -45,9 +47,11 @@ enum
|
||||
ECMA_OBJECT_PROTOTYPE_TO_STRING,
|
||||
ECMA_OBJECT_PROTOTYPE_VALUE_OF,
|
||||
ECMA_OBJECT_PROTOTYPE_TO_LOCALE_STRING,
|
||||
ECMA_OBJECT_PROTOTYPE_GET_PROTO,
|
||||
ECMA_OBJECT_PROTOTYPE_IS_PROTOTYPE_OF,
|
||||
ECMA_OBJECT_PROTOTYPE_HAS_OWN_PROPERTY,
|
||||
ECMA_OBJECT_PROTOTYPE_PROPERTY_IS_ENUMERABLE,
|
||||
ECMA_OBJECT_PROTOTYPE_SET_PROTO
|
||||
};
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object-prototype.inc.h"
|
||||
@@ -143,7 +147,23 @@ static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_has_own_property (ecma_object_t *obj_p, /**< this argument */
|
||||
ecma_string_t *prop_name_p) /**< first argument */
|
||||
{
|
||||
return ecma_make_boolean_value (ecma_op_object_has_own_property (obj_p, prop_name_p));
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
ecma_value_t status = ecma_proxy_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc);
|
||||
|
||||
if (ecma_is_value_true (status))
|
||||
{
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
return ecma_make_boolean_value (ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p));
|
||||
} /* ecma_builtin_object_prototype_object_has_own_property */
|
||||
|
||||
/**
|
||||
@@ -169,7 +189,7 @@ ecma_builtin_object_prototype_object_is_prototype_of (ecma_object_t *obj_p, /**<
|
||||
|
||||
ecma_object_t *v_obj_p = ecma_get_object_from_value (v_obj_value);
|
||||
|
||||
ecma_value_t ret_value = ecma_make_boolean_value (ecma_op_object_is_prototype_of (obj_p, v_obj_p));
|
||||
ecma_value_t ret_value = ecma_op_object_is_prototype_of (obj_p, v_obj_p);
|
||||
|
||||
ecma_deref_object (v_obj_p);
|
||||
|
||||
@@ -189,19 +209,19 @@ static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_property_is_enumerable (ecma_object_t *obj_p, /**< this argument */
|
||||
ecma_string_t *prop_name_p) /**< first argument */
|
||||
{
|
||||
/* 3. */
|
||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
||||
prop_name_p,
|
||||
NULL,
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc);
|
||||
|
||||
/* 4. */
|
||||
if (property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
||||
if (!ecma_is_value_true (status))
|
||||
{
|
||||
return ecma_make_boolean_value (ecma_is_property_enumerable (property));
|
||||
return status;
|
||||
}
|
||||
|
||||
return ECMA_VALUE_FALSE;
|
||||
bool is_enumerable = (prop_desc.flags & ECMA_PROP_IS_ENUMERABLE);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
return ecma_make_boolean_value (is_enumerable);
|
||||
} /* ecma_builtin_object_prototype_object_property_is_enumerable */
|
||||
|
||||
/**
|
||||
@@ -259,6 +279,14 @@ ecma_builtin_object_prototype_dispatch_routine (uint16_t builtin_routine_id, /**
|
||||
{
|
||||
ret_value = ecma_builtin_object_prototype_object_is_prototype_of (obj_p, arguments_list_p[0]);
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
else if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_GET_PROTO)
|
||||
{
|
||||
ret_value = ecma_builtin_object_object_get_prototype_of (obj_p);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015)*/
|
||||
|
||||
else
|
||||
{
|
||||
ret_value = ecma_builtin_object_prototype_object_to_locale_string (obj_p);
|
||||
@@ -271,6 +299,13 @@ ecma_builtin_object_prototype_dispatch_routine (uint16_t builtin_routine_id, /**
|
||||
|
||||
JERRY_ASSERT (builtin_routine_id >= ECMA_OBJECT_PROTOTYPE_HAS_OWN_PROPERTY);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_SET_PROTO)
|
||||
{
|
||||
return ecma_builtin_object_object_set_proto (this_arg, arguments_list_p[0]);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015)*/
|
||||
|
||||
ecma_string_t *prop_name_p = ecma_op_to_prop_name (arguments_list_p[0]);
|
||||
|
||||
if (prop_name_p == NULL)
|
||||
|
||||
@@ -27,6 +27,11 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_OBJECT,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
ACCESSOR_READ_WRITE (LIT_MAGIC_STRING__PROTO__,
|
||||
ECMA_OBJECT_PROTOTYPE_GET_PROTO,
|
||||
ECMA_OBJECT_PROTOTYPE_SET_PROTO,
|
||||
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_TO_STRING_UL, ECMA_OBJECT_PROTOTYPE_TO_STRING, 0, 0)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-proxy-object.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "jrt.h"
|
||||
#include "ecma-builtin-object.h"
|
||||
@@ -136,11 +137,18 @@ ecma_builtin_object_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
||||
ecma_value_t
|
||||
ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
jmem_cpointer_t prototype_cp = obj_p->u2.prototype_cp;
|
||||
|
||||
if (prototype_cp != JMEM_CP_NULL)
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_object_t *prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, prototype_cp);
|
||||
return ecma_proxy_object_get_prototype_of (obj_p);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (obj_p);
|
||||
|
||||
if (proto_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_object_t *prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
|
||||
ecma_ref_object (prototype_p);
|
||||
return ecma_make_object_value (prototype_p);
|
||||
}
|
||||
@@ -149,77 +157,6 @@ ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p) /**< routine'
|
||||
} /* ecma_builtin_object_object_get_prototype_of */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
|
||||
/**
|
||||
* [[SetPrototypeOf]]
|
||||
*
|
||||
* See also:
|
||||
* ES2015 9.1.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_set_prototype_of (ecma_value_t o_value, /**< O */
|
||||
ecma_value_t v_value) /**< V */
|
||||
{
|
||||
/* 1. */
|
||||
JERRY_ASSERT (ecma_is_value_object (o_value));
|
||||
JERRY_ASSERT (ecma_is_value_object (v_value) || ecma_is_value_null (v_value));
|
||||
|
||||
ecma_object_t *o_p = ecma_get_object_from_value (o_value);
|
||||
|
||||
jmem_cpointer_t v_cp;
|
||||
|
||||
if (ecma_is_value_null (v_value))
|
||||
{
|
||||
v_cp = JMEM_CP_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_SET_NON_NULL_POINTER (v_cp, ecma_get_object_from_value (v_value));
|
||||
}
|
||||
|
||||
/* 3., 4. */
|
||||
if (v_cp == o_p->u2.prototype_cp)
|
||||
{
|
||||
ecma_ref_object (o_p);
|
||||
return ecma_make_object_value (o_p);
|
||||
}
|
||||
|
||||
/* 2., 5. */
|
||||
if (!ecma_get_object_extensible (o_p))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("cannot set prototype."));
|
||||
}
|
||||
|
||||
/* 6., 7., 8. */
|
||||
jmem_cpointer_t p_cp = v_cp;
|
||||
while (p_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_object_t *p_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, p_cp);
|
||||
|
||||
/* b. */
|
||||
if (p_p == o_p)
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("cannot set prototype."));
|
||||
}
|
||||
|
||||
/* c.i. TODO: es2015-subset profile does not support having a different
|
||||
* [[GetPrototypeOf]] internal method */
|
||||
|
||||
/* c.ii. */
|
||||
p_cp = p_p->u2.prototype_cp;
|
||||
}
|
||||
|
||||
/* 9. */
|
||||
o_p->u2.prototype_cp = v_cp;
|
||||
|
||||
/* 10. */
|
||||
ecma_ref_object (o_p);
|
||||
return ecma_make_object_value (o_p);
|
||||
} /* ecma_set_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object object's 'setPrototypeOf' routine
|
||||
*
|
||||
@@ -251,13 +188,101 @@ ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's f
|
||||
return ecma_copy_value (arg1);
|
||||
}
|
||||
|
||||
/* 6. TODO: es2015-subset profile does not support having a different
|
||||
* [[SetPrototypeOf]] internal method */
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
|
||||
ecma_value_t status;
|
||||
|
||||
/* 5-8. */
|
||||
return ecma_set_prototype_of (arg1, arg2);
|
||||
/* 5. */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
status = ecma_proxy_object_set_prototype_of (obj_p, arg2);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
status = ecma_op_ordinary_object_set_prototype_of (obj_p, arg2);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot set [[Prototype]]."));
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (status));
|
||||
ecma_ref_object (obj_p);
|
||||
|
||||
return arg1;
|
||||
} /* ecma_builtin_object_object_set_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object object's set __proto__ routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, B.2.2.1.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_object_object_set_proto (ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
/* 1., 2. */
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_check_object_coercible (arg1)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
/* 3. */
|
||||
if (!ecma_is_value_object (arg2) && !ecma_is_value_null (arg2))
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
/* 4. */
|
||||
if (!ecma_is_value_object (arg1))
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
|
||||
ecma_value_t status;
|
||||
|
||||
/* 5. */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
status = ecma_proxy_object_set_prototype_of (obj_p, arg2);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
status = ecma_op_ordinary_object_set_prototype_of (obj_p, arg2);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot set [[Prototype]]."));
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (status));
|
||||
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
} /* ecma_builtin_object_object_set_proto */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
@@ -294,6 +319,155 @@ ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**<
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
* SetIntegrityLevel operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 7.3.14
|
||||
*
|
||||
* @return ECMA_VALUE_ERROR - if the operation raised an error
|
||||
* ECMA_VALUE_{TRUE/FALSE} - depends on whether the integrity level has been set sucessfully
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_set_integrity_level (ecma_object_t *obj_p, /**< object */
|
||||
bool is_seal) /**< true - set "sealed"
|
||||
* false - set "frozen" */
|
||||
{
|
||||
/* 3. */
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_value_t status = ecma_proxy_object_prevent_extensions (obj_p);
|
||||
|
||||
if (!ecma_is_value_true (status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
ecma_op_ordinary_object_prevent_extensions (obj_p);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
/* 6. */
|
||||
uint32_t opts = ECMA_LIST_CONVERT_FAST_ARRAYS;
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
opts |= ECMA_LIST_SYMBOLS;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
if (is_seal)
|
||||
{
|
||||
/* 8.a */
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[i]);
|
||||
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||
|
||||
/* 8.a.i */
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&prop_desc);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
/* 8.a.ii */
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
ecma_collection_free (props_p);
|
||||
return define_own_prop_ret;
|
||||
}
|
||||
|
||||
ecma_free_value (define_own_prop_ret);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 9.a */
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[i]);
|
||||
|
||||
/* 9.1 */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 9.2 */
|
||||
if ((prop_desc.flags & (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
|
||||
== (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
|
||||
{
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_WRITABLE;
|
||||
}
|
||||
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||
|
||||
/* 9.3 */
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&prop_desc);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
/* 9.4 */
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
ecma_collection_free (props_p);
|
||||
return define_own_prop_ret;
|
||||
}
|
||||
|
||||
ecma_free_value (define_own_prop_ret);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
return ECMA_VALUE_TRUE;
|
||||
} /* ecma_builtin_object_set_integrity_level */
|
||||
|
||||
/**
|
||||
* The Object object's 'seal' routine
|
||||
*
|
||||
@@ -306,46 +480,19 @@ ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**<
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||
ecma_value_t status = ecma_builtin_object_set_integrity_level (obj_p, true);
|
||||
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
/* 2.a */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
if (!ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 2.b */
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||
|
||||
/* 2.c */
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&prop_desc);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
ecma_collection_free (props_p);
|
||||
return define_own_prop_ret;
|
||||
}
|
||||
|
||||
ecma_free_value (define_own_prop_ret);
|
||||
return status;
|
||||
}
|
||||
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
/* 3. */
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Object cannot be sealed."));
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
/* 4. */
|
||||
ecma_ref_object (obj_p);
|
||||
@@ -364,53 +511,19 @@ ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument *
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||
ecma_value_t status = ecma_builtin_object_set_integrity_level (obj_p, false);
|
||||
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
/* 2.a */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
if (!ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 2.b */
|
||||
if ((prop_desc.flags & (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
|
||||
== (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
|
||||
{
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_WRITABLE;
|
||||
}
|
||||
|
||||
/* 2.c */
|
||||
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||
|
||||
/* 2.d */
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&prop_desc);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
ecma_collection_free (props_p);
|
||||
return define_own_prop_ret;
|
||||
}
|
||||
|
||||
ecma_free_value (define_own_prop_ret);
|
||||
return status;
|
||||
}
|
||||
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
/* 3. */
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Object cannot be frozen."));
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
/* 4. */
|
||||
ecma_ref_object (obj_p);
|
||||
@@ -429,7 +542,30 @@ ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument
|
||||
ecma_value_t
|
||||
ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_value_t status = ecma_proxy_object_prevent_extensions (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot set [[Extensible]] property of the object."));
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (status));
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
ecma_op_ordinary_object_prevent_extensions (obj_p);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
ecma_ref_object (obj_p);
|
||||
|
||||
return ecma_make_object_value (obj_p);
|
||||
@@ -446,13 +582,34 @@ ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routin
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine's argument */
|
||||
int mode) /**< routine mode */
|
||||
ecma_builtin_object_test_integrity_level (ecma_object_t *obj_p, /**< routine's argument */
|
||||
int mode) /**< routine mode */
|
||||
{
|
||||
JERRY_ASSERT (mode == ECMA_OBJECT_ROUTINE_IS_FROZEN || mode == ECMA_OBJECT_ROUTINE_IS_SEALED);
|
||||
|
||||
/* 3. */
|
||||
if (ecma_get_object_extensible (obj_p))
|
||||
bool is_extensible;
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_value_t status = ecma_proxy_object_is_extensible (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
is_extensible = ecma_is_value_true (status);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
is_extensible = ecma_op_ordinary_object_is_extensible (obj_p);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (is_extensible)
|
||||
{
|
||||
return ECMA_VALUE_FALSE;
|
||||
}
|
||||
@@ -463,6 +620,13 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
||||
/* 2. */
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
@@ -470,22 +634,32 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
/* 2.a */
|
||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
||||
property_name_p,
|
||||
NULL,
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc);
|
||||
|
||||
/* 2.b for isFrozen */
|
||||
if (mode == ECMA_OBJECT_ROUTINE_IS_FROZEN
|
||||
&& ECMA_PROPERTY_GET_TYPE (property) != ECMA_PROPERTY_TYPE_NAMEDACCESSOR
|
||||
&& ecma_is_property_writable (property))
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
ret_value = ECMA_VALUE_FALSE;
|
||||
ret_value = status;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_false (status))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_writable_data = ((prop_desc.flags & (ECMA_PROP_IS_VALUE_DEFINED | ECMA_PROP_IS_WRITABLE))
|
||||
== (ECMA_PROP_IS_VALUE_DEFINED | ECMA_PROP_IS_WRITABLE));
|
||||
bool is_configurable = (prop_desc.flags & ECMA_PROP_IS_CONFIGURABLE);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
/* 2.b for isFrozen */
|
||||
/* 2.b for isSealed, 2.c for isFrozen */
|
||||
if (ecma_is_property_configurable (property))
|
||||
if ((mode == ECMA_OBJECT_ROUTINE_IS_FROZEN && is_writable_data)
|
||||
|| is_configurable)
|
||||
{
|
||||
ret_value = ECMA_VALUE_FALSE;
|
||||
break;
|
||||
@@ -495,7 +669,7 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_frozen_or_sealed_helper */
|
||||
} /* ecma_builtin_object_test_integrity_level */
|
||||
|
||||
/**
|
||||
* The Object object's 'isExtensible' routine
|
||||
@@ -509,7 +683,14 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
||||
ecma_value_t
|
||||
ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
return ecma_make_boolean_value (ecma_get_object_extensible (obj_p));
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
return ecma_proxy_object_is_extensible (obj_p);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
return ecma_make_boolean_value (ecma_op_ordinary_object_is_extensible (obj_p));
|
||||
} /* ecma_builtin_object_object_is_extensible */
|
||||
|
||||
/**
|
||||
@@ -543,7 +724,16 @@ ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, /*
|
||||
/* 3. */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
if (ecma_op_object_get_own_property_descriptor (obj_p, name_str_p, &prop_desc))
|
||||
ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, name_str_p, &prop_desc);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_true (status))
|
||||
{
|
||||
/* 4. */
|
||||
ecma_object_t *desc_obj_p = ecma_op_from_property_descriptor (&prop_desc);
|
||||
@@ -583,6 +773,14 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
||||
| ECMA_LIST_ENUMERABLE);
|
||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (prop_names_p == NULL)
|
||||
{
|
||||
ecma_deref_object (props_p);
|
||||
return ret_value;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t *buffer_p = prop_names_p->buffer_p;
|
||||
|
||||
/* 4. */
|
||||
@@ -783,6 +981,13 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object *
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||
| ECMA_LIST_ENUMERABLE
|
||||
| ECMA_LIST_SYMBOLS);
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
{
|
||||
ecma_deref_object (from_obj_p);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
@@ -792,8 +997,17 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object *
|
||||
|
||||
/* 5.c.i-ii */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t desc_status = ecma_op_object_get_own_property_descriptor (from_obj_p, property_name_p, &prop_desc);
|
||||
|
||||
if (!ecma_op_object_get_own_property_descriptor (from_obj_p, property_name_p, &prop_desc))
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (desc_status))
|
||||
{
|
||||
ret_value = desc_status;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
if (ecma_is_value_false (desc_status))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1056,8 +1270,7 @@ ecma_builtin_object_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
|
||||
case ECMA_OBJECT_ROUTINE_IS_SEALED:
|
||||
case ECMA_OBJECT_ROUTINE_IS_FROZEN:
|
||||
{
|
||||
return ecma_builtin_object_frozen_or_sealed_helper (obj_p,
|
||||
builtin_routine_id);
|
||||
return ecma_builtin_object_test_integrity_level (obj_p, builtin_routine_id);
|
||||
}
|
||||
case ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE:
|
||||
{
|
||||
|
||||
@@ -19,6 +19,10 @@ ecma_value_t ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p);
|
||||
|
||||
ecma_value_t ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1,
|
||||
ecma_value_t arg2);
|
||||
|
||||
ecma_value_t ecma_builtin_object_object_set_proto (ecma_value_t arg1,
|
||||
ecma_value_t arg2);
|
||||
|
||||
ecma_value_t ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p);
|
||||
|
||||
ecma_value_t ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p);
|
||||
|
||||
@@ -22,10 +22,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.2.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -35,6 +34,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_OBJECT_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF, 1, 1)
|
||||
|
||||
@@ -24,10 +24,6 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_PROMISE,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FLAG_WRITABLE)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* ECMA-262 v6, 25.4.5.4 */
|
||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||
|
||||
@@ -553,7 +553,7 @@ ecma_builtin_promise_race_or_all (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ret))
|
||||
{
|
||||
if (is_done)
|
||||
if (!is_done)
|
||||
{
|
||||
ret = ecma_op_iterator_close (iterator);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -35,6 +35,10 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_PROMISE_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_PROMISE_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_REJECT, ecma_builtin_promise_reject, 1, 1)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/* 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-proxy-object.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-proxy.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID proxy
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup proxy ECMA Proxy object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Proxy object's 'revocable' routine
|
||||
*
|
||||
* See also:
|
||||
* ES2015 26.2.2.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_proxy_object_revocable (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t target, /**< target argument */
|
||||
ecma_value_t handler) /**< handler argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
|
||||
ecma_object_t *rev_proxy_p = ecma_proxy_create_revocable (target, handler);
|
||||
|
||||
if (JERRY_UNLIKELY (rev_proxy_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
return ecma_make_object_value (rev_proxy_p);
|
||||
} /* ecma_builtin_proxy_object_revocable */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Proxy object
|
||||
*
|
||||
* See also:
|
||||
* ES2015 26.2.2
|
||||
*
|
||||
* @return raised error
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_proxy_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);
|
||||
|
||||
/* 1. */
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor Proxy requires 'new'"));
|
||||
} /* ecma_builtin_proxy_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in proxy object
|
||||
*
|
||||
* See also:
|
||||
* ES2015 26.2.2
|
||||
*
|
||||
* @return ECMA_VALUE_ERROR - if the operation fails
|
||||
* new proxy object - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_proxy_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);
|
||||
|
||||
/* 2. */
|
||||
ecma_object_t *proxy_p = ecma_proxy_create (arguments_list_len > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED,
|
||||
arguments_list_len > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED);
|
||||
|
||||
if (JERRY_UNLIKELY (proxy_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
return ecma_make_object_value (proxy_p);
|
||||
} /* ecma_builtin_proxy_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
@@ -0,0 +1,42 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Proxy object built-in description
|
||||
*/
|
||||
|
||||
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
2,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_PROXY_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_REVOCABLE, ecma_builtin_proxy_object_revocable, 2, 2)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -37,6 +36,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_RANGE_ERROR_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -37,6 +36,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -13,12 +13,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-builtin-function-prototype.h"
|
||||
#include "ecma-iterator-object.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-builtin-object.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-proxy-object.h"
|
||||
#include "jcontext.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT)
|
||||
@@ -37,13 +41,19 @@
|
||||
enum
|
||||
{
|
||||
ECMA_REFLECT_OBJECT_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1,
|
||||
ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF_UL, /* ECMA-262 v6, 26.1.8 */
|
||||
ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF_UL, /* ECMA-262 v6, 26.1.14 */
|
||||
ECMA_REFLECT_OBJECT_GET, /* ECMA-262 v6, 26.1.6 */
|
||||
ECMA_REFLECT_OBJECT_SET, /* ECMA-262 v6, 26.1.13 */
|
||||
ECMA_REFLECT_OBJECT_HAS, /* ECMA-262 v6, 26.1.9 */
|
||||
ECMA_REFLECT_OBJECT_DELETE_PROPERTY, /* ECMA-262 v6, 26.1.4 */
|
||||
ECMA_REFLECT_OBJECT_CONSTRUCT, /* ECMA-262, 26.1.2 */
|
||||
ECMA_REFLECT_OBJECT_OWN_KEYS, /* ECMA-262 v6, 26.1.11 */
|
||||
ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF, /* ECMA-262 v6, 26.1.8 */
|
||||
ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF, /* ECMA-262 v6, 26.1.14 */
|
||||
ECMA_REFLECT_OBJECT_APPLY, /* ECMA-262 v6, 26.1.1 */
|
||||
ECMA_REFLECT_OBJECT_DEFINE_PROPERTY, /* ECMA-262 v6, 26.1.3 */
|
||||
ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_UL, /* ECMA-262 v5, 26.1.7 */
|
||||
ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR, /* ECMA-262 v6, 26.1.7 */
|
||||
ECMA_REFLECT_OBJECT_IS_EXTENSIBLE, /* ECMA-262 v6, 26.1.10 */
|
||||
ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS_UL, /* ECMA-262 v6, 26.1.12 */
|
||||
ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS, /* ECMA-262 v6, 26.1.12 */
|
||||
};
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-reflect.inc.h"
|
||||
@@ -77,6 +87,134 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
|
||||
JERRY_UNUSED (this_arg);
|
||||
JERRY_UNUSED (arguments_number);
|
||||
|
||||
if (builtin_routine_id < ECMA_REFLECT_OBJECT_CONSTRUCT)
|
||||
{
|
||||
/* 1. */
|
||||
if (arguments_number == 0 || !ecma_is_value_object (arguments_list[0]))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an Object."));
|
||||
}
|
||||
|
||||
/* 2. */
|
||||
ecma_string_t *name_str_p = ecma_op_to_prop_name (((arguments_number > 1) ? arguments_list[1]
|
||||
: ECMA_VALUE_UNDEFINED));
|
||||
|
||||
/* 3. */
|
||||
if (name_str_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t ret_value;
|
||||
ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]);
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
case ECMA_REFLECT_OBJECT_GET:
|
||||
{
|
||||
ecma_value_t receiver = arguments_list[0];
|
||||
|
||||
/* 4. */
|
||||
if (arguments_number > 2)
|
||||
{
|
||||
receiver = arguments_list[2];
|
||||
}
|
||||
|
||||
ret_value = ecma_op_object_get_with_receiver (target_p, name_str_p, receiver);
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_REFLECT_OBJECT_HAS:
|
||||
{
|
||||
ret_value = ecma_op_object_has_property (target_p, name_str_p);
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_REFLECT_OBJECT_DELETE_PROPERTY:
|
||||
{
|
||||
ret_value = ecma_op_object_delete (target_p, name_str_p, false);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (builtin_routine_id == ECMA_REFLECT_OBJECT_SET);
|
||||
|
||||
ecma_value_t receiver = arguments_list[0];
|
||||
|
||||
if (arguments_number > 3)
|
||||
{
|
||||
receiver = arguments_list[3];
|
||||
}
|
||||
|
||||
ret_value = ecma_op_object_put_with_receiver (target_p, name_str_p, arguments_list[2], receiver, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (name_str_p);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
if (builtin_routine_id == ECMA_REFLECT_OBJECT_OWN_KEYS)
|
||||
{
|
||||
/* 1. */
|
||||
if (arguments_number == 0 || !ecma_is_value_object (arguments_list[0]))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an Object."));
|
||||
}
|
||||
|
||||
ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]);
|
||||
|
||||
/* 2. 3. */
|
||||
return ecma_builtin_helper_object_get_properties (target_p, ECMA_LIST_SYMBOLS);
|
||||
}
|
||||
|
||||
if (builtin_routine_id == ECMA_REFLECT_OBJECT_CONSTRUCT)
|
||||
{
|
||||
/* 1. */
|
||||
if (arguments_number < 1 || !ecma_is_constructor (arguments_list[0]))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Target is not a constructor"));
|
||||
}
|
||||
|
||||
ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]);
|
||||
|
||||
/* 2. */
|
||||
ecma_object_t *new_target_p = target_p;
|
||||
|
||||
if (arguments_number > 2)
|
||||
{
|
||||
/* 3. */
|
||||
if (!ecma_is_constructor (arguments_list[2]))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Target is not a constructor"));
|
||||
}
|
||||
|
||||
new_target_p = ecma_get_object_from_value (arguments_list[2]);
|
||||
}
|
||||
|
||||
/* 4. */
|
||||
if (arguments_number < 2)
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Reflect.construct requires the second argument be an object"));
|
||||
}
|
||||
|
||||
ecma_collection_t *coll_p = ecma_op_create_list_from_array_like (arguments_list[1], false);
|
||||
|
||||
if (coll_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t ret_value = ecma_op_function_construct (target_p,
|
||||
new_target_p,
|
||||
coll_p->buffer_p,
|
||||
coll_p->item_count);
|
||||
|
||||
ecma_collection_free (coll_p);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
if (!ecma_is_value_object (arguments_list[0]))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an Object."));
|
||||
@@ -84,25 +222,32 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
case ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF_UL:
|
||||
case ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF:
|
||||
{
|
||||
return ecma_builtin_object_object_get_prototype_of (ecma_get_object_from_value (arguments_list[0]));
|
||||
}
|
||||
case ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF_UL:
|
||||
case ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF:
|
||||
{
|
||||
ecma_value_t result = ecma_builtin_object_object_set_prototype_of (arguments_list[0], arguments_list[1]);
|
||||
bool is_error = ECMA_IS_VALUE_ERROR (result);
|
||||
|
||||
if (is_error)
|
||||
if (!ecma_is_value_object (arguments_list[1]) && !ecma_is_value_null (arguments_list[1]))
|
||||
{
|
||||
jcontext_release_exception ();
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("proto is neither Object nor Null."));
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]);
|
||||
ecma_value_t status;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
status = ecma_proxy_object_set_prototype_of (obj_p, arguments_list[1]);
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
{
|
||||
ecma_free_value (result);
|
||||
status = ecma_op_ordinary_object_set_prototype_of (obj_p, arguments_list[1]);
|
||||
}
|
||||
|
||||
return ecma_make_boolean_value (!is_error);
|
||||
return status;
|
||||
}
|
||||
case ECMA_REFLECT_OBJECT_APPLY:
|
||||
{
|
||||
@@ -124,22 +269,32 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t result = ecma_builtin_object_object_define_property (obj_p, name_str_p, arguments_list[2]);
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t conv_result = ecma_op_to_property_descriptor (arguments_list[2], &prop_desc);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (conv_result))
|
||||
{
|
||||
ecma_deref_ecma_string (name_str_p);
|
||||
return conv_result;
|
||||
}
|
||||
|
||||
ecma_value_t result = ecma_op_object_define_own_property (obj_p,
|
||||
name_str_p,
|
||||
&prop_desc);
|
||||
|
||||
ecma_deref_ecma_string (name_str_p);
|
||||
bool is_error = ECMA_IS_VALUE_ERROR (result);
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
if (is_error)
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_free_value (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ecma_make_boolean_value (!is_error);
|
||||
bool boolean_result = ecma_op_to_boolean (result);
|
||||
|
||||
return ecma_make_boolean_value (boolean_result);
|
||||
}
|
||||
case ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_UL:
|
||||
case ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR:
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]);
|
||||
ecma_string_t *name_str_p = ecma_op_to_prop_name (arguments_list[1]);
|
||||
@@ -160,9 +315,19 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (builtin_routine_id == ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS_UL);
|
||||
JERRY_ASSERT (builtin_routine_id == ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS);
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]);
|
||||
return ecma_builtin_object_object_prevent_extensions (obj_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
return ecma_proxy_object_prevent_extensions (obj_p);
|
||||
}
|
||||
#endif /* !ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
ecma_op_ordinary_object_prevent_extensions (obj_p);
|
||||
|
||||
return ECMA_VALUE_TRUE;
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_reflect_dispatch_routine */
|
||||
|
||||
@@ -21,11 +21,17 @@
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_APPLY, ECMA_REFLECT_OBJECT_APPLY, 3, 3)
|
||||
ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ECMA_REFLECT_OBJECT_DEFINE_PROPERTY, 3, 3)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_UL, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF_UL, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET, ECMA_REFLECT_OBJECT_GET, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET, ECMA_REFLECT_OBJECT_SET, NON_FIXED, 3)
|
||||
ROUTINE (LIT_MAGIC_STRING_HAS, ECMA_REFLECT_OBJECT_HAS, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_DELETE_PROPERTY_UL, ECMA_REFLECT_OBJECT_DELETE_PROPERTY, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_OWN_KEYS_UL, ECMA_REFLECT_OBJECT_OWN_KEYS, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_CONSTRUCT, ECMA_REFLECT_OBJECT_CONSTRUCT, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_EXTENSIBLE, ECMA_REFLECT_OBJECT_IS_EXTENSIBLE, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS_UL, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF_UL, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF, 2, 2)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_REFLECT) */
|
||||
|
||||
|
||||
@@ -62,18 +62,14 @@ ecma_builtin_regexp_prototype_flags_helper (ecma_value_t this, /**< this value *
|
||||
{
|
||||
if (!ecma_object_is_regexp_object (this))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object"));
|
||||
}
|
||||
|
||||
ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) ecma_get_object_from_value (this);
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t,
|
||||
re_obj_p->u.class_prop.u.value);
|
||||
|
||||
if (bc_p != NULL)
|
||||
{
|
||||
*flags_p = bc_p->header.status_flags;
|
||||
}
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
|
||||
re_obj_p->u.class_prop.u.value);
|
||||
|
||||
*flags_p = bc_p->header.status_flags;
|
||||
return ECMA_VALUE_EMPTY;
|
||||
} /* ecma_builtin_regexp_prototype_flags_helper */
|
||||
|
||||
@@ -137,6 +133,75 @@ ecma_builtin_regexp_prototype_get_flags (ecma_value_t this_arg) /**< this argume
|
||||
return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
|
||||
} /* ecma_builtin_regexp_prototype_get_flags */
|
||||
|
||||
/**
|
||||
* The EscapeRegExpPattern method.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 21.2.3.2.4
|
||||
*
|
||||
* @return ecma_value_t
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_op_escape_regexp_pattern (ecma_string_t *pattern_str_p) /**< RegExp pattern */
|
||||
{
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
|
||||
|
||||
ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start_p, pattern_start_size);
|
||||
|
||||
const lit_utf8_byte_t *pattern_str_curr_p = pattern_start_p;
|
||||
const lit_utf8_byte_t *pattern_str_end_p = pattern_start_p + pattern_start_size;
|
||||
|
||||
while (pattern_str_curr_p < pattern_str_end_p)
|
||||
{
|
||||
ecma_char_t c = lit_cesu8_read_next (&pattern_str_curr_p);
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case LIT_CHAR_SLASH:
|
||||
{
|
||||
ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\/", 2);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_LF:
|
||||
{
|
||||
ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\n", 2);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_CR:
|
||||
{
|
||||
ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\r", 2);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_LS:
|
||||
{
|
||||
ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\u2028", 6);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_PS:
|
||||
{
|
||||
ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\u2029", 6);
|
||||
break;
|
||||
}
|
||||
case LIT_CHAR_BACKSLASH:
|
||||
{
|
||||
JERRY_ASSERT (pattern_str_curr_p < pattern_str_end_p);
|
||||
ecma_stringbuilder_append_char (&builder, LIT_CHAR_BACKSLASH);
|
||||
ecma_stringbuilder_append_char (&builder, lit_cesu8_read_next (&pattern_str_curr_p));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ecma_stringbuilder_append_char (&builder, c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size);
|
||||
|
||||
return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
|
||||
} /* ecma_op_escape_regexp_pattern */
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'source' accessor property
|
||||
*
|
||||
@@ -153,20 +218,14 @@ ecma_builtin_regexp_prototype_get_source (ecma_value_t this_arg) /**< this argum
|
||||
{
|
||||
if (!ecma_object_is_regexp_object (this_arg))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object"));
|
||||
}
|
||||
|
||||
ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) ecma_get_object_from_value (this_arg);
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t,
|
||||
re_obj_p->u.class_prop.u.value);
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
|
||||
re_obj_p->u.class_prop.u.value);
|
||||
|
||||
if (bc_p != NULL)
|
||||
{
|
||||
ecma_ref_ecma_string (ecma_get_string_from_value (bc_p->source));
|
||||
return bc_p->source;
|
||||
}
|
||||
|
||||
return ecma_make_string_value (ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP));
|
||||
return ecma_op_escape_regexp_pattern (ecma_get_string_from_value (bc_p->source));
|
||||
} /* ecma_builtin_regexp_prototype_get_source */
|
||||
|
||||
/**
|
||||
@@ -314,95 +373,53 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
|
||||
ecma_value_t flags_arg) /**< flags */
|
||||
{
|
||||
if (!ecma_object_is_regexp_object (this_arg)
|
||||
/* The builtin RegExp.prototype object does not have [[RegExpMatcher]] internal slot */
|
||||
|| ecma_get_object_from_value (this_arg) == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE))
|
||||
#if !ENABLED (JERRY_ES2015)
|
||||
|| ecma_get_object_from_value (this_arg) == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)
|
||||
#endif /* !ENABLED (JERRY_ES2015) */
|
||||
)
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object"));
|
||||
}
|
||||
|
||||
uint16_t flags = 0;
|
||||
ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_extended_object_t *regexp_obj_p = (ecma_extended_object_t *) this_obj_p;
|
||||
re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
|
||||
regexp_obj_p->u.class_prop.u.value);
|
||||
|
||||
if (ecma_object_is_regexp_object (pattern_arg)
|
||||
&& ecma_get_object_from_value (pattern_arg) != ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE))
|
||||
ecma_value_t status = ecma_builtin_helper_def_prop (this_obj_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
|
||||
ecma_make_uint32_value (0),
|
||||
ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROP_IS_THROW);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (status));
|
||||
|
||||
if (ecma_object_is_regexp_object (pattern_arg))
|
||||
{
|
||||
if (!ecma_is_value_undefined (flags_arg))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument"));
|
||||
}
|
||||
|
||||
/* Compile from existing RegExp object. */
|
||||
ecma_extended_object_t *target_p = (ecma_extended_object_t *) ecma_get_object_from_value (pattern_arg);
|
||||
re_compiled_code_t *target_bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t,
|
||||
target_p->u.class_prop.u.value);
|
||||
ecma_extended_object_t *pattern_obj_p = (ecma_extended_object_t *) ecma_get_object_from_value (pattern_arg);
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
|
||||
pattern_obj_p->u.class_prop.u.value);
|
||||
|
||||
ecma_object_t *this_object_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_extended_object_t *current_p = (ecma_extended_object_t *) this_object_p;
|
||||
|
||||
re_compiled_code_t *current_bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t,
|
||||
current_p->u.class_prop.u.value);
|
||||
|
||||
JERRY_ASSERT (current_bc_p != NULL);
|
||||
ecma_bytecode_deref ((ecma_compiled_code_t *) current_bc_p);
|
||||
|
||||
JERRY_ASSERT (target_bc_p != NULL);
|
||||
ecma_bytecode_ref ((ecma_compiled_code_t *) target_bc_p);
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (current_p->u.class_prop.u.value, target_bc_p);
|
||||
ecma_regexp_initialize_props (this_object_p,
|
||||
ecma_get_string_from_value (target_bc_p->source),
|
||||
target_bc_p->header.status_flags);
|
||||
return ecma_copy_value (this_arg);
|
||||
ecma_ref_object (this_obj_p);
|
||||
/* ecma_op_create_regexp_from_bytecode will never throw an error while re-initalizing the regexp object, so we
|
||||
* can deref the old bytecode without leaving a dangling pointer. */
|
||||
ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
|
||||
return ecma_op_create_regexp_from_bytecode (this_obj_p, bc_p);
|
||||
}
|
||||
|
||||
ecma_string_t *pattern_string_p = ecma_regexp_read_pattern_str_helper (pattern_arg);
|
||||
ecma_value_t ret_value = ecma_op_create_regexp_from_pattern (this_obj_p, pattern_arg, flags_arg);
|
||||
|
||||
/* Get source string. */
|
||||
if (pattern_string_p == NULL)
|
||||
if (!ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
ecma_ref_object (this_obj_p);
|
||||
ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
|
||||
}
|
||||
|
||||
/* Parse flags. */
|
||||
if (!ecma_is_value_undefined (flags_arg))
|
||||
{
|
||||
ecma_string_t *flags_str_p = ecma_op_to_string (flags_arg);
|
||||
if (JERRY_UNLIKELY (flags_str_p == NULL))
|
||||
{
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t parsed_flags_val = ecma_regexp_parse_flags (flags_str_p, &flags);
|
||||
ecma_deref_ecma_string (flags_str_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (parsed_flags_val))
|
||||
{
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
return parsed_flags_val;
|
||||
}
|
||||
}
|
||||
|
||||
/* Try to compile bytecode from new source. */
|
||||
const re_compiled_code_t *new_bc_p = NULL;
|
||||
ecma_value_t bc_val = re_compile_bytecode (&new_bc_p, pattern_string_p, flags);
|
||||
if (ECMA_IS_VALUE_ERROR (bc_val))
|
||||
{
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
return bc_val;
|
||||
}
|
||||
|
||||
ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.u.value);
|
||||
|
||||
re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t, *bc_prop_p);
|
||||
|
||||
JERRY_ASSERT (old_bc_p != NULL);
|
||||
ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (*bc_prop_p, new_bc_p);
|
||||
ecma_regexp_initialize_props (this_obj_p, pattern_string_p, flags);
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
|
||||
return ecma_copy_value (this_arg);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_compile */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ANNEXB) */
|
||||
@@ -453,6 +470,7 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.10.6.3
|
||||
* ECMA-262 v6, 21.2.5.13
|
||||
*
|
||||
* @return true - if match is not null
|
||||
* false - otherwise
|
||||
@@ -463,12 +481,35 @@ static ecma_value_t
|
||||
ecma_builtin_regexp_prototype_test (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (!ecma_is_value_object (this_arg))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("'this' value is not an object"));
|
||||
}
|
||||
|
||||
ecma_string_t *arg_str_p = ecma_op_to_string (arg);
|
||||
|
||||
if (JERRY_UNLIKELY (arg_str_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t result = ecma_op_regexp_exec (this_arg, arg_str_p);
|
||||
|
||||
ecma_deref_ecma_string (arg_str_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
ecma_value_t result = ecma_builtin_regexp_prototype_exec (this_arg, arg);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_value_t ret_value = ecma_make_boolean_value (!ecma_is_value_null (result));
|
||||
ecma_free_value (result);
|
||||
@@ -545,22 +586,11 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t,
|
||||
re_obj_p->u.class_prop.u.value);
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
|
||||
re_obj_p->u.class_prop.u.value);
|
||||
|
||||
ecma_string_t *source_p;
|
||||
uint16_t flags;
|
||||
|
||||
if (bc_p != NULL)
|
||||
{
|
||||
source_p = ecma_get_string_from_value (bc_p->source);
|
||||
flags = bc_p->header.status_flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
source_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
flags = RE_FLAG_EMPTY;
|
||||
}
|
||||
ecma_string_t *source_p = ecma_get_string_from_value (bc_p->source);
|
||||
uint16_t flags = bc_p->header.status_flags;
|
||||
|
||||
ecma_stringbuilder_t result = ecma_stringbuilder_create ();
|
||||
ecma_stringbuilder_append_byte (&result, LIT_CHAR_SLASH);
|
||||
|
||||
@@ -29,31 +29,31 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_FLAGS,
|
||||
ecma_builtin_regexp_prototype_get_flags,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SOURCE,
|
||||
ecma_builtin_regexp_prototype_get_source,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_GLOBAL,
|
||||
ecma_builtin_regexp_prototype_get_global,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_IGNORECASE_UL,
|
||||
ecma_builtin_regexp_prototype_get_ignorecase,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_MULTILINE,
|
||||
ecma_builtin_regexp_prototype_get_multiline,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_UNICODE,
|
||||
ecma_builtin_regexp_prototype_get_unicode,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_STICKY,
|
||||
ecma_builtin_regexp_prototype_get_sticky,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
ROUTINE (LIT_GLOBAL_SYMBOL_REPLACE, ecma_builtin_regexp_prototype_symbol_replace, 2, 2)
|
||||
ROUTINE (LIT_GLOBAL_SYMBOL_SEARCH, ecma_builtin_regexp_prototype_symbol_search, 1, 1)
|
||||
@@ -79,12 +79,12 @@ SIMPLE_VALUE (LIT_MAGIC_STRING_IGNORECASE_UL,
|
||||
SIMPLE_VALUE (LIT_MAGIC_STRING_MULTILINE,
|
||||
ECMA_VALUE_FALSE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* ECMA-262 v5, 15.10.7.5 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LASTINDEX_UL,
|
||||
0,
|
||||
ECMA_PROPERTY_FLAG_WRITABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_ANNEXB)
|
||||
ROUTINE (LIT_MAGIC_STRING_COMPILE, ecma_builtin_regexp_prototype_compile, 2, 1)
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "jcontext.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-regexp-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
@@ -41,34 +43,18 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in RegExp object
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_regexp_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_regexp_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_regexp_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in RegExp object
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
static ecma_value_t
|
||||
ecma_builtin_regexp_dispatch_helper (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
ecma_value_t pattern_value = ECMA_VALUE_UNDEFINED;
|
||||
ecma_value_t flags_value = ECMA_VALUE_UNDEFINED;
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_value_t new_pattern = ECMA_VALUE_EMPTY;
|
||||
ecma_value_t new_flags = ECMA_VALUE_EMPTY;
|
||||
bool create_regexp_from_bc = false;
|
||||
bool free_arguments = false;
|
||||
ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
ecma_object_t *new_target_p = NULL;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if (arguments_list_len > 0)
|
||||
@@ -90,88 +76,147 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
||||
return regexp_value;
|
||||
}
|
||||
|
||||
bool is_regexp = regexp_value == ECMA_VALUE_TRUE;
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
bool is_regexp = ecma_object_is_regexp_object (pattern_value);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
bool pattern_is_regexp = regexp_value == ECMA_VALUE_TRUE;
|
||||
re_compiled_code_t *bc_p = NULL;
|
||||
|
||||
if (is_regexp)
|
||||
if (new_target_p == NULL)
|
||||
{
|
||||
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP);
|
||||
|
||||
if (pattern_is_regexp && ecma_is_value_undefined (flags_value))
|
||||
{
|
||||
ecma_object_t *pattern_obj_p = ecma_get_object_from_value (pattern_value);
|
||||
|
||||
ecma_value_t pattern_constructor = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_CONSTRUCTOR);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (pattern_constructor))
|
||||
{
|
||||
return pattern_constructor;
|
||||
}
|
||||
|
||||
bool is_same = ecma_op_same_value (ecma_make_object_value (new_target_p), pattern_constructor);
|
||||
ecma_free_value (pattern_constructor);
|
||||
|
||||
if (is_same)
|
||||
{
|
||||
return ecma_copy_value (pattern_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ecma_object_is_regexp_object (pattern_value))
|
||||
{
|
||||
ecma_extended_object_t *pattern_obj_p = (ecma_extended_object_t *) ecma_get_object_from_value (pattern_value);
|
||||
bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
|
||||
pattern_obj_p->u.class_prop.u.value);
|
||||
|
||||
create_regexp_from_bc = ecma_is_value_undefined (flags_value);
|
||||
|
||||
if (!create_regexp_from_bc)
|
||||
{
|
||||
pattern_value = bc_p->source;
|
||||
}
|
||||
}
|
||||
else if (pattern_is_regexp)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_object_t *pattern_obj_p = ecma_get_object_from_value (pattern_value);
|
||||
|
||||
new_pattern = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_SOURCE);
|
||||
pattern_value = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_SOURCE);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (new_pattern))
|
||||
if (ECMA_IS_VALUE_ERROR (pattern_value))
|
||||
{
|
||||
return new_pattern;
|
||||
return pattern_value;
|
||||
}
|
||||
|
||||
pattern_value = new_pattern;
|
||||
|
||||
if (ecma_is_value_undefined (flags_value))
|
||||
{
|
||||
new_flags = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_FLAGS);
|
||||
flags_value = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_FLAGS);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (new_flags))
|
||||
if (ECMA_IS_VALUE_ERROR (flags_value))
|
||||
{
|
||||
ecma_free_value (new_pattern);
|
||||
return new_flags;
|
||||
ecma_free_value (pattern_value);
|
||||
return flags_value;
|
||||
}
|
||||
|
||||
flags_value = new_flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags_value = ecma_copy_value (flags_value);
|
||||
}
|
||||
|
||||
free_arguments = true;
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
if (ecma_object_is_regexp_object (pattern_value))
|
||||
{
|
||||
if (ecma_is_value_undefined (flags_value))
|
||||
{
|
||||
return ecma_copy_value (pattern_value);
|
||||
}
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument of RegExp call."));
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
}
|
||||
|
||||
ecma_string_t *pattern_string_p = ecma_regexp_read_pattern_str_helper (pattern_value);
|
||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||
ecma_object_t *new_target_obj_p = ecma_op_regexp_alloc (new_target_p);
|
||||
|
||||
if (pattern_string_p == NULL)
|
||||
if (JERRY_LIKELY (new_target_obj_p != NULL))
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
uint16_t flags = 0;
|
||||
|
||||
if (!ecma_is_value_undefined (flags_value))
|
||||
{
|
||||
ecma_string_t *flags_string_p = ecma_op_to_string (flags_value);
|
||||
|
||||
if (JERRY_UNLIKELY (flags_string_p == NULL))
|
||||
{
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret_value = ecma_regexp_parse_flags (flags_string_p, &flags);
|
||||
ecma_deref_ecma_string (flags_string_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
goto cleanup;
|
||||
}
|
||||
JERRY_ASSERT (ecma_is_value_empty (ret_value));
|
||||
}
|
||||
|
||||
ret_value = ecma_op_create_regexp_object (pattern_string_p, flags);
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
|
||||
cleanup:
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_free_value (new_pattern);
|
||||
ecma_free_value (new_flags);
|
||||
if (create_regexp_from_bc)
|
||||
{
|
||||
ret_value = ecma_op_create_regexp_from_bytecode (new_target_obj_p, bc_p);
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (ret_value));
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
{
|
||||
ret_value = ecma_op_create_regexp_from_pattern (new_target_obj_p, pattern_value, flags_value);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
ecma_deref_object (new_target_obj_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (free_arguments)
|
||||
{
|
||||
ecma_free_value (pattern_value);
|
||||
ecma_free_value (flags_value);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_dispatch_helper */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in RegExp object
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_regexp_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_regexp_dispatch_helper (arguments_list_p,
|
||||
arguments_list_len);
|
||||
} /* ecma_builtin_regexp_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in RegExp object
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_regexp_dispatch_helper (arguments_list_p,
|
||||
arguments_list_len);
|
||||
} /* ecma_builtin_regexp_dispatch_construct */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
|
||||
@@ -21,10 +21,9 @@
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
|
||||
/* ECMA-262 v5, 15.10.5 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
2,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* ECMA-262 v5, 15.10.5.1 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
@@ -32,6 +31,10 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_REGEXP_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ECMA-262 v6, 21.2.4.2 */
|
||||
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
|
||||
ecma_builtin_regexp_species_get,
|
||||
|
||||
@@ -52,7 +52,7 @@ ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ecma_builtin_set_prototype_object_values, 0
|
||||
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE,
|
||||
ecma_builtin_set_prototype_object_size_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/* ECMA-262 v6, 23.2.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ECMA-262 v6, 23.1 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
|
||||
@@ -208,9 +208,8 @@ ecma_builtin_string_prototype_object_concat (ecma_string_t *this_string_p, /**<
|
||||
const ecma_value_t *argument_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
ecma_ref_ecma_string (this_string_p);
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (this_string_p);
|
||||
|
||||
ecma_string_t *string_to_return = this_string_p;
|
||||
/* 5 */
|
||||
for (uint32_t arg_index = 0; arg_index < arguments_number; ++arg_index)
|
||||
{
|
||||
@@ -219,17 +218,17 @@ ecma_builtin_string_prototype_object_concat (ecma_string_t *this_string_p, /**<
|
||||
|
||||
if (JERRY_UNLIKELY (get_arg_string_p == NULL))
|
||||
{
|
||||
ecma_deref_ecma_string (string_to_return);
|
||||
ecma_stringbuilder_destroy (&builder);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
string_to_return = ecma_concat_ecma_strings (string_to_return, get_arg_string_p);
|
||||
ecma_stringbuilder_append (&builder, get_arg_string_p);
|
||||
|
||||
ecma_deref_ecma_string (get_arg_string_p);
|
||||
}
|
||||
|
||||
/* 6 */
|
||||
return ecma_make_string_value (string_to_return);
|
||||
return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
|
||||
} /* ecma_builtin_string_prototype_object_concat */
|
||||
|
||||
/**
|
||||
@@ -284,93 +283,98 @@ ecma_builtin_string_prototype_object_locale_compare (ecma_string_t *this_string_
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_string_prototype_object_match (ecma_value_t this_to_string_value, /**< this argument */
|
||||
ecma_builtin_string_prototype_object_match (ecma_value_t this_argument, /**< this argument */
|
||||
ecma_value_t regexp_arg) /**< routine's argument */
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* 3. */
|
||||
if (!(ecma_is_value_undefined (regexp_arg) || ecma_is_value_null (regexp_arg)))
|
||||
{
|
||||
/* 3.a */
|
||||
ecma_value_t matcher = ecma_op_get_method_by_symbol_id (regexp_arg, LIT_GLOBAL_SYMBOL_MATCH);
|
||||
|
||||
/* 3.b */
|
||||
if (ECMA_IS_VALUE_ERROR (matcher))
|
||||
{
|
||||
return matcher;
|
||||
}
|
||||
|
||||
/* 3.c */
|
||||
if (!ecma_is_value_undefined (matcher))
|
||||
{
|
||||
/* 3.c.i */
|
||||
ecma_object_t *matcher_method = ecma_get_object_from_value (matcher);
|
||||
ecma_value_t result = ecma_op_function_call (matcher_method, regexp_arg, &this_to_string_value, 1);
|
||||
ecma_value_t result = ecma_op_function_call (matcher_method, regexp_arg, &this_argument, 1);
|
||||
ecma_deref_object (matcher_method);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/* 4. */
|
||||
ecma_string_t *this_str_p = ecma_op_to_string (this_argument);
|
||||
|
||||
/* 5. */
|
||||
if (JERRY_UNLIKELY (this_str_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
ecma_object_t *regexp_obj_p = ecma_op_regexp_alloc (NULL);
|
||||
|
||||
if (JERRY_UNLIKELY (regexp_obj_p == NULL))
|
||||
{
|
||||
ecma_deref_ecma_string (this_str_p);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t new_regexp = ecma_op_create_regexp_from_pattern (regexp_obj_p, regexp_arg, ECMA_VALUE_UNDEFINED);
|
||||
|
||||
/* 7. */
|
||||
if (ECMA_IS_VALUE_ERROR (new_regexp))
|
||||
{
|
||||
|
||||
ecma_deref_object (regexp_obj_p);
|
||||
ecma_deref_ecma_string (this_str_p);
|
||||
return new_regexp;
|
||||
}
|
||||
ecma_value_t this_str_value = ecma_make_string_value (this_str_p);
|
||||
|
||||
/* 8. */
|
||||
ecma_value_t ret_value = ecma_op_invoke_by_symbol_id (new_regexp, LIT_GLOBAL_SYMBOL_MATCH, &this_str_value, 1);
|
||||
|
||||
ecma_deref_ecma_string (this_str_p);
|
||||
ecma_free_value (new_regexp);
|
||||
|
||||
return ret_value;
|
||||
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
if (ecma_object_is_regexp_object (regexp_arg))
|
||||
{
|
||||
return ecma_regexp_match_helper (regexp_arg, this_to_string_value);
|
||||
return ecma_regexp_match_helper (regexp_arg, this_argument);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_string_t *pattern_p = ecma_regexp_read_pattern_str_helper (regexp_arg);
|
||||
ecma_object_t *regexp_obj_p = ecma_op_regexp_alloc (NULL);
|
||||
|
||||
if (JERRY_UNLIKELY (pattern_p == NULL))
|
||||
if (JERRY_UNLIKELY (regexp_obj_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t new_regexp = ecma_op_create_regexp_object (pattern_p, 0);
|
||||
|
||||
ecma_deref_ecma_string (pattern_p);
|
||||
ecma_value_t new_regexp = ecma_op_create_regexp_from_pattern (regexp_obj_p, regexp_arg, ECMA_VALUE_UNDEFINED);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (new_regexp))
|
||||
{
|
||||
ecma_deref_object (regexp_obj_p);
|
||||
return new_regexp;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_object_t *new_regexp_obj = ecma_get_object_from_value (new_regexp);
|
||||
|
||||
ecma_value_t func_value = ecma_op_object_get_by_symbol_id (new_regexp_obj, LIT_GLOBAL_SYMBOL_MATCH);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (func_value) || !ecma_op_is_callable (func_value))
|
||||
{
|
||||
ecma_deref_object (new_regexp_obj);
|
||||
|
||||
if (!ECMA_IS_VALUE_ERROR (func_value))
|
||||
{
|
||||
ecma_free_value (func_value);
|
||||
ecma_raise_type_error (ECMA_ERR_MSG ("@@match is not callable."));
|
||||
}
|
||||
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_object_t *func_obj = ecma_get_object_from_value (func_value);
|
||||
|
||||
ecma_string_t *str_p = ecma_op_to_string (this_to_string_value);
|
||||
|
||||
if (JERRY_UNLIKELY (str_p == NULL))
|
||||
{
|
||||
ecma_deref_object (new_regexp_obj);
|
||||
ecma_deref_object (func_obj);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t str_value = ecma_make_string_value (str_p);
|
||||
|
||||
ecma_value_t result = ecma_op_function_call (func_obj, new_regexp, &str_value, 1);
|
||||
|
||||
ecma_deref_ecma_string (str_p);
|
||||
ecma_deref_object (new_regexp_obj);
|
||||
ecma_deref_object (func_obj);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
ecma_value_t result = ecma_regexp_match_helper (new_regexp, this_to_string_value);
|
||||
ecma_value_t result = ecma_regexp_match_helper (new_regexp, this_argument);
|
||||
|
||||
ecma_free_value (new_regexp);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
return result;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
} /* ecma_builtin_string_prototype_object_match */
|
||||
|
||||
/**
|
||||
@@ -478,9 +482,8 @@ ecma_builtin_string_prototype_object_replace (ecma_value_t this_value, /**< this
|
||||
{
|
||||
if (!memcmp (curr_p, search_buf_p, search_size))
|
||||
{
|
||||
replace_ctx.builder = ecma_stringbuilder_create ();
|
||||
const lit_utf8_size_t byte_offset = (lit_utf8_size_t) (curr_p - replace_ctx.string_p);
|
||||
ecma_stringbuilder_append_raw (&replace_ctx.builder, replace_ctx.string_p, byte_offset);
|
||||
replace_ctx.builder = ecma_stringbuilder_create_raw (replace_ctx.string_p, byte_offset);
|
||||
|
||||
if (replace_ctx.replace_str_p == NULL)
|
||||
{
|
||||
@@ -626,10 +629,24 @@ ecma_builtin_string_prototype_object_search (ecma_value_t this_value, /**< this
|
||||
goto cleanup_string;
|
||||
}
|
||||
|
||||
ecma_value_t new_regexp = ecma_op_create_regexp_object (pattern_p, 0);
|
||||
ecma_object_t *new_regexp_obj_p = ecma_op_regexp_alloc (NULL);
|
||||
|
||||
if (JERRY_UNLIKELY (new_regexp_obj_p == NULL))
|
||||
{
|
||||
ecma_deref_ecma_string (string_p);
|
||||
ecma_deref_ecma_string (pattern_p);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
ecma_value_t new_regexp = ecma_op_create_regexp_from_pattern (new_regexp_obj_p,
|
||||
ecma_make_string_value (pattern_p),
|
||||
ECMA_VALUE_UNDEFINED);
|
||||
|
||||
ecma_deref_ecma_string (pattern_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (new_regexp))
|
||||
{
|
||||
ecma_deref_object (new_regexp_obj_p);
|
||||
goto cleanup_string;
|
||||
}
|
||||
|
||||
@@ -1325,6 +1342,13 @@ ecma_builtin_string_prototype_dispatch_routine (uint16_t builtin_routine_id, /**
|
||||
ecma_value_t arg1 = arguments_list_p[0];
|
||||
ecma_value_t arg2 = arguments_list_p[1];
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
if (builtin_routine_id == ECMA_STRING_PROTOTYPE_MATCH)
|
||||
{
|
||||
return ecma_builtin_string_prototype_object_match (this_arg, arg1);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
|
||||
if (builtin_routine_id <= ECMA_STRING_PROTOTYPE_CHAR_CODE_AT)
|
||||
{
|
||||
return ecma_builtin_string_prototype_char_at_helper (this_arg,
|
||||
@@ -1373,11 +1397,6 @@ ecma_builtin_string_prototype_dispatch_routine (uint16_t builtin_routine_id, /**
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
case ECMA_STRING_PROTOTYPE_MATCH:
|
||||
{
|
||||
ret_value = ecma_builtin_string_prototype_object_match (to_string_val, arg1);
|
||||
break;
|
||||
}
|
||||
case ECMA_STRING_PROTOTYPE_REPLACE:
|
||||
{
|
||||
ret_value = ecma_builtin_string_prototype_object_replace (to_string_val, arg1, arg2);
|
||||
|
||||
@@ -235,6 +235,7 @@ ecma_builtin_string_object_raw (ecma_value_t this_arg, /**< 'this' argument */
|
||||
/* 12.f-g */
|
||||
if (next_index >= number_of_substitutions)
|
||||
{
|
||||
next_index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.5.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -37,6 +36,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_STRING_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, ecma_builtin_string_object_from_char_code, NON_FIXED, 1)
|
||||
|
||||
@@ -28,10 +28,6 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_SYMBOL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FLAG_WRITABLE)
|
||||
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_symbol_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_symbol_prototype_object_value_of, 0, 0)
|
||||
ROUTINE_CONFIGURABLE_ONLY (LIT_GLOBAL_SYMBOL_TO_PRIMITIVE,
|
||||
|
||||
@@ -27,7 +27,11 @@
|
||||
/* ECMA-262 v6, 19.4.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_STRING_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -39,47 +43,58 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.2 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_HAS_INSTANCE,
|
||||
LIT_GLOBAL_SYMBOL_HAS_INSTANCE)
|
||||
LIT_GLOBAL_SYMBOL_HAS_INSTANCE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.3 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE,
|
||||
LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE)
|
||||
LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.4 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_ITERATOR,
|
||||
LIT_GLOBAL_SYMBOL_ITERATOR)
|
||||
LIT_GLOBAL_SYMBOL_ITERATOR,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.6 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_MATCH,
|
||||
LIT_GLOBAL_SYMBOL_MATCH)
|
||||
LIT_GLOBAL_SYMBOL_MATCH,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.8 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_REPLACE,
|
||||
LIT_GLOBAL_SYMBOL_REPLACE)
|
||||
LIT_GLOBAL_SYMBOL_REPLACE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.9 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_SEARCH,
|
||||
LIT_GLOBAL_SYMBOL_SEARCH)
|
||||
LIT_GLOBAL_SYMBOL_SEARCH,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.10 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_SPECIES,
|
||||
LIT_GLOBAL_SYMBOL_SPECIES)
|
||||
LIT_GLOBAL_SYMBOL_SPECIES,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.11 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_SPLIT,
|
||||
LIT_GLOBAL_SYMBOL_SPLIT)
|
||||
LIT_GLOBAL_SYMBOL_SPLIT,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.12 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_PRIMITIVE,
|
||||
LIT_GLOBAL_SYMBOL_TO_PRIMITIVE)
|
||||
LIT_GLOBAL_SYMBOL_TO_PRIMITIVE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.13 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_STRING_TAG,
|
||||
LIT_GLOBAL_SYMBOL_TO_STRING_TAG)
|
||||
LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ECMA-262 v6, 19.4.2.14 */
|
||||
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_UNSCOPABLES,
|
||||
LIT_GLOBAL_SYMBOL_UNSCOPABLES)
|
||||
LIT_GLOBAL_SYMBOL_UNSCOPABLES,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -37,6 +36,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_SYNTAX_ERROR_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -37,6 +36,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_SYNTAX_ERROR_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
@@ -37,6 +36,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_URI_ERROR_UL,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/* ECMA-262 v6, 23.3.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ECMA-262 v6, 23.1 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/* ECMA-262 v6, 23.4.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ECMA-262 v6, 23.4 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
|
||||
@@ -15,9 +15,11 @@
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "jcontext.h"
|
||||
#include "jrt-bit-fields.h"
|
||||
@@ -42,15 +44,15 @@ typedef const ecma_builtin_property_descriptor_t *ecma_builtin_property_list_ref
|
||||
/**
|
||||
* Definition of built-in dispatch routine function pointer.
|
||||
*/
|
||||
typedef ecma_value_t (*ecma_builtin_dispatch_routine_t)(uint16_t builtin_routine_id,
|
||||
ecma_value_t this_arg,
|
||||
const ecma_value_t arguments_list[],
|
||||
ecma_length_t arguments_number);
|
||||
typedef ecma_value_t (*ecma_builtin_dispatch_routine_t) (uint16_t builtin_routine_id,
|
||||
ecma_value_t this_arg,
|
||||
const ecma_value_t arguments_list[],
|
||||
ecma_length_t arguments_number);
|
||||
/**
|
||||
* Definition of built-in dispatch call function pointer.
|
||||
*/
|
||||
typedef ecma_value_t (*ecma_builtin_dispatch_call_t)(const ecma_value_t arguments_list[],
|
||||
ecma_length_t arguments_number);
|
||||
typedef ecma_value_t (*ecma_builtin_dispatch_call_t) (const ecma_value_t arguments_list[],
|
||||
ecma_length_t arguments_number);
|
||||
/**
|
||||
* Definition of a builtin descriptor which contains the builtin object's:
|
||||
* - prototype objects's id (13-bits)
|
||||
@@ -348,6 +350,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
|
||||
|
||||
ecma_object_t *prototype_obj_p;
|
||||
|
||||
/* cppcheck-suppress arrayIndexOutOfBoundsCond */
|
||||
if (JERRY_UNLIKELY (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT))
|
||||
{
|
||||
prototype_obj_p = NULL;
|
||||
@@ -384,7 +387,14 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
|
||||
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p, ext_object_size, obj_type);
|
||||
|
||||
ecma_set_object_extensible (obj_p, (obj_builtin_id != ECMA_BUILTIN_ID_TYPE_ERROR_THROWER));
|
||||
if (JERRY_UNLIKELY (obj_builtin_id == ECMA_BUILTIN_ID_TYPE_ERROR_THROWER))
|
||||
{
|
||||
ecma_op_ordinary_object_prevent_extensions (obj_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_op_ordinary_object_set_extensible (obj_p);
|
||||
}
|
||||
|
||||
/*
|
||||
* [[Class]] property of built-in object is not stored explicitly.
|
||||
@@ -406,13 +416,13 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
|
||||
|
||||
built_in_props_p->id = (uint8_t) obj_builtin_id;
|
||||
built_in_props_p->routine_id = (uint16_t) obj_builtin_id;
|
||||
built_in_props_p->instantiated_bitset[0] = 0;
|
||||
built_in_props_p->u.instantiated_bitset[0] = 0;
|
||||
|
||||
if (property_count > 32)
|
||||
{
|
||||
built_in_props_p->length_and_bitset_size = 1 << ECMA_BUILT_IN_BITSET_SHIFT;
|
||||
|
||||
uint32_t *instantiated_bitset_p = built_in_props_p->instantiated_bitset;
|
||||
uint32_t *instantiated_bitset_p = built_in_props_p->u.instantiated_bitset;
|
||||
instantiated_bitset_p[1] = 0;
|
||||
instantiated_bitset_p[2] = 0;
|
||||
}
|
||||
@@ -436,6 +446,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||
|
||||
#if !ENABLED (JERRY_ES2015)
|
||||
#if ENABLED (JERRY_BUILTIN_STRING)
|
||||
case ECMA_BUILTIN_ID_STRING_PROTOTYPE:
|
||||
{
|
||||
@@ -494,10 +505,18 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL;
|
||||
ext_object_p->u.class_prop.u.value = ECMA_NULL_POINTER;
|
||||
|
||||
re_compiled_code_t *bc_p = re_compile_bytecode (ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP),
|
||||
RE_FLAG_EMPTY);
|
||||
|
||||
JERRY_ASSERT (bc_p != NULL);
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, bc_p);
|
||||
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
#endif /* !ENABLED (JERRY_ES2015) */
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (obj_type != ECMA_OBJECT_TYPE_CLASS);
|
||||
@@ -520,7 +539,22 @@ ecma_finalize_builtins (void)
|
||||
{
|
||||
if (JERRY_CONTEXT (ecma_builtin_objects)[id] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_deref_object (ECMA_GET_NON_NULL_POINTER (ecma_object_t, JERRY_CONTEXT (ecma_builtin_objects)[id]));
|
||||
ecma_object_t *obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, JERRY_CONTEXT (ecma_builtin_objects)[id]);
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* Note: In ES2015 a function object may contain tagged template literal collection. Whenever
|
||||
this function is assigned to a builtin function or function routine during the GC it may cause unresolvable
|
||||
circle since one part of the circle is a weak reference (marked by GC) and the other part is hard reference
|
||||
(reference count). In this case when the function which contains the tagged template literal collection
|
||||
is getting GC marked the arrays in the collection are still holding weak references to properties/prototypes
|
||||
which prevents these objects from getting freed. Releasing the property list and the prototype reference
|
||||
manually eliminates the existence of the unresolvable circle described above. */
|
||||
ecma_gc_free_properties (obj_p);
|
||||
obj_p->u1.property_list_cp = JMEM_CP_NULL;
|
||||
obj_p->u2.prototype_cp = JMEM_CP_NULL;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
JERRY_CONTEXT (ecma_builtin_objects)[id] = JMEM_CP_NULL;
|
||||
}
|
||||
}
|
||||
@@ -537,6 +571,8 @@ static ecma_object_t *
|
||||
ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**< identifier of built-in object */
|
||||
uint16_t routine_id, /**< builtin-wide identifier of the built-in
|
||||
* object's routine property */
|
||||
uint16_t name_id, /**< magic string id of 'name' property */
|
||||
uint16_t flags, /**< see also: ecma_builtin_routine_flags */
|
||||
uint8_t length_prop_value) /**< value of 'length' property */
|
||||
{
|
||||
JERRY_ASSERT (length_prop_value < (1 << ECMA_BUILT_IN_BITSET_SHIFT));
|
||||
@@ -545,17 +581,6 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**
|
||||
|
||||
size_t ext_object_size = sizeof (ecma_extended_object_t);
|
||||
|
||||
size_t property_count = ecma_builtin_get_property_count (builtin_id);
|
||||
|
||||
if (property_count > 32)
|
||||
{
|
||||
/* Only 64 extra properties supported at the moment.
|
||||
* This can be extended to 256 later. */
|
||||
JERRY_ASSERT (property_count <= (32 + 64));
|
||||
|
||||
ext_object_size += sizeof (uint32_t) * 2;
|
||||
}
|
||||
|
||||
ecma_object_t *func_obj_p = ecma_create_object (prototype_obj_p,
|
||||
ext_object_size,
|
||||
ECMA_OBJECT_TYPE_FUNCTION);
|
||||
@@ -567,16 +592,8 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**
|
||||
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
|
||||
ext_func_obj_p->u.built_in.id = (uint8_t) builtin_id;
|
||||
ext_func_obj_p->u.built_in.routine_id = routine_id;
|
||||
ext_func_obj_p->u.built_in.instantiated_bitset[0] = 0;
|
||||
|
||||
if (property_count > 32)
|
||||
{
|
||||
length_prop_value = (uint8_t) (length_prop_value | (1 << ECMA_BUILT_IN_BITSET_SHIFT));
|
||||
|
||||
uint32_t *instantiated_bitset_p = ext_func_obj_p->u.built_in.instantiated_bitset;
|
||||
instantiated_bitset_p[1] = 0;
|
||||
instantiated_bitset_p[2] = 0;
|
||||
}
|
||||
ext_func_obj_p->u.built_in.u.builtin_routine.name = name_id;
|
||||
ext_func_obj_p->u.built_in.u.builtin_routine.bitset = flags;
|
||||
|
||||
ext_func_obj_p->u.built_in.length_and_bitset_size = length_prop_value;
|
||||
|
||||
@@ -590,10 +607,15 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**
|
||||
*/
|
||||
static ecma_object_t *
|
||||
ecma_builtin_make_function_object_for_getter_accessor (ecma_builtin_id_t builtin_id, /**< id of built-in object */
|
||||
uint16_t routine_id) /**< builtin-wide id of the built-in
|
||||
uint16_t routine_id, /**< builtin-wide id of the built-in
|
||||
* object's routine property */
|
||||
uint16_t name_id) /**< magic string id of 'name' property */
|
||||
{
|
||||
return ecma_builtin_make_function_object_for_routine (builtin_id, routine_id, 0);
|
||||
return ecma_builtin_make_function_object_for_routine (builtin_id,
|
||||
routine_id,
|
||||
name_id,
|
||||
ECMA_BUILTIN_ROUTINE_GETTER,
|
||||
0);
|
||||
} /* ecma_builtin_make_function_object_for_getter_accessor */
|
||||
|
||||
/**
|
||||
@@ -603,12 +625,140 @@ ecma_builtin_make_function_object_for_getter_accessor (ecma_builtin_id_t builtin
|
||||
*/
|
||||
static ecma_object_t *
|
||||
ecma_builtin_make_function_object_for_setter_accessor (ecma_builtin_id_t builtin_id, /**< id of built-in object */
|
||||
uint16_t routine_id) /**< builtin-wide id of the built-in
|
||||
uint16_t routine_id, /**< builtin-wide id of the built-in
|
||||
* object's routine property */
|
||||
uint16_t name_id) /**< magic string id of 'name' property */
|
||||
{
|
||||
return ecma_builtin_make_function_object_for_routine (builtin_id, routine_id, 1);
|
||||
return ecma_builtin_make_function_object_for_routine (builtin_id,
|
||||
routine_id,
|
||||
name_id,
|
||||
ECMA_BUILTIN_ROUTINE_SETTER,
|
||||
1);
|
||||
} /* ecma_builtin_make_function_object_for_setter_accessor */
|
||||
|
||||
/**
|
||||
* Lazy instantiation of builtin routine property of builtin object
|
||||
*
|
||||
* If the property is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t *
|
||||
ecma_builtin_routine_try_to_instantiate_property (ecma_object_t *object_p, /**< object */
|
||||
ecma_string_t *string_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
JERRY_ASSERT (ecma_builtin_function_is_routine (object_p));
|
||||
|
||||
if (ecma_string_is_length (string_p))
|
||||
{
|
||||
/*
|
||||
* Lazy instantiation of 'length' property
|
||||
*/
|
||||
|
||||
ecma_property_t *len_prop_p;
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
uint16_t *bitset_p = &ext_func_p->u.built_in.u.builtin_routine.bitset;
|
||||
if (*bitset_p & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED)
|
||||
{
|
||||
/* length property was already instantiated */
|
||||
return NULL;
|
||||
}
|
||||
/* We mark that the property was lazily instantiated,
|
||||
* as it is configurable and so can be deleted (ECMA-262 v6, 19.2.4.1) */
|
||||
*bitset_p |= ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED;
|
||||
ecma_property_value_t *len_prop_value_p = ecma_create_named_data_property (object_p,
|
||||
string_p,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE,
|
||||
&len_prop_p);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
/* We don't need to mark that the property was already lazy instantiated,
|
||||
* as it is non-configurable and so can't be deleted (ECMA-262 v5, 13.2.5) */
|
||||
ecma_property_value_t *len_prop_value_p = ecma_create_named_data_property (object_p,
|
||||
string_p,
|
||||
ECMA_PROPERTY_FIXED,
|
||||
&len_prop_p);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
uint8_t length = ext_func_p->u.built_in.length_and_bitset_size;
|
||||
JERRY_ASSERT (length < (1 << ECMA_BUILT_IN_BITSET_SHIFT));
|
||||
|
||||
len_prop_value_p->value = ecma_make_integer_value (length);
|
||||
|
||||
return len_prop_p;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/*
|
||||
* Lazy instantiation of 'name' property
|
||||
*/
|
||||
if (ecma_compare_ecma_string_to_magic_id (string_p, LIT_MAGIC_STRING_NAME))
|
||||
{
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
uint16_t *bitset_p = &ext_func_p->u.built_in.u.builtin_routine.bitset;
|
||||
|
||||
if (*bitset_p & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED)
|
||||
{
|
||||
/* name property was already instantiated */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We mark that the property was lazily instantiated */
|
||||
*bitset_p |= ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED;
|
||||
ecma_property_t *name_prop_p;
|
||||
ecma_property_value_t *name_prop_value_p = ecma_create_named_data_property (object_p,
|
||||
string_p,
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE,
|
||||
&name_prop_p);
|
||||
|
||||
ecma_string_t *name_p;
|
||||
lit_magic_string_id_t name_id = ext_func_p->u.built_in.u.builtin_routine.name;
|
||||
|
||||
if (JERRY_UNLIKELY (name_id > LIT_NON_INTERNAL_MAGIC_STRING__COUNT))
|
||||
{
|
||||
/* Note: Whenever new intrinsic routine is being added this mapping should be updated as well! */
|
||||
if (JERRY_UNLIKELY (name_id == LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES))
|
||||
{
|
||||
name_p = ecma_get_magic_string (LIT_MAGIC_STRING_VALUES);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (LIT_IS_GLOBAL_SYMBOL (name_id));
|
||||
name_p = ecma_op_get_global_symbol (name_id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name_p = ecma_get_magic_string (name_id);
|
||||
}
|
||||
|
||||
char *prefix_p = NULL;
|
||||
lit_utf8_size_t prefix_size = 0;
|
||||
|
||||
if (*bitset_p & (ECMA_BUILTIN_ROUTINE_GETTER | ECMA_BUILTIN_ROUTINE_SETTER))
|
||||
{
|
||||
prefix_size = 4;
|
||||
prefix_p = (*bitset_p & ECMA_BUILTIN_ROUTINE_GETTER) ? "get " : "set ";
|
||||
}
|
||||
|
||||
name_prop_value_p->value = ecma_op_function_form_name (name_p, prefix_p, prefix_size);
|
||||
|
||||
if (JERRY_UNLIKELY (name_id > LIT_NON_INTERNAL_MAGIC_STRING__COUNT))
|
||||
{
|
||||
ecma_deref_ecma_string (name_p);
|
||||
}
|
||||
|
||||
return name_prop_p;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
return NULL;
|
||||
} /* ecma_builtin_routine_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
@@ -623,37 +773,6 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
|
||||
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
&& ecma_builtin_function_is_routine (object_p))
|
||||
{
|
||||
if (ecma_string_is_length (string_p))
|
||||
{
|
||||
/*
|
||||
* Lazy instantiation of 'length' property
|
||||
*
|
||||
* Note:
|
||||
* We don't need to mark that the property was already lazy instantiated,
|
||||
* as it is non-configurable and so can't be deleted
|
||||
*/
|
||||
|
||||
ecma_property_t *len_prop_p;
|
||||
ecma_property_value_t *len_prop_value_p = ecma_create_named_data_property (object_p,
|
||||
string_p,
|
||||
ECMA_PROPERTY_FIXED,
|
||||
&len_prop_p);
|
||||
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
uint8_t length = ext_obj_p->u.built_in.length_and_bitset_size & ((1 << ECMA_BUILT_IN_BITSET_SHIFT) - 1);
|
||||
|
||||
len_prop_value_p->value = ecma_make_integer_value (length);
|
||||
|
||||
return len_prop_p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lit_magic_string_id_t magic_string_id = ecma_get_string_magic (string_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
@@ -673,6 +792,7 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
|
||||
ecma_built_in_props_t *built_in_props_p;
|
||||
ecma_object_type_t object_type = ecma_get_object_type (object_p);
|
||||
JERRY_ASSERT (object_type != ECMA_OBJECT_TYPE_FUNCTION || !ecma_builtin_function_is_routine (object_p));
|
||||
|
||||
if (object_type == ECMA_OBJECT_TYPE_CLASS || object_type == ECMA_OBJECT_TYPE_ARRAY)
|
||||
{
|
||||
@@ -703,7 +823,7 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
|
||||
uint32_t index = (uint32_t) (curr_property_p - property_list_p);
|
||||
|
||||
uint32_t *bitset_p = built_in_props_p->instantiated_bitset + (index >> 5);
|
||||
uint32_t *bitset_p = built_in_props_p->u.instantiated_bitset + (index >> 5);
|
||||
|
||||
uint32_t bit_for_index = (uint32_t) (1u << (index & 0x1f));
|
||||
|
||||
@@ -793,13 +913,13 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case ECMA_BUILTIN_PROPERTY_SYMBOL:
|
||||
{
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw ((lit_utf8_byte_t *) "Symbol.", 7);
|
||||
|
||||
lit_magic_string_id_t symbol_desc_id = (lit_magic_string_id_t) curr_property_p->value;
|
||||
|
||||
ecma_string_t *symbol_desc_p;
|
||||
symbol_desc_p = ecma_append_magic_string_to_string (ecma_get_magic_string (LIT_MAGIC_STRING_SYMBOL_DOT_UL),
|
||||
symbol_desc_id);
|
||||
ecma_stringbuilder_append_magic (&builder, symbol_desc_id);
|
||||
|
||||
ecma_value_t symbol_desc_value = ecma_make_string_value (symbol_desc_p);
|
||||
ecma_value_t symbol_desc_value = ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
|
||||
|
||||
ecma_string_t *symbol_p = ecma_new_symbol_from_descriptor_string (symbol_desc_value);
|
||||
lit_magic_string_id_t symbol_id = (lit_magic_string_id_t) curr_property_p->magic_string_id;
|
||||
@@ -838,6 +958,8 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
ecma_object_t *func_obj_p;
|
||||
func_obj_p = ecma_builtin_make_function_object_for_routine (builtin_id,
|
||||
ECMA_GET_ROUTINE_ID (curr_property_p->value),
|
||||
curr_property_p->magic_string_id,
|
||||
ECMA_BUILTIN_ROUTINE_NO_OPTS,
|
||||
ECMA_GET_ROUTINE_LENGTH (curr_property_p->value));
|
||||
value = ecma_make_object_value (func_obj_p);
|
||||
break;
|
||||
@@ -847,8 +969,12 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
is_accessor = true;
|
||||
uint16_t getter_id = ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID (curr_property_p->value);
|
||||
uint16_t setter_id = ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID (curr_property_p->value);
|
||||
getter_p = ecma_builtin_make_function_object_for_getter_accessor (builtin_id, getter_id);
|
||||
setter_p = ecma_builtin_make_function_object_for_setter_accessor (builtin_id, setter_id);
|
||||
getter_p = ecma_builtin_make_function_object_for_getter_accessor (builtin_id,
|
||||
getter_id,
|
||||
curr_property_p->magic_string_id);
|
||||
setter_p = ecma_builtin_make_function_object_for_setter_accessor (builtin_id,
|
||||
setter_id,
|
||||
curr_property_p->magic_string_id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -857,7 +983,8 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
|
||||
is_accessor = true;
|
||||
getter_p = ecma_builtin_make_function_object_for_getter_accessor (builtin_id,
|
||||
curr_property_p->value);
|
||||
curr_property_p->value,
|
||||
curr_property_p->magic_string_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -900,6 +1027,53 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
return prop_p;
|
||||
} /* ecma_builtin_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* List names of a built-in function's lazy instantiated properties
|
||||
*
|
||||
* See also:
|
||||
* ecma_builtin_routine_try_to_instantiate_property
|
||||
*/
|
||||
void
|
||||
ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped 'non-enumerable'
|
||||
* collection */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
JERRY_ASSERT (ecma_builtin_function_is_routine (object_p));
|
||||
|
||||
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
|
||||
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
|
||||
|
||||
ecma_collection_t *for_enumerable_p = main_collection_p;
|
||||
JERRY_UNUSED (for_enumerable_p);
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
if (!is_array_indices_only)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED))
|
||||
{
|
||||
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
}
|
||||
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED))
|
||||
{
|
||||
/* Unintialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME));
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
}
|
||||
} /* ecma_builtin_routine_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
* List names of a built-in object's lazy instantiated properties
|
||||
*
|
||||
@@ -915,85 +1089,82 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
||||
* collection */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
JERRY_ASSERT (ecma_get_object_type (object_p) != ECMA_OBJECT_TYPE_FUNCTION
|
||||
|| !ecma_builtin_function_is_routine (object_p));
|
||||
|
||||
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
|
||||
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
|
||||
|
||||
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
&& ecma_builtin_function_is_routine (object_p))
|
||||
ecma_built_in_props_t *built_in_props_p;
|
||||
ecma_object_type_t object_type = ecma_get_object_type (object_p);
|
||||
|
||||
if (object_type == ECMA_OBJECT_TYPE_CLASS || object_type == ECMA_OBJECT_TYPE_ARRAY)
|
||||
{
|
||||
ecma_collection_t *for_enumerable_p = main_collection_p;
|
||||
JERRY_UNUSED (for_enumerable_p);
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
built_in_props_p = &((ecma_extended_built_in_object_t *) object_p)->built_in;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_built_in_props_t *built_in_props_p;
|
||||
ecma_object_type_t object_type = ecma_get_object_type (object_p);
|
||||
built_in_props_p = &((ecma_extended_object_t *) object_p)->u.built_in;
|
||||
}
|
||||
|
||||
if (object_type == ECMA_OBJECT_TYPE_CLASS || object_type == ECMA_OBJECT_TYPE_ARRAY)
|
||||
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_props_p->id;
|
||||
|
||||
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
|
||||
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
|
||||
|
||||
const ecma_builtin_property_descriptor_t *curr_property_p = ecma_builtin_property_list_references[builtin_id];
|
||||
|
||||
ecma_length_t index = 0;
|
||||
uint32_t *bitset_p = built_in_props_p->u.instantiated_bitset;
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (separate_enumerable ? non_enum_collection_p
|
||||
: main_collection_p);
|
||||
|
||||
while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT)
|
||||
{
|
||||
if (index == 32)
|
||||
{
|
||||
built_in_props_p = &((ecma_extended_built_in_object_t *) object_p)->built_in;
|
||||
bitset_p++;
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
built_in_props_p = &((ecma_extended_object_t *) object_p)->u.built_in;
|
||||
}
|
||||
|
||||
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_props_p->id;
|
||||
|
||||
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
|
||||
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
|
||||
|
||||
const ecma_builtin_property_descriptor_t *curr_property_p = ecma_builtin_property_list_references[builtin_id];
|
||||
|
||||
ecma_length_t index = 0;
|
||||
uint32_t *bitset_p = built_in_props_p->instantiated_bitset;
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (separate_enumerable ? non_enum_collection_p
|
||||
: main_collection_p);
|
||||
|
||||
while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT)
|
||||
{
|
||||
if (index == 32)
|
||||
{
|
||||
bitset_p++;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* Builtin symbol properties are internal magic strings which must not be listed */
|
||||
if (curr_property_p->magic_string_id > LIT_NON_INTERNAL_MAGIC_STRING__COUNT)
|
||||
{
|
||||
curr_property_p++;
|
||||
continue;
|
||||
}
|
||||
/* Builtin symbol properties are internal magic strings which must not be listed */
|
||||
if (curr_property_p->magic_string_id > LIT_NON_INTERNAL_MAGIC_STRING__COUNT)
|
||||
{
|
||||
curr_property_p++;
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) curr_property_p->magic_string_id);
|
||||
ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) curr_property_p->magic_string_id);
|
||||
|
||||
if (is_array_indices_only && ecma_string_get_array_index (name_p) == ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
if (is_array_indices_only && ecma_string_get_array_index (name_p) == ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
{
|
||||
curr_property_p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t bit_for_index = (uint32_t) 1u << index;
|
||||
|
||||
if (!(*bitset_p & bit_for_index) || ecma_op_ordinary_object_has_own_property (object_p, name_p))
|
||||
{
|
||||
ecma_value_t name = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->magic_string_id);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (curr_property_p->attributes & ECMA_PROPERTY_FLAG_ENUMERABLE)
|
||||
{
|
||||
curr_property_p++;
|
||||
continue;
|
||||
ecma_collection_push_back (main_collection_p, name);
|
||||
}
|
||||
|
||||
uint32_t bit_for_index = (uint32_t) 1u << index;
|
||||
|
||||
if (!(*bitset_p & bit_for_index) || ecma_op_object_has_own_property (object_p, name_p))
|
||||
else
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
{
|
||||
ecma_value_t name = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->magic_string_id);
|
||||
|
||||
ecma_collection_push_back (for_non_enumerable_p, name);
|
||||
}
|
||||
|
||||
curr_property_p++;
|
||||
index++;
|
||||
}
|
||||
|
||||
curr_property_p++;
|
||||
index++;
|
||||
}
|
||||
} /* ecma_builtin_list_lazy_property_names */
|
||||
|
||||
@@ -1004,15 +1175,12 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */
|
||||
uint16_t builtin_routine_id, /**< builtin-wide identifier
|
||||
* of the built-in object's
|
||||
* routine property */
|
||||
ecma_builtin_dispatch_routine (ecma_extended_object_t *func_obj_p, /**< builtin object */
|
||||
ecma_value_t this_arg_value, /**< 'this' argument value */
|
||||
const ecma_value_t *arguments_list_p, /**< list of arguments passed to routine */
|
||||
ecma_length_t arguments_list_len) /**< length of arguments' list */
|
||||
{
|
||||
JERRY_ASSERT (builtin_object_id < ECMA_BUILTIN_ID__COUNT);
|
||||
JERRY_ASSERT (ecma_builtin_function_is_routine ((ecma_object_t *) func_obj_p));
|
||||
|
||||
ecma_value_t padded_arguments_list_p[3] = { ECMA_VALUE_UNDEFINED, ECMA_VALUE_UNDEFINED, ECMA_VALUE_UNDEFINED };
|
||||
|
||||
@@ -1039,10 +1207,10 @@ ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-i
|
||||
arguments_list_p = padded_arguments_list_p;
|
||||
}
|
||||
|
||||
return ecma_builtin_routines[builtin_object_id] (builtin_routine_id,
|
||||
this_arg_value,
|
||||
arguments_list_p,
|
||||
arguments_list_len);
|
||||
return ecma_builtin_routines[func_obj_p->u.built_in.id] (func_obj_p->u.built_in.routine_id,
|
||||
this_arg_value,
|
||||
arguments_list_p,
|
||||
arguments_list_len);
|
||||
} /* ecma_builtin_dispatch_routine */
|
||||
|
||||
/**
|
||||
@@ -1059,27 +1227,19 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
|
||||
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ecma_builtin_function_is_routine (obj_p))
|
||||
{
|
||||
ret_value = ecma_builtin_dispatch_routine (ext_obj_p->u.built_in.id,
|
||||
ext_obj_p->u.built_in.routine_id,
|
||||
this_arg_value,
|
||||
arguments_list_p,
|
||||
arguments_list_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_builtin_id_t builtin_object_id = ext_obj_p->u.built_in.id;
|
||||
JERRY_ASSERT (builtin_object_id < sizeof (ecma_builtin_call_functions) / sizeof (ecma_builtin_dispatch_call_t));
|
||||
return ecma_builtin_call_functions[builtin_object_id] (arguments_list_p, arguments_list_len);
|
||||
return ecma_builtin_dispatch_routine (ext_obj_p,
|
||||
this_arg_value,
|
||||
arguments_list_p,
|
||||
arguments_list_len);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (!ecma_is_value_empty (ret_value));
|
||||
|
||||
return ret_value;
|
||||
ecma_builtin_id_t builtin_object_id = ext_obj_p->u.built_in.id;
|
||||
JERRY_ASSERT (builtin_object_id < sizeof (ecma_builtin_call_functions) / sizeof (ecma_builtin_dispatch_call_t));
|
||||
return ecma_builtin_call_functions[builtin_object_id] (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_dispatch_call */
|
||||
|
||||
/**
|
||||
@@ -1089,16 +1249,36 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
|
||||
ecma_object_t *new_target_p, /**< new target */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< arguments list length */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
|
||||
|
||||
if (ecma_builtin_function_is_routine (obj_p))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Built-in routines have no constructor."));
|
||||
}
|
||||
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
ecma_builtin_id_t builtin_object_id = ext_obj_p->u.built_in.id;
|
||||
JERRY_ASSERT (builtin_object_id < sizeof (ecma_builtin_construct_functions) / sizeof (ecma_builtin_dispatch_call_t));
|
||||
return ecma_builtin_construct_functions[builtin_object_id] (arguments_list_p, arguments_list_len);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_object_t *old_new_target = JERRY_CONTEXT (current_new_target);
|
||||
JERRY_CONTEXT (current_new_target) = new_target_p;
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
JERRY_UNUSED (new_target_p);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
ecma_value_t ret_value = ecma_builtin_construct_functions[builtin_object_id] (arguments_list_p, arguments_list_len);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
JERRY_CONTEXT (current_new_target) = old_new_target;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,11 +85,18 @@ ecma_value_t
|
||||
ecma_builtin_dispatch_call (ecma_object_t *obj_p, ecma_value_t this_arg_value,
|
||||
const ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len);
|
||||
ecma_value_t
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *obj_p,
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *obj_p, ecma_object_t *new_target_p,
|
||||
const ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len);
|
||||
ecma_property_t *
|
||||
ecma_builtin_routine_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *string_p);
|
||||
ecma_property_t *
|
||||
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *string_p);
|
||||
void
|
||||
ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
|
||||
@@ -46,14 +46,99 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ARRAY,
|
||||
array)
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_STRING)
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
# if ENABLED (JERRY_BUILTIN_STRING)
|
||||
/* The String.prototype object (21.1.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
string_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_STRING) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_BOOLEAN)
|
||||
/* The Boolean.prototype object (19.3.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
boolean_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_NUMBER)
|
||||
/* The Number.prototype object (20.1.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
number_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_DATE)
|
||||
/* The Date.prototype object (20.3.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
date_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_DATE) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
/* The RegExp.prototype object (21.2.5) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
regexp_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
# if ENABLED (JERRY_BUILTIN_STRING)
|
||||
/* The String.prototype object (15.5.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
string_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_STRING) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_BOOLEAN)
|
||||
/* The Boolean.prototype object (15.6.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
boolean_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_NUMBER)
|
||||
/* The Number.prototype object (15.7.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
number_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_DATE)
|
||||
/* The Date.prototype object (15.9.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
date_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_DATE) */
|
||||
|
||||
# if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
/* The RegExp.prototype object (15.10.6) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
regexp_prototype)
|
||||
# endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
#endif /* !ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_STRING)
|
||||
/* The String object (15.5.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_STRING,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -63,13 +148,6 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_STRING,
|
||||
#endif /* ENABLED (JERRY_BUILTIN_STRING) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_BOOLEAN)
|
||||
/* The Boolean.prototype object (15.6.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
boolean_prototype)
|
||||
|
||||
/* The Boolean object (15.6.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BOOLEAN,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -79,13 +157,6 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BOOLEAN,
|
||||
#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_NUMBER)
|
||||
/* The Number.prototype object (15.7.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
number_prototype)
|
||||
|
||||
/* The Number object (15.7.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_NUMBER,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -137,13 +208,6 @@ BUILTIN (ECMA_BUILTIN_ID_JSON,
|
||||
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_DATE)
|
||||
/* The Date.prototype object (15.9.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
date_prototype)
|
||||
|
||||
/* The Date object (15.9.3) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_DATE,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -153,13 +217,6 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_DATE,
|
||||
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
/* The RegExp.prototype object (15.10.6) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_CLASS,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
regexp_prototype)
|
||||
|
||||
/* The RegExp object (15.10) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_REGEXP,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -168,6 +225,12 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_REGEXP,
|
||||
regexp)
|
||||
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
#define ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID ECMA_BUILTIN_ID_ERROR
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
#define ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE
|
||||
#endif /* ENABLED (JERRY_ES2015 */
|
||||
|
||||
/* The Error object (15.11.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -193,7 +256,7 @@ BUILTIN (ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE,
|
||||
/* The EvalError object (15.11.6.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_EVAL_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID,
|
||||
true,
|
||||
eval_error)
|
||||
|
||||
@@ -207,7 +270,7 @@ BUILTIN (ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE,
|
||||
/* The RangeError object (15.11.6.2) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_RANGE_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID,
|
||||
true,
|
||||
range_error)
|
||||
|
||||
@@ -221,7 +284,7 @@ BUILTIN (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE,
|
||||
/* The ReferenceError object (15.11.6.3) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_REFERENCE_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID,
|
||||
true,
|
||||
reference_error)
|
||||
|
||||
@@ -235,7 +298,7 @@ BUILTIN (ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE,
|
||||
/* The SyntaxError object (15.11.6.4) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_SYNTAX_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID,
|
||||
true,
|
||||
syntax_error)
|
||||
|
||||
@@ -249,7 +312,7 @@ BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE,
|
||||
/* The TypeError object (15.11.6.5) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_TYPE_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID,
|
||||
true,
|
||||
type_error)
|
||||
|
||||
@@ -263,7 +326,7 @@ BUILTIN (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE,
|
||||
/* The URIError object (15.11.6.6) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_URI_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID,
|
||||
true,
|
||||
uri_error)
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ERRORS) */
|
||||
@@ -507,6 +570,15 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_WEAKSET,
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
|
||||
/* The Proxy routine (ECMA-262 v6, 26.2.1) */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_PROXY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
proxy)
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
|
||||
/* Intrinsic hidden builtin object */
|
||||
|
||||
@@ -736,11 +736,11 @@ ecma_builtin_typedarray_prototype_filter (ecma_value_t this_arg, /**< this argum
|
||||
|
||||
ecma_value_t call_args[] = { get_value, current_index, this_arg };
|
||||
|
||||
ecma_value_t call_value = ecma_op_function_call (func_object_p, cb_this_arg, call_args, 3);
|
||||
|
||||
ecma_fast_free_value (current_index);
|
||||
ecma_fast_free_value (get_value);
|
||||
|
||||
ecma_value_t call_value = ecma_op_function_call (func_object_p, cb_this_arg, call_args, 3);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (call_value))
|
||||
{
|
||||
goto cleanup;
|
||||
@@ -1134,36 +1134,41 @@ ecma_builtin_typedarray_prototype_join (ecma_value_t this_arg, /**< this argumen
|
||||
}
|
||||
|
||||
/* 7-8. */
|
||||
ecma_string_t *return_string_p = ecma_op_typedarray_get_to_string_at_index (obj_p, 0);
|
||||
ecma_string_t *first_string_p = ecma_op_typedarray_get_to_string_at_index (obj_p, 0);
|
||||
|
||||
if (JERRY_UNLIKELY (return_string_p == NULL))
|
||||
if (JERRY_UNLIKELY (first_string_p == NULL))
|
||||
{
|
||||
ecma_deref_ecma_string (separator_string_p);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (first_string_p);
|
||||
|
||||
ecma_deref_ecma_string (first_string_p);
|
||||
|
||||
/* 9-10. */
|
||||
for (uint32_t k = 1; k < length; k++)
|
||||
{
|
||||
/* 10.a */
|
||||
return_string_p = ecma_concat_ecma_strings (return_string_p, separator_string_p);
|
||||
ecma_stringbuilder_append (&builder, separator_string_p);
|
||||
|
||||
/* 10.d */
|
||||
ecma_string_t *next_string_p = ecma_op_typedarray_get_to_string_at_index (obj_p, k);
|
||||
|
||||
if (JERRY_UNLIKELY (next_string_p == NULL))
|
||||
{
|
||||
ecma_stringbuilder_destroy (&builder);
|
||||
ecma_deref_ecma_string (separator_string_p);
|
||||
ecma_deref_ecma_string (return_string_p);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
return_string_p = ecma_concat_ecma_strings (return_string_p, next_string_p);
|
||||
ecma_stringbuilder_append (&builder, next_string_p);
|
||||
|
||||
ecma_deref_ecma_string (next_string_p);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (separator_string_p);
|
||||
ret_value = ecma_make_string_value (return_string_p);
|
||||
ret_value = ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
@@ -30,20 +30,20 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
/* ES2015 22.2.3.1 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BUFFER,
|
||||
ecma_builtin_typedarray_prototype_buffer_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
/* ES2015 22.2.3.2 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
|
||||
ecma_builtin_typedarray_prototype_bytelength_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
/* ES2015 22.2.3.3 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_OFFSET_UL,
|
||||
ecma_builtin_typedarray_prototype_byteoffset_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ES2015 22.2.3.17 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_LENGTH,
|
||||
ecma_builtin_typedarray_prototype_length_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* ECMA-262 v6, 23.1.3.13 */
|
||||
|
||||
@@ -32,18 +32,13 @@
|
||||
/* ES2015 22.2.5 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
3,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ES2015 22.2.5.1 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U,
|
||||
TYPEDARRAY_BYTES_PER_ELEMENT,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.5 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
3,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.5 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
TYPEDARRAY_MAGIC_STRING_ID,
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
/* ES2015 22.2.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
3,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
/* ES2015 22.2.2 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
|
||||
@@ -73,7 +73,7 @@ ecma_op_new_array_object (ecma_length_t length) /**< length of the new array */
|
||||
ecma_object_t *array_prototype_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE);
|
||||
#else /* !ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||
ecma_object_t *array_prototype_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
#endif /* (ENABLED (JERRY_BUILTIN_ARRAY)) */
|
||||
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||
|
||||
ecma_object_t *object_p = ecma_create_object (array_prototype_object_p,
|
||||
sizeof (ecma_extended_object_t),
|
||||
@@ -683,7 +683,14 @@ ecma_op_array_species_create (ecma_object_t *original_array_p, /**< The object f
|
||||
ecma_value_t constructor = ECMA_VALUE_UNDEFINED;
|
||||
ecma_value_t original_array = ecma_make_object_value (original_array_p);
|
||||
|
||||
if (ecma_is_value_array (original_array))
|
||||
ecma_value_t is_array = ecma_is_value_array (original_array);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (is_array))
|
||||
{
|
||||
return is_array;
|
||||
}
|
||||
|
||||
if (ecma_is_value_true (is_array))
|
||||
{
|
||||
constructor = ecma_op_object_get_by_magic_id (original_array_p, LIT_MAGIC_STRING_CONSTRUCTOR);
|
||||
if (ECMA_IS_VALUE_ERROR (constructor))
|
||||
@@ -733,7 +740,7 @@ ecma_op_array_species_create (ecma_object_t *original_array_p, /**< The object f
|
||||
ecma_value_t len_val = ecma_make_uint32_value (length);
|
||||
ecma_object_t *ctor_object_p = ecma_get_object_from_value (constructor);
|
||||
ecma_value_t ret_val = ecma_op_function_construct (ctor_object_p,
|
||||
ECMA_VALUE_UNDEFINED,
|
||||
ctor_object_p,
|
||||
&len_val,
|
||||
1);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "ecma-arraybuffer-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user