Compare commits
369 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fdeb7c1d6 | |||
| d7404700ad | |||
| b044d4ad76 | |||
| 0d7f26e2c4 | |||
| fa81944743 | |||
| a78c8d4f16 | |||
| 563a5d93e9 | |||
| 7734f87fbb | |||
| 2fe06f82f1 | |||
| b73100d933 | |||
| e693854dae | |||
| 3c5fb342be | |||
| b7a2a153aa | |||
| 608bc9e5ff | |||
| 05b4bda927 | |||
| 24af089643 | |||
| f46d061d19 | |||
| 71d4e12105 | |||
| c4948936c2 | |||
| f3d49f65dd | |||
| 22eabd0e0b | |||
| daf3b36ea6 | |||
| 51244b6d08 | |||
| 8b41bf306a | |||
| 332e216736 | |||
| 4a331b2edc | |||
| e3decffdd3 | |||
| 210b631b21 | |||
| c8ce7d8791 | |||
| 0d7b461185 | |||
| d6070a9fed | |||
| 0fd1ed6f27 | |||
| be8ae3aae8 | |||
| f1dd59e4bd | |||
| 9a8160176c | |||
| be83ff6b71 | |||
| d0e8629342 | |||
| 1725e014b8 | |||
| c407e8a04c | |||
| b6c2e6eb54 | |||
| b3b1dfdabd | |||
| 2960dffb50 | |||
| 08da8bc7aa | |||
| dc3de8d8ae | |||
| aedd55b1f8 | |||
| 003694d259 | |||
| 22e52e45af | |||
| 420643d645 | |||
| 9e0709e401 | |||
| 40b38f70ef | |||
| 183600dff2 | |||
| fa2ddb2466 | |||
| 300570381f | |||
| dc15944ebd | |||
| e21e4a18ba | |||
| 518fcf2c6a | |||
| 8cb2be6001 | |||
| 2a29b72a83 | |||
| 85bb2113fe | |||
| ea5ad2a06f | |||
| 9596a7e1d6 | |||
| 7bfbc701d8 | |||
| 52616f7d8c | |||
| 456fb046ba | |||
| d27a07edf4 | |||
| e2893f26a1 | |||
| d0b4e7dd04 | |||
| 0428b51e35 | |||
| b6f2ff1ba7 | |||
| 3c0beaf87d | |||
| b1237dbc5a | |||
| e0d8c4ca10 | |||
| 40d930d62c | |||
| 1db16c3a1c | |||
| d3b8bed2c1 | |||
| c525b1f10a | |||
| fb4b18a515 | |||
| df6995d0f6 | |||
| 4b5fad748f | |||
| f7382ce8c4 | |||
| 9b33fc8cbd | |||
| 7c0b1ca88a | |||
| 531f1e9687 | |||
| 6cc9848afc | |||
| b8bc013fc0 | |||
| dc458d29fb | |||
| 89db9253c8 | |||
| 5ceffd209e | |||
| e70cfed57a | |||
| 99fa823bab | |||
| 1a4972fc3f | |||
| 1829d2df55 | |||
| 67d677a1bc | |||
| 59eb0787ba | |||
| e188407d3a | |||
| 99ae94b7c0 | |||
| 041df1ec3c | |||
| 4443c88bf4 | |||
| bfc495f0cb | |||
| d31871d7c9 | |||
| 31988877b2 | |||
| 9634ca556e | |||
| cc03c08c3d | |||
| bdc608f2fb | |||
| 132de45c0b | |||
| 51efba40b4 | |||
| 0bc42a3fd5 | |||
| fee3a600af | |||
| 42b4af5921 | |||
| 336fa45fa7 | |||
| c5ed46f5ac | |||
| 35c0a6e299 | |||
| 8956eff2bd | |||
| 1b01bb034f | |||
| f41afeb89f | |||
| 110f75c99d | |||
| 14e95a4775 | |||
| b7508c636c | |||
| 0c6b306429 | |||
| 9725936848 | |||
| cbeecdb703 | |||
| 12211d8aaa | |||
| aeb8431aff | |||
| f63e4c363b | |||
| 4d422e17df | |||
| 16d0e83b64 | |||
| 2e8a8f5caa | |||
| 37850bbfef | |||
| b2d34724d4 | |||
| 1c6f334f62 | |||
| 62356796fc | |||
| 279d4d4119 | |||
| fc2218e828 | |||
| 3bf2bc50bc | |||
| d006f068f4 | |||
| 996bf76f59 | |||
| 2ddf134cef | |||
| 6b43ef8605 | |||
| aadfa13c38 | |||
| 7f6f562adb | |||
| a0a71da025 | |||
| c31452c138 | |||
| bd0cb33172 | |||
| 830011c033 | |||
| 70566a52fb | |||
| a1189cfb62 | |||
| 134f0c0d0f | |||
| 7295c48638 | |||
| 22766a855e | |||
| bf630c0c54 | |||
| a7d129c8b2 | |||
| 8bdb32cc88 | |||
| 359643b5b2 | |||
| 8d24c70513 | |||
| 8cf5f96c15 | |||
| fca0c94002 | |||
| 8eda9bc1c3 | |||
| 12184d7922 | |||
| be95aa33b4 | |||
| 204de302aa | |||
| 213544ae47 | |||
| b4b55a67a2 | |||
| 55c7590767 | |||
| 84f60c19ce | |||
| 3b5224b98d | |||
| c0cc5a1b08 | |||
| 419ccff611 | |||
| b16b400d5b | |||
| 452c78182d | |||
| da69589f05 | |||
| 58f71e6ffa | |||
| 4996542f02 | |||
| 798655a871 | |||
| dc458111ba | |||
| 35d9b1ab17 | |||
| e1fc90db0e | |||
| 923fd128b5 | |||
| f48f926a39 | |||
| 859954b330 | |||
| 44b1b9855d | |||
| 525c35f148 | |||
| 55423ab82a | |||
| 3a505bda6b | |||
| 3b7d254e6a | |||
| a8b627a80c | |||
| 06135da642 | |||
| f2a67876eb | |||
| ab8fa74b86 | |||
| 6f83da4c0b | |||
| fc3cfc4fdc | |||
| cbae33a689 | |||
| f93fa98a75 | |||
| eee41ec734 | |||
| 6a342fcdd6 | |||
| d1faed7d03 | |||
| cc9a657425 | |||
| 222e774cc2 | |||
| 6639bbc580 | |||
| d801fc70bb | |||
| 1edfa81c76 | |||
| 1c34539997 | |||
| 42ab062441 | |||
| 11818f1cb0 | |||
| 87f60da14f | |||
| 448c239f08 | |||
| 072aedb4ef | |||
| eebbed143d | |||
| 351b88184c | |||
| 3d797b8836 | |||
| 4b352758c1 | |||
| b7aa21ebc7 | |||
| 100a012931 | |||
| 99ad34af4a | |||
| 9e83032ada | |||
| 48f34adea5 | |||
| 3b73562fa5 | |||
| 59e0d6e262 | |||
| 7b589d1381 | |||
| 3fb6f15730 | |||
| edf66f4e9b | |||
| 6a2767a09a | |||
| d85988af96 | |||
| d60587f838 | |||
| 7df87b7778 | |||
| fd1f7eab9f | |||
| a40eb9bab8 | |||
| fd8203ce98 | |||
| 2e86bdae6f | |||
| 09c5d98e25 | |||
| 390916e989 | |||
| 5320f5a396 | |||
| e8bc7a2b93 | |||
| 8f39d90f7c | |||
| 7518b7bfe6 | |||
| f0e432c9b9 | |||
| 84a56efd4f | |||
| fc2a2f94fd | |||
| 9e323cdcd6 | |||
| ede1957932 | |||
| 6f515f079e | |||
| 848a9854c3 | |||
| 7dc2d1dcd7 | |||
| eb97860509 | |||
| 0f754ff33c | |||
| 3e23a3b62f | |||
| e54666b448 | |||
| b206d60842 | |||
| 466dc903fb | |||
| c17da4f33b | |||
| cfaecc6698 | |||
| 2180d979b7 | |||
| 6a848a36fd | |||
| cd7720ee08 | |||
| 64774d30ae | |||
| 21e17a1412 | |||
| 5ed8647b9e | |||
| 2096fba571 | |||
| c3bb516e4a | |||
| c3510fc03d | |||
| f1883b9e7d | |||
| 2a89eec98b | |||
| f5e3faeaff | |||
| 32962f067e | |||
| 07c7eb8a20 | |||
| 32c74fff22 | |||
| fbca37fde6 | |||
| 195b0d3c3a | |||
| e9664b78cd | |||
| 3763ac8371 | |||
| f7391a94ae | |||
| 26626947c0 | |||
| 57abd26c33 | |||
| a8fb4eee1e | |||
| 711b06d018 | |||
| 0121b2bbcf | |||
| 4eae760180 | |||
| 2b3faf683d | |||
| 9ab4872244 | |||
| 97a0febaff | |||
| 8f7565db5f | |||
| 137dd8d1f5 | |||
| 35a3df3f28 | |||
| f2013fcb1a | |||
| 5c7df1cb2d | |||
| 053b05f185 | |||
| 25b81c106c | |||
| a7c654617d | |||
| 1acbf83d1a | |||
| 6c03e0f0af | |||
| b1115fbcfc | |||
| dc44b8b933 | |||
| c05686b668 | |||
| 40e63d1207 | |||
| 0eae2f6207 | |||
| 62f8d7c885 | |||
| 4452e79204 | |||
| 8d9788d1b5 | |||
| aa8832a985 | |||
| 436fcbb4b7 | |||
| 62025cfa41 | |||
| 87441635e1 | |||
| 83c44d20b3 | |||
| 17e63e892a | |||
| 9f85d21578 | |||
| 951d7e6842 | |||
| 6e79bb148e | |||
| 376cfea47e | |||
| 57de923770 | |||
| fc30f003ba | |||
| f3d3c34c30 | |||
| fbde788d1f | |||
| 6221b670d1 | |||
| 83459c1fac | |||
| c04fe24253 | |||
| 9fbd0cce6c | |||
| e04bbdfff4 | |||
| c79659d3b2 | |||
| 3111d0e0f2 | |||
| 115ad9a41c | |||
| 2933947534 | |||
| 5d51fe8f27 | |||
| 91818bea93 | |||
| 1b84a17dc7 | |||
| 57f389dcf4 | |||
| 96edec1a62 | |||
| 086c4ebf13 | |||
| 142f79ce05 | |||
| 4afcc709b8 | |||
| 24196b69da | |||
| 1c4cfe3e20 | |||
| 8bccbbf08f | |||
| 1088273bc3 | |||
| 3e661c0c5a | |||
| a315a6534e | |||
| 14e4476084 | |||
| e79059c94b | |||
| 91e87fe34f | |||
| 952fb23e0e | |||
| 29758101a3 | |||
| ea77a79461 | |||
| 3ba6adcc71 | |||
| 2f1908f894 | |||
| c6a4a86257 | |||
| f0578b2c25 | |||
| e3c1451d42 | |||
| 5fa0a690eb | |||
| 26d48c3e28 | |||
| 744a64c6fd | |||
| ee1da14577 | |||
| d0435e1db0 | |||
| 47f2f0ea8b | |||
| 97e348528a | |||
| fd075322fb | |||
| b47c36ad18 | |||
| 3af0079a0e | |||
| 996459714c | |||
| ddd48b30f0 | |||
| d29364c34e | |||
| 77237960a7 | |||
| 3c69dfab2c | |||
| 54a5a650aa | |||
| ff2e75ed2e | |||
| a834288096 | |||
| 566e81451e | |||
| 3b7475b01d | |||
| dec9dbc926 | |||
| 14a9a1a1f0 | |||
| 9c7511221f | |||
| 051febfed7 |
+21
-39
@@ -20,9 +20,9 @@ matrix:
|
|||||||
apt:
|
apt:
|
||||||
packages: [doxygen, cppcheck, vera++]
|
packages: [doxygen, cppcheck, vera++]
|
||||||
|
|
||||||
- name: "Linux/x86-64 Build & Correctness Tests"
|
- name: "Linux/x86-64 Build, Correctness & Debugger Tests"
|
||||||
env:
|
env:
|
||||||
- OPTS="--quiet --jerry-tests --jerry-test-suite"
|
- OPTS="--quiet --jerry-tests --jerry-test-suite --jerry-debugger"
|
||||||
|
|
||||||
- name: "Linux/x86 (cpointer-32bit) Build & Correctness Tests"
|
- name: "Linux/x86 (cpointer-32bit) Build & Correctness Tests"
|
||||||
env:
|
env:
|
||||||
@@ -55,22 +55,14 @@ matrix:
|
|||||||
apt:
|
apt:
|
||||||
packages: [gcc-multilib]
|
packages: [gcc-multilib]
|
||||||
|
|
||||||
- name: "Unit Tests"
|
|
||||||
env:
|
|
||||||
- OPTS="--unittests"
|
|
||||||
|
|
||||||
- name: "Unit Tests (INIT_FINI)"
|
|
||||||
env:
|
|
||||||
- OPTS="--unittests --buildoptions=--cmake-param=-DFEATURE_INIT_FINI=ON"
|
|
||||||
|
|
||||||
- name: "Debugger Tests"
|
|
||||||
env:
|
|
||||||
- OPTS="--jerry-debugger"
|
|
||||||
|
|
||||||
- name: "Conformance Tests"
|
- name: "Conformance Tests"
|
||||||
env:
|
env:
|
||||||
- OPTS="--test262"
|
- OPTS="--test262"
|
||||||
|
|
||||||
|
- name: "Unit Tests"
|
||||||
|
env:
|
||||||
|
- OPTS="--unittests"
|
||||||
|
|
||||||
- name: "ASAN Tests"
|
- name: "ASAN Tests"
|
||||||
env:
|
env:
|
||||||
# Skipping maximum stack usage related tests due to 'detect_stack_use_after_return=1' ASAN option.
|
# Skipping maximum stack usage related tests due to 'detect_stack_use_after_return=1' ASAN option.
|
||||||
@@ -95,7 +87,7 @@ matrix:
|
|||||||
sources: ubuntu-toolchain-r-test
|
sources: ubuntu-toolchain-r-test
|
||||||
packages: [gcc-5, gcc-5-multilib]
|
packages: [gcc-5, gcc-5-multilib]
|
||||||
|
|
||||||
- name: "Coverity Scan"
|
- name: "Coverity Scan & SonarQube"
|
||||||
env:
|
env:
|
||||||
# Declaration of the encrypted COVERITY_SCAN_TOKEN, created via the
|
# Declaration of the encrypted COVERITY_SCAN_TOKEN, created via the
|
||||||
# "travis encrypt" command using the project repo's public key.
|
# "travis encrypt" command using the project repo's public key.
|
||||||
@@ -108,24 +100,14 @@ matrix:
|
|||||||
notification_email: rsipka.uszeged@partner.samsung.com
|
notification_email: rsipka.uszeged@partner.samsung.com
|
||||||
build_command: "tools/build.py --clean"
|
build_command: "tools/build.py --clean"
|
||||||
branch_pattern: master
|
branch_pattern: master
|
||||||
script: skip # Changed to nop, Coverity Scan has already built the project by the time 'script' stage is reached.
|
|
||||||
|
|
||||||
- name: "SonarQube"
|
|
||||||
addons:
|
|
||||||
sonarcloud:
|
sonarcloud:
|
||||||
organization: "jerryscript-project"
|
organization: "jerryscript-project"
|
||||||
|
# Coverity Scan has already built the project by the time 'script' stage is reached.
|
||||||
script: tools/check-sonarqube.sh
|
script: tools/check-sonarqube.sh
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- '${HOME}/.sonar/cache'
|
- '${HOME}/.sonar/cache'
|
||||||
|
|
||||||
- name: "ESP8266 Build Test"
|
|
||||||
install: make -f ./targets/esp8266/Makefile.travis install-noapt
|
|
||||||
script: make -f ./targets/esp8266/Makefile.travis script
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages: [wget]
|
|
||||||
|
|
||||||
- name: "Mbed OS 5/K64F Build Test"
|
- name: "Mbed OS 5/K64F Build Test"
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
@@ -137,6 +119,15 @@ matrix:
|
|||||||
install: make -f ./targets/mbedos5/Makefile.travis install
|
install: make -f ./targets/mbedos5/Makefile.travis install
|
||||||
script: make -f ./targets/mbedos5/Makefile.travis script
|
script: make -f ./targets/mbedos5/Makefile.travis script
|
||||||
|
|
||||||
|
- name: "Zephyr/Arduino 101 Build Test"
|
||||||
|
language: python # NOTE: only way to ensure python>=2.7.10 on Trusty image
|
||||||
|
python: 3.6
|
||||||
|
install: make -f ./targets/zephyr/Makefile.travis install-noapt
|
||||||
|
script: make -f ./targets/zephyr/Makefile.travis script
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages: [gperf, dfu-util, device-tree-compiler]
|
||||||
|
|
||||||
- name: "NuttX/STM32F4 Build Test"
|
- name: "NuttX/STM32F4 Build Test"
|
||||||
install: make -f targets/nuttx-stm32f4/Makefile.travis install-noapt
|
install: make -f targets/nuttx-stm32f4/Makefile.travis install-noapt
|
||||||
script: make -f targets/nuttx-stm32f4/Makefile.travis script
|
script: make -f targets/nuttx-stm32f4/Makefile.travis script
|
||||||
@@ -154,21 +145,12 @@ matrix:
|
|||||||
- sourceline: ppa:team-gcc-arm-embedded/ppa
|
- sourceline: ppa:team-gcc-arm-embedded/ppa
|
||||||
packages: [clang-3.9, gcc-arm-embedded, gcc-multilib]
|
packages: [clang-3.9, gcc-arm-embedded, gcc-multilib]
|
||||||
|
|
||||||
- name: "Tizen RT/Artik053 Build Test"
|
- name: "ESP8266 Build Test"
|
||||||
|
install: make -f ./targets/esp8266/Makefile.travis install-noapt
|
||||||
|
script: make -f ./targets/esp8266/Makefile.travis script
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources:
|
packages: [wget]
|
||||||
- sourceline: ppa:team-gcc-arm-embedded/ppa
|
|
||||||
packages: [gcc-arm-embedded, genromfs]
|
|
||||||
install: make -f ./targets/tizenrt-artik053/Makefile.travis install
|
|
||||||
script: make -f ./targets/tizenrt-artik053/Makefile.travis script
|
|
||||||
|
|
||||||
- name: "Zephyr/Arduino 101 Build Test"
|
|
||||||
install: make -f ./targets/zephyr/Makefile.travis install-noapt
|
|
||||||
script: make -f ./targets/zephyr/Makefile.travis script
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages: [gperf, dfu-util, device-tree-compiler, python3-ply, python3-pip]
|
|
||||||
|
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -100,6 +100,12 @@ if(USING_MSVC)
|
|||||||
set(ENABLE_STRIP_MESSAGE " (FORCED BY COMPILER)")
|
set(ENABLE_STRIP_MESSAGE " (FORCED BY COMPILER)")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CYGWIN)
|
||||||
|
set(ENABLE_LTO OFF)
|
||||||
|
|
||||||
|
set(ENABLE_LTO_MESSAGE " (FORCED BY PLATFORM)")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Status messages
|
# Status messages
|
||||||
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
|
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
|
||||||
message(STATUS "CMAKE_C_COMPILER_ID " ${CMAKE_C_COMPILER_ID})
|
message(STATUS "CMAKE_C_COMPILER_ID " ${CMAKE_C_COMPILER_ID})
|
||||||
@@ -179,7 +185,7 @@ if("${PLATFORM}" STREQUAL "DARWIN")
|
|||||||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Sqc <TARGET> <LINK_FLAGS> <OBJECTS>")
|
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Sqc <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||||
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
|
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
|
||||||
elseif(USING_GCC OR USING_CLANG)
|
elseif(NOT CYGWIN AND (USING_GCC OR USING_CLANG))
|
||||||
jerry_add_link_flags(-Wl,-z,noexecstack)
|
jerry_add_link_flags(-Wl,-z,noexecstack)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -92,7 +92,10 @@ commit_msg_filepath = sys.argv[1]
|
|||||||
with open(commit_msg_filepath, "r+") as f:
|
with open(commit_msg_filepath, "r+") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
f.seek(0, 0)
|
f.seek(0, 0)
|
||||||
f.write("%s\n\nJerryScript-DCO-1.0-Signed-off-by: <Your Name> <Your Email>" % content)
|
if "Signed-off-by" not in content:
|
||||||
|
f.write("\n\nJerryScript-DCO-1.0-Signed-off-by: <Your Name> <Your Email>\n%s" % content)
|
||||||
|
else:
|
||||||
|
f.write(content)
|
||||||
```
|
```
|
||||||
|
|
||||||
Please refer [Git Hooks](http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) for more information.
|
Please refer [Git Hooks](http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) for more information.
|
||||||
|
|||||||
+4
-8
@@ -17,20 +17,16 @@ platform:
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- FEATURE_DEBUGGER: ON
|
- JERRY_DEBUGGER: ON
|
||||||
- FEATURE_DEBUGGER: OFF
|
- JERRY_DEBUGGER: OFF
|
||||||
|
|
||||||
# Steps of a job.
|
# Steps of a job.
|
||||||
init:
|
init:
|
||||||
- cmake -version
|
- cmake -version
|
||||||
before_build:
|
before_build:
|
||||||
- if "%PLATFORM%"=="Win32" cmake -G"Visual Studio 15 2017" -Bbuild -H. -DFEATURE_DEBUGGER=%FEATURE_DEBUGGER%
|
- if "%PLATFORM%"=="Win32" cmake -G"Visual Studio 15 2017" -Bbuild -H. -DJERRY_DEBUGGER=%JERRY_DEBUGGER%
|
||||||
- if "%PLATFORM%"=="x64" cmake -G"Visual Studio 15 2017 Win64" -Bbuild -H. -DFEATURE_DEBUGGER=%FEATURE_DEBUGGER%
|
- if "%PLATFORM%"=="x64" cmake -G"Visual Studio 15 2017 Win64" -Bbuild -H. -DJERRY_DEBUGGER=%JERRY_DEBUGGER%
|
||||||
build:
|
build:
|
||||||
project: build\Jerry.sln
|
project: build\Jerry.sln
|
||||||
parallel: true
|
parallel: true
|
||||||
verbosity: minimal
|
verbosity: minimal
|
||||||
|
|
||||||
artifacts:
|
|
||||||
- path: build\bin\$(configuration)\
|
|
||||||
name: JerryScriptBinary
|
|
||||||
|
|||||||
@@ -194,7 +194,33 @@ The default value is 512.
|
|||||||
|---------|----------------------------------------------|
|
|---------|----------------------------------------------|
|
||||||
| C: | `-DJERRY_GLOBAL_HEAP_SIZE=(int)` |
|
| C: | `-DJERRY_GLOBAL_HEAP_SIZE=(int)` |
|
||||||
| CMake: | `--DJERRY_GLOBAL_HEAP_SIZE=(int)` |
|
| CMake: | `--DJERRY_GLOBAL_HEAP_SIZE=(int)` |
|
||||||
| Python: | `--heap-size=(int)` |
|
| Python: | `--mem-heap=(int)` |
|
||||||
|
|
||||||
|
### Garbage collection limit
|
||||||
|
|
||||||
|
This option can be used to adjust the maximum allowed heap usage increase until triggering the next garbage collection, in bytes.
|
||||||
|
When the total allocated memory size reaches the current gc limit, garbage collection will be triggered to try and reduce clutter from unreachable objects.
|
||||||
|
If the total allocated memory can't be reduced below the current limit, then the limit will be increased by the amount specified via this option.
|
||||||
|
Similarly, when the total allocated memory goes well below the current gc limit, the limit is reduced by this amount.
|
||||||
|
The default value is 1/32 of the total heap size, but not greater than 8192 bytes.
|
||||||
|
A value of 0 will use the default value.
|
||||||
|
|
||||||
|
| Options | |
|
||||||
|
|---------|----------------------------------------------|
|
||||||
|
| C: | `-DJERRY_GC_LIMIT=(int)` |
|
||||||
|
| CMake: | `-DJERRY_GC_LIMIT=(int)` |
|
||||||
|
| Python: | `--gc-limit=(int)` |
|
||||||
|
|
||||||
|
### GC mark recursion limit
|
||||||
|
|
||||||
|
This option can be used to adjust the maximum recursion depth during the GC mark phase. The provided value should be an integer, which represents the allowed number of recursive calls. Increasing the depth of the recursion reduces the time of GC cycles, however increases stack usage.
|
||||||
|
A value of 0 will prevent any recursive GC calls.
|
||||||
|
|
||||||
|
| Options | |
|
||||||
|
|---------|---------------------------------------------------|
|
||||||
|
| C: | `-DJERRY_GC_MARK_LIMIT=(int)` |
|
||||||
|
| CMake: | `-DJERRY_GC_MARK_LIMIT=(int)` |
|
||||||
|
| Python: | `--gc-mark-limit=(int)` |
|
||||||
|
|
||||||
### Stack limit
|
### Stack limit
|
||||||
|
|
||||||
@@ -287,3 +313,21 @@ $ gcc -Wall -o demo_app demo_app.c gen_src/jerryscript.c gen_src/jerryscript-por
|
|||||||
Please note that the headers must be available on the include path.
|
Please note that the headers must be available on the include path.
|
||||||
|
|
||||||
In addition there is a `-DENABLE_ALL_IN_ONE_SOURCE=ON` CMake option to use this kind of sources during the build.
|
In addition there is a `-DENABLE_ALL_IN_ONE_SOURCE=ON` CMake option to use this kind of sources during the build.
|
||||||
|
|
||||||
|
# Target specific information
|
||||||
|
|
||||||
|
## x86 with GCC
|
||||||
|
|
||||||
|
When building for Intel 32 bit architecture it is possible that GCC uses conservative options, thus assuming the most
|
||||||
|
basic floating-point support (that is it does not generate SSE or others instructions).
|
||||||
|
However this could lead to loss off precision and/or different results than what is required by the JavaScript standard
|
||||||
|
in regards of floating-point values and arithmetic.
|
||||||
|
|
||||||
|
To resolve this precision problem it is advised to use at least SSE2.
|
||||||
|
To do this with GCC please provide the `-mfpmath=sse -msse2` options during build.
|
||||||
|
|
||||||
|
These options can also be specified via the `build.py` script:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ ./tools/build.py --compile-flag=-mfpmath=sse --compile-flag=-msse2 --compile-flag=-m32
|
||||||
|
```
|
||||||
|
|||||||
+742
-23
@@ -224,6 +224,7 @@ for the item by default, and if the `init_cb` field is not NULL, it will be call
|
|||||||
an additional custom initializer. The `deinit_cb` (if non-`NULL`) is called during a call to `jerry_cleanup ()` to run
|
an additional custom initializer. The `deinit_cb` (if non-`NULL`) is called during a call to `jerry_cleanup ()` to run
|
||||||
any custom deinitialization *before* the VM has been fully cleaned up. The `finalize_cb` (if non-`NULL`) is also called
|
any custom deinitialization *before* the VM has been fully cleaned up. The `finalize_cb` (if non-`NULL`) is also called
|
||||||
during a call to `jerry_cleanup ()` to run any custom deinitialization *after* the VM has been fully cleaned up.
|
during a call to `jerry_cleanup ()` to run any custom deinitialization *after* the VM has been fully cleaned up.
|
||||||
|
If bytes_needed field is 0, no buffer is allocated for the manager, callback functions are called with NULL pointer.
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
|
|
||||||
@@ -315,6 +316,11 @@ Enum that contains the supported binary operation types
|
|||||||
- JERRY_BIN_OP_GREATER - greater relation (>)
|
- JERRY_BIN_OP_GREATER - greater relation (>)
|
||||||
- JERRY_BIN_OP_GREATER_EQUAL - greater or equal relation (>=)
|
- JERRY_BIN_OP_GREATER_EQUAL - greater or equal relation (>=)
|
||||||
- JERRY_BIN_OP_INSTANCEOF - instanceof operation
|
- JERRY_BIN_OP_INSTANCEOF - instanceof operation
|
||||||
|
- JERRY_BIN_OP_ADD - addition operator (+)
|
||||||
|
- JERRY_BIN_OP_SUB - subtraction operator (-)
|
||||||
|
- JERRY_BIN_OP_MUL - multiplication operator (*)
|
||||||
|
- JERRY_BIN_OP_DIV - division operator (/)
|
||||||
|
- JERRY_BIN_OP_REM - remainder operator (%)
|
||||||
|
|
||||||
*New in version 2.0*.
|
*New in version 2.0*.
|
||||||
|
|
||||||
@@ -440,6 +446,9 @@ typedef jerry_value_t (*jerry_external_handler_t) (const jerry_value_t function_
|
|||||||
|
|
||||||
Native free callback of an object. It is used in `jerry_object_native_info_t` and for external Array buffers.
|
Native free callback of an object. It is used in `jerry_object_native_info_t` and for external Array buffers.
|
||||||
|
|
||||||
|
*Note*:
|
||||||
|
- Referred values by this method must have at least 1 reference. (Correct API usage satisfies this condition)
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
|
|
||||||
```c
|
```c
|
||||||
@@ -447,6 +456,7 @@ typedef void (*jerry_object_native_free_callback_t) (void *native_p);
|
|||||||
```
|
```
|
||||||
|
|
||||||
*New in version 2.0*: Renamed from `jerry_object_free_callback_t`.
|
*New in version 2.0*: Renamed from `jerry_object_free_callback_t`.
|
||||||
|
*Changed in version 2.2*: API calls are once again allowed. (See note)
|
||||||
|
|
||||||
**See also**
|
**See also**
|
||||||
|
|
||||||
@@ -591,6 +601,22 @@ typedef jerry_value_t (*jerry_vm_exec_stop_callback_t) (void *user_p);
|
|||||||
|
|
||||||
- [jerry_set_vm_exec_stop_callback](#jerry_set_vm_exec_stop_callback)
|
- [jerry_set_vm_exec_stop_callback](#jerry_set_vm_exec_stop_callback)
|
||||||
|
|
||||||
|
## jerry_promise_state_t
|
||||||
|
|
||||||
|
Enum which describes the state of a Promise.
|
||||||
|
|
||||||
|
Possible values:
|
||||||
|
|
||||||
|
- JERRY_PROMISE_STATE_NONE - Invalid/Unknown state (possibly called on a non-promise object).
|
||||||
|
- JERRY_PROMISE_STATE_PENDING - Promise is in "Pending" state.
|
||||||
|
- JERRY_PROMISE_STATE_FULFILLED - Promise is in "Fulfilled" state.
|
||||||
|
- JERRY_PROMISE_STATE_REJECTED - Promise is in "Rejected" state.
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_get_promise_result](#jerry_get_promise_result)
|
||||||
|
|
||||||
## jerry_typedarray_type_t
|
## jerry_typedarray_type_t
|
||||||
|
|
||||||
@@ -2790,7 +2816,7 @@ main (void)
|
|||||||
|
|
||||||
// Read the string into a byte buffer.
|
// Read the string into a byte buffer.
|
||||||
jerry_size_t string_size = jerry_get_string_size (value);
|
jerry_size_t string_size = jerry_get_string_size (value);
|
||||||
jerry_char_t *string_buffer_p = (jerry_char_t *) malloc (sizeof (jerry_char_t) * string_size);
|
jerry_char_t *string_buffer_p = (jerry_char_t *) malloc (sizeof (jerry_char_t) * (string_size + 1));
|
||||||
|
|
||||||
jerry_size_t copied_bytes = jerry_string_to_char_buffer (value, string_buffer_p, string_size);
|
jerry_size_t copied_bytes = jerry_string_to_char_buffer (value, string_buffer_p, string_size);
|
||||||
string_buffer_p[copied_bytes] = '\0';
|
string_buffer_p[copied_bytes] = '\0';
|
||||||
@@ -3227,6 +3253,144 @@ jerry_value_to_string (const jerry_value_t value);
|
|||||||
|
|
||||||
These APIs all depend on the ES2015-subset profile (or on some build options).
|
These APIs all depend on the ES2015-subset profile (or on some build options).
|
||||||
|
|
||||||
|
## jerry_get_promise_result
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
The function returns the result of a Promise object.
|
||||||
|
|
||||||
|
*Notes*:
|
||||||
|
- 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_PROMISE`) and can be checked
|
||||||
|
in runtime with the `JERRY_FEATURE_PROMISE` feature enum value,
|
||||||
|
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||||
|
- The ES2015-subset profile enables this by default.
|
||||||
|
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
jerry_value_t
|
||||||
|
jerry_get_promise_result (const jerry_value_t promise);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `promise` - the input Promise object.
|
||||||
|
- return
|
||||||
|
- The result of the Promise.
|
||||||
|
- If the Promise is not resolved yet the result is the 'undefined' value.
|
||||||
|
- A TypeError is returned if the input argument was not a Promise object or
|
||||||
|
the Promise support was not built into the library.
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
[doctest]: # (test="compile")
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <jerryscript.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
example (void)
|
||||||
|
{
|
||||||
|
// acquire/create a promise object.
|
||||||
|
jerry_value_t promise = jerry_create_promise ();
|
||||||
|
{
|
||||||
|
// prepare the argumnent for the resolve or reject.
|
||||||
|
jerry_value_t argument = jerry_create_number (33);
|
||||||
|
|
||||||
|
jerry_value_t is_ok = jerry_resolve_or_reject_promise (promise,
|
||||||
|
argument,
|
||||||
|
true);
|
||||||
|
// 'is_ok' should be checked if it is an error or not.
|
||||||
|
// skipped in this example
|
||||||
|
jerry_release_value (is_ok);
|
||||||
|
jerry_release_value (argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_value_t promise_result = jerry_get_promise_result (promise);
|
||||||
|
// 'promise_result' is now the number 33.
|
||||||
|
|
||||||
|
jerry_release_value (promise_result);
|
||||||
|
jerry_release_value (promise);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_create_promise](#jerry_create_promise)
|
||||||
|
- [jerry_promise_state_t](#jerry_promise_state_t)
|
||||||
|
|
||||||
|
## jerry_get_promise_state
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
*Notes*:
|
||||||
|
- 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_PROMISE`) and can be checked
|
||||||
|
in runtime with the `JERRY_FEATURE_PROMISE` feature enum value,
|
||||||
|
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||||
|
- The ES2015-subset profile enables this by default.
|
||||||
|
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
jerry_promise_state_t
|
||||||
|
jerry_get_promise_state (const jerry_value_t promise);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `promise` - the input promise object.
|
||||||
|
- return
|
||||||
|
- [jerry_promise_state_t](#jerry_promise_state_t)
|
||||||
|
- `JERRY_PROMISE_STATE_NONE` is returned if the input argument was not a promise object or
|
||||||
|
the Promise support was not built into the library.
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
[doctest]: # (test="compile")
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <jerryscript.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
example (void)
|
||||||
|
{
|
||||||
|
// acquire/create a promise object.
|
||||||
|
jerry_value_t promise = jerry_create_promise ();
|
||||||
|
|
||||||
|
jerry_promise_state_t start_state = jerry_get_promise_state (promise);
|
||||||
|
// a Promise have a default state of JERRY_PROMISE_STATE_PENDING
|
||||||
|
|
||||||
|
{
|
||||||
|
// prepare the argumnent for the resolve or reject.
|
||||||
|
jerry_value_t argument = jerry_create_number (33);
|
||||||
|
|
||||||
|
jerry_value_t is_ok = jerry_resolve_or_reject_promise (promise,
|
||||||
|
argument,
|
||||||
|
true);
|
||||||
|
// 'is_ok' should be checked if it is an error or not.
|
||||||
|
// skipped in this example
|
||||||
|
jerry_release_value (is_ok);
|
||||||
|
jerry_release_value (argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_promise_state_t current_state = jerry_get_promise_state (promise);
|
||||||
|
// at this point the Promise should be in the JERRY_PROMISE_STATE_FULFILLED state.
|
||||||
|
|
||||||
|
jerry_release_value (promise);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_create_promise](#jerry_create_promise)
|
||||||
|
- [jerry_promise_state_t](#jerry_promise_state_t)
|
||||||
|
|
||||||
## jerry_resolve_or_reject_promise
|
## jerry_resolve_or_reject_promise
|
||||||
|
|
||||||
**Summary**
|
**Summary**
|
||||||
@@ -3544,7 +3708,7 @@ jerry_create_arraybuffer_external (const jerry_length_t size
|
|||||||
- `free_cb` - the callback function called when the object is released
|
- `free_cb` - the callback function called when the object is released
|
||||||
- return value
|
- return value
|
||||||
- the new ArrayBuffer as a `jerry_value_t`
|
- the new ArrayBuffer as a `jerry_value_t`
|
||||||
- if the `size` is zero or `buffer_p` is a null pointer will return RangeError
|
- if the `size` is zero or `buffer_p` is a null pointer this will return an empty ArrayBuffer.
|
||||||
|
|
||||||
*New in version 2.0*.
|
*New in version 2.0*.
|
||||||
|
|
||||||
@@ -4064,7 +4228,7 @@ jerry_value_t
|
|||||||
jerry_create_string (const jerry_char_t *str_p);
|
jerry_create_string (const jerry_char_t *str_p);
|
||||||
```
|
```
|
||||||
|
|
||||||
- `str_p` - pointer to string
|
- `str_p` - non-null pointer to string
|
||||||
- return value - value of the created string
|
- return value - value of the created string
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
@@ -4103,7 +4267,7 @@ jerry_create_string_sz (const jerry_char_t *str_p,
|
|||||||
jerry_size_t str_size)
|
jerry_size_t str_size)
|
||||||
```
|
```
|
||||||
|
|
||||||
- `str_p` - pointer to string
|
- `str_p` - non-null pointer to string
|
||||||
- `str_size` - size of the string
|
- `str_size` - size of the string
|
||||||
- return value - value of the created string
|
- return value - value of the created string
|
||||||
|
|
||||||
@@ -4134,8 +4298,9 @@ jerry_create_string_sz (const jerry_char_t *str_p,
|
|||||||
|
|
||||||
Create string from a valid UTF8 string.
|
Create string from a valid UTF8 string.
|
||||||
|
|
||||||
*Note*: The difference from [jerry_create_string](#jerry_create_string) is that it accepts utf-8 string instead of cesu-8 string.
|
*Note*:
|
||||||
*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
- The difference from [jerry_create_string](#jerry_create_string) is that it accepts utf-8 string instead of cesu-8 string.
|
||||||
|
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
||||||
is no longer needed.
|
is no longer needed.
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
@@ -4145,7 +4310,7 @@ jerry_value_t
|
|||||||
jerry_create_string_from_utf8 (const jerry_char_t *str_p);
|
jerry_create_string_from_utf8 (const jerry_char_t *str_p);
|
||||||
```
|
```
|
||||||
|
|
||||||
- `str_p` - pointer to string
|
- `str_p` - non-null pointer to string
|
||||||
- return value - value of the created string
|
- return value - value of the created string
|
||||||
|
|
||||||
*New in version 2.0*.
|
*New in version 2.0*.
|
||||||
@@ -4175,19 +4340,20 @@ jerry_create_string_from_utf8 (const jerry_char_t *str_p);
|
|||||||
|
|
||||||
Create string from a valid UTF8 string.
|
Create string from a valid UTF8 string.
|
||||||
|
|
||||||
*Note*: The difference from [jerry_create_string_sz](#jerry_create_string_sz) is that it accepts utf-8 string instead of cesu-8 string.
|
*Note*:
|
||||||
*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
- The difference from [jerry_create_string_sz](#jerry_create_string_sz) is that it accepts utf-8 string instead of cesu-8 string.
|
||||||
|
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
||||||
is no longer needed.
|
is no longer needed.
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
|
|
||||||
```c
|
```c
|
||||||
jerry_value_t
|
jerry_value_t
|
||||||
jerry_create_string_sz (const jerry_char_t *str_p,
|
jerry_create_string_sz_from_utf8 (const jerry_char_t *str_p,
|
||||||
jerry_size_t str_size)
|
jerry_size_t str_size)
|
||||||
```
|
```
|
||||||
|
|
||||||
- `str_p` - pointer to string
|
- `str_p` - non-null pointer to string
|
||||||
- `str_size` - size of the string
|
- `str_size` - size of the string
|
||||||
- return value - value of the created string
|
- return value - value of the created string
|
||||||
|
|
||||||
@@ -4679,6 +4845,65 @@ main (void)
|
|||||||
- [jerry_delete_property](#jerry_delete_property)
|
- [jerry_delete_property](#jerry_delete_property)
|
||||||
|
|
||||||
|
|
||||||
|
## jerry_has_internal_property
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Checks whether the object has the given internal property.
|
||||||
|
|
||||||
|
*Note*:
|
||||||
|
- Properties which were not created with [jerry_set_internal_property](#jerry_set_internal_property) are excluded
|
||||||
|
during the operation.
|
||||||
|
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
||||||
|
is no longer needed.
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
bool
|
||||||
|
jerry_has_internal_property (const jerry_value_t obj_val,
|
||||||
|
const jerry_value_t prop_name_val);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `obj_val` - object value
|
||||||
|
- `prop_name_val` - property name
|
||||||
|
- return value
|
||||||
|
- true, if the property exists
|
||||||
|
- false, otherwise
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
[doctest]: # ()
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include "jerryscript.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
jerry_value_t global_object = jerry_get_global_object ();
|
||||||
|
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property");
|
||||||
|
|
||||||
|
bool has_internal_js_prop = jerry_has_internal_property (global_object, prop_name);
|
||||||
|
|
||||||
|
jerry_release_value (prop_name);
|
||||||
|
jerry_release_value (global_object);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_delete_internal_property](#jerry_delete_internal_property)
|
||||||
|
- [jerry_get_internal_property](#jerry_get_internal_property)
|
||||||
|
- [jerry_set_internal_property](#jerry_set_internal_property)
|
||||||
|
|
||||||
|
|
||||||
## jerry_delete_property
|
## jerry_delete_property
|
||||||
|
|
||||||
**Summary**
|
**Summary**
|
||||||
@@ -4768,6 +4993,52 @@ jerry_delete_property_by_index (const jerry_value_t obj_val,
|
|||||||
- [jerry_get_property_by_index](#jerry_get_property_by_index)
|
- [jerry_get_property_by_index](#jerry_get_property_by_index)
|
||||||
- [jerry_set_property_by_index](#jerry_set_property_by_index)
|
- [jerry_set_property_by_index](#jerry_set_property_by_index)
|
||||||
|
|
||||||
|
## jerry_delete_internal_property
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Delete an internal property from an object.
|
||||||
|
|
||||||
|
*Note*: Properties which were not created with [jerry_set_internal_property](#jerry_set_internal_property) are excluded
|
||||||
|
during the operation.
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
bool
|
||||||
|
jerry_delete_internal_property (const jerry_value_t obj_val,
|
||||||
|
const jerry_value_t prop_name_val);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `obj_val` - object value
|
||||||
|
- `prop_name_val` - property name
|
||||||
|
- return value
|
||||||
|
- true, if property was deleted successfully
|
||||||
|
- false, otherwise
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
```c
|
||||||
|
{
|
||||||
|
jerry_value_t global_object = jerry_get_global_object ();
|
||||||
|
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property");
|
||||||
|
|
||||||
|
bool delete_result = jerry_delete_internal_property (global_object, prop_name);
|
||||||
|
/* use "delete_result" */
|
||||||
|
|
||||||
|
jerry_release_value (prop_name);
|
||||||
|
jerry_release_value (global_object);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_has_internal_property](#jerry_has_internal_property)
|
||||||
|
- [jerry_get_internal_property](#jerry_get_internal_property)
|
||||||
|
- [jerry_set_internal_property](#jerry_set_internal_property)
|
||||||
|
|
||||||
|
|
||||||
## jerry_get_property
|
## jerry_get_property
|
||||||
|
|
||||||
@@ -4880,6 +5151,68 @@ jerry_get_property_by_index (const jerry_value_t obj_val,
|
|||||||
- [jerry_set_property](#jerry_set_property)
|
- [jerry_set_property](#jerry_set_property)
|
||||||
- [jerry_set_property_by_index](#jerry_set_property_by_index)
|
- [jerry_set_property_by_index](#jerry_set_property_by_index)
|
||||||
|
|
||||||
|
## jerry_get_internal_property
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Get value of an internal property to the specified object with the given name.
|
||||||
|
|
||||||
|
*Note*:
|
||||||
|
- Properties which were not created with [jerry_set_internal_property](#jerry_set_internal_property) are excluded
|
||||||
|
during the operation.
|
||||||
|
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
||||||
|
is no longer needed.
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
jerry_value_t
|
||||||
|
jerry_get_internal_property (const jerry_value_t obj_val,
|
||||||
|
const jerry_value_t prop_name_val);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `obj_val` - object value
|
||||||
|
- `prop_name_val` - property name
|
||||||
|
- return value
|
||||||
|
- value of property, if the internal property exists
|
||||||
|
- undefined value, if the, if the internal does not property exists
|
||||||
|
- thrown error, otherwise
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
[doctest]: # ()
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include "jerryscript.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
jerry_value_t global_object = jerry_get_global_object ();
|
||||||
|
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property");
|
||||||
|
|
||||||
|
jerry_value_t prop_value = jerry_get_internal_property (global_object, prop_name);
|
||||||
|
|
||||||
|
/* use "prop_value" then release it. */
|
||||||
|
|
||||||
|
jerry_release_value (prop_value);
|
||||||
|
jerry_release_value (prop_name);
|
||||||
|
jerry_release_value (global_object);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_has_internal_property](#jerry_has_internal_property)
|
||||||
|
- [jerry_delete_internal_property](#jerry_delete_internal_property)
|
||||||
|
- [jerry_set_internal_property](#jerry_set_internal_property)
|
||||||
|
|
||||||
|
|
||||||
## jerry_set_property
|
## jerry_set_property
|
||||||
|
|
||||||
@@ -4997,6 +5330,70 @@ jerry_set_property_by_index (const jerry_value_t obj_val,
|
|||||||
- [jerry_get_property_by_index](#jerry_get_property_by_index)
|
- [jerry_get_property_by_index](#jerry_get_property_by_index)
|
||||||
|
|
||||||
|
|
||||||
|
## jerry_set_internal_property
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Set an internal property to the specified object with the given name.
|
||||||
|
|
||||||
|
*Note*:
|
||||||
|
- The property cannot be accessed from the JavaScript context, only from the public API.
|
||||||
|
- It is different from [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) in that any jerry API value
|
||||||
|
can be hidden from the JavaScript context, not only native pointers.
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
bool
|
||||||
|
jerry_set_internal_property (const jerry_value_t obj_val,
|
||||||
|
const jerry_value_t prop_name_val,
|
||||||
|
const jerry_value_t value_to_set)
|
||||||
|
```
|
||||||
|
|
||||||
|
- `obj_val` - object value
|
||||||
|
- `prop_name_val` - property name
|
||||||
|
- `value_to_set` - value to set
|
||||||
|
- return value
|
||||||
|
- true, if success
|
||||||
|
- thrown error, otherwise
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
[doctest]: # ()
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include "jerryscript.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
jerry_value_t global_object = jerry_get_global_object ();
|
||||||
|
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property");
|
||||||
|
jerry_value_t value_to_set = jerry_create_number (5);
|
||||||
|
|
||||||
|
bool set_result = jerry_set_internal_property (global_object, prop_name, value_to_set);
|
||||||
|
|
||||||
|
/* check the result of internal property set call */
|
||||||
|
|
||||||
|
jerry_release_value (value_to_set);
|
||||||
|
jerry_release_value (prop_name);
|
||||||
|
jerry_release_value (global_object);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_has_internal_property](#jerry_has_internal_property)
|
||||||
|
- [jerry_delete_internal_property](#jerry_delete_internal_property)
|
||||||
|
- [jerry_get_internal_property](#jerry_get_internal_property)
|
||||||
|
|
||||||
|
|
||||||
## jerry_init_property_descriptor_fields
|
## jerry_init_property_descriptor_fields
|
||||||
|
|
||||||
**Summary**
|
**Summary**
|
||||||
@@ -5541,7 +5938,8 @@ jerry_set_prototype (const jerry_value_t obj_val,
|
|||||||
**Summary**
|
**Summary**
|
||||||
|
|
||||||
Get native pointer by the given type information.
|
Get native pointer by the given type information.
|
||||||
The pointer and the type information are previously associated with the object by jerry_set_object_native_pointer.
|
The pointer and the type information are previously associated with the object by
|
||||||
|
[jerry_set_object_native_pointer](#jerry_set_object_native_pointer).
|
||||||
|
|
||||||
*Note*: `out_native_pointer_p` can be NULL, and it means the
|
*Note*: `out_native_pointer_p` can be NULL, and it means the
|
||||||
caller doesn't want to get the native_pointer.
|
caller doesn't want to get the native_pointer.
|
||||||
@@ -5748,15 +6146,18 @@ main (void)
|
|||||||
**Summary**
|
**Summary**
|
||||||
|
|
||||||
Set native pointer and an optional type information for the specified object.
|
Set native pointer and an optional type information for the specified object.
|
||||||
You can get them by calling jerry_get_object_native_pointer later.
|
You can get them by calling [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) later.
|
||||||
|
|
||||||
*Note*: If native pointer was already set for the object, its value is updated.
|
*Notes*:
|
||||||
|
- If a native pointer was already set for the object with the same type information, its value is updated.
|
||||||
|
- If a non-NULL free callback is specified in the native type information,
|
||||||
|
it will be called by the garbage collector when the object is freed.
|
||||||
|
- If the object is only referenced via the "global" object (or one of it's "child"),
|
||||||
|
the free callback will be invoked during the execution of `jerry_cleanup`.
|
||||||
|
- The free callback can invoke API functions.
|
||||||
|
|
||||||
*Note*: If a non-NULL free callback is specified in the native type information,
|
*Note*: If possible do not store API values in native pointers, rather check
|
||||||
it will be called by the garbage collector when the object is freed.
|
[jerry_set_internal_property](#jerry_set_internal_property).
|
||||||
This callback **must not** invoke API functions.
|
|
||||||
The type info always overwrites the previous value, so passing
|
|
||||||
a NULL value deletes the current type info.
|
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
|
|
||||||
@@ -5791,10 +6192,12 @@ best-practice example.
|
|||||||
**Summary**
|
**Summary**
|
||||||
|
|
||||||
Delete the native pointer of the specified object associated with the given native type info.
|
Delete the native pointer of the specified object associated with the given native type info.
|
||||||
You can get them by calling jerry_get_object_native_pointer later.
|
|
||||||
|
|
||||||
*Note*:
|
*Notes*:
|
||||||
- If the specified object has no matching native pointer for the given native type info the operation has no effect.
|
- If the specified object has no matching native pointer for the given native type info the operation has no effect.
|
||||||
|
- The method does not invoke the free callback specified in the type info.
|
||||||
|
If the native pointer should be freed then one must get the native pointer first and invoke the free callback manually
|
||||||
|
before calling this method.
|
||||||
- This operation cannot throw an exception.
|
- This operation cannot throw an exception.
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
@@ -6424,7 +6827,7 @@ jerry_create_context (uint32_t heap_size,
|
|||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
[doctest]: # (test="compile")
|
[doctest]: # (test="compile", name="02.API-REFERENCE-create-context.c")
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -7162,6 +7565,239 @@ main (void)
|
|||||||
- [jerry_create_external_function](#jerry_create_external_function)
|
- [jerry_create_external_function](#jerry_create_external_function)
|
||||||
|
|
||||||
|
|
||||||
|
## jerry_get_resource_name
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Get the resource name (usually a file name) of the currently executed script or the given function object.
|
||||||
|
|
||||||
|
This function is typically called from native callbacks.
|
||||||
|
|
||||||
|
*Notes*:
|
||||||
|
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
||||||
|
is no longer needed.
|
||||||
|
- This feature depends on build option (`JERRY_LINE_INFO`) and can be checked
|
||||||
|
in runtime with the `JERRY_FEATURE_LINE_INFO` feature enum value,
|
||||||
|
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
jerry_value_t
|
||||||
|
jerry_get_resource_name (jerry_value_t value);
|
||||||
|
```
|
||||||
|
- `value` - api value to obtain the resource name from
|
||||||
|
- return string value constructed from
|
||||||
|
- the currently executed function object's resource name, if the given value is undefined
|
||||||
|
- resource name of the function object, if the given value is a function object
|
||||||
|
- "<anonymous>", otherwise
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
[doctest]: # (name="02.API-REFERENCE-jsresourcename.c")
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "jerryscript.h"
|
||||||
|
|
||||||
|
static jerry_value_t
|
||||||
|
resource_name_handler (const jerry_value_t function_obj,
|
||||||
|
const jerry_value_t this_val,
|
||||||
|
const jerry_value_t args_p[],
|
||||||
|
const jerry_length_t args_count)
|
||||||
|
{
|
||||||
|
jerry_value_t undefined_value = jerry_create_undefined ();
|
||||||
|
jerry_value_t resource_name = jerry_get_resource_name (args_count > 0 ? args_p[0] : undefined_value);
|
||||||
|
jerry_release_value (undefined_value);
|
||||||
|
|
||||||
|
return resource_name;
|
||||||
|
} /* resource_name_handler */
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
jerry_value_t global = jerry_get_global_object ();
|
||||||
|
|
||||||
|
/* Register the "resourceName" method. */
|
||||||
|
{
|
||||||
|
jerry_value_t func = jerry_create_external_function (resource_name_handler);
|
||||||
|
jerry_value_t name = jerry_create_string ((const jerry_char_t *) "resourceName");
|
||||||
|
jerry_value_t result = jerry_set_property (global, name, func);
|
||||||
|
jerry_release_value (result);
|
||||||
|
jerry_release_value (name);
|
||||||
|
jerry_release_value (func);
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_release_value (global);
|
||||||
|
|
||||||
|
const jerry_char_t source[] = "function myFunction() { return resourceName() }; myFunction()";
|
||||||
|
const jerry_char_t resource[] = "demo.js";
|
||||||
|
|
||||||
|
jerry_value_t program = jerry_parse (resource,
|
||||||
|
sizeof (resource) - 1,
|
||||||
|
source,
|
||||||
|
sizeof (source) - 1,
|
||||||
|
JERRY_PARSE_NO_OPTS);
|
||||||
|
|
||||||
|
if (!jerry_value_is_error (program))
|
||||||
|
{
|
||||||
|
/* `run_result` contains "demo.js" */
|
||||||
|
jerry_value_t run_result = jerry_run (program);
|
||||||
|
|
||||||
|
/* usage of `run_result` */
|
||||||
|
|
||||||
|
jerry_release_value (run_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_release_value (program);
|
||||||
|
jerry_cleanup ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_create_external_function](#jerry_create_external_function)
|
||||||
|
|
||||||
|
## jerry_get_new_target
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Returns the current "new.target" JavaScript function at the call site.
|
||||||
|
|
||||||
|
If used outside of a native C function it will return "undefined" value.
|
||||||
|
|
||||||
|
*Notes*:
|
||||||
|
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
|
||||||
|
is no longer needed.
|
||||||
|
- This feature depends on build option (`JERRY_ES2015`) and can be checked
|
||||||
|
in runtime with the `JERRY_FEATURE_SYMBOL` feature enum value (as symbols are enabled in case of ES2015),
|
||||||
|
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
|
||||||
|
- If the ES2015 mode is not enabled this method will always return the "undefined" value.
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
jerry_value_t
|
||||||
|
jerry_get_new_target (void);
|
||||||
|
```
|
||||||
|
- return
|
||||||
|
- "undefined" - if at the call site it was not a constructor call.
|
||||||
|
- function object - if the current call site is in a constructor call.
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example 1**
|
||||||
|
|
||||||
|
[doctest]: # (name="02.API-REFERENCE-jsnewtarget-01.c")
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <jerryscript.h>
|
||||||
|
|
||||||
|
static jerry_value_t
|
||||||
|
demo_handler (const jerry_value_t func_obj_val,
|
||||||
|
const jerry_value_t this_val,
|
||||||
|
const jerry_value_t args_p[],
|
||||||
|
const jerry_length_t args_cnt)
|
||||||
|
{
|
||||||
|
jerry_value_t new_target = jerry_get_new_target ();
|
||||||
|
|
||||||
|
/* new_target is the "demo" JS function object */
|
||||||
|
if (jerry_value_get_type (new_target) == JERRY_TYPE_FUNCTION)
|
||||||
|
{
|
||||||
|
printf ("This is a construct call\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_release_value (new_target);
|
||||||
|
|
||||||
|
return jerry_create_undefined ();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char** argv)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
jerry_value_t function_val = jerry_create_external_function (demo_handler);
|
||||||
|
|
||||||
|
jerry_value_t ret_val = jerry_construct_object (function_val, NULL, 0);
|
||||||
|
|
||||||
|
jerry_release_value (ret_val);
|
||||||
|
jerry_release_value (function_val);
|
||||||
|
|
||||||
|
jerry_cleanup ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example 2**
|
||||||
|
|
||||||
|
[doctest]: # (name="02.API-REFERENCE-jsnewtarget-02.c")
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <jerryscript.h>
|
||||||
|
|
||||||
|
static jerry_value_t
|
||||||
|
demo_handler (const jerry_value_t func_obj_val,
|
||||||
|
const jerry_value_t this_val,
|
||||||
|
const jerry_value_t args_p[],
|
||||||
|
const jerry_length_t args_cnt)
|
||||||
|
{
|
||||||
|
jerry_value_t new_target = jerry_get_new_target ();
|
||||||
|
|
||||||
|
/* new_target is a JS function object */
|
||||||
|
if (jerry_value_get_type (new_target) == JERRY_TYPE_FUNCTION)
|
||||||
|
{
|
||||||
|
printf ("This is a construct call\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_release_value (new_target);
|
||||||
|
|
||||||
|
return jerry_create_undefined ();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char** argv)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
/* register C method */
|
||||||
|
jerry_value_t global_obj_val = jerry_get_global_object ();
|
||||||
|
jerry_value_t function_val = jerry_create_external_function (demo_handler);
|
||||||
|
jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) "demo");
|
||||||
|
jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val);
|
||||||
|
jerry_release_value (result_val);
|
||||||
|
jerry_release_value (function_name_val);
|
||||||
|
jerry_release_value (function_val);
|
||||||
|
jerry_release_value (global_obj_val);
|
||||||
|
|
||||||
|
/* Invoke C method via JS */
|
||||||
|
const char *src = "new demo ()";
|
||||||
|
jerry_value_t ret_val = jerry_eval ((const jerry_char_t *) src,
|
||||||
|
strlen (src),
|
||||||
|
JERRY_PARSE_NO_OPTS);
|
||||||
|
|
||||||
|
jerry_release_value (ret_val);
|
||||||
|
|
||||||
|
jerry_cleanup ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_construct_object](#jerry_construct_object)
|
||||||
|
|
||||||
# ArrayBuffer and TypedArray functions
|
# ArrayBuffer and TypedArray functions
|
||||||
|
|
||||||
These APIs all depend on the ES2015-subset profile.
|
These APIs all depend on the ES2015-subset profile.
|
||||||
@@ -7390,6 +8026,89 @@ jerry_get_arraybuffer_pointer (const jerry_value_t value);
|
|||||||
|
|
||||||
- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external)
|
- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external)
|
||||||
|
|
||||||
|
## jerry_is_arraybuffer_detachable
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Get if the ArrayBuffer is detachable.
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
jerry_value_t
|
||||||
|
jerry_is_arraybuffer_detachable (const jerry_value_t value);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `value` - ArrayBuffer to be detached
|
||||||
|
- return
|
||||||
|
- boolean value if success
|
||||||
|
- Error otherwise
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
```c
|
||||||
|
{
|
||||||
|
// create the ArrayBuffer
|
||||||
|
jerry_value_t buffer = jerry_create_arraybuffer (16);
|
||||||
|
|
||||||
|
jerry_value_t res = jerry_is_arraybuffer_detachable (buffer);
|
||||||
|
bool is_detachable = jerry_get_boolean_value (res);
|
||||||
|
|
||||||
|
// release buffer as it is not needed after this point
|
||||||
|
jerry_release_value (res);
|
||||||
|
jerry_release_value (buffer);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_detach_arraybuffer](#jerry_detach_arraybuffer)
|
||||||
|
|
||||||
|
## jerry_detach_arraybuffer
|
||||||
|
|
||||||
|
**Summary**
|
||||||
|
|
||||||
|
Detach the underlying data block from ArrayBuffer and set its bytelength to 0.
|
||||||
|
|
||||||
|
This operation requires the ArrayBuffer to be external that created by
|
||||||
|
`jerry_create_arraybuffer_external`.
|
||||||
|
|
||||||
|
**Prototype**
|
||||||
|
|
||||||
|
```c
|
||||||
|
jerry_value_t
|
||||||
|
jerry_detach_arraybuffer (const jerry_value_t value);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `value` - ArrayBuffer to be detached
|
||||||
|
- return
|
||||||
|
- null value if success
|
||||||
|
- Error otherwise
|
||||||
|
|
||||||
|
*New in version 2.2*.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
```c
|
||||||
|
{
|
||||||
|
uint8_t buf[1];
|
||||||
|
jerry_size_t length = 1;
|
||||||
|
// create the ArrayBuffer
|
||||||
|
jerry_value_t buffer = jerry_create_arraybuffer (length, buf, NULL);
|
||||||
|
|
||||||
|
jerry_value_t res = jerry_detach_arraybuffer (buffer);
|
||||||
|
|
||||||
|
// release buffer as it is not needed after this point
|
||||||
|
jerry_release_value (res);
|
||||||
|
jerry_release_value (buffer);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**See also**
|
||||||
|
|
||||||
|
- [jerry_is_arraybuffer_detachable](#jerry_is_arraybuffer_detachable)
|
||||||
|
|
||||||
## jerry_get_dataview_buffer
|
## jerry_get_dataview_buffer
|
||||||
|
|
||||||
|
|||||||
+24
-11
@@ -634,14 +634,21 @@ print_value (const jerry_value_t jsvalue)
|
|||||||
/* String value */
|
/* String value */
|
||||||
else if (jerry_value_is_string (value))
|
else if (jerry_value_is_string (value))
|
||||||
{
|
{
|
||||||
|
jerry_char_t str_buf_p[256];
|
||||||
|
|
||||||
/* Determining required buffer size */
|
/* Determining required buffer size */
|
||||||
jerry_size_t req_sz = jerry_get_string_size (value);
|
jerry_size_t req_sz = jerry_get_string_size (value);
|
||||||
jerry_char_t str_buf_p[req_sz + 1];
|
|
||||||
|
|
||||||
jerry_string_to_char_buffer (value, str_buf_p, req_sz);
|
if (req_sz <= 255)
|
||||||
str_buf_p[req_sz] = '\0';
|
{
|
||||||
|
jerry_string_to_char_buffer (value, str_buf_p, req_sz);
|
||||||
printf ("%s", (const char *) str_buf_p);
|
str_buf_p[req_sz] = '\0';
|
||||||
|
printf ("%s", (const char *) str_buf_p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("error: buffer isn't big enough");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Object reference */
|
/* Object reference */
|
||||||
else if (jerry_value_is_object (value))
|
else if (jerry_value_is_object (value))
|
||||||
@@ -721,14 +728,21 @@ print_value (const jerry_value_t jsvalue)
|
|||||||
/* String value */
|
/* String value */
|
||||||
else if (jerry_value_is_string (value))
|
else if (jerry_value_is_string (value))
|
||||||
{
|
{
|
||||||
|
jerry_char_t str_buf_p[256];
|
||||||
|
|
||||||
/* Determining required buffer size */
|
/* Determining required buffer size */
|
||||||
jerry_size_t req_sz = jerry_get_string_size (value);
|
jerry_size_t req_sz = jerry_get_string_size (value);
|
||||||
jerry_char_t str_buf_p[req_sz + 1];
|
|
||||||
|
|
||||||
jerry_string_to_char_buffer (value, str_buf_p, req_sz);
|
if (req_sz <= 255)
|
||||||
str_buf_p[req_sz] = '\0';
|
{
|
||||||
|
jerry_string_to_char_buffer (value, str_buf_p, req_sz);
|
||||||
printf ("%s", (const char *) str_buf_p);
|
str_buf_p[req_sz] = '\0';
|
||||||
|
printf ("%s", (const char *) str_buf_p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("error: buffer isn't big enough");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Object reference */
|
/* Object reference */
|
||||||
else if (jerry_value_is_object (value))
|
else if (jerry_value_is_object (value))
|
||||||
@@ -737,7 +751,6 @@ print_value (const jerry_value_t jsvalue)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
|
||||||
jerry_release_value (value);
|
jerry_release_value (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-3
@@ -83,10 +83,14 @@ information.
|
|||||||
void jerry_port_print_char (char c);
|
void jerry_port_print_char (char c);
|
||||||
```
|
```
|
||||||
|
|
||||||
### ES2015 Module system helper functions
|
### ES2015 Module system
|
||||||
|
|
||||||
The module system requires two specific functions for opening and closing files.
|
The port API provides functions that can be used by the module system to open
|
||||||
It also requires a platform specific way of normalizing file paths.
|
and close source files, and normalize file paths.
|
||||||
|
The `jerry_port_get_native_module` port function can be used to provide native
|
||||||
|
modules to the engine. This function will be called when an import/export
|
||||||
|
statement is encountered with an unknown module specifier, which embedders can
|
||||||
|
use to supply native module objects based on the module name argument.
|
||||||
|
|
||||||
```c
|
```c
|
||||||
/**
|
/**
|
||||||
@@ -126,6 +130,25 @@ jerry_port_normalize_path (const char *in_path_p, /**< input file path */
|
|||||||
// write to out_buf_p the normalized path
|
// write to out_buf_p the normalized path
|
||||||
// return length of written path
|
// return length of written path
|
||||||
} /* jerry_port_normalize_path */
|
} /* jerry_port_normalize_path */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the module object of a native module.
|
||||||
|
*
|
||||||
|
* Note:
|
||||||
|
* This port function is called by jerry-core when ES2015_MODULE_SYSTEM
|
||||||
|
* is enabled.
|
||||||
|
*
|
||||||
|
* @param name String value of the module specifier.
|
||||||
|
*
|
||||||
|
* @return Undefined, if 'name' is not a native module
|
||||||
|
* jerry_value_t containing the module object, otherwise
|
||||||
|
*/
|
||||||
|
jerry_value_t
|
||||||
|
jerry_port_get_native_module (jerry_value_t name) /**< module specifier */
|
||||||
|
{
|
||||||
|
(void) name;
|
||||||
|
return jerry_create_undefined ();
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Date
|
## Date
|
||||||
|
|||||||
+3
-1
@@ -310,8 +310,10 @@ wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resource nam
|
|||||||
size_t resource_name_size, /**< size of resource name */
|
size_t resource_name_size, /**< size of resource name */
|
||||||
const jerry_char_t *source_p, /**< source code */
|
const jerry_char_t *source_p, /**< source code */
|
||||||
size_t source_size, /**< source code size */
|
size_t source_size, /**< source code size */
|
||||||
void *user_p __attribute__((unused))) /**< user pointer */
|
void *user_p /**< user pointer */)
|
||||||
{
|
{
|
||||||
|
(void) user_p;
|
||||||
|
|
||||||
jerry_value_t ret_val = jerry_parse (resource_name_p,
|
jerry_value_t ret_val = jerry_parse (resource_name_p,
|
||||||
resource_name_size,
|
resource_name_size,
|
||||||
source_p,
|
source_p,
|
||||||
|
|||||||
@@ -421,6 +421,9 @@ For example usage see [jerryx_set_properties](#jerryx_set_properties).
|
|||||||
|
|
||||||
Hard assert for scripts. The routine calls `jerry_port_fatal` on assertion failure.
|
Hard assert for scripts. The routine calls `jerry_port_fatal` on assertion failure.
|
||||||
|
|
||||||
|
If the `JERRY_FEATURE_LINE_INFO` runtime feature is enabled (build option: `JERRY_LINE_INFO`)
|
||||||
|
a backtrace is also printed out.
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
|
|
||||||
```c
|
```c
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using the `__cleanup__` variable attribute. For other compilers, no support has
|
|||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
[doctest]: # (test="compile")
|
[doctest]: # (test="compile", name="11.EXT-REFERENCE-AUTORELEASE.c")
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#include "jerryscript.h"
|
#include "jerryscript.h"
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ resolved using the native JerryScript module resolver `jerryx_module_native_reso
|
|||||||
`jerryx_module_resolve()`. Native modules are registered during application startup and by calling `dlopen()` by means
|
`jerryx_module_resolve()`. Native modules are registered during application startup and by calling `dlopen()` by means
|
||||||
of library constructors, support for which can be turned on using the `FEATURE_INIT_FINI` build flag. In the absence of
|
of library constructors, support for which can be turned on using the `FEATURE_INIT_FINI` build flag. In the absence of
|
||||||
such a flag, the module registration and unregistration functions are exposed as global symbols which can be called
|
such a flag, the module registration and unregistration functions are exposed as global symbols which can be called
|
||||||
explicitly.
|
explicitly. Note: `FEATURE_INIT_FINI` build flag isn't supported on Windows, because Microsoft Visual C/C++ Compiler
|
||||||
|
doesn't support library constructors and destructors.
|
||||||
|
|
||||||
## jerryx_module_resolve
|
## jerryx_module_resolve
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
The module system allows users to write import and export statements in scripts, which can be used to separate the logic of the application into custom modules.
|
The module system allows users to write import and export statements in scripts, which can be used to separate the logic of the application into custom modules.
|
||||||
The standard's relevant part can be found [here](https://www.ecma-international.org/ecma-262/6.0/#sec-modules).
|
The standard's relevant part can be found [here](https://www.ecma-international.org/ecma-262/6.0/#sec-modules).
|
||||||
|
Embedders wishing to use native builtin modules with ES6 imports can use the [Port API](05.PORT-API.md#es2015-module-system) to do so.
|
||||||
|
|
||||||
## General
|
## General
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ set(JERRY_SYSTEM_ALLOCATOR OFF CACHE BOOL "Enable system allocato
|
|||||||
set(JERRY_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
|
set(JERRY_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
|
||||||
set(JERRY_VM_EXEC_STOP OFF CACHE BOOL "Enable VM execution stopping?")
|
set(JERRY_VM_EXEC_STOP OFF CACHE BOOL "Enable VM execution stopping?")
|
||||||
set(JERRY_GLOBAL_HEAP_SIZE "(512)" CACHE STRING "Size of memory heap, in kilobytes")
|
set(JERRY_GLOBAL_HEAP_SIZE "(512)" CACHE STRING "Size of memory heap, in kilobytes")
|
||||||
|
set(JERRY_GC_LIMIT "(0)" CACHE STRING "Heap usage limit to trigger garbage collection")
|
||||||
set(JERRY_STACK_LIMIT "(0)" CACHE STRING "Maximum stack usage size, in kilobytes")
|
set(JERRY_STACK_LIMIT "(0)" CACHE STRING "Maximum stack usage size, in kilobytes")
|
||||||
|
set(JERRY_GC_MARK_LIMIT "(8)" CACHE STRING "Maximum depth of recursion during GC mark phase")
|
||||||
|
|
||||||
# Option overrides
|
# Option overrides
|
||||||
if(USING_MSVC)
|
if(USING_MSVC)
|
||||||
@@ -101,7 +103,9 @@ message(STATUS "JERRY_SYSTEM_ALLOCATOR " ${JERRY_SYSTEM_ALLOCATOR})
|
|||||||
message(STATUS "JERRY_VALGRIND " ${JERRY_VALGRIND})
|
message(STATUS "JERRY_VALGRIND " ${JERRY_VALGRIND})
|
||||||
message(STATUS "JERRY_VM_EXEC_STOP " ${JERRY_VM_EXEC_STOP})
|
message(STATUS "JERRY_VM_EXEC_STOP " ${JERRY_VM_EXEC_STOP})
|
||||||
message(STATUS "JERRY_GLOBAL_HEAP_SIZE " ${JERRY_GLOBAL_HEAP_SIZE})
|
message(STATUS "JERRY_GLOBAL_HEAP_SIZE " ${JERRY_GLOBAL_HEAP_SIZE})
|
||||||
|
message(STATUS "JERRY_GC_LIMIT " ${JERRY_GC_LIMIT})
|
||||||
message(STATUS "JERRY_STACK_LIMIT " ${JERRY_STACK_LIMIT})
|
message(STATUS "JERRY_STACK_LIMIT " ${JERRY_STACK_LIMIT})
|
||||||
|
message(STATUS "JERRY_GC_MARK_LIMIT " ${JERRY_GC_MARK_LIMIT})
|
||||||
|
|
||||||
# Include directories
|
# Include directories
|
||||||
set(INCLUDE_CORE_PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
set(INCLUDE_CORE_PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
@@ -204,6 +208,11 @@ if(DEFINED JERRY_ATTR_GLOBAL_HEAP)
|
|||||||
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ATTR_GLOBAL_HEAP=${JERRY_ATTR_GLOBAL_HEAP})
|
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ATTR_GLOBAL_HEAP=${JERRY_ATTR_GLOBAL_HEAP})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Memory usage limit for triggering garbage collection
|
||||||
|
if(JERRY_GC_LIMIT)
|
||||||
|
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_GC_LIMIT=${JERRY_GC_LIMIT})
|
||||||
|
endif()
|
||||||
|
|
||||||
# Helper macro to set 0/1 switch as Jerry Defines
|
# Helper macro to set 0/1 switch as Jerry Defines
|
||||||
macro(jerry_add_define01 NAME)
|
macro(jerry_add_define01 NAME)
|
||||||
if(${NAME})
|
if(${NAME})
|
||||||
@@ -298,6 +307,9 @@ set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_GLOBAL_HEAP_SIZE=${JERRY_GLOBAL_HEAP_SI
|
|||||||
# Maximum size of stack memory usage
|
# Maximum size of stack memory usage
|
||||||
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_STACK_LIMIT=${JERRY_STACK_LIMIT})
|
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_STACK_LIMIT=${JERRY_STACK_LIMIT})
|
||||||
|
|
||||||
|
# Maximum depth of recursion during GC mark phase
|
||||||
|
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_GC_MARK_LIMIT=${JERRY_GC_MARK_LIMIT})
|
||||||
|
|
||||||
## This function is to read "config.h" for default values
|
## This function is to read "config.h" for default values
|
||||||
function(read_set_defines FILE PREFIX OUTPUTVAR)
|
function(read_set_defines FILE PREFIX OUTPUTVAR)
|
||||||
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}" INPUT_FILE_CONTENTS)
|
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}" INPUT_FILE_CONTENTS)
|
||||||
@@ -388,6 +400,11 @@ target_include_directories(${JERRY_CORE_NAME} PRIVATE ${INCLUDE_CORE_PRIVATE})
|
|||||||
|
|
||||||
set(JERRY_CORE_PKGCONFIG_REQUIRES)
|
set(JERRY_CORE_PKGCONFIG_REQUIRES)
|
||||||
set(JERRY_CORE_PKGCONFIG_LIBS)
|
set(JERRY_CORE_PKGCONFIG_LIBS)
|
||||||
|
set(JERRY_CORE_PKGCONFIG_CFLAGS)
|
||||||
|
|
||||||
|
if(ENABLE_LTO)
|
||||||
|
set(JERRY_CORE_PKGCONFIG_CFLAGS "${JERRY_CORE_PKGCONFIG_CFLAGS} -flto")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(JERRY_LIBM)
|
if(JERRY_LIBM)
|
||||||
target_link_libraries(${JERRY_CORE_NAME} jerry-libm)
|
target_link_libraries(${JERRY_CORE_NAME} jerry-libm)
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ snapshot_get_global_flags (bool has_regex, /**< regex literal is present */
|
|||||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||||
flags |= (has_regex ? JERRY_SNAPSHOT_HAS_REGEX_LITERAL : 0);
|
flags |= (has_regex ? JERRY_SNAPSHOT_HAS_REGEX_LITERAL : 0);
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||||
#if ENABLED (JERRY_ES2015_CLASS)
|
#if ENABLED (JERRY_ES2015)
|
||||||
flags |= (has_class ? JERRY_SNAPSHOT_HAS_CLASS_LITERAL : 0);
|
flags |= (has_class ? JERRY_SNAPSHOT_HAS_CLASS_LITERAL : 0);
|
||||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
} /* snapshot_get_global_flags */
|
} /* snapshot_get_global_flags */
|
||||||
@@ -63,9 +63,9 @@ snapshot_check_global_flags (uint32_t global_flags) /**< global flags */
|
|||||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||||
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_REGEX_LITERAL;
|
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_REGEX_LITERAL;
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||||
#if ENABLED (JERRY_ES2015_CLASS)
|
#if ENABLED (JERRY_ES2015)
|
||||||
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_CLASS_LITERAL;
|
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_CLASS_LITERAL;
|
||||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
return global_flags == snapshot_get_global_flags (false, false);
|
return global_flags == snapshot_get_global_flags (false, false);
|
||||||
} /* snapshot_check_global_flags */
|
} /* snapshot_check_global_flags */
|
||||||
@@ -160,12 +160,19 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
|
|||||||
uint8_t *copied_code_start_p = snapshot_buffer_p + globals_p->snapshot_buffer_write_offset;
|
uint8_t *copied_code_start_p = snapshot_buffer_p + globals_p->snapshot_buffer_write_offset;
|
||||||
ecma_compiled_code_t *copied_code_p = (ecma_compiled_code_t *) copied_code_start_p;
|
ecma_compiled_code_t *copied_code_p = (ecma_compiled_code_t *) copied_code_start_p;
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_CLASS)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (compiled_code_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS)
|
||||||
|
{
|
||||||
|
const char * const error_message_p = "Unsupported feature: tagged template literals.";
|
||||||
|
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
|
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
|
||||||
{
|
{
|
||||||
globals_p->class_found = true;
|
globals_p->class_found = true;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||||
if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FUNCTION))
|
if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FUNCTION))
|
||||||
@@ -179,7 +186,7 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
|
|||||||
|
|
||||||
globals_p->snapshot_buffer_write_offset += sizeof (ecma_compiled_code_t);
|
globals_p->snapshot_buffer_write_offset += sizeof (ecma_compiled_code_t);
|
||||||
|
|
||||||
ecma_value_t pattern = ((re_compiled_code_t *) compiled_code_p)->pattern;
|
ecma_value_t pattern = ((re_compiled_code_t *) compiled_code_p)->source;
|
||||||
ecma_string_t *pattern_string_p = ecma_get_string_from_value (pattern);
|
ecma_string_t *pattern_string_p = ecma_get_string_from_value (pattern);
|
||||||
|
|
||||||
ecma_length_t pattern_size = 0;
|
ecma_length_t pattern_size = 0;
|
||||||
@@ -292,10 +299,11 @@ static_snapshot_error_unsupported_literal (snapshot_globals_t *globals_p, /**< s
|
|||||||
|
|
||||||
ecma_string_t *error_message_p = ecma_new_ecma_string_from_utf8 (error_prefix, sizeof (error_prefix) - 1);
|
ecma_string_t *error_message_p = ecma_new_ecma_string_from_utf8 (error_prefix, sizeof (error_prefix) - 1);
|
||||||
|
|
||||||
literal = ecma_op_to_string (literal);
|
|
||||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (literal));
|
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (literal));
|
||||||
|
|
||||||
ecma_string_t *literal_string_p = ecma_get_string_from_value (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);
|
error_message_p = ecma_concat_ecma_strings (error_message_p, literal_string_p);
|
||||||
ecma_deref_ecma_string (literal_string_p);
|
ecma_deref_ecma_string (literal_string_p);
|
||||||
|
|
||||||
@@ -416,7 +424,7 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (compiled_code_p))
|
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
buffer_p += ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG;
|
buffer_p += ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG;
|
||||||
literal_start_p = ((ecma_value_t *) buffer_p) - argument_end;
|
literal_start_p = ((ecma_value_t *) buffer_p) - argument_end;
|
||||||
@@ -488,7 +496,7 @@ jerry_snapshot_set_offsets (uint32_t *buffer_p, /**< buffer */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (bytecode_p))
|
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||||
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
||||||
@@ -581,7 +589,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
|||||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) byte_p;
|
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) byte_p;
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (bytecode_p))
|
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
argument_end = args_p->argument_end;
|
argument_end = args_p->argument_end;
|
||||||
}
|
}
|
||||||
@@ -595,7 +603,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
|||||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) byte_p;
|
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) byte_p;
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (bytecode_p))
|
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
argument_end = args_p->argument_end;
|
argument_end = args_p->argument_end;
|
||||||
}
|
}
|
||||||
@@ -738,9 +746,9 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
|||||||
JERRY_UNUSED (resource_name_p);
|
JERRY_UNUSED (resource_name_p);
|
||||||
JERRY_UNUSED (resource_name_length);
|
JERRY_UNUSED (resource_name_length);
|
||||||
|
|
||||||
#if ENABLED (JERRY_LINE_INFO)
|
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||||
JERRY_CONTEXT (resource_name) = ECMA_VALUE_UNDEFINED;
|
JERRY_CONTEXT (resource_name) = ECMA_VALUE_UNDEFINED;
|
||||||
#endif /* ENABLED (JERRY_LINE_INFO) */
|
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||||
|
|
||||||
snapshot_globals_t globals;
|
snapshot_globals_t globals;
|
||||||
ecma_value_t parse_status;
|
ecma_value_t parse_status;
|
||||||
@@ -762,7 +770,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
|||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (parse_status))
|
if (ECMA_IS_VALUE_ERROR (parse_status))
|
||||||
{
|
{
|
||||||
return ecma_create_error_reference (JERRY_CONTEXT (error_value), true);
|
return ecma_create_error_reference_from_context ();
|
||||||
}
|
}
|
||||||
|
|
||||||
JERRY_ASSERT (bytecode_data_p != NULL);
|
JERRY_ASSERT (bytecode_data_p != NULL);
|
||||||
@@ -795,7 +803,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
|||||||
|
|
||||||
if (!(generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STATIC))
|
if (!(generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STATIC))
|
||||||
{
|
{
|
||||||
ecma_collection_header_t *lit_pool_p = ecma_new_values_collection ();
|
ecma_collection_t *lit_pool_p = ecma_new_collection ();
|
||||||
|
|
||||||
ecma_save_literals_add_compiled_code (bytecode_data_p, lit_pool_p);
|
ecma_save_literals_add_compiled_code (bytecode_data_p, lit_pool_p);
|
||||||
|
|
||||||
@@ -982,8 +990,7 @@ jerry_snapshot_result (const uint32_t *snapshot_p, /**< snapshot */
|
|||||||
if (as_function)
|
if (as_function)
|
||||||
{
|
{
|
||||||
ecma_object_t *lex_env_p = ecma_get_global_environment ();
|
ecma_object_t *lex_env_p = ecma_get_global_environment ();
|
||||||
ecma_object_t *func_obj_p = ecma_op_create_function_object (lex_env_p,
|
ecma_object_t *func_obj_p = ecma_op_create_simple_function_object (lex_env_p, bytecode_p);
|
||||||
bytecode_p);
|
|
||||||
|
|
||||||
if (!(bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
if (!(bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
||||||
{
|
{
|
||||||
@@ -1048,7 +1055,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
|
|||||||
static void
|
static void
|
||||||
scan_snapshot_functions (const uint8_t *buffer_p, /**< snapshot buffer start */
|
scan_snapshot_functions (const uint8_t *buffer_p, /**< snapshot buffer start */
|
||||||
const uint8_t *buffer_end_p, /**< snapshot buffer end */
|
const uint8_t *buffer_end_p, /**< snapshot buffer end */
|
||||||
ecma_collection_header_t *lit_pool_p, /**< list of known values */
|
ecma_collection_t *lit_pool_p, /**< list of known values */
|
||||||
const uint8_t *literal_base_p) /**< start of literal data */
|
const uint8_t *literal_base_p) /**< start of literal data */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (buffer_end_p > buffer_p);
|
JERRY_ASSERT (buffer_end_p > buffer_p);
|
||||||
@@ -1091,7 +1098,7 @@ scan_snapshot_functions (const uint8_t *buffer_p, /**< snapshot buffer start */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (bytecode_p))
|
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||||
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
||||||
@@ -1169,7 +1176,7 @@ update_literal_offsets (uint8_t *buffer_p, /**< [in,out] snapshot buffer start *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (bytecode_p))
|
if (bytecode_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||||
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
byte_p += ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG;
|
||||||
@@ -1225,14 +1232,14 @@ jerry_merge_snapshots (const uint32_t **inp_buffers_p, /**< array of (pointers t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_collection_header_t *lit_pool_p = ecma_new_values_collection ();
|
ecma_collection_t *lit_pool_p = ecma_new_collection ();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < number_of_snapshots; i++)
|
for (uint32_t i = 0; i < number_of_snapshots; i++)
|
||||||
{
|
{
|
||||||
if (inp_buffer_sizes_p[i] < sizeof (jerry_snapshot_header_t))
|
if (inp_buffer_sizes_p[i] < sizeof (jerry_snapshot_header_t))
|
||||||
{
|
{
|
||||||
*error_p = "invalid snapshot file";
|
*error_p = "invalid snapshot file";
|
||||||
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_destroy (lit_pool_p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1243,7 +1250,7 @@ jerry_merge_snapshots (const uint32_t **inp_buffers_p, /**< array of (pointers t
|
|||||||
|| !snapshot_check_global_flags (header_p->global_flags))
|
|| !snapshot_check_global_flags (header_p->global_flags))
|
||||||
{
|
{
|
||||||
*error_p = "invalid snapshot version or unsupported features present";
|
*error_p = "invalid snapshot version or unsupported features present";
|
||||||
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_destroy (lit_pool_p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1271,7 +1278,7 @@ jerry_merge_snapshots (const uint32_t **inp_buffers_p, /**< array of (pointers t
|
|||||||
if (functions_size >= out_buffer_size)
|
if (functions_size >= out_buffer_size)
|
||||||
{
|
{
|
||||||
*error_p = "output buffer is too small";
|
*error_p = "output buffer is too small";
|
||||||
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_destroy (lit_pool_p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1543,42 +1550,6 @@ jerry_append_number_to_buffer (uint8_t *buffer_p, /**< buffer */
|
|||||||
utf8_str_size);
|
utf8_str_size);
|
||||||
} /* jerry_append_number_to_buffer */
|
} /* jerry_append_number_to_buffer */
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the passed ecma-string is a valid identifier.
|
|
||||||
*
|
|
||||||
* @return true - if the ecma-string is a valid identifier,
|
|
||||||
* false - otherwise
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
ecma_string_is_valid_identifier (const ecma_string_t *string_p)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
ECMA_STRING_TO_UTF8_STRING (string_p, str_buffer_p, str_buffer_size);
|
|
||||||
|
|
||||||
if (lit_char_is_identifier_start (str_buffer_p))
|
|
||||||
{
|
|
||||||
const uint8_t *str_start_p = str_buffer_p;
|
|
||||||
const uint8_t *str_end_p = str_buffer_p + str_buffer_size;
|
|
||||||
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
while (str_start_p < str_end_p)
|
|
||||||
{
|
|
||||||
if (!lit_char_is_identifier_part (str_start_p))
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lit_utf8_incr (&str_start_p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} /* ecma_string_is_valid_identifier */
|
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
|
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1615,41 +1586,32 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
JERRY_ASSERT ((header_p->lit_table_offset % sizeof (uint32_t)) == 0);
|
JERRY_ASSERT ((header_p->lit_table_offset % sizeof (uint32_t)) == 0);
|
||||||
const uint8_t *literal_base_p = snapshot_data_p + header_p->lit_table_offset;
|
const uint8_t *literal_base_p = snapshot_data_p + header_p->lit_table_offset;
|
||||||
|
|
||||||
ecma_collection_header_t *lit_pool_p = ecma_new_values_collection ();
|
ecma_collection_t *lit_pool_p = ecma_new_collection ();
|
||||||
scan_snapshot_functions (snapshot_data_p + header_p->func_offsets[0],
|
scan_snapshot_functions (snapshot_data_p + header_p->func_offsets[0],
|
||||||
literal_base_p,
|
literal_base_p,
|
||||||
lit_pool_p,
|
lit_pool_p,
|
||||||
literal_base_p);
|
literal_base_p);
|
||||||
|
|
||||||
lit_utf8_size_t literal_count = 0;
|
lit_utf8_size_t literal_count = 0;
|
||||||
ecma_value_t *iterator_p = ecma_collection_iterator_init (lit_pool_p);
|
ecma_value_t *buffer_p = lit_pool_p->buffer_p;
|
||||||
|
|
||||||
/* Count the valid and non-magic identifiers in the list. */
|
/* Count the valid and non-magic identifiers in the list. */
|
||||||
while (iterator_p != NULL)
|
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||||
{
|
{
|
||||||
if (ecma_is_value_string (*iterator_p))
|
if (ecma_is_value_string (buffer_p[i]))
|
||||||
{
|
{
|
||||||
ecma_string_t *literal_p = ecma_get_string_from_value (*iterator_p);
|
ecma_string_t *literal_p = ecma_get_string_from_value (buffer_p[i]);
|
||||||
|
|
||||||
/* NOTE:
|
if (ecma_get_string_magic (literal_p) == LIT_MAGIC_STRING__COUNT)
|
||||||
* We don't save a literal (in C format) which isn't a valid
|
|
||||||
* identifier or it's a magic string.
|
|
||||||
* TODO:
|
|
||||||
* Save all of the literals in C format as well.
|
|
||||||
*/
|
|
||||||
if (ecma_get_string_magic (literal_p) == LIT_MAGIC_STRING__COUNT
|
|
||||||
&& (!is_c_format || ecma_string_is_valid_identifier (literal_p)))
|
|
||||||
{
|
{
|
||||||
literal_count++;
|
literal_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator_p = ecma_collection_iterator_next (iterator_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (literal_count == 0)
|
if (literal_count == 0)
|
||||||
{
|
{
|
||||||
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_destroy (lit_pool_p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1659,31 +1621,23 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
JMEM_DEFINE_LOCAL_ARRAY (literal_array, literal_count, ecma_string_t *);
|
JMEM_DEFINE_LOCAL_ARRAY (literal_array, literal_count, ecma_string_t *);
|
||||||
lit_utf8_size_t literal_idx = 0;
|
lit_utf8_size_t literal_idx = 0;
|
||||||
|
|
||||||
iterator_p = ecma_collection_iterator_init (lit_pool_p);
|
buffer_p = lit_pool_p->buffer_p;
|
||||||
|
|
||||||
while (iterator_p != NULL)
|
/* Count the valid and non-magic identifiers in the list. */
|
||||||
|
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||||
{
|
{
|
||||||
if (ecma_is_value_string (*iterator_p))
|
if (ecma_is_value_string (buffer_p[i]))
|
||||||
{
|
{
|
||||||
ecma_string_t *literal_p = ecma_get_string_from_value (*iterator_p);
|
ecma_string_t *literal_p = ecma_get_string_from_value (buffer_p[i]);
|
||||||
|
|
||||||
/* NOTE:
|
if (ecma_get_string_magic (literal_p) == LIT_MAGIC_STRING__COUNT)
|
||||||
* We don't save a literal (in C format) which isn't a valid
|
|
||||||
* identifier or it's a magic string.
|
|
||||||
* TODO:
|
|
||||||
* Save all of the literals in C format as well.
|
|
||||||
*/
|
|
||||||
if (ecma_get_string_magic (literal_p) == LIT_MAGIC_STRING__COUNT
|
|
||||||
&& (!is_c_format || ecma_string_is_valid_identifier (literal_p)))
|
|
||||||
{
|
{
|
||||||
literal_array[literal_idx++] = literal_p;
|
literal_array[literal_idx++] = literal_p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator_p = ecma_collection_iterator_next (iterator_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_destroy (lit_pool_p);
|
||||||
|
|
||||||
/* Sort the strings by size at first, then lexicographically. */
|
/* Sort the strings by size at first, then lexicographically. */
|
||||||
jerry_save_literals_sort (literal_array, literal_count);
|
jerry_save_literals_sort (literal_array, literal_count);
|
||||||
@@ -1710,7 +1664,29 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
for (lit_utf8_size_t i = 0; i < literal_count; i++)
|
for (lit_utf8_size_t i = 0; i < literal_count; i++)
|
||||||
{
|
{
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, " \"", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, " \"", 0);
|
||||||
lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p, buffer_end_p, literal_array[i]);
|
ECMA_STRING_TO_UTF8_STRING (literal_array[i], str_buffer_p, str_buffer_size);
|
||||||
|
for (lit_utf8_size_t j = 0; j < str_buffer_size; j++)
|
||||||
|
{
|
||||||
|
uint8_t byte = str_buffer_p[j];
|
||||||
|
if (byte < 32 || byte > 127)
|
||||||
|
{
|
||||||
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "\\x", 0);
|
||||||
|
ecma_char_t hex_digit = (ecma_char_t) (byte >> 4);
|
||||||
|
*lit_buf_p++ = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
|
||||||
|
hex_digit = (lit_utf8_byte_t) (byte & 0xf);
|
||||||
|
*lit_buf_p++ = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (byte == '\\' || byte == '"')
|
||||||
|
{
|
||||||
|
*lit_buf_p++ = '\\';
|
||||||
|
}
|
||||||
|
*lit_buf_p++ = byte;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size);
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "\"", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "\"", 0);
|
||||||
|
|
||||||
if (i < literal_count - 1)
|
if (i < literal_count - 1)
|
||||||
@@ -1782,7 +1758,6 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
|
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
|
||||||
} /* jerry_get_literals_from_snapshot */
|
} /* jerry_get_literals_from_snapshot */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate snapshot function from specified source and arguments
|
* Generate snapshot function from specified source and arguments
|
||||||
*
|
*
|
||||||
|
|||||||
+644
-116
File diff suppressed because it is too large
Load Diff
+57
-81
@@ -79,18 +79,10 @@
|
|||||||
# define JERRY_ES2015 1
|
# define JERRY_ES2015 1
|
||||||
#endif /* !defined (JERRY_ES2015) */
|
#endif /* !defined (JERRY_ES2015) */
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_BUILTIN
|
|
||||||
# define JERRY_ES2015_BUILTIN JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_BUILTIN_DATAVIEW
|
#ifndef JERRY_ES2015_BUILTIN_DATAVIEW
|
||||||
# define JERRY_ES2015_BUILTIN_DATAVIEW JERRY_ES2015
|
# define JERRY_ES2015_BUILTIN_DATAVIEW JERRY_ES2015
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN_DATAVIEW) */
|
#endif /* !defined (JERRY_ES2015_BUILTIN_DATAVIEW) */
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_BUILTIN_ITERATOR
|
|
||||||
# define JERRY_ES2015_BUILTIN_ITERATOR JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN_ITERATOR) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_BUILTIN_MAP
|
#ifndef JERRY_ES2015_BUILTIN_MAP
|
||||||
# define JERRY_ES2015_BUILTIN_MAP JERRY_ES2015
|
# define JERRY_ES2015_BUILTIN_MAP JERRY_ES2015
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN_MAP) */
|
#endif /* !defined (JERRY_ES2015_BUILTIN_MAP) */
|
||||||
@@ -99,50 +91,30 @@
|
|||||||
# define JERRY_ES2015_BUILTIN_SET JERRY_ES2015
|
# define JERRY_ES2015_BUILTIN_SET JERRY_ES2015
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN_SET) */
|
#endif /* !defined (JERRY_ES2015_BUILTIN_SET) */
|
||||||
|
|
||||||
|
#ifndef JERRY_ES2015_BUILTIN_WEAKMAP
|
||||||
|
# define JERRY_ES2015_BUILTIN_WEAKMAP JERRY_ES2015
|
||||||
|
#endif /* !defined (JERRY_ES2015_BUILTIN_WEAKMAP) */
|
||||||
|
|
||||||
|
#ifndef JERRY_ES2015_BUILTIN_WEAKSET
|
||||||
|
# define JERRY_ES2015_BUILTIN_WEAKSET JERRY_ES2015
|
||||||
|
#endif /* !defined (JERRY_ES2015_BUILTIN_WEAKSET) */
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_BUILTIN_PROMISE
|
#ifndef JERRY_ES2015_BUILTIN_PROMISE
|
||||||
# define JERRY_ES2015_BUILTIN_PROMISE JERRY_ES2015
|
# define JERRY_ES2015_BUILTIN_PROMISE JERRY_ES2015
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN_PROMISE) */
|
#endif /* !defined (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_BUILTIN_SYMBOL
|
#ifndef JERRY_ES2015_BUILTIN_REFLECT
|
||||||
# define JERRY_ES2015_BUILTIN_SYMBOL JERRY_ES2015
|
# define JERRY_ES2015_BUILTIN_REFLECT JERRY_ES2015
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* !defined (JERRY_ES2015_BUILTIN_REFLECT) */
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_BUILTIN_TYPEDARRAY
|
#ifndef JERRY_ES2015_BUILTIN_TYPEDARRAY
|
||||||
# define JERRY_ES2015_BUILTIN_TYPEDARRAY JERRY_ES2015
|
# define JERRY_ES2015_BUILTIN_TYPEDARRAY JERRY_ES2015
|
||||||
#endif /* !defined (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
#endif /* !defined (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_ARROW_FUNCTION
|
|
||||||
# define JERRY_ES2015_ARROW_FUNCTION JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_ARROW_FUNCTION) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_CLASS
|
|
||||||
# define JERRY_ES2015_CLASS JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_CLASS) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_FOR_OF
|
|
||||||
# define JERRY_ES2015_FOR_OF JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_FOR_OF) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER
|
|
||||||
# define JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_FUNCTION_REST_PARAMETER
|
|
||||||
# define JERRY_ES2015_FUNCTION_REST_PARAMETER JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_FUNCTION_REST_PARAMETER) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_OBJECT_INITIALIZER
|
|
||||||
# define JERRY_ES2015_OBJECT_INITIALIZER JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_OBJECT_INITIALIZER) */
|
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_MODULE_SYSTEM
|
#ifndef JERRY_ES2015_MODULE_SYSTEM
|
||||||
# define JERRY_ES2015_MODULE_SYSTEM JERRY_ES2015
|
# define JERRY_ES2015_MODULE_SYSTEM JERRY_ES2015
|
||||||
#endif /* !defined (JERRY_ES2015_MODULE_SYSTEM) */
|
#endif /* !defined (JERRY_ES2015_MODULE_SYSTEM) */
|
||||||
|
|
||||||
#ifndef JERRY_ES2015_TEMPLATE_STRINGS
|
|
||||||
# define JERRY_ES2015_TEMPLATE_STRINGS JERRY_ES2015
|
|
||||||
#endif /* !defined (JERRY_ES2015_TEMPLATE_STRINGS) */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Engine internal and misc configurations.
|
* Engine internal and misc configurations.
|
||||||
*/
|
*/
|
||||||
@@ -207,6 +179,15 @@
|
|||||||
# define JERRY_GLOBAL_HEAP_SIZE (512)
|
# define JERRY_GLOBAL_HEAP_SIZE (512)
|
||||||
#endif /* !defined (JERRY_GLOBAL_HEAP_SIZE) */
|
#endif /* !defined (JERRY_GLOBAL_HEAP_SIZE) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The allowed heap usage limit until next garbage collection, in bytes.
|
||||||
|
*
|
||||||
|
* If value is 0, the default is 1/32 of JERRY_HEAP_SIZE
|
||||||
|
*/
|
||||||
|
#ifndef JERRY_GC_LIMIT
|
||||||
|
# define JERRY_GC_LIMIT 0
|
||||||
|
#endif /* !defined (JERRY_GC_LIMIT) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum stack usage size in kilobytes
|
* Maximum stack usage size in kilobytes
|
||||||
*
|
*
|
||||||
@@ -220,6 +201,15 @@
|
|||||||
# define JERRY_STACK_LIMIT (0)
|
# define JERRY_STACK_LIMIT (0)
|
||||||
#endif /* !defined (JERRY_STACK_LIMIT) */
|
#endif /* !defined (JERRY_STACK_LIMIT) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum depth of recursion during GC mark phase
|
||||||
|
*
|
||||||
|
* Default value: 8
|
||||||
|
*/
|
||||||
|
#ifndef JERRY_GC_MARK_LIMIT
|
||||||
|
# define JERRY_GC_MARK_LIMIT (8)
|
||||||
|
#endif /* !defined (JERRY_GC_MARK_LIMIT) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable/Disable property lookup cache.
|
* Enable/Disable property lookup cache.
|
||||||
*
|
*
|
||||||
@@ -465,7 +455,6 @@
|
|||||||
# define JERRY_ATTR_GLOBAL_HEAP
|
# define JERRY_ATTR_GLOBAL_HEAP
|
||||||
#endif /* !defined (JERRY_ATTR_GLOBAL_HEAP) */
|
#endif /* !defined (JERRY_ATTR_GLOBAL_HEAP) */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanity check for macros to see if the values are 0 or 1
|
* Sanity check for macros to see if the values are 0 or 1
|
||||||
*
|
*
|
||||||
@@ -526,18 +515,6 @@
|
|||||||
|| ((JERRY_ES2015 != 0) && (JERRY_ES2015 != 1))
|
|| ((JERRY_ES2015 != 0) && (JERRY_ES2015 != 1))
|
||||||
# error "Invalid value for JERRY_ES2015 macro."
|
# error "Invalid value for JERRY_ES2015 macro."
|
||||||
#endif
|
#endif
|
||||||
#if !defined (JERRY_ES2015_ARROW_FUNCTION) \
|
|
||||||
|| ((JERRY_ES2015_ARROW_FUNCTION != 0) && (JERRY_ES2015_ARROW_FUNCTION != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_ARROW_FUNCTION macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_BUILTIN) \
|
|
||||||
|| ((JERRY_ES2015_BUILTIN != 0) && (JERRY_ES2015_BUILTIN != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_BUILTIN_ITERATOR) \
|
|
||||||
|| ((JERRY_ES2015_BUILTIN_ITERATOR != 0) && (JERRY_ES2015_BUILTIN_ITERATOR != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN_ITERATOR macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_BUILTIN_DATAVIEW) \
|
#if !defined (JERRY_ES2015_BUILTIN_DATAVIEW) \
|
||||||
|| ((JERRY_ES2015_BUILTIN_DATAVIEW != 0) && (JERRY_ES2015_BUILTIN_DATAVIEW != 1))
|
|| ((JERRY_ES2015_BUILTIN_DATAVIEW != 0) && (JERRY_ES2015_BUILTIN_DATAVIEW != 1))
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN_DATAVIEW macro."
|
# error "Invalid value for JERRY_ES2015_BUILTIN_DATAVIEW macro."
|
||||||
@@ -546,50 +523,34 @@
|
|||||||
|| ((JERRY_ES2015_BUILTIN_MAP != 0) && (JERRY_ES2015_BUILTIN_MAP != 1))
|
|| ((JERRY_ES2015_BUILTIN_MAP != 0) && (JERRY_ES2015_BUILTIN_MAP != 1))
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN_MAP macro."
|
# error "Invalid value for JERRY_ES2015_BUILTIN_MAP macro."
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined (JERRY_ES2015_BUILTIN_REFLECT) \
|
||||||
|
|| ((JERRY_ES2015_BUILTIN_REFLECT != 0) && (JERRY_ES2015_BUILTIN_REFLECT != 1))
|
||||||
|
# error "Invalid value for JERRY_ES2015_BUILTIN_REFLECT macro."
|
||||||
|
#endif
|
||||||
#if !defined (JERRY_ES2015_BUILTIN_SET) \
|
#if !defined (JERRY_ES2015_BUILTIN_SET) \
|
||||||
|| ((JERRY_ES2015_BUILTIN_SET != 0) && (JERRY_ES2015_BUILTIN_SET != 1))
|
|| ((JERRY_ES2015_BUILTIN_SET != 0) && (JERRY_ES2015_BUILTIN_SET != 1))
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN_SET macro."
|
# error "Invalid value for JERRY_ES2015_BUILTIN_SET macro."
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined (JERRY_ES2015_BUILTIN_WEAKMAP) \
|
||||||
|
|| ((JERRY_ES2015_BUILTIN_WEAKMAP != 0) && (JERRY_ES2015_BUILTIN_WEAKMAP != 1))
|
||||||
|
# error "Invalid value for JERRY_ES2015_BUILTIN_WEAKMAP macro."
|
||||||
|
#endif
|
||||||
|
#if !defined (JERRY_ES2015_BUILTIN_WEAKSET) \
|
||||||
|
|| ((JERRY_ES2015_BUILTIN_WEAKSET != 0) && (JERRY_ES2015_BUILTIN_WEAKSET != 1))
|
||||||
|
# error "Invalid value for JERRY_ES2015_BUILTIN_WEAKSET macro."
|
||||||
|
#endif
|
||||||
#if !defined (JERRY_ES2015_BUILTIN_PROMISE) \
|
#if !defined (JERRY_ES2015_BUILTIN_PROMISE) \
|
||||||
|| ((JERRY_ES2015_BUILTIN_PROMISE != 0) && (JERRY_ES2015_BUILTIN_PROMISE != 1))
|
|| ((JERRY_ES2015_BUILTIN_PROMISE != 0) && (JERRY_ES2015_BUILTIN_PROMISE != 1))
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN_PROMISE macro."
|
# error "Invalid value for JERRY_ES2015_BUILTIN_PROMISE macro."
|
||||||
#endif
|
#endif
|
||||||
#if !defined (JERRY_ES2015_BUILTIN_SYMBOL) \
|
|
||||||
|| ((JERRY_ES2015_BUILTIN_SYMBOL != 0) && (JERRY_ES2015_BUILTIN_SYMBOL != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN_SYMBOL macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_BUILTIN_TYPEDARRAY) \
|
#if !defined (JERRY_ES2015_BUILTIN_TYPEDARRAY) \
|
||||||
|| ((JERRY_ES2015_BUILTIN_TYPEDARRAY != 0) && (JERRY_ES2015_BUILTIN_TYPEDARRAY != 1))
|
|| ((JERRY_ES2015_BUILTIN_TYPEDARRAY != 0) && (JERRY_ES2015_BUILTIN_TYPEDARRAY != 1))
|
||||||
# error "Invalid value for JERRY_ES2015_BUILTIN_TYPEDARRAY macro."
|
# error "Invalid value for JERRY_ES2015_BUILTIN_TYPEDARRAY macro."
|
||||||
#endif
|
#endif
|
||||||
#if !defined (JERRY_ES2015_CLASS) \
|
|
||||||
|| ((JERRY_ES2015_CLASS != 0) && (JERRY_ES2015_CLASS != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_CLASS macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_FOR_OF) \
|
|
||||||
|| ((JERRY_ES2015_FOR_OF != 0) && (JERRY_ES2015_FOR_OF != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_FOR_OF macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER) \
|
|
||||||
|| ((JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER != 0) && (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_FUNCTION_REST_PARAMETER) \
|
|
||||||
|| ((JERRY_ES2015_FUNCTION_REST_PARAMETER != 0) && (JERRY_ES2015_FUNCTION_REST_PARAMETER != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_FUNCTION_REST_PARAMETER macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_OBJECT_INITIALIZER) \
|
|
||||||
|| ((JERRY_ES2015_OBJECT_INITIALIZER != 0) && (JERRY_ES2015_OBJECT_INITIALIZER != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_OBJECT_INITIALIZER macro."
|
|
||||||
#endif
|
|
||||||
#if !defined (JERRY_ES2015_MODULE_SYSTEM) \
|
#if !defined (JERRY_ES2015_MODULE_SYSTEM) \
|
||||||
|| ((JERRY_ES2015_MODULE_SYSTEM != 0) && (JERRY_ES2015_MODULE_SYSTEM != 1))
|
|| ((JERRY_ES2015_MODULE_SYSTEM != 0) && (JERRY_ES2015_MODULE_SYSTEM != 1))
|
||||||
# error "Invalid value for JERRY_ES2015_MODULE_SYSTEM macro."
|
# error "Invalid value for JERRY_ES2015_MODULE_SYSTEM macro."
|
||||||
#endif
|
#endif
|
||||||
#if !defined (JERRY_ES2015_TEMPLATE_STRINGS) \
|
|
||||||
|| ((JERRY_ES2015_TEMPLATE_STRINGS != 0) && (JERRY_ES2015_TEMPLATE_STRINGS != 1))
|
|
||||||
# error "Invalid value for JERRY_ES2015_TEMPLATE_STRINGS macro."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal options.
|
* Internal options.
|
||||||
@@ -613,9 +574,15 @@
|
|||||||
#if !defined (JERRY_GLOBAL_HEAP_SIZE) || (JERRY_GLOBAL_HEAP_SIZE <= 0)
|
#if !defined (JERRY_GLOBAL_HEAP_SIZE) || (JERRY_GLOBAL_HEAP_SIZE <= 0)
|
||||||
# error "Invalid value for 'JERRY_GLOBAL_HEAP_SIZE' macro."
|
# error "Invalid value for 'JERRY_GLOBAL_HEAP_SIZE' macro."
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined (JERRY_GC_LIMIT) || (JERRY_GC_LIMIT < 0)
|
||||||
|
# error "Invalid value for 'JERRY_GC_LIMIT' macro."
|
||||||
|
#endif
|
||||||
#if !defined (JERRY_STACK_LIMIT) || (JERRY_STACK_LIMIT < 0)
|
#if !defined (JERRY_STACK_LIMIT) || (JERRY_STACK_LIMIT < 0)
|
||||||
# error "Invalid value for 'JERRY_STACK_LIMIT' macro."
|
# error "Invalid value for 'JERRY_STACK_LIMIT' macro."
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined (JERRY_GC_MARK_LIMIT) || (JERRY_GC_MARK_LIMIT < 0)
|
||||||
|
# error "Invalid value for 'JERRY_GC_MARK_LIMIT' macro."
|
||||||
|
#endif
|
||||||
#if !defined (JERRY_LCACHE) \
|
#if !defined (JERRY_LCACHE) \
|
||||||
|| ((JERRY_LCACHE != 0) && (JERRY_LCACHE != 1))
|
|| ((JERRY_LCACHE != 0) && (JERRY_LCACHE != 1))
|
||||||
# error "Invalid value for 'JERRY_LCACHE' macro."
|
# error "Invalid value for 'JERRY_LCACHE' macro."
|
||||||
@@ -685,7 +652,6 @@
|
|||||||
# error "Invalid value for 'JERRY_VM_EXEC_STOP' macro."
|
# error "Invalid value for 'JERRY_VM_EXEC_STOP' macro."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define ENABLED(FEATURE) ((FEATURE) == 1)
|
#define ENABLED(FEATURE) ((FEATURE) == 1)
|
||||||
#define DISABLED(FEATURE) ((FEATURE) != 1)
|
#define DISABLED(FEATURE) ((FEATURE) != 1)
|
||||||
|
|
||||||
@@ -700,4 +666,14 @@
|
|||||||
# error "Date does not support float32"
|
# error "Date does not support float32"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap container types into a single guard
|
||||||
|
*/
|
||||||
|
#if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET) \
|
||||||
|
|| ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP) || ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||||
|
# define JERRY_ES2015_BUILTIN_CONTAINER 1
|
||||||
|
#else
|
||||||
|
# define JERRY_ES2015_BUILTIN_CONTAINER 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !JERRYSCRIPT_CONFIG_H */
|
#endif /* !JERRYSCRIPT_CONFIG_H */
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "byte-code.h"
|
#include "byte-code.h"
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
|
#include "ecma-array-object.h"
|
||||||
#include "ecma-builtin-helpers.h"
|
#include "ecma-builtin-helpers.h"
|
||||||
#include "ecma-conversion.h"
|
#include "ecma-conversion.h"
|
||||||
#include "ecma-eval.h"
|
#include "ecma-eval.h"
|
||||||
@@ -234,7 +235,7 @@ jerry_debugger_send_scope_chain (void)
|
|||||||
|
|
||||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||||
{
|
{
|
||||||
if ((lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_NON_CLOSURE) != 0)
|
if ((lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) != 0)
|
||||||
{
|
{
|
||||||
message_type_p->string[buffer_pos++] = JERRY_DEBUGGER_SCOPE_NON_CLOSURE;
|
message_type_p->string[buffer_pos++] = JERRY_DEBUGGER_SCOPE_NON_CLOSURE;
|
||||||
}
|
}
|
||||||
@@ -250,7 +251,7 @@ jerry_debugger_send_scope_chain (void)
|
|||||||
}
|
}
|
||||||
else if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND)
|
else if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND)
|
||||||
{
|
{
|
||||||
if (ecma_get_lex_env_outer_reference (lex_env_p) == NULL)
|
if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL)
|
||||||
{
|
{
|
||||||
message_type_p->string[buffer_pos++] = JERRY_DEBUGGER_SCOPE_GLOBAL;
|
message_type_p->string[buffer_pos++] = JERRY_DEBUGGER_SCOPE_GLOBAL;
|
||||||
break;
|
break;
|
||||||
@@ -261,7 +262,8 @@ jerry_debugger_send_scope_chain (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lex_env_p = ecma_get_lex_env_outer_reference (lex_env_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
message_type_p->type = JERRY_DEBUGGER_SCOPE_CHAIN_END;
|
message_type_p->type = JERRY_DEBUGGER_SCOPE_CHAIN_END;
|
||||||
@@ -302,7 +304,7 @@ jerry_debugger_get_variable_type (ecma_value_t value) /**< input ecma value */
|
|||||||
{
|
{
|
||||||
JERRY_ASSERT (ecma_is_value_object (value));
|
JERRY_ASSERT (ecma_is_value_object (value));
|
||||||
|
|
||||||
if (ecma_object_get_class_name (ecma_get_object_from_value (value)) == LIT_MAGIC_STRING_ARRAY_UL)
|
if (ecma_get_object_type (ecma_get_object_from_value (value)) == ECMA_OBJECT_TYPE_ARRAY)
|
||||||
{
|
{
|
||||||
ret_value = JERRY_DEBUGGER_VALUE_ARRAY;
|
ret_value = JERRY_DEBUGGER_VALUE_ARRAY;
|
||||||
}
|
}
|
||||||
@@ -430,14 +432,14 @@ jerry_debugger_send_scope_variables (const uint8_t *recv_buffer_p) /**< pointer
|
|||||||
|
|
||||||
while (chain_index != 0)
|
while (chain_index != 0)
|
||||||
{
|
{
|
||||||
lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p);
|
if (JERRY_UNLIKELY (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL))
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (lex_env_p == NULL))
|
|
||||||
{
|
{
|
||||||
jerry_debugger_send_type (JERRY_DEBUGGER_SCOPE_VARIABLES_END);
|
jerry_debugger_send_type (JERRY_DEBUGGER_SCOPE_VARIABLES_END);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp);
|
||||||
|
|
||||||
if ((ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND)
|
if ((ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND)
|
||||||
|| (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE))
|
|| (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE))
|
||||||
{
|
{
|
||||||
@@ -445,17 +447,23 @@ jerry_debugger_send_scope_variables (const uint8_t *recv_buffer_p) /**< pointer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_property_header_t *prop_iter_p;
|
jmem_cpointer_t prop_iter_cp;
|
||||||
|
|
||||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||||
{
|
{
|
||||||
prop_iter_p = ecma_get_property_list (lex_env_p);
|
prop_iter_cp = lex_env_p->u1.property_list_cp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
|
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
|
||||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||||
prop_iter_p = ecma_get_property_list (binding_obj_p);
|
|
||||||
|
if (JERRY_UNLIKELY (ecma_op_object_is_fast_array (binding_obj_p)))
|
||||||
|
{
|
||||||
|
ecma_fast_array_convert_to_normal (binding_obj_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_iter_cp = binding_obj_p->u1.property_list_cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_string_t, message_string_p);
|
JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_string_t, message_string_p);
|
||||||
@@ -463,8 +471,9 @@ jerry_debugger_send_scope_variables (const uint8_t *recv_buffer_p) /**< pointer
|
|||||||
|
|
||||||
size_t buffer_pos = 0;
|
size_t buffer_pos = 0;
|
||||||
|
|
||||||
while (prop_iter_p != NULL)
|
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));
|
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||||
|
|
||||||
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
||||||
@@ -494,27 +503,26 @@ jerry_debugger_send_scope_variables (const uint8_t *recv_buffer_p) /**< pointer
|
|||||||
ecma_deref_ecma_string (prop_name);
|
ecma_deref_ecma_string (prop_name);
|
||||||
|
|
||||||
ecma_property_value_t prop_value_p = prop_pair_p->values[i];
|
ecma_property_value_t prop_value_p = prop_pair_p->values[i];
|
||||||
ecma_value_t property_value;
|
|
||||||
|
|
||||||
uint8_t variable_type = jerry_debugger_get_variable_type (prop_value_p.value);
|
uint8_t variable_type = jerry_debugger_get_variable_type (prop_value_p.value);
|
||||||
|
|
||||||
property_value = ecma_op_to_string (prop_value_p.value);
|
ecma_string_t *str_p = ecma_op_to_string (prop_value_p.value);
|
||||||
|
JERRY_ASSERT (str_p != NULL);
|
||||||
|
|
||||||
if (!jerry_debugger_copy_variables_to_string_message (variable_type,
|
if (!jerry_debugger_copy_variables_to_string_message (variable_type,
|
||||||
ecma_get_string_from_value (property_value),
|
str_p,
|
||||||
message_string_p,
|
message_string_p,
|
||||||
&buffer_pos))
|
&buffer_pos))
|
||||||
{
|
{
|
||||||
ecma_free_value (property_value);
|
ecma_deref_ecma_string (str_p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_value (property_value);
|
ecma_deref_ecma_string (str_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t,
|
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||||
prop_iter_p->next_property_cp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message_string_p->type = JERRY_DEBUGGER_SCOPE_VARIABLES_END;
|
message_string_p->type = JERRY_DEBUGGER_SCOPE_VARIABLES_END;
|
||||||
@@ -547,28 +555,23 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
|
|||||||
{
|
{
|
||||||
if (eval_string_p[4] != JERRY_DEBUGGER_EVAL_EVAL)
|
if (eval_string_p[4] != JERRY_DEBUGGER_EVAL_EVAL)
|
||||||
{
|
{
|
||||||
|
JERRY_ASSERT (eval_string_p[4] == JERRY_DEBUGGER_EVAL_THROW || eval_string_p[4] == JERRY_DEBUGGER_EVAL_ABORT);
|
||||||
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_EXCEPTION_THROWN);
|
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_EXCEPTION_THROWN);
|
||||||
JERRY_CONTEXT (error_value) = result;
|
|
||||||
|
|
||||||
/* Stop where the error is caught. */
|
/* Stop where the error is caught. */
|
||||||
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_STOP);
|
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_STOP);
|
||||||
JERRY_CONTEXT (debugger_stop_context) = NULL;
|
JERRY_CONTEXT (debugger_stop_context) = NULL;
|
||||||
|
|
||||||
if (eval_string_p[4] == JERRY_DEBUGGER_EVAL_THROW)
|
jcontext_raise_exception (result);
|
||||||
{
|
jcontext_set_abort_flag (eval_string_p[4] == JERRY_DEBUGGER_EVAL_ABORT);
|
||||||
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_EXCEPTION;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_EXCEPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ecma_is_value_string (result))
|
if (!ecma_is_value_string (result))
|
||||||
{
|
{
|
||||||
ecma_value_t to_string_value = ecma_op_to_string (result);
|
ecma_string_t *str_p = ecma_op_to_string (result);
|
||||||
|
ecma_value_t to_string_value = ecma_make_string_value (str_p);
|
||||||
ecma_free_value (result);
|
ecma_free_value (result);
|
||||||
result = to_string_value;
|
result = to_string_value;
|
||||||
}
|
}
|
||||||
@@ -605,8 +608,10 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Primitive type. */
|
/* Primitive type. */
|
||||||
message = ecma_op_to_string (result);
|
ecma_string_t *str_p = ecma_op_to_string (result);
|
||||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (message));
|
JERRY_ASSERT (str_p != NULL);
|
||||||
|
|
||||||
|
message = ecma_make_string_value (str_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_value (result);
|
ecma_free_value (result);
|
||||||
@@ -1145,7 +1150,6 @@ jerry_debugger_receive (jerry_debugger_uint8_data_t **message_data_p) /**< [out]
|
|||||||
}
|
}
|
||||||
} /* jerry_debugger_receive */
|
} /* jerry_debugger_receive */
|
||||||
|
|
||||||
|
|
||||||
#undef JERRY_DEBUGGER_CHECK_PACKET_SIZE
|
#undef JERRY_DEBUGGER_CHECK_PACKET_SIZE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1209,7 +1213,6 @@ jerry_debugger_send_type (jerry_debugger_header_type_t type) /**< message type *
|
|||||||
jerry_debugger_send (sizeof (jerry_debugger_send_type_t));
|
jerry_debugger_send (sizeof (jerry_debugger_send_type_t));
|
||||||
} /* jerry_debugger_send_type */
|
} /* jerry_debugger_send_type */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the type signal to the client.
|
* Send the type signal to the client.
|
||||||
*
|
*
|
||||||
@@ -1409,10 +1412,16 @@ jerry_debugger_exception_object_to_string (ecma_value_t exception_obj_value) /**
|
|||||||
{
|
{
|
||||||
ecma_object_t *object_p = ecma_get_object_from_value (exception_obj_value);
|
ecma_object_t *object_p = ecma_get_object_from_value (exception_obj_value);
|
||||||
|
|
||||||
ecma_object_t *prototype_p = ecma_get_object_prototype (object_p);
|
jmem_cpointer_t prototype_cp = object_p->u2.prototype_cp;
|
||||||
|
|
||||||
if (prototype_p == NULL
|
if (prototype_cp == JMEM_CP_NULL)
|
||||||
|| ecma_get_object_type (prototype_p) != ECMA_OBJECT_TYPE_GENERAL
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, prototype_cp);
|
||||||
|
|
||||||
|
if (ecma_get_object_type (prototype_p) != ECMA_OBJECT_TYPE_GENERAL
|
||||||
|| !ecma_get_object_is_builtin (prototype_p))
|
|| !ecma_get_object_is_builtin (prototype_p))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1502,12 +1511,11 @@ jerry_debugger_exception_object_to_string (ecma_value_t exception_obj_value) /**
|
|||||||
* false - otherwise
|
* false - otherwise
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
jerry_debugger_send_exception_string (void)
|
jerry_debugger_send_exception_string (ecma_value_t exception_value)
|
||||||
{
|
{
|
||||||
|
JERRY_ASSERT (jcontext_has_pending_exception ());
|
||||||
ecma_string_t *string_p = NULL;
|
ecma_string_t *string_p = NULL;
|
||||||
|
|
||||||
ecma_value_t exception_value = JERRY_CONTEXT (error_value);
|
|
||||||
|
|
||||||
if (ecma_is_value_object (exception_value))
|
if (ecma_is_value_object (exception_value))
|
||||||
{
|
{
|
||||||
string_p = jerry_debugger_exception_object_to_string (exception_value);
|
string_p = jerry_debugger_exception_object_to_string (exception_value);
|
||||||
@@ -1524,8 +1532,7 @@ jerry_debugger_send_exception_string (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
exception_value = ecma_op_to_string (exception_value);
|
string_p = ecma_op_to_string (exception_value);
|
||||||
string_p = ecma_get_string_from_value (exception_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ECMA_STRING_TO_UTF8_STRING (string_p, string_data_p, string_size);
|
ECMA_STRING_TO_UTF8_STRING (string_p, string_data_p, string_size);
|
||||||
|
|||||||
@@ -484,7 +484,7 @@ bool jerry_debugger_send_string (uint8_t message_type, uint8_t sub_type, const u
|
|||||||
bool jerry_debugger_send_function_cp (jerry_debugger_header_type_t type, ecma_compiled_code_t *compiled_code_p);
|
bool jerry_debugger_send_function_cp (jerry_debugger_header_type_t type, ecma_compiled_code_t *compiled_code_p);
|
||||||
bool jerry_debugger_send_parse_function (uint32_t line, uint32_t column);
|
bool jerry_debugger_send_parse_function (uint32_t line, uint32_t column);
|
||||||
void jerry_debugger_send_memstats (void);
|
void jerry_debugger_send_memstats (void);
|
||||||
bool jerry_debugger_send_exception_string (void);
|
bool jerry_debugger_send_exception_string (ecma_value_t exception_value);
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_DEBUGGER) */
|
#endif /* ENABLED (JERRY_DEBUGGER) */
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ JERRY_STATIC_ASSERT (sizeof (ecma_property_value_t) == sizeof (ecma_value_t),
|
|||||||
JERRY_STATIC_ASSERT (((sizeof (ecma_property_value_t) - 1) & sizeof (ecma_property_value_t)) == 0,
|
JERRY_STATIC_ASSERT (((sizeof (ecma_property_value_t) - 1) & sizeof (ecma_property_value_t)) == 0,
|
||||||
size_of_ecma_property_value_t_must_be_power_of_2);
|
size_of_ecma_property_value_t_must_be_power_of_2);
|
||||||
|
|
||||||
JERRY_STATIC_ASSERT (sizeof (ecma_string_t) == sizeof (uint64_t),
|
|
||||||
size_of_ecma_string_t_must_be_less_than_or_equal_to_8_bytes);
|
|
||||||
|
|
||||||
JERRY_STATIC_ASSERT (sizeof (ecma_extended_object_t) - sizeof (ecma_object_t) <= sizeof (uint64_t),
|
JERRY_STATIC_ASSERT (sizeof (ecma_extended_object_t) - sizeof (ecma_object_t) <= sizeof (uint64_t),
|
||||||
size_of_ecma_extended_object_part_must_be_less_than_or_equal_to_8_bytes);
|
size_of_ecma_extended_object_part_must_be_less_than_or_equal_to_8_bytes);
|
||||||
|
|
||||||
@@ -155,7 +152,35 @@ ecma_dealloc_string (ecma_string_t *string_p) /**< string to be freed */
|
|||||||
} /* ecma_dealloc_string */
|
} /* ecma_dealloc_string */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate memory for string with character data
|
* Allocate memory for extended ecma-string descriptor
|
||||||
|
*
|
||||||
|
* @return pointer to allocated memory
|
||||||
|
*/
|
||||||
|
inline ecma_extended_string_t * JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
ecma_alloc_extended_string (void)
|
||||||
|
{
|
||||||
|
#if ENABLED (JERRY_MEM_STATS)
|
||||||
|
jmem_stats_allocate_string_bytes (sizeof (ecma_extended_string_t));
|
||||||
|
#endif /* ENABLED (JERRY_MEM_STATS) */
|
||||||
|
|
||||||
|
return (ecma_extended_string_t *) jmem_heap_alloc_block (sizeof (ecma_extended_string_t));
|
||||||
|
} /* ecma_alloc_extended_string */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dealloc memory from extended ecma-string descriptor
|
||||||
|
*/
|
||||||
|
inline void JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
ecma_dealloc_extended_string (ecma_extended_string_t *ext_string_p) /**< extended string to be freed */
|
||||||
|
{
|
||||||
|
#if ENABLED (JERRY_MEM_STATS)
|
||||||
|
jmem_stats_free_string_bytes (sizeof (ecma_extended_string_t));
|
||||||
|
#endif /* ENABLED (JERRY_MEM_STATS) */
|
||||||
|
|
||||||
|
jmem_heap_free_block (ext_string_p, sizeof (ecma_extended_string_t));
|
||||||
|
} /* ecma_dealloc_extended_string */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate memory for an string with character data
|
||||||
*
|
*
|
||||||
* @return pointer to allocated memory
|
* @return pointer to allocated memory
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -73,6 +73,18 @@ ecma_string_t *ecma_alloc_string (void);
|
|||||||
*/
|
*/
|
||||||
void ecma_dealloc_string (ecma_string_t *string_p);
|
void ecma_dealloc_string (ecma_string_t *string_p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate memory for extended ecma-string descriptor
|
||||||
|
*
|
||||||
|
* @return pointer to allocated memory
|
||||||
|
*/
|
||||||
|
ecma_extended_string_t *ecma_alloc_extended_string (void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dealloc memory from extended ecma-string descriptor
|
||||||
|
*/
|
||||||
|
void ecma_dealloc_extended_string (ecma_extended_string_t *string_p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate memory for string with character data
|
* Allocate memory for string with character data
|
||||||
*
|
*
|
||||||
|
|||||||
+799
-382
File diff suppressed because it is too large
Load Diff
+409
-143
@@ -62,6 +62,7 @@ typedef enum
|
|||||||
ECMA_STATUS_HIGH_PRESSURE_GC = (1u << 2), /**< last gc was under high pressure */
|
ECMA_STATUS_HIGH_PRESSURE_GC = (1u << 2), /**< last gc was under high pressure */
|
||||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
||||||
ECMA_STATUS_EXCEPTION = (1u << 3), /**< last exception is a normal exception */
|
ECMA_STATUS_EXCEPTION = (1u << 3), /**< last exception is a normal exception */
|
||||||
|
ECMA_STATUS_ABORT = (1u << 4), /**< last exception is an abort */
|
||||||
} ecma_status_flag_t;
|
} ecma_status_flag_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +77,6 @@ typedef enum
|
|||||||
ECMA_TYPE_SYMBOL = 4, /**< pointer to description of a symbol */
|
ECMA_TYPE_SYMBOL = 4, /**< pointer to description of a symbol */
|
||||||
ECMA_TYPE_DIRECT_STRING = 5, /**< directly encoded string values */
|
ECMA_TYPE_DIRECT_STRING = 5, /**< directly encoded string values */
|
||||||
ECMA_TYPE_ERROR = 7, /**< pointer to description of an error reference (only supported by C API) */
|
ECMA_TYPE_ERROR = 7, /**< pointer to description of an error reference (only supported by C API) */
|
||||||
ECMA_TYPE_POINTER = ECMA_TYPE_ERROR, /**< a generic aligned pointer */
|
|
||||||
ECMA_TYPE_SNAPSHOT_OFFSET = ECMA_TYPE_ERROR, /**< offset to a snapshot number/string */
|
ECMA_TYPE_SNAPSHOT_OFFSET = ECMA_TYPE_ERROR, /**< offset to a snapshot number/string */
|
||||||
ECMA_TYPE___MAX = ECMA_TYPE_ERROR /** highest value for ecma types */
|
ECMA_TYPE___MAX = ECMA_TYPE_ERROR /** highest value for ecma types */
|
||||||
} ecma_type_t;
|
} ecma_type_t;
|
||||||
@@ -106,6 +106,9 @@ typedef enum
|
|||||||
ECMA_PARSE_HAS_IMPL_SUPER = (1u << 4), /**< the current context has implicit parent class */
|
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_HAS_STATIC_SUPER = (1u << 5), /**< the current context is a static class method */
|
||||||
ECMA_PARSE_EVAL = (1u << 6), /**< eval is called */
|
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_GENERATOR_FUNCTION = (1u << 9), /**< generator function is parsed */
|
||||||
} ecma_parse_opts_t;
|
} ecma_parse_opts_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -189,6 +192,9 @@ enum
|
|||||||
ECMA_VALUE_REGISTER_REF = ECMA_MAKE_VALUE (8), /**< register reference,
|
ECMA_VALUE_REGISTER_REF = ECMA_MAKE_VALUE (8), /**< register reference,
|
||||||
* a special "base" value for vm */
|
* a special "base" value for vm */
|
||||||
ECMA_VALUE_IMPLICIT_CONSTRUCTOR = ECMA_MAKE_VALUE (9), /**< special value for bound class constructors */
|
ECMA_VALUE_IMPLICIT_CONSTRUCTOR = ECMA_MAKE_VALUE (9), /**< special value for bound class constructors */
|
||||||
|
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 */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||||
@@ -328,9 +334,12 @@ typedef enum
|
|||||||
* that are not indices */
|
* that are not indices */
|
||||||
ECMA_LIST_ENUMERABLE = (1 << 1), /**< exclude non-enumerable properties */
|
ECMA_LIST_ENUMERABLE = (1 << 1), /**< exclude non-enumerable properties */
|
||||||
ECMA_LIST_PROTOTYPE = (1 << 2), /**< list properties from prototype chain */
|
ECMA_LIST_PROTOTYPE = (1 << 2), /**< list properties from prototype chain */
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ECMA_LIST_SYMBOLS = (1 << 3), /**< list symbol properties only */
|
ECMA_LIST_SYMBOLS = (1 << 3), /**< list symbol properties */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
ECMA_LIST_SYMBOLS_ONLY = (1 << 4), /**< list symbol properties only */
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
ECMA_LIST_CONVERT_FAST_ARRAYS = (1 << 5), /**< after listing the properties convert
|
||||||
|
* the fast access mode array back to normal array */
|
||||||
} ecma_list_properties_options_t;
|
} ecma_list_properties_options_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,8 +503,8 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
jmem_cpointer_t getter_p; /**< pointer to getter object */
|
jmem_cpointer_t getter_cp; /**< compressed pointer to getter object */
|
||||||
jmem_cpointer_t setter_p; /**< pointer to setter object */
|
jmem_cpointer_t setter_cp; /**< compressed pointer to setter object */
|
||||||
} ecma_getter_setter_pointers_t;
|
} ecma_getter_setter_pointers_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -564,11 +573,6 @@ typedef struct
|
|||||||
#define ECMA_PROPERTY_VALUE_PTR(property_p) \
|
#define ECMA_PROPERTY_VALUE_PTR(property_p) \
|
||||||
((ecma_property_value_t *) ECMA_PROPERTY_VALUE_DATA_PTR (property_p))
|
((ecma_property_value_t *) ECMA_PROPERTY_VALUE_DATA_PTR (property_p))
|
||||||
|
|
||||||
/**
|
|
||||||
* Depth limit for property search (maximum prototype chain depth).
|
|
||||||
*/
|
|
||||||
#define ECMA_PROPERTY_SEARCH_DEPTH_LIMIT 128
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property reference. It contains the value pointer
|
* Property reference. It contains the value pointer
|
||||||
* for real, and the value itself for virtual properties.
|
* for real, and the value itself for virtual properties.
|
||||||
@@ -606,15 +610,15 @@ typedef enum
|
|||||||
{
|
{
|
||||||
ECMA_OBJECT_TYPE_GENERAL = 0, /**< all objects that are not belongs to the sub-types below. */
|
ECMA_OBJECT_TYPE_GENERAL = 0, /**< all objects that are not belongs to the sub-types below. */
|
||||||
ECMA_OBJECT_TYPE_CLASS = 1, /**< Objects with class property */
|
ECMA_OBJECT_TYPE_CLASS = 1, /**< Objects with class property */
|
||||||
ECMA_OBJECT_TYPE_FUNCTION = 2, /**< Function objects (15.3), created through 13.2 routine */
|
ECMA_OBJECT_TYPE_ARRAY = 2, /**< Array object (15.4) */
|
||||||
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION = 3, /**< External (host) function object */
|
ECMA_OBJECT_TYPE_PSEUDO_ARRAY = 3, /**< Array-like object, such as Arguments object (10.6) */
|
||||||
ECMA_OBJECT_TYPE_ARRAY = 4, /**< Array object (15.4) */
|
/* Note: these 4 types must be in this order. See IsCallable operation. */
|
||||||
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 5, /**< Function objects (15.3), created through 15.3.4.5 routine */
|
ECMA_OBJECT_TYPE_FUNCTION = 4, /**< Function objects (15.3), created through 13.2 routine */
|
||||||
ECMA_OBJECT_TYPE_PSEUDO_ARRAY = 6, /**< Array-like object, such as Arguments object (10.6) */
|
#if ENABLED (JERRY_ES2015)
|
||||||
#if ENABLED (JERRY_ES2015_ARROW_FUNCTION)
|
ECMA_OBJECT_TYPE_ARROW_FUNCTION = 5, /**< arrow function objects */
|
||||||
ECMA_OBJECT_TYPE_ARROW_FUNCTION = 7, /**< arrow function objects */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
#endif /* ENABLED (JERRY_ES2015_ARROW_FUNCTION) */
|
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. */
|
/* Types between 13-15 cannot have a built-in flag. See ecma_lexical_environment_type_t. */
|
||||||
|
|
||||||
ECMA_OBJECT_TYPE__MAX /**< maximum value */
|
ECMA_OBJECT_TYPE__MAX /**< maximum value */
|
||||||
@@ -653,7 +657,8 @@ typedef enum
|
|||||||
ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND /**< maximum value */
|
ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_SUPER_OBJECT_BOUND /**< maximum value */
|
||||||
} ecma_lexical_environment_type_t;
|
} ecma_lexical_environment_type_t;
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Types of array iterators.
|
* Types of array iterators.
|
||||||
*/
|
*/
|
||||||
@@ -662,8 +667,9 @@ typedef enum
|
|||||||
ECMA_ITERATOR_KEYS, /**< List only key indices */
|
ECMA_ITERATOR_KEYS, /**< List only key indices */
|
||||||
ECMA_ITERATOR_VALUES, /**< List only key values */
|
ECMA_ITERATOR_VALUES, /**< List only key values */
|
||||||
ECMA_ITERATOR_KEYS_VALUES, /**< List key indices and values */
|
ECMA_ITERATOR_KEYS_VALUES, /**< List key indices and values */
|
||||||
} ecma_iterator_type_t;
|
} ecma_array_iterator_type_t;
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Offset for JERRY_CONTEXT (status_flags) top 8 bits.
|
* Offset for JERRY_CONTEXT (status_flags) top 8 bits.
|
||||||
@@ -713,19 +719,32 @@ typedef enum
|
|||||||
/**
|
/**
|
||||||
* Non closure flag for debugger.
|
* Non closure flag for debugger.
|
||||||
*/
|
*/
|
||||||
#if ENABLED (JERRY_DEBUGGER)
|
#define ECMA_OBJECT_FLAG_BLOCK ECMA_OBJECT_FLAG_EXTENSIBLE
|
||||||
#define ECMA_OBJECT_FLAG_NON_CLOSURE 0x20
|
|
||||||
#endif /* ENABLED (JERRY_DEBUGGER) */
|
/**
|
||||||
|
* Bitshift index for an ecma-object reference count field
|
||||||
|
*/
|
||||||
|
#define ECMA_OBJECT_REF_SHIFT 6
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitmask for an ecma-object reference count field
|
||||||
|
*/
|
||||||
|
#define ECMA_OBJECT_REF_MASK (((1u << 10) - 1) << ECMA_OBJECT_REF_SHIFT)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value for increasing or decreasing the object reference counter.
|
* Value for increasing or decreasing the object reference counter.
|
||||||
*/
|
*/
|
||||||
#define ECMA_OBJECT_REF_ONE (1u << 6)
|
#define ECMA_OBJECT_REF_ONE (1u << ECMA_OBJECT_REF_SHIFT)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum value of the object reference counter (1023).
|
* Represents non-visited white object
|
||||||
*/
|
*/
|
||||||
#define ECMA_OBJECT_MAX_REF (0x3ffu << 6)
|
#define ECMA_OBJECT_NON_VISITED (0x3ffu << ECMA_OBJECT_REF_SHIFT)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum value of the object reference counter (1022).
|
||||||
|
*/
|
||||||
|
#define ECMA_OBJECT_MAX_REF (ECMA_OBJECT_NON_VISITED - ECMA_OBJECT_REF_ONE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of ECMA-object or lexical environment
|
* Description of ECMA-object or lexical environment
|
||||||
@@ -736,18 +755,27 @@ typedef struct
|
|||||||
/** type : 4 bit : ecma_object_type_t or ecma_lexical_environment_type_t
|
/** type : 4 bit : ecma_object_type_t or ecma_lexical_environment_type_t
|
||||||
depending on ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV
|
depending on ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV
|
||||||
flags : 2 bit : ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV,
|
flags : 2 bit : ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV,
|
||||||
ECMA_OBJECT_FLAG_EXTENSIBLE or ECMA_OBJECT_FLAG_NON_CLOSURE
|
ECMA_OBJECT_FLAG_EXTENSIBLE or ECMA_OBJECT_FLAG_BLOCK
|
||||||
refs : 10 bit (max 1023) */
|
refs : 10 bit (max 1022) */
|
||||||
uint16_t type_flags_refs;
|
uint16_t type_flags_refs;
|
||||||
|
|
||||||
/** next in the object chain maintained by the garbage collector */
|
/** next in the object chain maintained by the garbage collector */
|
||||||
jmem_cpointer_t gc_next_cp;
|
jmem_cpointer_t gc_next_cp;
|
||||||
|
|
||||||
/** compressed pointer to property list or bound object */
|
/** compressed pointer to property list or bound object */
|
||||||
jmem_cpointer_t property_list_or_bound_object_cp;
|
union
|
||||||
|
{
|
||||||
|
jmem_cpointer_t property_list_cp; /**< compressed pointer to object's
|
||||||
|
* or declerative lexical environments's property list */
|
||||||
|
jmem_cpointer_t bound_object_cp; /**< compressed pointer to lexical environments's the bound object */
|
||||||
|
} u1;
|
||||||
|
|
||||||
/** object prototype or outer reference */
|
/** object prototype or outer reference */
|
||||||
jmem_cpointer_t prototype_or_outer_reference_cp;
|
union
|
||||||
|
{
|
||||||
|
jmem_cpointer_t prototype_cp; /**< compressed pointer to the object's prototype */
|
||||||
|
jmem_cpointer_t outer_reference_cp; /**< compressed pointer to the lexical environments's outer reference */
|
||||||
|
} u2;
|
||||||
} ecma_object_t;
|
} ecma_object_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -817,7 +845,13 @@ typedef struct
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t length; /**< length property value */
|
uint32_t length; /**< length property value */
|
||||||
ecma_property_t length_prop; /**< length property */
|
union
|
||||||
|
{
|
||||||
|
ecma_property_t length_prop; /**< length property */
|
||||||
|
uint32_t hole_count; /**< number of array holes in a fast access mode array
|
||||||
|
* multiplied ECMA_FAST_ACCESS_HOLE_ONE */
|
||||||
|
} u;
|
||||||
|
|
||||||
} array;
|
} array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -827,12 +861,12 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint8_t type; /**< pseudo array type, e.g. Arguments, TypedArray, ArrayIterator */
|
uint8_t type; /**< pseudo array type, e.g. Arguments, TypedArray, ArrayIterator */
|
||||||
uint8_t extra_info; /**< extra information about the object.
|
uint8_t extra_info; /**< extra information about the object.
|
||||||
* e.g. element_width_shift for typed arrays,
|
* e.g. the specific builtin id for typed arrays,
|
||||||
* [[IterationKind]] property for %Iterator% */
|
* [[IterationKind]] property for %Iterator% */
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
uint16_t length; /**< for arguments: length of names */
|
uint16_t length; /**< for arguments: length of names */
|
||||||
uint16_t class_id; /**< for typedarray: the specific class name */
|
uint16_t class_id; /**< for typedarray: the specific class name id */
|
||||||
uint16_t iterator_index; /**< for %Iterator%: [[%Iterator%NextIndex]] property */
|
uint16_t iterator_index; /**< for %Iterator%: [[%Iterator%NextIndex]] property */
|
||||||
} u1;
|
} u1;
|
||||||
union
|
union
|
||||||
@@ -840,6 +874,7 @@ typedef struct
|
|||||||
ecma_value_t lex_env_cp; /**< for arguments: lexical environment */
|
ecma_value_t lex_env_cp; /**< for arguments: lexical environment */
|
||||||
ecma_value_t arraybuffer; /**< for typedarray: internal arraybuffer */
|
ecma_value_t arraybuffer; /**< for typedarray: internal arraybuffer */
|
||||||
ecma_value_t iterated_value; /**< for %Iterator%: [[IteratedObject]] property */
|
ecma_value_t iterated_value; /**< for %Iterator%: [[IteratedObject]] property */
|
||||||
|
ecma_value_t spread_value; /**< for spread object: spreaded element */
|
||||||
} u2;
|
} u2;
|
||||||
} pseudo_array;
|
} pseudo_array;
|
||||||
|
|
||||||
@@ -865,6 +900,18 @@ typedef struct
|
|||||||
ecma_built_in_props_t built_in; /**< built-in object part */
|
ecma_built_in_props_t built_in; /**< built-in object part */
|
||||||
} ecma_extended_built_in_object_t;
|
} ecma_extended_built_in_object_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alignment for the fast access mode array length.
|
||||||
|
* The real length is aligned up for allocating the underlying buffer.
|
||||||
|
*/
|
||||||
|
#define ECMA_FAST_ARRAY_ALIGNMENT (8)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Align the length of the fast mode array to get the allocated size of the underlying buffer
|
||||||
|
*/
|
||||||
|
#define ECMA_FAST_ARRAY_ALIGN_LENGTH(length) \
|
||||||
|
(uint32_t) ((((length)) + ECMA_FAST_ARRAY_ALIGNMENT - 1) / ECMA_FAST_ARRAY_ALIGNMENT * ECMA_FAST_ARRAY_ALIGNMENT)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiled byte code data.
|
* Compiled byte code data.
|
||||||
*/
|
*/
|
||||||
@@ -892,7 +939,7 @@ typedef struct
|
|||||||
|
|
||||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_ARROW_FUNCTION)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of arrow function objects.
|
* Description of arrow function objects.
|
||||||
@@ -918,18 +965,35 @@ typedef struct
|
|||||||
|
|
||||||
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_ARROW_FUNCTION) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET)
|
#if ENABLED (JERRY_ES2015_BUILTIN_CONTAINER)
|
||||||
/**
|
/**
|
||||||
* Description of Map/Set objects.
|
* Flags for container objects
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef enum
|
||||||
{
|
{
|
||||||
ecma_extended_object_t header; /**< header part */
|
ECMA_CONTAINER_FLAGS_EMPTY = (0), /** empty flags */
|
||||||
uint32_t size; /**< size of the map object */
|
ECMA_CONTAINER_FLAGS_WEAK = (1 << 0) /** container object is weak */
|
||||||
} ecma_map_object_t;
|
} ecma_container_flags_t;
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ECMA_PROP_NO_OPTS = (0), /** empty property descriptor */
|
||||||
|
ECMA_PROP_IS_GET_DEFINED = (1 << 0), /** Is [[Get]] defined? */
|
||||||
|
ECMA_PROP_IS_SET_DEFINED = (1 << 1), /** Is [[Set]] defined? */
|
||||||
|
|
||||||
|
ECMA_PROP_IS_CONFIGURABLE = (1 << 2), /** [[Configurable]] */
|
||||||
|
ECMA_PROP_IS_ENUMERABLE = (1 << 3), /** [[Enumerable]] */
|
||||||
|
ECMA_PROP_IS_WRITABLE = (1 << 4), /** [[Writable]] */
|
||||||
|
ECMA_PROP_IS_THROW = (1 << 5), /** Flag that controls failure handling */
|
||||||
|
|
||||||
|
ECMA_PROP_IS_VALUE_DEFINED = (1 << 6), /** Is [[Value]] defined? */
|
||||||
|
ECMA_PROP_IS_CONFIGURABLE_DEFINED = (1 << 7), /** Is [[Configurable]] defined? */
|
||||||
|
ECMA_PROP_IS_ENUMERABLE_DEFINED = (1 << 8), /** Is [[Enumerable]] defined? */
|
||||||
|
ECMA_PROP_IS_WRITABLE_DEFINED = (1 << 9), /** Is [[Writable]] defined? */
|
||||||
|
} ecma_property_descriptor_status_flags_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of ECMA property descriptor
|
* Description of ECMA property descriptor
|
||||||
@@ -939,35 +1003,13 @@ typedef struct
|
|||||||
* Note:
|
* Note:
|
||||||
* If a component of descriptor is undefined then corresponding
|
* If a component of descriptor is undefined then corresponding
|
||||||
* field should contain it's default value.
|
* field should contain it's default value.
|
||||||
|
* The struct members must be in this order or keep in sync with ecma_property_flags_t and ECMA_IS_THROW flag.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/** Is [[Value]] defined? */
|
|
||||||
unsigned int is_value_defined : 1;
|
|
||||||
|
|
||||||
/** Is [[Get]] defined? */
|
/** any combination of ecma_property_descriptor_status_flags_t bits */
|
||||||
unsigned int is_get_defined : 1;
|
uint16_t flags;
|
||||||
|
|
||||||
/** Is [[Set]] defined? */
|
|
||||||
unsigned int is_set_defined : 1;
|
|
||||||
|
|
||||||
/** Is [[Writable]] defined? */
|
|
||||||
unsigned int is_writable_defined : 1;
|
|
||||||
|
|
||||||
/** [[Writable]] */
|
|
||||||
unsigned int is_writable : 1;
|
|
||||||
|
|
||||||
/** Is [[Enumerable]] defined? */
|
|
||||||
unsigned int is_enumerable_defined : 1;
|
|
||||||
|
|
||||||
/** [[Enumerable]] */
|
|
||||||
unsigned int is_enumerable : 1;
|
|
||||||
|
|
||||||
/** Is [[Configurable]] defined? */
|
|
||||||
unsigned int is_configurable_defined : 1;
|
|
||||||
|
|
||||||
/** [[Configurable]] */
|
|
||||||
unsigned int is_configurable : 1;
|
|
||||||
|
|
||||||
/** [[Value]] */
|
/** [[Value]] */
|
||||||
ecma_value_t value;
|
ecma_value_t value;
|
||||||
@@ -979,12 +1021,44 @@ typedef struct
|
|||||||
ecma_object_t *set_p;
|
ecma_object_t *set_p;
|
||||||
} ecma_property_descriptor_t;
|
} ecma_property_descriptor_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitfield which represents a namedata property options in an ecma_property_descriptor_t
|
||||||
|
* Attributes:
|
||||||
|
* - is_get_defined, is_set_defined : false
|
||||||
|
* - is_configurable, is_writable, is_enumerable : undefined (false)
|
||||||
|
* - is_throw : undefined (false)
|
||||||
|
* - is_value_defined : true
|
||||||
|
* - is_configurable_defined, is_writable_defined, is_enumerable_defined : true
|
||||||
|
*/
|
||||||
|
#define ECMA_NAME_DATA_PROPERTY_DESCRIPTOR_BITS 0x3c0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitmask to get a the physical property flags from an ecma_property_descriptor
|
||||||
|
*/
|
||||||
|
#define ECMA_PROPERTY_FLAGS_MASK 0x1c
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag that controls failure handling during defining property
|
||||||
|
*
|
||||||
|
* Note: This flags represents the [[DefineOwnProperty]] (P, Desc, Throw) 3rd argument
|
||||||
|
*/
|
||||||
|
#define ECMA_IS_THROW (1 << 5)
|
||||||
|
|
||||||
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||||
/**
|
/**
|
||||||
* Description of an ecma-number
|
* Description of an ecma-number
|
||||||
*/
|
*/
|
||||||
typedef float ecma_number_t;
|
typedef float ecma_number_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It makes possible to read/write an ecma_number_t as uint32_t without strict aliasing rule violation.
|
||||||
|
*/
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
ecma_number_t as_ecma_number_t;
|
||||||
|
uint32_t as_uint32_t;
|
||||||
|
} ecma_number_accessor_t;
|
||||||
|
|
||||||
#define DOUBLE_TO_ECMA_NUMBER_T(value) (ecma_number_t) (value)
|
#define DOUBLE_TO_ECMA_NUMBER_T(value) (ecma_number_t) (value)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1021,6 +1095,15 @@ typedef float ecma_number_t;
|
|||||||
*/
|
*/
|
||||||
typedef double ecma_number_t;
|
typedef double ecma_number_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It makes possible to read/write an ecma_number_t as uint64_t without strict aliasing rule violation.
|
||||||
|
*/
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
ecma_number_t as_ecma_number_t;
|
||||||
|
uint64_t as_uint64_t;
|
||||||
|
} ecma_number_accessor_t;
|
||||||
|
|
||||||
#define DOUBLE_TO_ECMA_NUMBER_T(value) value
|
#define DOUBLE_TO_ECMA_NUMBER_T(value) value
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1091,6 +1174,26 @@ typedef double ecma_number_t;
|
|||||||
* See also: ECMA_262 v5, 15.7.3.2
|
* See also: ECMA_262 v5, 15.7.3.2
|
||||||
*/
|
*/
|
||||||
# define ECMA_NUMBER_MAX_VALUE (FLT_MAX)
|
# define ECMA_NUMBER_MAX_VALUE (FLT_MAX)
|
||||||
|
/**
|
||||||
|
* Number.EPSILON
|
||||||
|
*
|
||||||
|
* See also: ECMA_262 v6, 20.1.2.1
|
||||||
|
*/
|
||||||
|
# define ECMA_NUMBER_EPSILON ((ecma_number_t) 1.1920928955078125e-7)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number.MAX_SAFE_INTEGER
|
||||||
|
*
|
||||||
|
* See also: ECMA_262 v6, 20.1.2.6
|
||||||
|
*/
|
||||||
|
# define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0xFFFFFF)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number.MIN_SAFE_INTEGER
|
||||||
|
*
|
||||||
|
* See also: ECMA_262 v6, 20.1.2.8
|
||||||
|
*/
|
||||||
|
# define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0xFFFFFF)
|
||||||
#elif ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
#elif ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||||
/**
|
/**
|
||||||
* Number.MAX_VALUE (i.e., the maximum value of ecma-number)
|
* Number.MAX_VALUE (i.e., the maximum value of ecma-number)
|
||||||
@@ -1098,12 +1201,34 @@ typedef double ecma_number_t;
|
|||||||
* See also: ECMA_262 v5, 15.7.3.2
|
* See also: ECMA_262 v5, 15.7.3.2
|
||||||
*/
|
*/
|
||||||
# define ECMA_NUMBER_MAX_VALUE ((ecma_number_t) 1.7976931348623157e+308)
|
# define ECMA_NUMBER_MAX_VALUE ((ecma_number_t) 1.7976931348623157e+308)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number.MIN_VALUE (i.e., the smallest positive value of ecma-number)
|
* Number.MIN_VALUE (i.e., the smallest positive value of ecma-number)
|
||||||
*
|
*
|
||||||
* See also: ECMA_262 v5, 15.7.3.3
|
* See also: ECMA_262 v5, 15.7.3.3
|
||||||
*/
|
*/
|
||||||
# define ECMA_NUMBER_MIN_VALUE ((ecma_number_t) 5e-324)
|
# define ECMA_NUMBER_MIN_VALUE ((ecma_number_t) 5e-324)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number.EPSILON
|
||||||
|
*
|
||||||
|
* See also: ECMA_262 v6, 20.1.2.1
|
||||||
|
*/
|
||||||
|
# define ECMA_NUMBER_EPSILON ((ecma_number_t) 2.2204460492503130808472633361816e-16)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number.MAX_SAFE_INTEGER
|
||||||
|
*
|
||||||
|
* See also: ECMA_262 v6, 20.1.2.6
|
||||||
|
*/
|
||||||
|
# define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0x1FFFFFFFFFFFFF)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number.MIN_SAFE_INTEGER
|
||||||
|
*
|
||||||
|
* See also: ECMA_262 v6, 20.1.2.8
|
||||||
|
*/
|
||||||
|
# define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0x1FFFFFFFFFFFFF)
|
||||||
#endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
#endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1161,57 +1286,36 @@ typedef double ecma_number_t;
|
|||||||
*/
|
*/
|
||||||
#define ECMA_STRING_NOT_ARRAY_INDEX UINT32_MAX
|
#define ECMA_STRING_NOT_ARRAY_INDEX UINT32_MAX
|
||||||
|
|
||||||
/*
|
|
||||||
* Ecma-collection: a growable list of ecma-values. Currently the list is
|
|
||||||
* a chain list, where appending new items at the end is cheap operation.
|
|
||||||
*
|
|
||||||
* Enumerating elements is also cheap, since each page is terminated by a
|
|
||||||
* special ecma-value: collection-type. This type has a pointer to the next
|
|
||||||
* chunk. The last chunk is terminated by a NULL pointer. There when the
|
|
||||||
* next value is requested from the iterator it simply checks the next
|
|
||||||
* memory location. If it is not a collection-type value, it returns with
|
|
||||||
* the value. Otherwise it gets the start address of the next chunk, and
|
|
||||||
* return the value there.
|
|
||||||
*
|
|
||||||
* The collection-type value is always the last item of a collection chunk,
|
|
||||||
* even if the chunk is not completely filled with values (this is only true
|
|
||||||
* for the last chunk). Each chunk must have at least one non collection-type
|
|
||||||
* value as well.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection flags.
|
* Ecma-collection: a growable list of ecma-values.
|
||||||
*/
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
ECMA_COLLECTION_NO_REF_OBJECTS = (1u << 0), /**< do not increase the refcount of objects */
|
|
||||||
ECMA_COLLECTION_NO_COPY = (1u << 1), /**< do not copy values */
|
|
||||||
} ecma_collection_flag_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Description of a collection's header.
|
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
jmem_cpointer_t first_chunk_cp; /**< compressed pointer to first chunk with collection's data */
|
uint32_t item_count; /**< number of items in the collection */
|
||||||
jmem_cpointer_t last_chunk_cp; /**< compressed pointer to last chunk with collection's data */
|
uint32_t capacity; /**< number of items can be stored in the underlying buffer */
|
||||||
ecma_length_t item_count; /**< number of items in the collection */
|
ecma_value_t *buffer_p; /**< underlying data buffer */
|
||||||
} ecma_collection_header_t;
|
} ecma_collection_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of items stored by a collection chunk (excluding the last collection-type value).
|
* Initial capacity of an ecma-collection
|
||||||
*/
|
*/
|
||||||
#define ECMA_COLLECTION_CHUNK_ITEMS 5
|
#define ECMA_COLLECTION_INITIAL_CAPACITY 4
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection chunk item.
|
* Ecma-collenction grow factor when the collection underlying buffer need to be reallocated
|
||||||
*/
|
*/
|
||||||
typedef struct
|
#define ECMA_COLLECTION_GROW_FACTOR (ECMA_COLLECTION_INITIAL_CAPACITY * 2)
|
||||||
{
|
|
||||||
ecma_value_t items[ECMA_COLLECTION_CHUNK_ITEMS + 1]; /**< ecma-value list, where the last value is a special
|
/**
|
||||||
* collection-type value which points to the next chunk,
|
* Compute the total allocated size of the collection based on it's capacity
|
||||||
* so the chunk area is enlarged by one for this value */
|
*/
|
||||||
} ecma_collection_chunk_t;
|
#define ECMA_COLLECTION_ALLOCATED_SIZE(capacity) \
|
||||||
|
(uint32_t) (sizeof (ecma_collection_t) + (capacity * sizeof (ecma_value_t)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial allocated size of an ecma-collection
|
||||||
|
*/
|
||||||
|
#define ECMA_COLLECTION_INITIAL_SIZE ECMA_COLLECTION_ALLOCATED_SIZE (ECMA_COLLECTION_INITIAL_CAPACITY)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct string types (2 bit).
|
* Direct string types (2 bit).
|
||||||
@@ -1250,6 +1354,14 @@ typedef enum
|
|||||||
#define ECMA_CREATE_DIRECT_STRING(type, value) \
|
#define ECMA_CREATE_DIRECT_STRING(type, value) \
|
||||||
((uintptr_t) (ECMA_TYPE_DIRECT_STRING | ((type) << ECMA_VALUE_SHIFT) | (value) << ECMA_DIRECT_STRING_SHIFT))
|
((uintptr_t) (ECMA_TYPE_DIRECT_STRING | ((type) << ECMA_VALUE_SHIFT) | (value) << ECMA_DIRECT_STRING_SHIFT))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an ecma direct string from the given number.
|
||||||
|
*
|
||||||
|
* Note: the given number must be less or equal than ECMA_DIRECT_STRING_MAX_IMM
|
||||||
|
*/
|
||||||
|
#define ECMA_CREATE_DIRECT_UINT32_STRING(uint32_number) \
|
||||||
|
((ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the string is direct.
|
* Checks whether the string is direct.
|
||||||
*/
|
*/
|
||||||
@@ -1286,8 +1398,10 @@ typedef enum
|
|||||||
(((uintptr_t) (string_p)) >> ECMA_DIRECT_STRING_SHIFT)
|
(((uintptr_t) (string_p)) >> ECMA_DIRECT_STRING_SHIFT)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifier for ecma-string's actual data container
|
* Maximum number of bytes that a long-utf8-string is able to store
|
||||||
*/
|
*/
|
||||||
|
#define ECMA_STRING_SIZE_LIMIT UINT32_MAX
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
ECMA_STRING_CONTAINER_HEAP_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
|
ECMA_STRING_CONTAINER_HEAP_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
|
||||||
@@ -1296,17 +1410,15 @@ typedef enum
|
|||||||
* maximum size is 2^32. */
|
* maximum size is 2^32. */
|
||||||
ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
|
ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
|
||||||
stored locally in the string's descriptor */
|
stored locally in the string's descriptor */
|
||||||
|
ECMA_STRING_CONTAINER_HEAP_ASCII_STRING, /**< actual data is on the heap as an ASCII string
|
||||||
|
* maximum size is 2^16. */
|
||||||
ECMA_STRING_CONTAINER_MAGIC_STRING_EX, /**< the ecma-string is equal to one of external magic strings */
|
ECMA_STRING_CONTAINER_MAGIC_STRING_EX, /**< the ecma-string is equal to one of external magic strings */
|
||||||
|
|
||||||
ECMA_STRING_CONTAINER_SYMBOL, /**< the ecma-string is a symbol */
|
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_MAP_KEY, /**< the ecma-string is a map key string */
|
||||||
|
|
||||||
ECMA_STRING_LITERAL_NUMBER, /**< a literal number which is used solely by the literal storage
|
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_MAP_KEY /**< maximum value */
|
||||||
* so no string processing function supports this type except
|
|
||||||
* the ecma_deref_ecma_string function. */
|
|
||||||
|
|
||||||
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_LITERAL_NUMBER /**< maximum value */
|
|
||||||
} ecma_string_container_t;
|
} ecma_string_container_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1317,12 +1429,29 @@ typedef enum
|
|||||||
/**
|
/**
|
||||||
* Value for increasing or decreasing the reference counter.
|
* Value for increasing or decreasing the reference counter.
|
||||||
*/
|
*/
|
||||||
#define ECMA_STRING_REF_ONE (1u << 3)
|
#define ECMA_STRING_REF_ONE (1u << 4)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum value of the reference counter (8191).
|
* Maximum value of the reference counter (4294967280).
|
||||||
*/
|
*/
|
||||||
#define ECMA_STRING_MAX_REF (0x1fffu << 3)
|
#define ECMA_STRING_MAX_REF (0xFFFFFFF0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag that identifies that the string is static which means it is stored in JERRY_CONTEXT (string_list_cp)
|
||||||
|
*/
|
||||||
|
#define ECMA_STATIC_STRING_FLAG (1 << 3)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an ecma-string as static string
|
||||||
|
*/
|
||||||
|
#define ECMA_SET_STRING_AS_STATIC(string_p) \
|
||||||
|
(string_p)->refs_and_container |= ECMA_STATIC_STRING_FLAG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the ecma-string is static string
|
||||||
|
*/
|
||||||
|
#define ECMA_STRING_IS_STATIC(string_p) \
|
||||||
|
((string_p)->refs_and_container & ECMA_STATIC_STRING_FLAG)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns with the container type of a string.
|
* Returns with the container type of a string.
|
||||||
@@ -1334,7 +1463,7 @@ typedef enum
|
|||||||
* Checks whether the reference counter is 1.
|
* Checks whether the reference counter is 1.
|
||||||
*/
|
*/
|
||||||
#define ECMA_STRING_IS_REF_EQUALS_TO_ONE(string_desc_p) \
|
#define ECMA_STRING_IS_REF_EQUALS_TO_ONE(string_desc_p) \
|
||||||
(((string_desc_p)->refs_and_container >> 3) == 1)
|
(((string_desc_p)->refs_and_container >> 4) == 1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ECMA string-value descriptor
|
* ECMA string-value descriptor
|
||||||
@@ -1342,43 +1471,107 @@ typedef enum
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/** Reference counter for the string */
|
/** Reference counter for the string */
|
||||||
uint16_t refs_and_container;
|
uint32_t refs_and_container;
|
||||||
|
|
||||||
/** Hash of the string (calculated from two last characters of the string) */
|
|
||||||
lit_string_hash_t hash;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actual data or identifier of it's place in container (depending on 'container' field)
|
* Actual data or identifier of it's place in container (depending on 'container' field)
|
||||||
*/
|
*/
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
/**
|
lit_string_hash_t hash; /**< hash of the ASCII/UTF8 string */
|
||||||
* Actual data of an utf-8 string type
|
|
||||||
*/
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint16_t size; /**< size of this utf-8 string in bytes */
|
|
||||||
uint16_t length; /**< length of this utf-8 string in characters */
|
|
||||||
} utf8_string;
|
|
||||||
|
|
||||||
lit_utf8_size_t long_utf8_string_size; /**< size of this long utf-8 string in bytes */
|
|
||||||
uint32_t uint32_number; /**< uint32-represented number placed locally in the descriptor */
|
|
||||||
uint32_t magic_string_ex_id; /**< identifier of an external magic string (lit_magic_string_ex_id_t) */
|
uint32_t magic_string_ex_id; /**< identifier of an external magic string (lit_magic_string_ex_id_t) */
|
||||||
ecma_value_t lit_number; /**< number (see ECMA_STRING_LITERAL_NUMBER) */
|
uint32_t uint32_number; /**< uint32-represented number placed locally in the descriptor */
|
||||||
uint32_t common_uint32_field; /**< for zeroing and comparison in some cases */
|
|
||||||
ecma_value_t symbol_descriptor; /**< symbol descriptor string-value */
|
|
||||||
ecma_value_t value; /**< original key value corresponds to the map key string */
|
|
||||||
} u;
|
} u;
|
||||||
} ecma_string_t;
|
} ecma_string_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Long ECMA string-value descriptor
|
* ECMA ASCII string-value descriptor
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
ecma_string_t header; /**< string header */
|
ecma_string_t header; /**< string header */
|
||||||
lit_utf8_size_t long_utf8_string_length; /**< length of this long utf-8 string in bytes */
|
uint16_t size; /**< size of this ASCII string in bytes */
|
||||||
} ecma_long_string_t;
|
} ecma_ascii_string_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ECMA long UTF8 string-value descriptor
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ecma_string_t header; /**< string header */
|
||||||
|
uint16_t size; /**< size of this utf-8 string in bytes */
|
||||||
|
uint16_t length; /**< length of this utf-8 string in bytes */
|
||||||
|
} ecma_utf8_string_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ECMA UTF8 string-value descriptor
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ecma_string_t header; /**< string header */
|
||||||
|
lit_utf8_size_t size; /**< size of this long utf-8 string in bytes */
|
||||||
|
lit_utf8_size_t length; /**< length of this long utf-8 string in bytes */
|
||||||
|
} ecma_long_utf8_string_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the start position of the string buffer of an ecma ASCII string
|
||||||
|
*/
|
||||||
|
#define ECMA_ASCII_STRING_GET_BUFFER(string_p) \
|
||||||
|
((lit_utf8_byte_t *) ((lit_utf8_byte_t *) (string_p) + sizeof (ecma_ascii_string_t)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the start position of the string buffer of an ecma UTF8 string
|
||||||
|
*/
|
||||||
|
#define ECMA_UTF8_STRING_GET_BUFFER(string_p) \
|
||||||
|
((lit_utf8_byte_t *) ((lit_utf8_byte_t *) (string_p) + sizeof (ecma_utf8_string_t)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the start position of the string buffer of an ecma long UTF8 string
|
||||||
|
*/
|
||||||
|
#define ECMA_LONG_UTF8_STRING_GET_BUFFER(string_p) \
|
||||||
|
((lit_utf8_byte_t *) ((lit_utf8_byte_t *) (string_p) + sizeof (ecma_long_utf8_string_t)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ECMA extended string-value descriptor
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ecma_string_t header; /**< string header */
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
ecma_value_t symbol_descriptor; /**< symbol descriptor string-value */
|
||||||
|
ecma_value_t value; /**< original key value corresponds to the map key string */
|
||||||
|
} u;
|
||||||
|
} ecma_extended_string_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String builder header
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
lit_utf8_size_t current_size; /**< size of the data in the buffer */
|
||||||
|
} ecma_stringbuilder_header_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get pointer to the beginning of the stored string in the string builder
|
||||||
|
*/
|
||||||
|
#define ECMA_STRINGBUILDER_STRING_PTR(header_p) \
|
||||||
|
((lit_utf8_byte_t *) (((lit_utf8_byte_t *) header_p) + sizeof (ecma_ascii_string_t)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the size of the stored string in the string builder
|
||||||
|
*/
|
||||||
|
#define ECMA_STRINGBUILDER_STRING_SIZE(header_p) \
|
||||||
|
((lit_utf8_size_t) (header_p->current_size - sizeof (ecma_ascii_string_t)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String builder handle
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ecma_stringbuilder_header_t *header_p; /**< pointer to header */
|
||||||
|
} ecma_stringbuilder_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abort flag for error reference.
|
* Abort flag for error reference.
|
||||||
@@ -1434,6 +1627,15 @@ typedef struct
|
|||||||
jmem_cpointer_t values[ECMA_LIT_STORAGE_VALUE_COUNT]; /**< list of values */
|
jmem_cpointer_t values[ECMA_LIT_STORAGE_VALUE_COUNT]; /**< list of values */
|
||||||
} ecma_lit_storage_item_t;
|
} ecma_lit_storage_item_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number storage item
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
jmem_cpointer_t next_cp; /**< cpointer ot next item */
|
||||||
|
jmem_cpointer_t values[ECMA_LIT_STORAGE_VALUE_COUNT]; /**< list of values */
|
||||||
|
} ecma_number_storage_item_t;
|
||||||
|
|
||||||
#if ENABLED (JERRY_LCACHE)
|
#if ENABLED (JERRY_LCACHE)
|
||||||
/**
|
/**
|
||||||
* Container of an LCache entry identifier
|
* Container of an LCache entry identifier
|
||||||
@@ -1470,6 +1672,32 @@ typedef struct
|
|||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function callback descriptor of a %TypedArray% object getter
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builtin id for the different types of TypedArray's
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ECMA_INT8_ARRAY, /**< Int8Array */
|
||||||
|
ECMA_UINT8_ARRAY, /**< Uint8Array */
|
||||||
|
ECMA_UINT8_CLAMPED_ARRAY, /**< Uint8ClampedArray */
|
||||||
|
ECMA_INT16_ARRAY, /**< Int16Array */
|
||||||
|
ECMA_UINT16_ARRAY, /**< Uint16Array */
|
||||||
|
ECMA_INT32_ARRAY, /**< Int32Array */
|
||||||
|
ECMA_UINT32_ARRAY, /**< Uint32Array */
|
||||||
|
ECMA_FLOAT32_ARRAY, /**< Float32Array */
|
||||||
|
ECMA_FLOAT64_ARRAY, /**< Float64Array */
|
||||||
|
} ecma_typedarray_type_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra information for ArrayBuffers.
|
* Extra information for ArrayBuffers.
|
||||||
*/
|
*/
|
||||||
@@ -1509,8 +1737,46 @@ typedef struct
|
|||||||
ecma_length_t array_length; /**< the array length */
|
ecma_length_t array_length; /**< the array length */
|
||||||
} ecma_extended_typedarray_object_t;
|
} ecma_extended_typedarray_object_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General structure for query %TypedArray% object's properties.
|
||||||
|
**/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ecma_object_t *array_buffer_p; /**< pointer to the typedArray's [[ViewedArrayBuffer]] internal slot */
|
||||||
|
lit_utf8_byte_t *buffer_p; /**< pointer to the underlying raw data buffer.
|
||||||
|
* Note:
|
||||||
|
* - This address is increased by the [ByteOffset]] internal property.
|
||||||
|
* - This address must be used during indexed read/write operation. */
|
||||||
|
ecma_typedarray_type_t id; /**< [[TypedArrayName]] internal slot */
|
||||||
|
uint32_t length; /**< [[ByteLength]] internal slot */
|
||||||
|
ecma_length_t offset; /**< [[ByteOffset]] internal slot. */
|
||||||
|
uint8_t shift; /**< the element size shift in the typedArray */
|
||||||
|
uint8_t element_size; /**< element size based on [[TypedArrayName]] in Table 49 */
|
||||||
|
} ecma_typedarray_info_t;
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executable (e.g. generator, async) object flags.
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ECMA_EXECUTABLE_OBJECT_COMPLETED = (1u << 0), /**< executable object is completed and cannot be resumed */
|
||||||
|
ECMA_EXECUTABLE_OBJECT_RUNNING = (1u << 1), /**< executable object is currently running */
|
||||||
|
/* Generator specific flags. */
|
||||||
|
ECMA_GENERATOR_ITERATE_AND_YIELD = (1u << 2), /**< the generator performs a yield* operation */
|
||||||
|
} ecma_executable_object_flags_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the executable object is waiting for resuming.
|
||||||
|
*/
|
||||||
|
#define ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED(extra_info) \
|
||||||
|
(!((extra_info) & (ECMA_EXECUTABLE_OBJECT_COMPLETED | ECMA_EXECUTABLE_OBJECT_RUNNING)))
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
|
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
|
||||||
/**
|
/**
|
||||||
* Description of DataView objects.
|
* Description of DataView objects.
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/* 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-alloc.h"
|
||||||
|
#include "ecma-gc.h"
|
||||||
|
#include "ecma-globals.h"
|
||||||
|
#include "ecma-helpers.h"
|
||||||
|
#include "jrt.h"
|
||||||
|
|
||||||
|
/** \addtogroup ecma ECMA
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate a collection of ecma values.
|
||||||
|
*
|
||||||
|
* @return pointer to the collection
|
||||||
|
*/
|
||||||
|
ecma_collection_t *
|
||||||
|
ecma_new_collection (void)
|
||||||
|
{
|
||||||
|
ecma_collection_t *collection_p;
|
||||||
|
collection_p = (ecma_collection_t *) jmem_heap_alloc_block (sizeof (ecma_collection_t));
|
||||||
|
|
||||||
|
collection_p->item_count = 0;
|
||||||
|
collection_p->capacity = ECMA_COLLECTION_INITIAL_CAPACITY;
|
||||||
|
const uint32_t size = ECMA_COLLECTION_ALLOCATED_SIZE (ECMA_COLLECTION_INITIAL_CAPACITY);
|
||||||
|
collection_p->buffer_p = (ecma_value_t *) jmem_heap_alloc_block (size);
|
||||||
|
|
||||||
|
return collection_p;
|
||||||
|
} /* ecma_new_collection */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocate a collection of ecma values without freeing it's values
|
||||||
|
*/
|
||||||
|
inline void JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
ecma_collection_destroy (ecma_collection_t *collection_p) /**< value collection */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (collection_p != NULL);
|
||||||
|
|
||||||
|
jmem_heap_free_block (collection_p->buffer_p, ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity));
|
||||||
|
jmem_heap_free_block (collection_p, sizeof (ecma_collection_t));
|
||||||
|
} /* ecma_collection_destroy */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free the object collection elements and deallocate the collection
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecma_collection_free_objects (ecma_collection_t *collection_p) /**< value collection */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (collection_p != NULL);
|
||||||
|
|
||||||
|
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||||
|
{
|
||||||
|
if (ecma_is_value_object (buffer_p[i]))
|
||||||
|
{
|
||||||
|
ecma_deref_object (ecma_get_object_from_value (buffer_p[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_collection_destroy (collection_p);
|
||||||
|
} /* ecma_collection_free_objects */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free the non-object collection elements and deallocate the collection
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecma_collection_free_if_not_object (ecma_collection_t *collection_p) /**< value collection */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (collection_p != NULL);
|
||||||
|
|
||||||
|
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||||
|
{
|
||||||
|
ecma_free_value_if_not_object (buffer_p[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_collection_destroy (collection_p);
|
||||||
|
} /* ecma_collection_free_if_not_object */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free the collection elements and deallocate the collection
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecma_collection_free (ecma_collection_t *collection_p) /**< value collection */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (collection_p != NULL);
|
||||||
|
|
||||||
|
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||||
|
{
|
||||||
|
ecma_free_value (buffer_p[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_collection_destroy (collection_p);
|
||||||
|
} /* ecma_collection_free */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append new value to ecma values collection
|
||||||
|
*
|
||||||
|
* Note: The reference count of the values are not increased
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecma_collection_push_back (ecma_collection_t *collection_p, /**< value collection */
|
||||||
|
ecma_value_t value) /**< ecma value to append */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (collection_p != NULL);
|
||||||
|
|
||||||
|
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||||
|
|
||||||
|
if (JERRY_LIKELY (collection_p->item_count < collection_p->capacity))
|
||||||
|
{
|
||||||
|
buffer_p[collection_p->item_count++] = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32_t new_capacity = collection_p->capacity + ECMA_COLLECTION_GROW_FACTOR;
|
||||||
|
const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity);
|
||||||
|
const uint32_t new_size = ECMA_COLLECTION_ALLOCATED_SIZE (new_capacity);
|
||||||
|
|
||||||
|
buffer_p = jmem_heap_realloc_block (buffer_p, old_size, new_size);
|
||||||
|
buffer_p[collection_p->item_count++] = value;
|
||||||
|
collection_p->capacity = new_capacity;
|
||||||
|
|
||||||
|
collection_p->buffer_p = buffer_p;
|
||||||
|
} /* ecma_collection_push_back */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
@@ -280,13 +280,87 @@ static const uint8_t ecma_uint4_clz[] = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
|||||||
*/
|
*/
|
||||||
#define EPSILON 0.0000001
|
#define EPSILON 0.0000001
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ECMA-defined conversion from string to number for different radixes (2, 8, 16).
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v5 9.3.1
|
||||||
|
* ECMA-262 v6 7.1.3.1
|
||||||
|
*
|
||||||
|
* @return NaN - if the conversion fails
|
||||||
|
* converted number - otherwise
|
||||||
|
*/
|
||||||
|
static ecma_number_t
|
||||||
|
ecma_utf8_string_to_number_by_radix (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||||
|
const lit_utf8_byte_t *end_p, /**< end of utf-8 string */
|
||||||
|
uint32_t radix) /**< radix */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (radix == 2 || radix == 8 || radix == 16);
|
||||||
|
ecma_number_t num = ECMA_NUMBER_ZERO;
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (radix <= 8)
|
||||||
|
{
|
||||||
|
lit_code_point_t upper_limit = LIT_CHAR_0 + radix;
|
||||||
|
|
||||||
|
for (const lit_utf8_byte_t * iter_p = str_p; iter_p <= end_p; iter_p++)
|
||||||
|
{
|
||||||
|
int32_t digit_value;
|
||||||
|
|
||||||
|
if (*iter_p >= LIT_CHAR_0 && *iter_p < upper_limit)
|
||||||
|
{
|
||||||
|
digit_value = (*iter_p - LIT_CHAR_0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ecma_number_make_nan ();
|
||||||
|
}
|
||||||
|
|
||||||
|
num = num * radix + (ecma_number_t) digit_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
for (const lit_utf8_byte_t * iter_p = str_p; iter_p <= end_p; iter_p++)
|
||||||
|
{
|
||||||
|
int32_t digit_value;
|
||||||
|
|
||||||
|
if (*iter_p >= LIT_CHAR_0
|
||||||
|
&& *iter_p <= LIT_CHAR_9)
|
||||||
|
{
|
||||||
|
digit_value = (*iter_p - LIT_CHAR_0);
|
||||||
|
}
|
||||||
|
else if (*iter_p >= LIT_CHAR_LOWERCASE_A
|
||||||
|
&& *iter_p <= LIT_CHAR_LOWERCASE_F)
|
||||||
|
{
|
||||||
|
digit_value = 10 + (*iter_p - LIT_CHAR_LOWERCASE_A);
|
||||||
|
}
|
||||||
|
else if (*iter_p >= LIT_CHAR_UPPERCASE_A
|
||||||
|
&& *iter_p <= LIT_CHAR_UPPERCASE_F)
|
||||||
|
{
|
||||||
|
digit_value = 10 + (*iter_p - LIT_CHAR_UPPERCASE_A);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ecma_number_make_nan ();
|
||||||
|
}
|
||||||
|
|
||||||
|
num = num * radix + (ecma_number_t) digit_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
|
} /* ecma_utf8_string_to_number_by_radix */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ECMA-defined conversion of string to Number.
|
* ECMA-defined conversion of string to Number.
|
||||||
*
|
*
|
||||||
* See also:
|
* See also:
|
||||||
* ECMA-262 v5, 9.3.1
|
* ECMA-262 v5, 9.3.1
|
||||||
*
|
*
|
||||||
* @return ecma-number
|
* @return NaN - if the conversion fails
|
||||||
|
* converted number - otherwise
|
||||||
*/
|
*/
|
||||||
ecma_number_t
|
ecma_number_t
|
||||||
ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||||
@@ -299,102 +373,52 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
return ECMA_NUMBER_ZERO;
|
return ECMA_NUMBER_ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lit_utf8_byte_t *str_curr_p = str_p;
|
ecma_string_trim_helper (&str_p, &str_size);
|
||||||
const lit_utf8_byte_t *str_end_p = str_p + str_size;
|
const lit_utf8_byte_t *end_p = str_p + (str_size - 1);
|
||||||
ecma_char_t code_unit;
|
|
||||||
|
|
||||||
while (str_curr_p < str_end_p)
|
if (str_size < 1)
|
||||||
{
|
|
||||||
code_unit = lit_utf8_peek_next (str_curr_p);
|
|
||||||
if (lit_char_is_white_space (code_unit) || lit_char_is_line_terminator (code_unit))
|
|
||||||
{
|
|
||||||
lit_utf8_incr (&str_curr_p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const lit_utf8_byte_t *begin_p = str_curr_p;
|
|
||||||
str_curr_p = (lit_utf8_byte_t *) str_end_p;
|
|
||||||
|
|
||||||
while (str_curr_p > str_p)
|
|
||||||
{
|
|
||||||
code_unit = lit_utf8_peek_prev (str_curr_p);
|
|
||||||
if (lit_char_is_white_space (code_unit) || lit_char_is_line_terminator (code_unit))
|
|
||||||
{
|
|
||||||
lit_utf8_decr (&str_curr_p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const lit_utf8_byte_t *end_p = str_curr_p - 1;
|
|
||||||
|
|
||||||
if (begin_p > end_p)
|
|
||||||
{
|
{
|
||||||
return ECMA_NUMBER_ZERO;
|
return ECMA_NUMBER_ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((end_p >= begin_p + 2)
|
if (end_p >= str_p + 2
|
||||||
&& begin_p[0] == LIT_CHAR_0
|
&& str_p[0] == LIT_CHAR_0)
|
||||||
&& (begin_p[1] == LIT_CHAR_LOWERCASE_X
|
|
||||||
|| begin_p[1] == LIT_CHAR_UPPERCASE_X))
|
|
||||||
{
|
{
|
||||||
/* Hex literal handling */
|
switch (LEXER_TO_ASCII_LOWERCASE (str_p[1]))
|
||||||
begin_p += 2;
|
|
||||||
|
|
||||||
ecma_number_t num = ECMA_NUMBER_ZERO;
|
|
||||||
|
|
||||||
for (const lit_utf8_byte_t * iter_p = begin_p;
|
|
||||||
iter_p <= end_p;
|
|
||||||
iter_p++)
|
|
||||||
{
|
{
|
||||||
int32_t digit_value;
|
case LIT_CHAR_LOWERCASE_X :
|
||||||
|
|
||||||
if (*iter_p >= LIT_CHAR_0
|
|
||||||
&& *iter_p <= LIT_CHAR_9)
|
|
||||||
{
|
{
|
||||||
digit_value = (*iter_p - LIT_CHAR_0);
|
return ecma_utf8_string_to_number_by_radix (str_p + 2, end_p, 16);
|
||||||
}
|
}
|
||||||
else if (*iter_p >= LIT_CHAR_LOWERCASE_A
|
case LIT_CHAR_LOWERCASE_O :
|
||||||
&& *iter_p <= LIT_CHAR_LOWERCASE_F)
|
|
||||||
{
|
{
|
||||||
digit_value = 10 + (*iter_p - LIT_CHAR_LOWERCASE_A);
|
return ecma_utf8_string_to_number_by_radix (str_p + 2, end_p, 8);
|
||||||
}
|
}
|
||||||
else if (*iter_p >= LIT_CHAR_UPPERCASE_A
|
case LIT_CHAR_LOWERCASE_B :
|
||||||
&& *iter_p <= LIT_CHAR_UPPERCASE_F)
|
|
||||||
{
|
{
|
||||||
digit_value = 10 + (*iter_p - LIT_CHAR_UPPERCASE_A);
|
return ecma_utf8_string_to_number_by_radix (str_p + 2, end_p, 2);
|
||||||
}
|
}
|
||||||
else
|
default:
|
||||||
{
|
{
|
||||||
return ecma_number_make_nan ();
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
num = num * 16 + (ecma_number_t) digit_value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sign = false; /* positive */
|
bool sign = false; /* positive */
|
||||||
|
|
||||||
if (*begin_p == LIT_CHAR_PLUS)
|
if (*str_p == LIT_CHAR_PLUS)
|
||||||
{
|
{
|
||||||
begin_p++;
|
str_p++;
|
||||||
}
|
}
|
||||||
else if (*begin_p == LIT_CHAR_MINUS)
|
else if (*str_p == LIT_CHAR_MINUS)
|
||||||
{
|
{
|
||||||
sign = true; /* negative */
|
sign = true; /* negative */
|
||||||
|
|
||||||
begin_p++;
|
str_p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin_p > end_p)
|
if (str_p > end_p)
|
||||||
{
|
{
|
||||||
return ecma_number_make_nan ();
|
return ecma_number_make_nan ();
|
||||||
}
|
}
|
||||||
@@ -404,7 +428,7 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
|
|
||||||
JERRY_ASSERT (strlen ((const char *) infinity_zt_str_p) == 8);
|
JERRY_ASSERT (strlen ((const char *) infinity_zt_str_p) == 8);
|
||||||
|
|
||||||
if ((end_p - begin_p) == (8 - 1) && memcmp (infinity_zt_str_p, begin_p, 8) == 0)
|
if ((end_p - str_p) == (8 - 1) && memcmp (infinity_zt_str_p, str_p, 8) == 0)
|
||||||
{
|
{
|
||||||
return ecma_number_make_infinity (sign);
|
return ecma_number_make_infinity (sign);
|
||||||
}
|
}
|
||||||
@@ -415,15 +439,15 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
bool digit_seen = false;
|
bool digit_seen = false;
|
||||||
|
|
||||||
/* Parsing digits before dot (or before end of digits part if there is no dot in number) */
|
/* Parsing digits before dot (or before end of digits part if there is no dot in number) */
|
||||||
while (begin_p <= end_p)
|
while (str_p <= end_p)
|
||||||
{
|
{
|
||||||
int32_t digit_value;
|
int32_t digit_value;
|
||||||
|
|
||||||
if (*begin_p >= LIT_CHAR_0
|
if (*str_p >= LIT_CHAR_0
|
||||||
&& *begin_p <= LIT_CHAR_9)
|
&& *str_p <= LIT_CHAR_9)
|
||||||
{
|
{
|
||||||
digit_seen = true;
|
digit_seen = true;
|
||||||
digit_value = (*begin_p - LIT_CHAR_0);
|
digit_value = (*str_p - LIT_CHAR_0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -443,29 +467,29 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
begin_p++;
|
str_p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin_p <= end_p
|
if (str_p <= end_p
|
||||||
&& *begin_p == LIT_CHAR_DOT)
|
&& *str_p == LIT_CHAR_DOT)
|
||||||
{
|
{
|
||||||
begin_p++;
|
str_p++;
|
||||||
|
|
||||||
if (!digit_seen && begin_p > end_p)
|
if (!digit_seen && str_p > end_p)
|
||||||
{
|
{
|
||||||
return ecma_number_make_nan ();
|
return ecma_number_make_nan ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parsing number's part that is placed after dot */
|
/* Parsing number's part that is placed after dot */
|
||||||
while (begin_p <= end_p)
|
while (str_p <= end_p)
|
||||||
{
|
{
|
||||||
int32_t digit_value;
|
int32_t digit_value;
|
||||||
|
|
||||||
if (*begin_p >= LIT_CHAR_0
|
if (*str_p >= LIT_CHAR_0
|
||||||
&& *begin_p <= LIT_CHAR_9)
|
&& *str_p <= LIT_CHAR_9)
|
||||||
{
|
{
|
||||||
digit_seen = true;
|
digit_seen = true;
|
||||||
digit_value = (*begin_p - LIT_CHAR_0);
|
digit_value = (*str_p - LIT_CHAR_0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -483,7 +507,7 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
e--;
|
e--;
|
||||||
}
|
}
|
||||||
|
|
||||||
begin_p++;
|
str_p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,40 +515,40 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
int32_t e_in_lit = 0;
|
int32_t e_in_lit = 0;
|
||||||
bool e_in_lit_sign = false;
|
bool e_in_lit_sign = false;
|
||||||
|
|
||||||
if (begin_p <= end_p
|
if (str_p <= end_p
|
||||||
&& (*begin_p == LIT_CHAR_LOWERCASE_E
|
&& (*str_p == LIT_CHAR_LOWERCASE_E
|
||||||
|| *begin_p == LIT_CHAR_UPPERCASE_E))
|
|| *str_p == LIT_CHAR_UPPERCASE_E))
|
||||||
{
|
{
|
||||||
begin_p++;
|
str_p++;
|
||||||
|
|
||||||
if (!digit_seen || begin_p > end_p)
|
if (!digit_seen || str_p > end_p)
|
||||||
{
|
{
|
||||||
return ecma_number_make_nan ();
|
return ecma_number_make_nan ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*begin_p == LIT_CHAR_PLUS)
|
if (*str_p == LIT_CHAR_PLUS)
|
||||||
{
|
{
|
||||||
begin_p++;
|
str_p++;
|
||||||
}
|
}
|
||||||
else if (*begin_p == LIT_CHAR_MINUS)
|
else if (*str_p == LIT_CHAR_MINUS)
|
||||||
{
|
{
|
||||||
e_in_lit_sign = true;
|
e_in_lit_sign = true;
|
||||||
begin_p++;
|
str_p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin_p > end_p)
|
if (str_p > end_p)
|
||||||
{
|
{
|
||||||
return ecma_number_make_nan ();
|
return ecma_number_make_nan ();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (begin_p <= end_p)
|
while (str_p <= end_p)
|
||||||
{
|
{
|
||||||
int32_t digit_value;
|
int32_t digit_value;
|
||||||
|
|
||||||
if (*begin_p >= LIT_CHAR_0
|
if (*str_p >= LIT_CHAR_0
|
||||||
&& *begin_p <= LIT_CHAR_9)
|
&& *str_p <= LIT_CHAR_9)
|
||||||
{
|
{
|
||||||
digit_value = (*begin_p - LIT_CHAR_0);
|
digit_value = (*str_p - LIT_CHAR_0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -543,7 +567,7 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
return sign ? -ECMA_NUMBER_ZERO : ECMA_NUMBER_ZERO;
|
return sign ? -ECMA_NUMBER_ZERO : ECMA_NUMBER_ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
begin_p++;
|
str_p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,12 +593,12 @@ ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
|||||||
e_sign = false;
|
e_sign = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin_p <= end_p)
|
if (str_p <= end_p)
|
||||||
{
|
{
|
||||||
return ecma_number_make_nan ();
|
return ecma_number_make_nan ();
|
||||||
}
|
}
|
||||||
|
|
||||||
JERRY_ASSERT (begin_p == end_p + 1);
|
JERRY_ASSERT (str_p == end_p + 1);
|
||||||
|
|
||||||
if (fraction_uint64 == 0)
|
if (fraction_uint64 == 0)
|
||||||
{
|
{
|
||||||
@@ -735,9 +759,7 @@ ecma_uint32_to_utf8_string (uint32_t value, /**< value to convert */
|
|||||||
uint32_t
|
uint32_t
|
||||||
ecma_number_to_uint32 (ecma_number_t num) /**< ecma-number */
|
ecma_number_to_uint32 (ecma_number_t num) /**< ecma-number */
|
||||||
{
|
{
|
||||||
if (ecma_number_is_nan (num)
|
if (JERRY_UNLIKELY (ecma_number_is_zero (num) || !ecma_number_is_finite (num)))
|
||||||
|| ecma_number_is_zero (num)
|
|
||||||
|| ecma_number_is_infinity (num))
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ecma-alloc.h"
|
#include "ecma-alloc.h"
|
||||||
|
#include "ecma-array-object.h"
|
||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "ecma-objects.h"
|
#include "ecma-objects.h"
|
||||||
#include "ecma-helpers.h"
|
#include "ecma-helpers.h"
|
||||||
@@ -37,6 +38,12 @@ ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create
|
|||||||
void *info_p) /**< native pointer's type info */
|
void *info_p) /**< native pointer's type info */
|
||||||
{
|
{
|
||||||
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||||
|
|
||||||
|
if (ecma_op_object_is_fast_array (obj_p))
|
||||||
|
{
|
||||||
|
ecma_fast_array_convert_to_normal (obj_p);
|
||||||
|
}
|
||||||
|
|
||||||
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
||||||
|
|
||||||
bool is_new = (property_p == NULL);
|
bool is_new = (property_p == NULL);
|
||||||
@@ -107,6 +114,12 @@ ecma_native_pointer_t *
|
|||||||
ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */
|
ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */
|
||||||
void *info_p) /**< native pointer's type info */
|
void *info_p) /**< native pointer's type info */
|
||||||
{
|
{
|
||||||
|
if (ecma_op_object_is_fast_array (obj_p))
|
||||||
|
{
|
||||||
|
/* Fast access mode array can not have native pointer properties */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||||
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
||||||
|
|
||||||
@@ -149,6 +162,12 @@ bool
|
|||||||
ecma_delete_native_pointer_property (ecma_object_t *obj_p, /**< object to delete property from */
|
ecma_delete_native_pointer_property (ecma_object_t *obj_p, /**< object to delete property from */
|
||||||
void *info_p) /**< native pointer's type info */
|
void *info_p) /**< native pointer's type info */
|
||||||
{
|
{
|
||||||
|
if (ecma_op_object_is_fast_array (obj_p))
|
||||||
|
{
|
||||||
|
/* Fast access mode array can not have native pointer properties */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||||
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
||||||
|
|
||||||
|
|||||||
@@ -58,15 +58,9 @@ ecma_number_pack (bool sign, /**< sign */
|
|||||||
(biased_exp << ECMA_NUMBER_FRACTION_WIDTH) |
|
(biased_exp << ECMA_NUMBER_FRACTION_WIDTH) |
|
||||||
((uint32_t) fraction));
|
((uint32_t) fraction));
|
||||||
|
|
||||||
union
|
ecma_number_accessor_t u;
|
||||||
{
|
u.as_uint32_t = packed_value;
|
||||||
uint32_t u32_value;
|
return u.as_ecma_number_t;
|
||||||
ecma_number_t float_value;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.u32_value = packed_value;
|
|
||||||
|
|
||||||
return u.float_value;
|
|
||||||
} /* ecma_number_pack */
|
} /* ecma_number_pack */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,15 +72,9 @@ ecma_number_unpack (ecma_number_t num, /**< ecma-number */
|
|||||||
uint32_t *biased_exp_p, /**< [out] biased exponent (optional) */
|
uint32_t *biased_exp_p, /**< [out] biased exponent (optional) */
|
||||||
uint64_t *fraction_p) /**< [out] fraction (optional) */
|
uint64_t *fraction_p) /**< [out] fraction (optional) */
|
||||||
{
|
{
|
||||||
union
|
ecma_number_accessor_t u;
|
||||||
{
|
u.as_ecma_number_t = num;
|
||||||
uint32_t u32_value;
|
uint32_t packed_value = u.as_uint32_t;
|
||||||
ecma_number_t float_value;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.float_value = num;
|
|
||||||
|
|
||||||
uint32_t packed_value = u.u32_value;
|
|
||||||
|
|
||||||
if (sign_p != NULL)
|
if (sign_p != NULL)
|
||||||
{
|
{
|
||||||
@@ -133,15 +121,9 @@ ecma_number_pack (bool sign, /**< sign */
|
|||||||
JERRY_ASSERT ((biased_exp & ~((1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)) == 0);
|
JERRY_ASSERT ((biased_exp & ~((1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)) == 0);
|
||||||
JERRY_ASSERT ((fraction & ~((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1)) == 0);
|
JERRY_ASSERT ((fraction & ~((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1)) == 0);
|
||||||
|
|
||||||
union
|
ecma_number_accessor_t u;
|
||||||
{
|
u.as_uint64_t = packed_value;
|
||||||
uint64_t u64_value;
|
return u.as_ecma_number_t;
|
||||||
ecma_number_t float_value;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.u64_value = packed_value;
|
|
||||||
|
|
||||||
return u.float_value;
|
|
||||||
} /* ecma_number_pack */
|
} /* ecma_number_pack */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,14 +135,9 @@ ecma_number_unpack (ecma_number_t num, /**< ecma-number */
|
|||||||
uint32_t *biased_exp_p, /**< [out] biased exponent (optional) */
|
uint32_t *biased_exp_p, /**< [out] biased exponent (optional) */
|
||||||
uint64_t *fraction_p) /**< [out] fraction (optional) */
|
uint64_t *fraction_p) /**< [out] fraction (optional) */
|
||||||
{
|
{
|
||||||
union
|
ecma_number_accessor_t u;
|
||||||
{
|
u.as_ecma_number_t = num;
|
||||||
uint64_t u64_value;
|
uint64_t packed_value = u.as_uint64_t;
|
||||||
ecma_number_t float_value;
|
|
||||||
} u;
|
|
||||||
u.float_value = num;
|
|
||||||
|
|
||||||
uint64_t packed_value = u.u64_value;
|
|
||||||
|
|
||||||
if (sign_p != NULL)
|
if (sign_p != NULL)
|
||||||
{
|
{
|
||||||
@@ -240,7 +217,7 @@ ecma_number_get_sign_field (ecma_number_t num) /**< ecma-number */
|
|||||||
fraction is filled with anything but not all zero bits,
|
fraction is filled with anything but not all zero bits,
|
||||||
* false - otherwise
|
* false - otherwise
|
||||||
*/
|
*/
|
||||||
inline bool JERRY_ATTR_ALWAYS_INLINE
|
extern inline bool JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
|
ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
|
||||||
{
|
{
|
||||||
bool is_nan = (num != num);
|
bool is_nan = (num != num);
|
||||||
@@ -267,9 +244,14 @@ ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
|
|||||||
ecma_number_t
|
ecma_number_t
|
||||||
ecma_number_make_nan (void)
|
ecma_number_make_nan (void)
|
||||||
{
|
{
|
||||||
return ecma_number_pack (false,
|
/* IEEE754 QNaN = sign bit: 0, exponent: all 1 bits, fraction: 1....0 */
|
||||||
(1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1u,
|
ecma_number_accessor_t f;
|
||||||
1u);
|
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||||
|
f.as_uint64_t = 0x7ff8000000000000ull; /* double QNaN, same as the C99 nan("") returns. */
|
||||||
|
#else /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
|
f.as_uint32_t = 0x7fc00000u; /* float QNaN, same as the C99 nanf("") returns. */
|
||||||
|
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
|
return f.as_ecma_number_t;
|
||||||
} /* ecma_number_make_nan */
|
} /* ecma_number_make_nan */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -282,9 +264,14 @@ ecma_number_t
|
|||||||
ecma_number_make_infinity (bool sign) /**< true - for negative Infinity,
|
ecma_number_make_infinity (bool sign) /**< true - for negative Infinity,
|
||||||
false - for positive Infinity */
|
false - for positive Infinity */
|
||||||
{
|
{
|
||||||
return ecma_number_pack (sign,
|
/* IEEE754 INF = sign bit: sign, exponent: all 1 bits, fraction: 0....0 */
|
||||||
(1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1u,
|
ecma_number_accessor_t f;
|
||||||
0u);
|
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||||
|
f.as_uint64_t = sign ? 0xfff0000000000000ull : 0x7ff0000000000000ull;
|
||||||
|
#else /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
|
f.as_uint32_t = sign ? 0xff800000u : 0x7f800000u;
|
||||||
|
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
|
return f.as_ecma_number_t;
|
||||||
} /* ecma_number_make_infinity */
|
} /* ecma_number_make_infinity */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -311,8 +298,6 @@ ecma_number_is_negative (ecma_number_t num) /**< ecma-number */
|
|||||||
bool
|
bool
|
||||||
ecma_number_is_zero (ecma_number_t num) /**< ecma-number */
|
ecma_number_is_zero (ecma_number_t num) /**< ecma-number */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
|
||||||
|
|
||||||
bool is_zero = (num == ECMA_NUMBER_ZERO);
|
bool is_zero = (num == ECMA_NUMBER_ZERO);
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
@@ -336,8 +321,6 @@ ecma_number_is_zero (ecma_number_t num) /**< ecma-number */
|
|||||||
bool
|
bool
|
||||||
ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */
|
ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
|
||||||
|
|
||||||
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
|
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
|
||||||
uint64_t fraction = ecma_number_get_fraction_field (num);
|
uint64_t fraction = ecma_number_get_fraction_field (num);
|
||||||
|
|
||||||
@@ -346,6 +329,24 @@ ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */
|
|||||||
&& (fraction == 0));
|
&& (fraction == 0));
|
||||||
} /* ecma_number_is_infinity */
|
} /* ecma_number_is_infinity */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if number is finite
|
||||||
|
*
|
||||||
|
* @return true - if number is finite
|
||||||
|
* false - if number is NaN or infinity
|
||||||
|
*/
|
||||||
|
extern inline bool JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
ecma_number_is_finite (ecma_number_t num) /**< ecma-number */
|
||||||
|
{
|
||||||
|
#if defined (__GNUC__) || defined (__clang__)
|
||||||
|
return __builtin_isfinite (num);
|
||||||
|
#elif defined (WIN32)
|
||||||
|
return isfinite (num);
|
||||||
|
#else
|
||||||
|
return !ecma_number_is_nan (num) && !ecma_number_is_infinity (num);
|
||||||
|
#endif /* defined (__GNUC__) || defined (__clang__) */
|
||||||
|
} /* ecma_number_is_finite */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fraction and exponent of the number
|
* Get fraction and exponent of the number
|
||||||
*
|
*
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -63,7 +63,7 @@ JERRY_STATIC_ASSERT ((ECMA_VALUE_FALSE | (1 << ECMA_DIRECT_SHIFT)) == ECMA_VALUE
|
|||||||
*
|
*
|
||||||
* @return type field
|
* @return type field
|
||||||
*/
|
*/
|
||||||
static inline ecma_type_t JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
extern inline ecma_type_t JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_get_value_type_field (ecma_value_t value) /**< ecma value */
|
ecma_get_value_type_field (ecma_value_t value) /**< ecma value */
|
||||||
{
|
{
|
||||||
return value & ECMA_VALUE_TYPE_MASK;
|
return value & ECMA_VALUE_TYPE_MASK;
|
||||||
@@ -289,7 +289,7 @@ ecma_is_value_float_number (ecma_value_t value) /**< ecma value */
|
|||||||
* @return true - if the value contains ecma-number value,
|
* @return true - if the value contains ecma-number value,
|
||||||
* false - otherwise
|
* false - otherwise
|
||||||
*/
|
*/
|
||||||
inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
extern inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_is_value_number (ecma_value_t value) /**< ecma value */
|
ecma_is_value_number (ecma_value_t value) /**< ecma value */
|
||||||
{
|
{
|
||||||
return (ecma_is_value_integer_number (value)
|
return (ecma_is_value_integer_number (value)
|
||||||
@@ -305,13 +305,13 @@ JERRY_STATIC_ASSERT ((ECMA_TYPE_STRING | 0x4) == ECMA_TYPE_DIRECT_STRING,
|
|||||||
* @return true - if the value contains ecma-string value,
|
* @return true - if the value contains ecma-string value,
|
||||||
* false - otherwise
|
* false - otherwise
|
||||||
*/
|
*/
|
||||||
inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
extern inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_is_value_string (ecma_value_t value) /**< ecma value */
|
ecma_is_value_string (ecma_value_t value) /**< ecma value */
|
||||||
{
|
{
|
||||||
return ((value & (ECMA_VALUE_TYPE_MASK - 0x4)) == ECMA_TYPE_STRING);
|
return ((value & (ECMA_VALUE_TYPE_MASK - 0x4)) == ECMA_TYPE_STRING);
|
||||||
} /* ecma_is_value_string */
|
} /* ecma_is_value_string */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/**
|
/**
|
||||||
* Check if the value is symbol.
|
* Check if the value is symbol.
|
||||||
*
|
*
|
||||||
@@ -323,7 +323,7 @@ ecma_is_value_symbol (ecma_value_t value) /**< ecma value */
|
|||||||
{
|
{
|
||||||
return (ecma_get_value_type_field (value) == ECMA_TYPE_SYMBOL);
|
return (ecma_get_value_type_field (value) == ECMA_TYPE_SYMBOL);
|
||||||
} /* ecma_is_value_symbol */
|
} /* ecma_is_value_symbol */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the value can be property name.
|
* Check if the value can be property name.
|
||||||
@@ -334,11 +334,11 @@ ecma_is_value_symbol (ecma_value_t value) /**< ecma value */
|
|||||||
inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_is_value_prop_name (ecma_value_t value) /**< ecma value */
|
ecma_is_value_prop_name (ecma_value_t value) /**< ecma value */
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
return ecma_is_value_string (value) || ecma_is_value_symbol (value);
|
return ecma_is_value_string (value) || ecma_is_value_symbol (value);
|
||||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#else /* !ENABLED (JERRY_ES2015) */
|
||||||
return ecma_is_value_string (value);
|
return ecma_is_value_string (value);
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
} /* ecma_is_value_prop_name */
|
} /* ecma_is_value_prop_name */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -389,18 +389,6 @@ ecma_is_value_error_reference (ecma_value_t value) /**< ecma value */
|
|||||||
return (ecma_get_value_type_field (value) == ECMA_TYPE_ERROR);
|
return (ecma_get_value_type_field (value) == ECMA_TYPE_ERROR);
|
||||||
} /* ecma_is_value_error_reference */
|
} /* ecma_is_value_error_reference */
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the value is an aligned pointer.
|
|
||||||
*
|
|
||||||
* @return true - if the value contains an aligned pointer,
|
|
||||||
* false - otherwise
|
|
||||||
*/
|
|
||||||
inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
|
||||||
ecma_is_value_pointer (ecma_value_t value) /**< ecma value */
|
|
||||||
{
|
|
||||||
return (ecma_get_value_type_field (value) == ECMA_TYPE_POINTER);
|
|
||||||
} /* ecma_is_value_pointer */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug assertion that specified value's type is one of ECMA-defined
|
* Debug assertion that specified value's type is one of ECMA-defined
|
||||||
* script-visible types, i.e.: undefined, null, boolean, number, string, object.
|
* script-visible types, i.e.: undefined, null, boolean, number, string, object.
|
||||||
@@ -417,6 +405,19 @@ ecma_check_value_type_is_spec_defined (ecma_value_t value) /**< ecma value */
|
|||||||
|| ecma_is_value_object (value));
|
|| ecma_is_value_object (value));
|
||||||
} /* ecma_check_value_type_is_spec_defined */
|
} /* ecma_check_value_type_is_spec_defined */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given argument is an array or not.
|
||||||
|
*
|
||||||
|
* @return true - if the given argument is an array object
|
||||||
|
* false - otherwise
|
||||||
|
*/
|
||||||
|
inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
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);
|
||||||
|
} /* ecma_is_value_array */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an ecma value from the given raw boolean.
|
* Creates an ecma value from the given raw boolean.
|
||||||
*
|
*
|
||||||
@@ -459,12 +460,23 @@ ecma_create_float_number (ecma_number_t ecma_number) /**< value of the float num
|
|||||||
return ecma_pointer_to_ecma_value (ecma_num_p) | ECMA_TYPE_FLOAT;
|
return ecma_pointer_to_ecma_value (ecma_num_p) | ECMA_TYPE_FLOAT;
|
||||||
} /* ecma_create_float_number */
|
} /* ecma_create_float_number */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode float number without checks.
|
||||||
|
*
|
||||||
|
* @return ecma-value
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_make_float_value (ecma_number_t *ecma_num_p) /**< pointer to the float number */
|
||||||
|
{
|
||||||
|
return ecma_pointer_to_ecma_value (ecma_num_p) | ECMA_TYPE_FLOAT;
|
||||||
|
} /* ecma_make_float_value */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new NaN value.
|
* Create a new NaN value.
|
||||||
*
|
*
|
||||||
* @return ecma-value
|
* @return ecma-value
|
||||||
*/
|
*/
|
||||||
inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
|
extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_make_nan_value (void)
|
ecma_make_nan_value (void)
|
||||||
{
|
{
|
||||||
return ecma_create_float_number (ecma_number_make_nan ());
|
return ecma_create_float_number (ecma_number_make_nan ());
|
||||||
@@ -478,26 +490,12 @@ ecma_make_nan_value (void)
|
|||||||
static inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
static inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_is_number_equal_to_positive_zero (ecma_number_t ecma_number) /**< number */
|
ecma_is_number_equal_to_positive_zero (ecma_number_t ecma_number) /**< number */
|
||||||
{
|
{
|
||||||
|
ecma_number_accessor_t u;
|
||||||
|
u.as_ecma_number_t = ecma_number;
|
||||||
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||||
union
|
return u.as_uint32_t == 0;
|
||||||
{
|
|
||||||
uint32_t u32_value;
|
|
||||||
ecma_number_t float_value;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.float_value = ecma_number;
|
|
||||||
|
|
||||||
return u.u32_value == 0;
|
|
||||||
#else /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
#else /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
union
|
return u.as_uint64_t == 0;
|
||||||
{
|
|
||||||
uint64_t u64_value;
|
|
||||||
ecma_number_t float_value;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.float_value = ecma_number;
|
|
||||||
|
|
||||||
return u.u64_value == 0;
|
|
||||||
#endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
#endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
} /* ecma_is_number_equal_to_positive_zero */
|
} /* ecma_is_number_equal_to_positive_zero */
|
||||||
|
|
||||||
@@ -562,9 +560,9 @@ inline ecma_value_t JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
|
|||||||
ecma_make_string_value (const ecma_string_t *ecma_string_p) /**< string to reference in value */
|
ecma_make_string_value (const ecma_string_t *ecma_string_p) /**< string to reference in value */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (ecma_string_p != NULL);
|
JERRY_ASSERT (ecma_string_p != NULL);
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
JERRY_ASSERT (!ecma_prop_name_is_symbol ((ecma_string_t *) ecma_string_p));
|
JERRY_ASSERT (!ecma_prop_name_is_symbol ((ecma_string_t *) ecma_string_p));
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
if ((((uintptr_t) ecma_string_p) & ECMA_VALUE_TYPE_MASK) != 0)
|
if ((((uintptr_t) ecma_string_p) & ECMA_VALUE_TYPE_MASK) != 0)
|
||||||
{
|
{
|
||||||
@@ -574,7 +572,7 @@ ecma_make_string_value (const ecma_string_t *ecma_string_p) /**< string to refer
|
|||||||
return ecma_pointer_to_ecma_value (ecma_string_p) | ECMA_TYPE_STRING;
|
return ecma_pointer_to_ecma_value (ecma_string_p) | ECMA_TYPE_STRING;
|
||||||
} /* ecma_make_string_value */
|
} /* ecma_make_string_value */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/**
|
/**
|
||||||
* Symbol value constructor
|
* Symbol value constructor
|
||||||
*
|
*
|
||||||
@@ -588,7 +586,7 @@ ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p) /**< symbol to refer
|
|||||||
|
|
||||||
return ecma_pointer_to_ecma_value (ecma_symbol_p) | ECMA_TYPE_SYMBOL;
|
return ecma_pointer_to_ecma_value (ecma_symbol_p) | ECMA_TYPE_SYMBOL;
|
||||||
} /* ecma_make_symbol_value */
|
} /* ecma_make_symbol_value */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property-name value constructor
|
* Property-name value constructor
|
||||||
@@ -600,12 +598,12 @@ ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p) /**< property
|
|||||||
{
|
{
|
||||||
JERRY_ASSERT (ecma_prop_name_p != NULL);
|
JERRY_ASSERT (ecma_prop_name_p != NULL);
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
if (ecma_prop_name_is_symbol ((ecma_string_t *) ecma_prop_name_p))
|
if (ecma_prop_name_is_symbol ((ecma_string_t *) ecma_prop_name_p))
|
||||||
{
|
{
|
||||||
return ecma_make_symbol_value (ecma_prop_name_p);
|
return ecma_make_symbol_value (ecma_prop_name_p);
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
return ecma_make_string_value (ecma_prop_name_p);
|
return ecma_make_string_value (ecma_prop_name_p);
|
||||||
} /* ecma_make_prop_name_value */
|
} /* ecma_make_prop_name_value */
|
||||||
@@ -647,29 +645,6 @@ ecma_make_error_reference_value (const ecma_error_reference_t *error_ref_p) /**<
|
|||||||
return ecma_pointer_to_ecma_value (error_ref_p) | ECMA_TYPE_ERROR;
|
return ecma_pointer_to_ecma_value (error_ref_p) | ECMA_TYPE_ERROR;
|
||||||
} /* ecma_make_error_reference_value */
|
} /* ecma_make_error_reference_value */
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an ecma value from an aligned pointer
|
|
||||||
*
|
|
||||||
* @return ecma-value representation of the aligned pointer
|
|
||||||
*/
|
|
||||||
inline ecma_value_t JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
|
|
||||||
ecma_make_pointer_value (const void *any_p) /**< any aligned pointer */
|
|
||||||
{
|
|
||||||
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
|
|
||||||
|
|
||||||
uintptr_t uint_ptr = (uintptr_t) any_p;
|
|
||||||
JERRY_ASSERT ((uint_ptr & ECMA_VALUE_TYPE_MASK) == 0);
|
|
||||||
return ((ecma_value_t) uint_ptr) | ECMA_TYPE_POINTER;
|
|
||||||
|
|
||||||
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
|
|
||||||
|
|
||||||
jmem_cpointer_t ptr_cp;
|
|
||||||
ECMA_SET_POINTER (ptr_cp, any_p);
|
|
||||||
return (((ecma_value_t) ptr_cp) << ECMA_VALUE_SHIFT) | ECMA_TYPE_POINTER;
|
|
||||||
|
|
||||||
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
|
|
||||||
} /* ecma_make_pointer_value */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get integer value from an integer ecma value
|
* Get integer value from an integer ecma value
|
||||||
*
|
*
|
||||||
@@ -696,6 +671,19 @@ ecma_get_float_from_value (ecma_value_t value) /**< ecma value */
|
|||||||
return *(ecma_number_t *) ecma_get_pointer_from_ecma_value (value);
|
return *(ecma_number_t *) ecma_get_pointer_from_ecma_value (value);
|
||||||
} /* ecma_get_float_from_value */
|
} /* ecma_get_float_from_value */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get floating point value pointer from an ecma value
|
||||||
|
*
|
||||||
|
* @return floating point value
|
||||||
|
*/
|
||||||
|
inline ecma_number_t * JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
ecma_get_pointer_from_float_value (ecma_value_t value) /**< ecma value */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_FLOAT);
|
||||||
|
|
||||||
|
return (ecma_number_t *) ecma_get_pointer_from_ecma_value (value);
|
||||||
|
} /* ecma_get_pointer_from_float_value */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get floating point value from an ecma value
|
* Get floating point value from an ecma value
|
||||||
*
|
*
|
||||||
@@ -730,7 +718,7 @@ ecma_get_string_from_value (ecma_value_t value) /**< ecma value */
|
|||||||
return (ecma_string_t *) ecma_get_pointer_from_ecma_value (value);
|
return (ecma_string_t *) ecma_get_pointer_from_ecma_value (value);
|
||||||
} /* ecma_get_string_from_value */
|
} /* ecma_get_string_from_value */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/**
|
/**
|
||||||
* Get pointer to ecma-string from ecma value
|
* Get pointer to ecma-string from ecma value
|
||||||
*
|
*
|
||||||
@@ -743,7 +731,7 @@ ecma_get_symbol_from_value (ecma_value_t value) /**< ecma value */
|
|||||||
|
|
||||||
return (ecma_string_t *) ecma_get_pointer_from_ecma_value (value);
|
return (ecma_string_t *) ecma_get_pointer_from_ecma_value (value);
|
||||||
} /* ecma_get_symbol_from_value */
|
} /* ecma_get_symbol_from_value */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get pointer to a property name from ecma value
|
* Get pointer to a property name from ecma value
|
||||||
@@ -789,23 +777,6 @@ ecma_get_error_reference_from_value (ecma_value_t value) /**< ecma value */
|
|||||||
return (ecma_error_reference_t *) ecma_get_pointer_from_ecma_value (value);
|
return (ecma_error_reference_t *) ecma_get_pointer_from_ecma_value (value);
|
||||||
} /* ecma_get_error_reference_from_value */
|
} /* ecma_get_error_reference_from_value */
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an aligned pointer from an ecma value
|
|
||||||
*
|
|
||||||
* @return pointer value
|
|
||||||
*/
|
|
||||||
inline void * JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
|
|
||||||
ecma_get_pointer_from_value (ecma_value_t value) /**< ecma value */
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_POINTER);
|
|
||||||
|
|
||||||
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
|
|
||||||
return (void *) (uintptr_t) ((value) & ~ECMA_VALUE_TYPE_MASK);
|
|
||||||
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
|
|
||||||
return ECMA_GET_POINTER (void, value >> ECMA_VALUE_SHIFT);
|
|
||||||
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
|
|
||||||
} /* ecma_get_pointer_from_value */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invert a boolean value
|
* Invert a boolean value
|
||||||
*
|
*
|
||||||
@@ -840,13 +811,13 @@ ecma_copy_value (ecma_value_t value) /**< value description */
|
|||||||
ecma_ref_ecma_string (ecma_get_string_from_value (value));
|
ecma_ref_ecma_string (ecma_get_string_from_value (value));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
case ECMA_TYPE_SYMBOL:
|
case ECMA_TYPE_SYMBOL:
|
||||||
{
|
{
|
||||||
ecma_ref_ecma_string (ecma_get_symbol_from_value (value));
|
ecma_ref_ecma_string (ecma_get_symbol_from_value (value));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
case ECMA_TYPE_OBJECT:
|
case ECMA_TYPE_OBJECT:
|
||||||
{
|
{
|
||||||
ecma_ref_object (ecma_get_object_from_value (value));
|
ecma_ref_object (ecma_get_object_from_value (value));
|
||||||
@@ -884,10 +855,10 @@ ecma_fast_copy_value (ecma_value_t value) /**< value description */
|
|||||||
*
|
*
|
||||||
* @return copy of the given value
|
* @return copy of the given value
|
||||||
*/
|
*/
|
||||||
ecma_value_t
|
inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_copy_value_if_not_object (ecma_value_t value) /**< value description */
|
ecma_copy_value_if_not_object (ecma_value_t value) /**< value description */
|
||||||
{
|
{
|
||||||
if (ecma_get_value_type_field (value) != ECMA_TYPE_OBJECT)
|
if (!ecma_is_value_object (value))
|
||||||
{
|
{
|
||||||
return ecma_copy_value (value);
|
return ecma_copy_value (value);
|
||||||
}
|
}
|
||||||
@@ -895,6 +866,30 @@ ecma_copy_value_if_not_object (ecma_value_t value) /**< value description */
|
|||||||
return value;
|
return value;
|
||||||
} /* ecma_copy_value_if_not_object */
|
} /* ecma_copy_value_if_not_object */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase reference counter of a value if it is an object.
|
||||||
|
*/
|
||||||
|
inline void JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
ecma_ref_if_object (ecma_value_t value) /**< value description */
|
||||||
|
{
|
||||||
|
if (ecma_is_value_object (value))
|
||||||
|
{
|
||||||
|
ecma_ref_object (ecma_get_object_from_value (value));
|
||||||
|
}
|
||||||
|
} /* ecma_ref_if_object */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrease reference counter of a value if it is an object.
|
||||||
|
*/
|
||||||
|
inline void JERRY_ATTR_ALWAYS_INLINE
|
||||||
|
ecma_deref_if_object (ecma_value_t value) /**< value description */
|
||||||
|
{
|
||||||
|
if (ecma_is_value_object (value))
|
||||||
|
{
|
||||||
|
ecma_deref_object (ecma_get_object_from_value (value));
|
||||||
|
}
|
||||||
|
} /* ecma_deref_if_object */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign a new value to an ecma-value
|
* Assign a new value to an ecma-value
|
||||||
*
|
*
|
||||||
@@ -1037,13 +1032,13 @@ ecma_free_value (ecma_value_t value) /**< value description */
|
|||||||
ecma_deref_ecma_string (string_p);
|
ecma_deref_ecma_string (string_p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
case ECMA_TYPE_SYMBOL:
|
case ECMA_TYPE_SYMBOL:
|
||||||
{
|
{
|
||||||
ecma_deref_ecma_string (ecma_get_symbol_from_value (value));
|
ecma_deref_ecma_string (ecma_get_symbol_from_value (value));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
case ECMA_TYPE_OBJECT:
|
case ECMA_TYPE_OBJECT:
|
||||||
{
|
{
|
||||||
ecma_deref_object (ecma_get_object_from_value (value));
|
ecma_deref_object (ecma_get_object_from_value (value));
|
||||||
@@ -1143,12 +1138,12 @@ ecma_get_typeof_lit_id (ecma_value_t value) /**< input ecma value */
|
|||||||
{
|
{
|
||||||
ret_value = LIT_MAGIC_STRING_STRING;
|
ret_value = LIT_MAGIC_STRING_STRING;
|
||||||
}
|
}
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
else if (ecma_is_value_symbol (value))
|
else if (ecma_is_value_symbol (value))
|
||||||
{
|
{
|
||||||
ret_value = LIT_MAGIC_STRING_SYMBOL;
|
ret_value = LIT_MAGIC_STRING_SYMBOL;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (ecma_is_value_object (value));
|
JERRY_ASSERT (ecma_is_value_object (value));
|
||||||
|
|||||||
@@ -1,200 +0,0 @@
|
|||||||
/* 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-alloc.h"
|
|
||||||
#include "ecma-globals.h"
|
|
||||||
#include "ecma-helpers.h"
|
|
||||||
#include "jrt.h"
|
|
||||||
|
|
||||||
/** \addtogroup ecma ECMA
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type of ecma error and ecma collection chunk must be the same.
|
|
||||||
*/
|
|
||||||
JERRY_STATIC_ASSERT (ECMA_TYPE_ERROR == ECMA_TYPE_POINTER,
|
|
||||||
ecma_type_error_must_be_the_same_as_ecma_type_pointer);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocate a collection of ecma values.
|
|
||||||
*
|
|
||||||
* @return pointer to the collection's header
|
|
||||||
*/
|
|
||||||
ecma_collection_header_t *
|
|
||||||
ecma_new_values_collection (void)
|
|
||||||
{
|
|
||||||
ecma_collection_header_t *header_p;
|
|
||||||
header_p = (ecma_collection_header_t *) jmem_pools_alloc (sizeof (ecma_collection_header_t));
|
|
||||||
|
|
||||||
header_p->item_count = 0;
|
|
||||||
header_p->first_chunk_cp = ECMA_NULL_POINTER;
|
|
||||||
header_p->last_chunk_cp = ECMA_NULL_POINTER;
|
|
||||||
|
|
||||||
return header_p;
|
|
||||||
} /* ecma_new_values_collection */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free the collection of ecma values.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
ecma_free_values_collection (ecma_collection_header_t *header_p, /**< collection's header */
|
|
||||||
uint32_t flags) /**< combination of ecma_collection_flag_t flags */
|
|
||||||
{
|
|
||||||
ecma_collection_chunk_t *chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
|
|
||||||
header_p->first_chunk_cp);
|
|
||||||
|
|
||||||
jmem_pools_free (header_p, sizeof (ecma_collection_header_t));
|
|
||||||
|
|
||||||
if (chunk_p == NULL)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
ecma_value_t *item_p = chunk_p->items;
|
|
||||||
|
|
||||||
JERRY_ASSERT (!ecma_is_value_pointer (*item_p));
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (!(flags & ECMA_COLLECTION_NO_COPY)
|
|
||||||
&& (!ecma_is_value_object (*item_p)
|
|
||||||
|| !(flags & ECMA_COLLECTION_NO_REF_OBJECTS)))
|
|
||||||
{
|
|
||||||
ecma_free_value (*item_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
item_p++;
|
|
||||||
}
|
|
||||||
while (!ecma_is_value_pointer (*item_p));
|
|
||||||
|
|
||||||
ecma_collection_chunk_t *next_chunk_p = (ecma_collection_chunk_t *) ecma_get_pointer_from_value (*item_p);
|
|
||||||
|
|
||||||
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
|
|
||||||
|
|
||||||
chunk_p = next_chunk_p;
|
|
||||||
}
|
|
||||||
while (chunk_p != NULL);
|
|
||||||
} /* ecma_free_values_collection */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append new value to ecma values collection
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
ecma_append_to_values_collection (ecma_collection_header_t *header_p, /**< collection's header */
|
|
||||||
ecma_value_t value, /**< ecma value to append */
|
|
||||||
uint32_t flags) /**< combination of ecma_collection_flag_t flags */
|
|
||||||
{
|
|
||||||
ecma_length_t item_index;
|
|
||||||
ecma_collection_chunk_t *chunk_p;
|
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (header_p->item_count == 0))
|
|
||||||
{
|
|
||||||
item_index = 0;
|
|
||||||
chunk_p = (ecma_collection_chunk_t *) jmem_heap_alloc_block (sizeof (ecma_collection_chunk_t));
|
|
||||||
|
|
||||||
ECMA_SET_POINTER (header_p->first_chunk_cp, chunk_p);
|
|
||||||
header_p->last_chunk_cp = header_p->first_chunk_cp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item_index = header_p->item_count % ECMA_COLLECTION_CHUNK_ITEMS;
|
|
||||||
|
|
||||||
chunk_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
|
|
||||||
header_p->last_chunk_cp);
|
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (item_index == 0))
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (ecma_is_value_pointer (chunk_p->items[ECMA_COLLECTION_CHUNK_ITEMS])
|
|
||||||
&& ecma_get_pointer_from_value (chunk_p->items[ECMA_COLLECTION_CHUNK_ITEMS]) == NULL);
|
|
||||||
|
|
||||||
ecma_collection_chunk_t *next_chunk_p;
|
|
||||||
next_chunk_p = (ecma_collection_chunk_t *) jmem_heap_alloc_block (sizeof (ecma_collection_chunk_t));
|
|
||||||
|
|
||||||
chunk_p->items[ECMA_COLLECTION_CHUNK_ITEMS] = ecma_make_pointer_value ((void *) next_chunk_p);
|
|
||||||
ECMA_SET_POINTER (header_p->last_chunk_cp, next_chunk_p);
|
|
||||||
|
|
||||||
chunk_p = next_chunk_p;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (ecma_is_value_pointer (chunk_p->items[item_index])
|
|
||||||
&& ecma_get_pointer_from_value (chunk_p->items[item_index]) == NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(flags & ECMA_COLLECTION_NO_COPY)
|
|
||||||
&& (!ecma_is_value_object (value)
|
|
||||||
|| !(flags & ECMA_COLLECTION_NO_REF_OBJECTS)))
|
|
||||||
{
|
|
||||||
value = ecma_copy_value (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
chunk_p->items[item_index] = value;
|
|
||||||
chunk_p->items[item_index + 1] = ecma_make_pointer_value (NULL);
|
|
||||||
header_p->item_count++;
|
|
||||||
} /* ecma_append_to_values_collection */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize new collection iterator for the collection
|
|
||||||
*
|
|
||||||
* @return pointer to the first item
|
|
||||||
*/
|
|
||||||
ecma_value_t *
|
|
||||||
ecma_collection_iterator_init (ecma_collection_header_t *header_p) /**< header of collection */
|
|
||||||
{
|
|
||||||
if (JERRY_UNLIKELY (!header_p || header_p->item_count == 0))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_collection_chunk_t *chunk_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
|
|
||||||
header_p->first_chunk_cp);
|
|
||||||
|
|
||||||
return chunk_p->items;
|
|
||||||
} /* ecma_collection_iterator_init */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move collection iterator to next element if there is any.
|
|
||||||
*
|
|
||||||
* @return pointer to the next item
|
|
||||||
*/
|
|
||||||
ecma_value_t *
|
|
||||||
ecma_collection_iterator_next (ecma_value_t *ecma_value_p) /**< current value */
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (ecma_value_p != NULL);
|
|
||||||
|
|
||||||
ecma_value_p++;
|
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (ecma_is_value_pointer (*ecma_value_p)))
|
|
||||||
{
|
|
||||||
ecma_value_p = ((ecma_collection_chunk_t *) ecma_get_pointer_from_value (*ecma_value_p))->items;
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_value_p == NULL || !ecma_is_value_pointer (*ecma_value_p));
|
|
||||||
return ecma_value_p;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ecma_value_p;
|
|
||||||
} /* ecma_collection_iterator_next */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
+301
-360
File diff suppressed because it is too large
Load Diff
@@ -50,11 +50,17 @@
|
|||||||
*/
|
*/
|
||||||
#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer)
|
#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status flags for ecma_string_get_chars function
|
||||||
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
ECMA_STRING_FLAG_EMPTY = 0,
|
ECMA_STRING_FLAG_EMPTY = 0, /**< No options are provided. */
|
||||||
ECMA_STRING_FLAG_IS_ASCII,
|
ECMA_STRING_FLAG_IS_ASCII = (1 << 0), /**< The string contains only ASCII characters. */
|
||||||
ECMA_STRING_FLAG_MUST_BE_FREED
|
ECMA_STRING_FLAG_REHASH_NEEDED = (1 << 1), /**< The hash of the string must be recalculated.
|
||||||
|
* For more details see ecma_append_chars_to_string */
|
||||||
|
ECMA_STRING_FLAG_IS_UINT32 = (1 << 2), /**< The string repesents an UINT32 number */
|
||||||
|
ECMA_STRING_FLAG_MUST_BE_FREED = (1 << 3), /**< The returned buffer must be freed */
|
||||||
} ecma_string_flag_t;
|
} ecma_string_flag_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +71,11 @@ typedef enum
|
|||||||
utf8_str_size) /**< [out] output buffer size */ \
|
utf8_str_size) /**< [out] output buffer size */ \
|
||||||
lit_utf8_size_t utf8_str_size; \
|
lit_utf8_size_t utf8_str_size; \
|
||||||
uint8_t utf8_ptr ## flags = ECMA_STRING_FLAG_EMPTY; \
|
uint8_t utf8_ptr ## flags = ECMA_STRING_FLAG_EMPTY; \
|
||||||
const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, &utf8_str_size, &utf8_ptr ## flags);
|
const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, \
|
||||||
|
&utf8_str_size, \
|
||||||
|
NULL, \
|
||||||
|
NULL, \
|
||||||
|
&utf8_ptr ## flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING'
|
* Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING'
|
||||||
@@ -137,19 +147,20 @@ typedef enum
|
|||||||
*/
|
*/
|
||||||
#define ECMA_BOOL_TO_BITFIELD(x) ((x) ? 1 : 0)
|
#define ECMA_BOOL_TO_BITFIELD(x) ((x) ? 1 : 0)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/**
|
/**
|
||||||
* JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol
|
* JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol
|
||||||
*/
|
*/
|
||||||
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (ecma_is_value_symbol ((value)))
|
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (ecma_is_value_symbol ((value)))
|
||||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#else /* !ENABLED (JERRY_ES2015) */
|
||||||
/**
|
/**
|
||||||
* JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol
|
* JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol
|
||||||
*/
|
*/
|
||||||
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (false)
|
#define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (false)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* ecma-helpers-value.c */
|
/* 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);
|
bool JERRY_ATTR_CONST ecma_is_value_direct (ecma_value_t value);
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_simple (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_simple (ecma_value_t value);
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_empty (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_empty (ecma_value_t value);
|
||||||
@@ -166,48 +177,50 @@ bool JERRY_ATTR_CONST ecma_are_values_integer_numbers (ecma_value_t first_value,
|
|||||||
bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value);
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value);
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value);
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value);
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value);
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_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_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_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_error_reference (ecma_value_t value);
|
||||||
bool JERRY_ATTR_CONST ecma_is_value_pointer (ecma_value_t value);
|
bool JERRY_ATTR_CONST ecma_is_value_array (ecma_value_t arg);
|
||||||
|
|
||||||
void ecma_check_value_type_is_spec_defined (ecma_value_t value);
|
void ecma_check_value_type_is_spec_defined (ecma_value_t value);
|
||||||
|
|
||||||
ecma_value_t JERRY_ATTR_CONST ecma_make_boolean_value (bool boolean_value);
|
ecma_value_t JERRY_ATTR_CONST ecma_make_boolean_value (bool boolean_value);
|
||||||
ecma_value_t JERRY_ATTR_CONST ecma_make_integer_value (ecma_integer_value_t integer_value);
|
ecma_value_t JERRY_ATTR_CONST ecma_make_integer_value (ecma_integer_value_t integer_value);
|
||||||
ecma_value_t ecma_make_nan_value (void);
|
ecma_value_t ecma_make_nan_value (void);
|
||||||
|
ecma_value_t ecma_make_float_value (ecma_number_t *ecma_num_p);
|
||||||
ecma_value_t ecma_make_number_value (ecma_number_t ecma_number);
|
ecma_value_t ecma_make_number_value (ecma_number_t ecma_number);
|
||||||
ecma_value_t ecma_make_int32_value (int32_t int32_number);
|
ecma_value_t ecma_make_int32_value (int32_t int32_number);
|
||||||
ecma_value_t ecma_make_uint32_value (uint32_t uint32_number);
|
ecma_value_t ecma_make_uint32_value (uint32_t uint32_number);
|
||||||
ecma_value_t JERRY_ATTR_PURE ecma_make_string_value (const ecma_string_t *ecma_string_p);
|
ecma_value_t JERRY_ATTR_PURE ecma_make_string_value (const ecma_string_t *ecma_string_p);
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ecma_value_t JERRY_ATTR_PURE ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p);
|
ecma_value_t JERRY_ATTR_PURE ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p);
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
ecma_value_t JERRY_ATTR_PURE ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p);
|
ecma_value_t JERRY_ATTR_PURE ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p);
|
||||||
ecma_value_t JERRY_ATTR_PURE ecma_make_magic_string_value (lit_magic_string_id_t id);
|
ecma_value_t JERRY_ATTR_PURE ecma_make_magic_string_value (lit_magic_string_id_t id);
|
||||||
ecma_value_t JERRY_ATTR_PURE ecma_make_object_value (const ecma_object_t *object_p);
|
ecma_value_t JERRY_ATTR_PURE ecma_make_object_value (const ecma_object_t *object_p);
|
||||||
ecma_value_t JERRY_ATTR_PURE ecma_make_error_reference_value (const ecma_error_reference_t *error_ref_p);
|
ecma_value_t JERRY_ATTR_PURE ecma_make_error_reference_value (const ecma_error_reference_t *error_ref_p);
|
||||||
ecma_value_t JERRY_ATTR_PURE ecma_make_pointer_value (const void *any_p);
|
|
||||||
ecma_integer_value_t JERRY_ATTR_CONST ecma_get_integer_from_value (ecma_value_t value);
|
ecma_integer_value_t JERRY_ATTR_CONST ecma_get_integer_from_value (ecma_value_t value);
|
||||||
ecma_number_t JERRY_ATTR_PURE ecma_get_float_from_value (ecma_value_t value);
|
ecma_number_t JERRY_ATTR_PURE ecma_get_float_from_value (ecma_value_t value);
|
||||||
|
ecma_number_t * ecma_get_pointer_from_float_value (ecma_value_t value);
|
||||||
ecma_number_t JERRY_ATTR_PURE ecma_get_number_from_value (ecma_value_t value);
|
ecma_number_t JERRY_ATTR_PURE ecma_get_number_from_value (ecma_value_t value);
|
||||||
ecma_string_t JERRY_ATTR_PURE *ecma_get_string_from_value (ecma_value_t value);
|
ecma_string_t JERRY_ATTR_PURE *ecma_get_string_from_value (ecma_value_t value);
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ecma_string_t JERRY_ATTR_PURE *ecma_get_symbol_from_value (ecma_value_t value);
|
ecma_string_t JERRY_ATTR_PURE *ecma_get_symbol_from_value (ecma_value_t value);
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
ecma_string_t JERRY_ATTR_PURE *ecma_get_prop_name_from_value (ecma_value_t value);
|
ecma_string_t JERRY_ATTR_PURE *ecma_get_prop_name_from_value (ecma_value_t value);
|
||||||
ecma_object_t JERRY_ATTR_PURE *ecma_get_object_from_value (ecma_value_t value);
|
ecma_object_t JERRY_ATTR_PURE *ecma_get_object_from_value (ecma_value_t value);
|
||||||
ecma_error_reference_t JERRY_ATTR_PURE *ecma_get_error_reference_from_value (ecma_value_t value);
|
ecma_error_reference_t JERRY_ATTR_PURE *ecma_get_error_reference_from_value (ecma_value_t value);
|
||||||
void * JERRY_ATTR_PURE ecma_get_pointer_from_value (ecma_value_t value);
|
|
||||||
ecma_value_t JERRY_ATTR_CONST ecma_invert_boolean_value (ecma_value_t value);
|
ecma_value_t JERRY_ATTR_CONST ecma_invert_boolean_value (ecma_value_t value);
|
||||||
ecma_value_t ecma_copy_value (ecma_value_t value);
|
ecma_value_t ecma_copy_value (ecma_value_t value);
|
||||||
ecma_value_t ecma_fast_copy_value (ecma_value_t value);
|
ecma_value_t ecma_fast_copy_value (ecma_value_t value);
|
||||||
ecma_value_t ecma_copy_value_if_not_object (ecma_value_t value);
|
ecma_value_t ecma_copy_value_if_not_object (ecma_value_t value);
|
||||||
|
void ecma_ref_if_object (ecma_value_t value);
|
||||||
|
void ecma_deref_if_object (ecma_value_t value);
|
||||||
ecma_value_t ecma_update_float_number (ecma_value_t float_value, ecma_number_t new_number);
|
ecma_value_t ecma_update_float_number (ecma_value_t float_value, ecma_number_t new_number);
|
||||||
void ecma_value_assign_value (ecma_value_t *value_p, ecma_value_t ecma_value);
|
void ecma_value_assign_value (ecma_value_t *value_p, ecma_value_t ecma_value);
|
||||||
void ecma_value_assign_number (ecma_value_t *value_p, ecma_number_t ecma_number);
|
void ecma_value_assign_number (ecma_value_t *value_p, ecma_number_t ecma_number);
|
||||||
@@ -218,10 +231,11 @@ void ecma_free_number (ecma_value_t value);
|
|||||||
lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value);
|
lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value);
|
||||||
|
|
||||||
/* ecma-helpers-string.c */
|
/* ecma-helpers-string.c */
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc);
|
ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc);
|
||||||
bool ecma_prop_name_is_symbol (ecma_string_t *string_p);
|
bool ecma_prop_name_is_symbol (ecma_string_t *string_p);
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
uint32_t ecma_op_advance_string_index (ecma_string_t *str_p, uint32_t index, bool is_unicode);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET)
|
#if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET)
|
||||||
ecma_string_t *ecma_new_map_key_string (ecma_value_t value);
|
ecma_string_t *ecma_new_map_key_string (ecma_value_t value);
|
||||||
bool ecma_prop_name_is_map_key (ecma_string_t *string_p);
|
bool ecma_prop_name_is_map_key (ecma_string_t *string_p);
|
||||||
@@ -230,10 +244,11 @@ ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p,
|
|||||||
ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p,
|
ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p,
|
||||||
lit_utf8_size_t string_size);
|
lit_utf8_size_t string_size);
|
||||||
ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit);
|
ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit);
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit);
|
ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit);
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number);
|
ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||||
|
ecma_string_t *ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number);
|
||||||
ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number);
|
ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||||
ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num);
|
ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num);
|
||||||
ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id);
|
ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id);
|
||||||
@@ -245,6 +260,7 @@ ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t
|
|||||||
ecma_string_t *ecma_append_magic_string_to_string (ecma_string_t *string1_p, lit_magic_string_id_t string2_id);
|
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_ref_ecma_string (ecma_string_t *string_p);
|
||||||
void ecma_deref_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);
|
||||||
ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
|
ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
|
||||||
uint32_t ecma_string_get_array_index (const ecma_string_t *str_p);
|
uint32_t ecma_string_get_array_index (const ecma_string_t *str_p);
|
||||||
|
|
||||||
@@ -270,7 +286,11 @@ ecma_substring_copy_to_utf8_buffer (const ecma_string_t *string_desc_p,
|
|||||||
lit_utf8_size_t buffer_size);
|
lit_utf8_size_t buffer_size);
|
||||||
void ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p,
|
void ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p,
|
||||||
lit_utf8_size_t buffer_size);
|
lit_utf8_size_t buffer_size);
|
||||||
const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p, lit_utf8_size_t *size_p, uint8_t *flags_p);
|
const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p,
|
||||||
|
lit_utf8_size_t *size_p,
|
||||||
|
lit_utf8_size_t *length_p,
|
||||||
|
lit_utf8_byte_t *uint32_buff_p,
|
||||||
|
uint8_t *flags_p);
|
||||||
bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id);
|
bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id);
|
||||||
bool ecma_string_is_empty (const ecma_string_t *string_p);
|
bool ecma_string_is_empty (const ecma_string_t *string_p);
|
||||||
bool ecma_string_is_length (const ecma_string_t *string_p);
|
bool ecma_string_is_length (const ecma_string_t *string_p);
|
||||||
@@ -295,8 +315,25 @@ lit_magic_string_id_t ecma_get_string_magic (const ecma_string_t *string_p);
|
|||||||
|
|
||||||
lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
|
lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
|
||||||
ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, ecma_length_t start_pos, ecma_length_t end_pos);
|
ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, ecma_length_t start_pos, ecma_length_t end_pos);
|
||||||
|
void ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p,
|
||||||
|
lit_utf8_size_t *utf8_str_size);
|
||||||
ecma_string_t *ecma_string_trim (const ecma_string_t *string_p);
|
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);
|
||||||
|
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);
|
||||||
|
void ecma_stringbuilder_append (ecma_stringbuilder_t *builder_p, const ecma_string_t *string_p);
|
||||||
|
void ecma_stringbuilder_append_magic (ecma_stringbuilder_t *builder_p, const lit_magic_string_id_t id);
|
||||||
|
void ecma_stringbuilder_append_raw (ecma_stringbuilder_t *builder_p,
|
||||||
|
const lit_utf8_byte_t *data_p,
|
||||||
|
const lit_utf8_size_t data_size);
|
||||||
|
void ecma_stringbuilder_append_char (ecma_stringbuilder_t *builder_p, const ecma_char_t c);
|
||||||
|
void ecma_stringbuilder_append_byte (ecma_stringbuilder_t *builder_p, const lit_utf8_byte_t);
|
||||||
|
ecma_string_t *ecma_stringbuilder_finalize (ecma_stringbuilder_t *builder_p);
|
||||||
|
void ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p);
|
||||||
|
|
||||||
/* ecma-helpers-number.c */
|
/* ecma-helpers-number.c */
|
||||||
ecma_number_t ecma_number_make_nan (void);
|
ecma_number_t ecma_number_make_nan (void);
|
||||||
ecma_number_t ecma_number_make_infinity (bool sign);
|
ecma_number_t ecma_number_make_infinity (bool sign);
|
||||||
@@ -304,6 +341,7 @@ bool ecma_number_is_nan (ecma_number_t num);
|
|||||||
bool ecma_number_is_negative (ecma_number_t num);
|
bool ecma_number_is_negative (ecma_number_t num);
|
||||||
bool ecma_number_is_zero (ecma_number_t num);
|
bool ecma_number_is_zero (ecma_number_t num);
|
||||||
bool ecma_number_is_infinity (ecma_number_t num);
|
bool ecma_number_is_infinity (ecma_number_t num);
|
||||||
|
bool ecma_number_is_finite (ecma_number_t num);
|
||||||
ecma_number_t
|
ecma_number_t
|
||||||
ecma_number_make_from_sign_mantissa_and_exponent (bool sign, uint64_t mantissa, int32_t exponent);
|
ecma_number_make_from_sign_mantissa_and_exponent (bool sign, uint64_t mantissa, int32_t exponent);
|
||||||
ecma_number_t ecma_number_get_prev (ecma_number_t num);
|
ecma_number_t ecma_number_get_prev (ecma_number_t num);
|
||||||
@@ -316,15 +354,13 @@ lit_utf8_size_t ecma_number_to_binary_floating_point_number (ecma_number_t num,
|
|||||||
lit_utf8_byte_t *out_digits_p,
|
lit_utf8_byte_t *out_digits_p,
|
||||||
int32_t *out_decimal_exp_p);
|
int32_t *out_decimal_exp_p);
|
||||||
|
|
||||||
/* ecma-helpers-values-collection.c */
|
/* ecma-helpers-collection.c */
|
||||||
ecma_collection_header_t *ecma_new_values_collection (void);
|
ecma_collection_t *ecma_new_collection (void);
|
||||||
void ecma_free_values_collection (ecma_collection_header_t *header_p, uint32_t flags);
|
void ecma_collection_push_back (ecma_collection_t *collection_p, ecma_value_t value);
|
||||||
void ecma_append_to_values_collection (ecma_collection_header_t *header_p, ecma_value_t v, uint32_t flags);
|
void ecma_collection_destroy (ecma_collection_t *collection_p);
|
||||||
|
void ecma_collection_free (ecma_collection_t *collection_p);
|
||||||
ecma_value_t *
|
void ecma_collection_free_if_not_object (ecma_collection_t *collection_p);
|
||||||
ecma_collection_iterator_init (ecma_collection_header_t *header_p);
|
void ecma_collection_free_objects (ecma_collection_t *collection_p);
|
||||||
ecma_value_t *
|
|
||||||
ecma_collection_iterator_next (ecma_value_t *iterator_p);
|
|
||||||
|
|
||||||
/* ecma-helpers.c */
|
/* ecma-helpers.c */
|
||||||
ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type);
|
ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type);
|
||||||
@@ -335,14 +371,13 @@ 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);
|
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_set_object_extensible (ecma_object_t *object_p, bool is_extensible);
|
||||||
ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (const ecma_object_t *object_p);
|
ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (const ecma_object_t *object_p);
|
||||||
ecma_object_t JERRY_ATTR_PURE *ecma_get_object_prototype (const ecma_object_t *object_p);
|
|
||||||
bool JERRY_ATTR_PURE ecma_get_object_is_builtin (const ecma_object_t *object_p);
|
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);
|
void ecma_set_object_is_builtin (ecma_object_t *object_p);
|
||||||
uint8_t ecma_get_object_builtin_id (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_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_outer_reference (const ecma_object_t *object_p);
|
||||||
ecma_property_header_t JERRY_ATTR_PURE *ecma_get_property_list (const ecma_object_t *object_p);
|
|
||||||
ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p);
|
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);
|
||||||
|
|
||||||
ecma_property_value_t *
|
ecma_property_value_t *
|
||||||
ecma_create_named_data_property (ecma_object_t *object_p, ecma_string_t *name_p, uint8_t prop_attributes,
|
ecma_create_named_data_property (ecma_object_t *object_p, ecma_string_t *name_p, uint8_t prop_attributes,
|
||||||
@@ -358,13 +393,12 @@ ecma_get_named_data_property (ecma_object_t *obj_p, ecma_string_t *name_p);
|
|||||||
void ecma_free_property (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p);
|
void ecma_free_property (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p);
|
||||||
|
|
||||||
void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p);
|
void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p);
|
||||||
uint32_t ecma_delete_array_properties (ecma_object_t *object_p, uint32_t new_length, uint32_t old_length);
|
|
||||||
|
|
||||||
void ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p,
|
void ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p,
|
||||||
ecma_value_t value);
|
ecma_value_t value);
|
||||||
|
|
||||||
ecma_object_t *ecma_get_named_accessor_property_getter (const ecma_property_value_t *prop_value_p);
|
ecma_getter_setter_pointers_t *
|
||||||
ecma_object_t *ecma_get_named_accessor_property_setter (const ecma_property_value_t *prop_value_p);
|
ecma_get_named_accessor_property (const ecma_property_value_t *prop_value_p);
|
||||||
void ecma_set_named_accessor_property_getter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p,
|
void ecma_set_named_accessor_property_getter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p,
|
||||||
ecma_object_t *getter_p);
|
ecma_object_t *getter_p);
|
||||||
void ecma_set_named_accessor_property_setter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p,
|
void ecma_set_named_accessor_property_setter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p,
|
||||||
@@ -389,10 +423,16 @@ ecma_value_t ecma_create_error_reference_from_context (void);
|
|||||||
ecma_value_t ecma_create_error_object_reference (ecma_object_t *object_p);
|
ecma_value_t ecma_create_error_object_reference (ecma_object_t *object_p);
|
||||||
void ecma_ref_error_reference (ecma_error_reference_t *error_ref_p);
|
void ecma_ref_error_reference (ecma_error_reference_t *error_ref_p);
|
||||||
void ecma_deref_error_reference (ecma_error_reference_t *error_ref_p);
|
void ecma_deref_error_reference (ecma_error_reference_t *error_ref_p);
|
||||||
ecma_value_t ecma_clear_error_reference (ecma_value_t value, bool set_abort_flag);
|
void ecma_raise_error_from_error_reference (ecma_value_t value);
|
||||||
|
|
||||||
void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p);
|
void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p);
|
||||||
void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
|
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)
|
||||||
|
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) */
|
||||||
#if (JERRY_STACK_LIMIT != 0)
|
#if (JERRY_STACK_LIMIT != 0)
|
||||||
uintptr_t ecma_get_current_stack_usage (void);
|
uintptr_t ecma_get_current_stack_usage (void);
|
||||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||||
|
|||||||
@@ -29,12 +29,21 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum number of GC loops on cleanup.
|
||||||
|
*/
|
||||||
|
#define JERRY_GC_LOOP_LIMIT 100
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize ECMA components
|
* Initialize ECMA components
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ecma_init (void)
|
ecma_init (void)
|
||||||
{
|
{
|
||||||
|
#if (JERRY_GC_MARK_LIMIT != 0)
|
||||||
|
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_lex_env ();
|
||||||
|
|
||||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
||||||
@@ -50,6 +59,11 @@ ecma_init (void)
|
|||||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
||||||
ecma_job_queue_init ();
|
ecma_job_queue_init ();
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
JERRY_CONTEXT (current_new_target) = JERRY_CONTEXT_INVALID_NEW_TARGET;
|
||||||
|
JERRY_CONTEXT (current_function_obj_p) = NULL;
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
} /* ecma_init */
|
} /* ecma_init */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,9 +72,23 @@ ecma_init (void)
|
|||||||
void
|
void
|
||||||
ecma_finalize (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_function_obj_p) == NULL);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
ecma_finalize_global_lex_env ();
|
ecma_finalize_global_lex_env ();
|
||||||
ecma_finalize_builtins ();
|
uint8_t runs = 0;
|
||||||
ecma_gc_run ();
|
do
|
||||||
|
{
|
||||||
|
ecma_finalize_builtins ();
|
||||||
|
ecma_gc_run ();
|
||||||
|
if (++runs >= JERRY_GC_LOOP_LIMIT)
|
||||||
|
{
|
||||||
|
jerry_fatal (ERR_UNTERMINATED_GC_LOOPS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (JERRY_CONTEXT (ecma_gc_new_objects) != 0);
|
||||||
ecma_finalize_lit_storage ();
|
ecma_finalize_lit_storage ();
|
||||||
} /* ecma_finalize */
|
} /* ecma_finalize */
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,19 @@
|
|||||||
|
|
||||||
#if ENABLED (JERRY_LCACHE)
|
#if ENABLED (JERRY_LCACHE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitshift index for calculating hash.
|
||||||
|
*/
|
||||||
|
#if ENABLED (JERRY_CPOINTER_32_BIT)
|
||||||
|
#define ECMA_LCACHE_HASH_BITSHIFT_INDEX (2 * JMEM_ALIGNMENT_LOG)
|
||||||
|
#else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
|
||||||
|
#define ECMA_LCACHE_HASH_BITSHIFT_INDEX 0
|
||||||
|
#endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mask for hash bits
|
* Mask for hash bits
|
||||||
*/
|
*/
|
||||||
#define ECMA_LCACHE_HASH_MASK (ECMA_LCACHE_HASH_ROWS_COUNT - 1)
|
#define ECMA_LCACHE_HASH_MASK ((ECMA_LCACHE_HASH_ROWS_COUNT - 1) << ECMA_LCACHE_HASH_BITSHIFT_INDEX)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bitshift index for creating property identifier
|
* Bitshift index for creating property identifier
|
||||||
@@ -69,15 +78,15 @@ ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to obj
|
|||||||
{
|
{
|
||||||
/* Randomize the property name with the object pointer using a xor operation,
|
/* Randomize the property name with the object pointer using a xor operation,
|
||||||
* so properties of different objects with the same name can be cached effectively. */
|
* so properties of different objects with the same name can be cached effectively. */
|
||||||
return (size_t) ((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK);
|
return (size_t) (((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK) >> ECMA_LCACHE_HASH_BITSHIFT_INDEX);
|
||||||
} /* ecma_lcache_row_index */
|
} /* ecma_lcache_row_index */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert an entry into LCache
|
* Insert an entry into LCache
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ecma_lcache_insert (ecma_object_t *object_p, /**< object */
|
ecma_lcache_insert (const ecma_object_t *object_p, /**< object */
|
||||||
jmem_cpointer_t name_cp, /**< property name */
|
const jmem_cpointer_t name_cp, /**< property name */
|
||||||
ecma_property_t *prop_p) /**< property */
|
ecma_property_t *prop_p) /**< property */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (object_p != NULL);
|
JERRY_ASSERT (object_p != NULL);
|
||||||
@@ -91,31 +100,32 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
|
|||||||
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
|
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
|
||||||
|
|
||||||
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
|
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
|
||||||
ecma_lcache_hash_entry_t *entries_p = JERRY_CONTEXT (lcache) [row_index];
|
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
|
||||||
|
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
|
||||||
|
|
||||||
uint32_t entry_index;
|
do
|
||||||
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
|
|
||||||
{
|
{
|
||||||
if (entries_p[entry_index].id == 0)
|
if (entry_p->id == 0)
|
||||||
{
|
{
|
||||||
break;
|
goto insert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry_p++;
|
||||||
|
}
|
||||||
|
while (entry_p < entry_end_p);
|
||||||
|
|
||||||
|
/* Invalidate the last entry. */
|
||||||
|
ecma_lcache_invalidate_entry (--entry_p);
|
||||||
|
|
||||||
|
/* Shift other entries towards the end. */
|
||||||
|
for (uint32_t i = 0; i < ECMA_LCACHE_HASH_ROW_LENGTH - 1; i++)
|
||||||
|
{
|
||||||
|
entry_p->id = entry_p[-1].id;
|
||||||
|
entry_p->prop_p = entry_p[-1].prop_p;
|
||||||
|
entry_p--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry_index == ECMA_LCACHE_HASH_ROW_LENGTH)
|
insert:
|
||||||
{
|
|
||||||
/* Invalidate the last entry. */
|
|
||||||
ecma_lcache_invalidate_entry (entries_p + ECMA_LCACHE_HASH_ROW_LENGTH - 1);
|
|
||||||
|
|
||||||
/* Shift other entries towards the end. */
|
|
||||||
for (uint32_t i = ECMA_LCACHE_HASH_ROW_LENGTH - 1; i > 0; i--)
|
|
||||||
{
|
|
||||||
entries_p[i] = entries_p[i - 1];
|
|
||||||
}
|
|
||||||
entry_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_lcache_hash_entry_t *entry_p = entries_p + entry_index;
|
|
||||||
entry_p->prop_p = prop_p;
|
entry_p->prop_p = prop_p;
|
||||||
entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp);
|
entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp);
|
||||||
|
|
||||||
@@ -129,7 +139,7 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
|
|||||||
* NULL otherwise
|
* NULL otherwise
|
||||||
*/
|
*/
|
||||||
inline ecma_property_t * JERRY_ATTR_ALWAYS_INLINE
|
inline ecma_property_t * JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
|
ecma_lcache_lookup (const ecma_object_t *object_p, /**< object */
|
||||||
const ecma_string_t *prop_name_p) /**< property's name */
|
const ecma_string_t *prop_name_p) /**< property's name */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (object_p != NULL);
|
JERRY_ASSERT (object_p != NULL);
|
||||||
@@ -138,17 +148,16 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
|
|||||||
jmem_cpointer_t object_cp;
|
jmem_cpointer_t object_cp;
|
||||||
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
|
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
|
||||||
|
|
||||||
ecma_property_t prop_name_type;
|
ecma_property_t prop_name_type = ECMA_DIRECT_STRING_PTR;
|
||||||
jmem_cpointer_t prop_name_cp;
|
jmem_cpointer_t prop_name_cp;
|
||||||
|
|
||||||
if (ECMA_IS_DIRECT_STRING (prop_name_p))
|
if (JERRY_UNLIKELY (ECMA_IS_DIRECT_STRING (prop_name_p)))
|
||||||
{
|
{
|
||||||
prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p);
|
prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p);
|
||||||
prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p);
|
prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prop_name_type = ECMA_DIRECT_STRING_PTR;
|
|
||||||
ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p);
|
ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,18 +165,18 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
|
|||||||
|
|
||||||
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
|
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
|
||||||
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
|
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
|
||||||
|
|
||||||
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp);
|
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp);
|
||||||
|
|
||||||
while (entry_p < entry_end_p)
|
do
|
||||||
{
|
{
|
||||||
if (entry_p->id == id && ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type)
|
if (entry_p->id == id && JERRY_LIKELY (ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type))
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p));
|
JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p));
|
||||||
return entry_p->prop_p;
|
return entry_p->prop_p;
|
||||||
}
|
}
|
||||||
entry_p++;
|
entry_p++;
|
||||||
}
|
}
|
||||||
|
while (entry_p < entry_end_p);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} /* ecma_lcache_lookup */
|
} /* ecma_lcache_lookup */
|
||||||
@@ -176,8 +185,8 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
|
|||||||
* Invalidate LCache entries associated with given object and property name / property
|
* Invalidate LCache entries associated with given object and property name / property
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */
|
ecma_lcache_invalidate (const ecma_object_t *object_p, /**< object */
|
||||||
jmem_cpointer_t name_cp, /**< property name */
|
const jmem_cpointer_t name_cp, /**< property name */
|
||||||
ecma_property_t *prop_p) /**< property */
|
ecma_property_t *prop_p) /**< property */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (object_p != NULL);
|
JERRY_ASSERT (object_p != NULL);
|
||||||
|
|||||||
@@ -24,10 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if ENABLED (JERRY_LCACHE)
|
#if ENABLED (JERRY_LCACHE)
|
||||||
|
void ecma_lcache_insert (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p);
|
||||||
void ecma_lcache_insert (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p);
|
ecma_property_t *ecma_lcache_lookup (const ecma_object_t *object_p, const ecma_string_t *prop_name_p);
|
||||||
ecma_property_t *ecma_lcache_lookup (ecma_object_t *object_p, const ecma_string_t *prop_name_p);
|
void ecma_lcache_invalidate (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p);
|
||||||
void ecma_lcache_invalidate (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p);
|
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_LCACHE) */
|
#endif /* ENABLED (JERRY_LCACHE) */
|
||||||
|
|
||||||
|
|||||||
@@ -25,14 +25,46 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
/**
|
||||||
|
* Free symbol list
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
ecma_free_symbol_list (jmem_cpointer_t symbol_list_cp) /**< symbol list */
|
||||||
|
{
|
||||||
|
while (symbol_list_cp != JMEM_CP_NULL)
|
||||||
|
{
|
||||||
|
ecma_lit_storage_item_t *symbol_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, symbol_list_cp);
|
||||||
|
|
||||||
|
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||||
|
{
|
||||||
|
if (symbol_list_p->values[i] != JMEM_CP_NULL)
|
||||||
|
{
|
||||||
|
ecma_string_t *string_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
||||||
|
symbol_list_p->values[i]);
|
||||||
|
|
||||||
|
JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p));
|
||||||
|
ecma_deref_ecma_string (string_p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jmem_cpointer_t next_item_cp = symbol_list_p->next_cp;
|
||||||
|
jmem_pools_free (symbol_list_p, sizeof (ecma_lit_storage_item_t));
|
||||||
|
symbol_list_cp = next_item_cp;
|
||||||
|
}
|
||||||
|
} /* ecma_free_symbol_list */
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free string list
|
* Free string list
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ecma_free_string_list (ecma_lit_storage_item_t *string_list_p) /**< string list */
|
ecma_free_string_list (jmem_cpointer_t string_list_cp) /**< string list */
|
||||||
{
|
{
|
||||||
while (string_list_p != NULL)
|
while (string_list_cp != JMEM_CP_NULL)
|
||||||
{
|
{
|
||||||
|
ecma_lit_storage_item_t *string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, string_list_cp);
|
||||||
|
|
||||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||||
{
|
{
|
||||||
if (string_list_p->values[i] != JMEM_CP_NULL)
|
if (string_list_p->values[i] != JMEM_CP_NULL)
|
||||||
@@ -41,27 +73,53 @@ ecma_free_string_list (ecma_lit_storage_item_t *string_list_p) /**< string list
|
|||||||
string_list_p->values[i]);
|
string_list_p->values[i]);
|
||||||
|
|
||||||
JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p));
|
JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p));
|
||||||
ecma_deref_ecma_string (string_p);
|
ecma_destroy_ecma_string (string_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_lit_storage_item_t *prev_item = string_list_p;
|
jmem_cpointer_t next_item_cp = string_list_p->next_cp;
|
||||||
string_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, string_list_p->next_cp);
|
jmem_pools_free (string_list_p, sizeof (ecma_lit_storage_item_t));
|
||||||
jmem_pools_free (prev_item, sizeof (ecma_lit_storage_item_t));
|
string_list_cp = next_item_cp;
|
||||||
}
|
}
|
||||||
} /* ecma_free_string_list */
|
} /* ecma_free_string_list */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free number list
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
ecma_free_number_list (jmem_cpointer_t number_list_cp) /**< string list */
|
||||||
|
{
|
||||||
|
while (number_list_cp != JMEM_CP_NULL)
|
||||||
|
{
|
||||||
|
ecma_number_storage_item_t *number_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_number_storage_item_t,
|
||||||
|
number_list_cp);
|
||||||
|
|
||||||
|
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||||
|
{
|
||||||
|
if (number_list_p->values[i] != JMEM_CP_NULL)
|
||||||
|
{
|
||||||
|
ecma_number_t *num_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_number_t, number_list_p->values[i]);
|
||||||
|
ecma_dealloc_number (num_p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jmem_cpointer_t next_item_cp = number_list_p->next_cp;
|
||||||
|
jmem_pools_free (number_list_p, sizeof (ecma_number_storage_item_t));
|
||||||
|
number_list_cp = next_item_cp;
|
||||||
|
}
|
||||||
|
} /* ecma_free_number_list */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize literal storage
|
* Finalize literal storage
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ecma_finalize_lit_storage (void)
|
ecma_finalize_lit_storage (void)
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ecma_free_string_list (JERRY_CONTEXT (symbol_list_first_p));
|
ecma_free_symbol_list (JERRY_CONTEXT (symbol_list_first_cp));
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
ecma_free_string_list (JERRY_CONTEXT (string_list_first_p));
|
ecma_free_string_list (JERRY_CONTEXT (string_list_first_cp));
|
||||||
ecma_free_string_list (JERRY_CONTEXT (number_list_first_p));
|
ecma_free_number_list (JERRY_CONTEXT (number_list_first_cp));
|
||||||
} /* ecma_finalize_lit_storage */
|
} /* ecma_finalize_lit_storage */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,11 +138,13 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
|
|||||||
return ecma_make_string_value (string_p);
|
return ecma_make_string_value (string_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_lit_storage_item_t *string_list_p = JERRY_CONTEXT (string_list_first_p);
|
jmem_cpointer_t string_list_cp = JERRY_CONTEXT (string_list_first_cp);
|
||||||
jmem_cpointer_t *empty_cpointer_p = NULL;
|
jmem_cpointer_t *empty_cpointer_p = NULL;
|
||||||
|
|
||||||
while (string_list_p != NULL)
|
while (string_list_cp != JMEM_CP_NULL)
|
||||||
{
|
{
|
||||||
|
ecma_lit_storage_item_t *string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, string_list_cp);
|
||||||
|
|
||||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||||
{
|
{
|
||||||
if (string_list_p->values[i] == JMEM_CP_NULL)
|
if (string_list_p->values[i] == JMEM_CP_NULL)
|
||||||
@@ -108,9 +168,10 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, string_list_p->next_cp);
|
string_list_cp = string_list_p->next_cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ECMA_SET_STRING_AS_STATIC (string_p);
|
||||||
jmem_cpointer_t result;
|
jmem_cpointer_t result;
|
||||||
JMEM_CP_SET_NON_NULL_POINTER (result, string_p);
|
JMEM_CP_SET_NON_NULL_POINTER (result, string_p);
|
||||||
|
|
||||||
@@ -129,8 +190,8 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
|
|||||||
new_item_p->values[i] = JMEM_CP_NULL;
|
new_item_p->values[i] = JMEM_CP_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JMEM_CP_SET_POINTER (new_item_p->next_cp, JERRY_CONTEXT (string_list_first_p));
|
new_item_p->next_cp = JERRY_CONTEXT (string_list_first_cp);
|
||||||
JERRY_CONTEXT (string_list_first_p) = new_item_p;
|
JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (string_list_first_cp), new_item_p);
|
||||||
|
|
||||||
return ecma_make_string_value (string_p);
|
return ecma_make_string_value (string_p);
|
||||||
} /* ecma_find_or_create_literal_string */
|
} /* ecma_find_or_create_literal_string */
|
||||||
@@ -152,11 +213,14 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
|
|||||||
|
|
||||||
JERRY_ASSERT (ecma_is_value_float_number (num));
|
JERRY_ASSERT (ecma_is_value_float_number (num));
|
||||||
|
|
||||||
ecma_lit_storage_item_t *number_list_p = JERRY_CONTEXT (number_list_first_p);
|
jmem_cpointer_t number_list_cp = JERRY_CONTEXT (number_list_first_cp);
|
||||||
jmem_cpointer_t *empty_cpointer_p = NULL;
|
jmem_cpointer_t *empty_cpointer_p = NULL;
|
||||||
|
|
||||||
while (number_list_p != NULL)
|
while (number_list_cp != JMEM_CP_NULL)
|
||||||
{
|
{
|
||||||
|
ecma_number_storage_item_t *number_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_number_storage_item_t,
|
||||||
|
number_list_cp);
|
||||||
|
|
||||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||||
{
|
{
|
||||||
if (number_list_p->values[i] == JMEM_CP_NULL)
|
if (number_list_p->values[i] == JMEM_CP_NULL)
|
||||||
@@ -168,29 +232,24 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ecma_string_t *value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
ecma_number_t *number_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_number_t,
|
||||||
number_list_p->values[i]);
|
number_list_p->values[i]);
|
||||||
|
|
||||||
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
|
if (*number_p == number_arg)
|
||||||
JERRY_ASSERT (ecma_is_value_float_number (value_p->u.lit_number));
|
|
||||||
|
|
||||||
if (ecma_get_float_from_value (value_p->u.lit_number) == number_arg)
|
|
||||||
{
|
{
|
||||||
ecma_free_value (num);
|
ecma_free_value (num);
|
||||||
return value_p->u.lit_number;
|
return ecma_make_float_value (number_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
number_list_p = JMEM_CP_GET_POINTER (ecma_lit_storage_item_t, number_list_p->next_cp);
|
number_list_cp = number_list_p->next_cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_string_t *string_p = ecma_alloc_string ();
|
ecma_number_t *num_p = ecma_get_pointer_from_float_value (num);
|
||||||
string_p->refs_and_container = ECMA_STRING_REF_ONE | ECMA_STRING_LITERAL_NUMBER;
|
|
||||||
string_p->u.lit_number = num;
|
|
||||||
|
|
||||||
jmem_cpointer_t result;
|
jmem_cpointer_t result;
|
||||||
JMEM_CP_SET_NON_NULL_POINTER (result, string_p);
|
JMEM_CP_SET_NON_NULL_POINTER (result, num_p);
|
||||||
|
|
||||||
if (empty_cpointer_p != NULL)
|
if (empty_cpointer_p != NULL)
|
||||||
{
|
{
|
||||||
@@ -198,8 +257,8 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_lit_storage_item_t *new_item_p;
|
ecma_number_storage_item_t *new_item_p;
|
||||||
new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t));
|
new_item_p = (ecma_number_storage_item_t *) jmem_pools_alloc (sizeof (ecma_number_storage_item_t));
|
||||||
|
|
||||||
new_item_p->values[0] = result;
|
new_item_p->values[0] = result;
|
||||||
for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||||
@@ -207,8 +266,8 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
|
|||||||
new_item_p->values[i] = JMEM_CP_NULL;
|
new_item_p->values[i] = JMEM_CP_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JMEM_CP_SET_POINTER (new_item_p->next_cp, JERRY_CONTEXT (number_list_first_p));
|
new_item_p->next_cp = JERRY_CONTEXT (number_list_first_cp);
|
||||||
JERRY_CONTEXT (number_list_first_p) = new_item_p;
|
JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (number_list_first_cp), new_item_p);
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
} /* ecma_find_or_create_literal_number */
|
} /* ecma_find_or_create_literal_number */
|
||||||
@@ -239,7 +298,7 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
|
|||||||
* Append the value at the end of the appropriate list if it is not present there.
|
* Append the value at the end of the appropriate list if it is not present there.
|
||||||
*/
|
*/
|
||||||
void ecma_save_literals_append_value (ecma_value_t value, /**< value to be appended */
|
void ecma_save_literals_append_value (ecma_value_t value, /**< value to be appended */
|
||||||
ecma_collection_header_t *lit_pool_p) /**< list of known values */
|
ecma_collection_t *lit_pool_p) /**< list of known values */
|
||||||
{
|
{
|
||||||
/* Unlike direct numbers, direct strings are converted to character literals. */
|
/* Unlike direct numbers, direct strings are converted to character literals. */
|
||||||
if (!ecma_is_value_string (value) && !ecma_is_value_float_number (value))
|
if (!ecma_is_value_string (value) && !ecma_is_value_float_number (value))
|
||||||
@@ -247,21 +306,19 @@ void ecma_save_literals_append_value (ecma_value_t value, /**< value to be appen
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_t *iterator_p = ecma_collection_iterator_init (lit_pool_p);
|
ecma_value_t *buffer_p = lit_pool_p->buffer_p;
|
||||||
|
|
||||||
while (iterator_p != NULL)
|
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||||
{
|
{
|
||||||
/* Strings / numbers are direct strings or stored in the literal storage.
|
/* Strings / numbers are direct strings or stored in the literal storage.
|
||||||
* Therefore direct comparison is enough to find the same strings / numbers. */
|
* Therefore direct comparison is enough to find the same strings / numbers. */
|
||||||
if (*iterator_p == value)
|
if (buffer_p[i] == value)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator_p = ecma_collection_iterator_next (iterator_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_append_to_values_collection (lit_pool_p, value, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_push_back (lit_pool_p, value);
|
||||||
} /* ecma_save_literals_append_value */
|
} /* ecma_save_literals_append_value */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,7 +326,7 @@ void ecma_save_literals_append_value (ecma_value_t value, /**< value to be appen
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< byte-code data */
|
ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< byte-code data */
|
||||||
ecma_collection_header_t *lit_pool_p) /**< list of known values */
|
ecma_collection_t *lit_pool_p) /**< list of known values */
|
||||||
{
|
{
|
||||||
ecma_value_t *literal_p;
|
ecma_value_t *literal_p;
|
||||||
uint32_t argument_end = 0;
|
uint32_t argument_end = 0;
|
||||||
@@ -289,7 +346,7 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
|
|||||||
const_literal_end = args_p->const_literal_end - register_end;
|
const_literal_end = args_p->const_literal_end - register_end;
|
||||||
literal_end = args_p->literal_end - register_end;
|
literal_end = args_p->literal_end - register_end;
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (compiled_code_p))
|
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
argument_end = args_p->argument_end;
|
argument_end = args_p->argument_end;
|
||||||
}
|
}
|
||||||
@@ -304,7 +361,7 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
|
|||||||
const_literal_end = args_p->const_literal_end - register_end;
|
const_literal_end = args_p->const_literal_end - register_end;
|
||||||
literal_end = args_p->literal_end - register_end;
|
literal_end = args_p->literal_end - register_end;
|
||||||
|
|
||||||
if (CBC_NON_STRICT_ARGUMENTS_NEEDED (compiled_code_p))
|
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||||
{
|
{
|
||||||
argument_end = args_p->argument_end;
|
argument_end = args_p->argument_end;
|
||||||
}
|
}
|
||||||
@@ -355,7 +412,7 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
|
|||||||
* false - otherwise
|
* false - otherwise
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, /**< list of known values */
|
ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, /**< list of known values */
|
||||||
uint32_t *buffer_p, /**< [out] output snapshot buffer */
|
uint32_t *buffer_p, /**< [out] output snapshot buffer */
|
||||||
size_t buffer_size, /**< size of the buffer */
|
size_t buffer_size, /**< size of the buffer */
|
||||||
size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */
|
size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */
|
||||||
@@ -378,18 +435,18 @@ ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, /**< list
|
|||||||
max_lit_table_size = (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT);
|
max_lit_table_size = (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_t *iterator_p = ecma_collection_iterator_init (lit_pool_p);
|
ecma_value_t *lit_buffer_p = lit_pool_p->buffer_p;
|
||||||
|
|
||||||
/* Compute the size of the literal pool. */
|
/* Compute the size of the literal pool. */
|
||||||
while (iterator_p != NULL)
|
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||||
{
|
{
|
||||||
if (ecma_is_value_float_number (*iterator_p))
|
if (ecma_is_value_float_number (lit_buffer_p[i]))
|
||||||
{
|
{
|
||||||
lit_table_size += (uint32_t) sizeof (ecma_number_t);
|
lit_table_size += (uint32_t) sizeof (ecma_number_t);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ecma_string_t *string_p = ecma_get_string_from_value (*iterator_p);
|
ecma_string_t *string_p = ecma_get_string_from_value (lit_buffer_p[i]);
|
||||||
|
|
||||||
lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint16_t) + ecma_string_get_size (string_p),
|
lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint16_t) + ecma_string_get_size (string_p),
|
||||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||||
@@ -398,11 +455,9 @@ ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, /**< list
|
|||||||
/* Check whether enough space is available and the maximum size is not reached. */
|
/* Check whether enough space is available and the maximum size is not reached. */
|
||||||
if (lit_table_size > max_lit_table_size)
|
if (lit_table_size > max_lit_table_size)
|
||||||
{
|
{
|
||||||
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_destroy (lit_pool_p);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator_p = ecma_collection_iterator_next (iterator_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lit_mem_to_snapshot_id_map_entry_t *map_p;
|
lit_mem_to_snapshot_id_map_entry_t *map_p;
|
||||||
@@ -420,28 +475,28 @@ ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, /**< list
|
|||||||
*out_map_p = map_p;
|
*out_map_p = map_p;
|
||||||
*out_map_len_p = total_count;
|
*out_map_len_p = total_count;
|
||||||
|
|
||||||
iterator_p = ecma_collection_iterator_init (lit_pool_p);
|
lit_buffer_p = lit_pool_p->buffer_p;
|
||||||
|
|
||||||
/* Generate literal pool data. */
|
/* Generate literal pool data. */
|
||||||
while (iterator_p != NULL)
|
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||||
{
|
{
|
||||||
map_p->literal_id = *iterator_p;
|
map_p->literal_id = lit_buffer_p[i];
|
||||||
map_p->literal_offset = (literal_offset << JERRY_SNAPSHOT_LITERAL_SHIFT) | ECMA_TYPE_SNAPSHOT_OFFSET;
|
map_p->literal_offset = (literal_offset << JERRY_SNAPSHOT_LITERAL_SHIFT) | ECMA_TYPE_SNAPSHOT_OFFSET;
|
||||||
|
|
||||||
ecma_length_t length;
|
ecma_length_t length;
|
||||||
|
|
||||||
if (ecma_is_value_float_number (*iterator_p))
|
if (ecma_is_value_float_number (lit_buffer_p[i]))
|
||||||
{
|
{
|
||||||
map_p->literal_offset |= JERRY_SNAPSHOT_LITERAL_IS_NUMBER;
|
map_p->literal_offset |= JERRY_SNAPSHOT_LITERAL_IS_NUMBER;
|
||||||
|
|
||||||
ecma_number_t num = ecma_get_float_from_value (*iterator_p);
|
ecma_number_t num = ecma_get_float_from_value (lit_buffer_p[i]);
|
||||||
memcpy (destination_p, &num, sizeof (ecma_number_t));
|
memcpy (destination_p, &num, sizeof (ecma_number_t));
|
||||||
|
|
||||||
length = JERRY_ALIGNUP (sizeof (ecma_number_t), JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
length = JERRY_ALIGNUP (sizeof (ecma_number_t), JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ecma_string_t *string_p = ecma_get_string_from_value (*iterator_p);
|
ecma_string_t *string_p = ecma_get_string_from_value (lit_buffer_p[i]);
|
||||||
length = ecma_string_get_size (string_p);
|
length = ecma_string_get_size (string_p);
|
||||||
|
|
||||||
*(uint16_t *) destination_p = (uint16_t) length;
|
*(uint16_t *) destination_p = (uint16_t) length;
|
||||||
@@ -455,11 +510,10 @@ ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, /**< list
|
|||||||
destination_p += length;
|
destination_p += length;
|
||||||
literal_offset += length;
|
literal_offset += length;
|
||||||
|
|
||||||
iterator_p = ecma_collection_iterator_next (iterator_p);
|
|
||||||
map_p++;
|
map_p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_values_collection (lit_pool_p, ECMA_COLLECTION_NO_COPY);
|
ecma_collection_destroy (lit_pool_p);
|
||||||
return true;
|
return true;
|
||||||
} /* ecma_save_literals_for_snapshot */
|
} /* ecma_save_literals_for_snapshot */
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ ecma_value_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p,
|
|||||||
ecma_value_t ecma_find_or_create_literal_number (ecma_number_t number_arg);
|
ecma_value_t ecma_find_or_create_literal_number (ecma_number_t number_arg);
|
||||||
|
|
||||||
#if ENABLED (JERRY_SNAPSHOT_SAVE)
|
#if ENABLED (JERRY_SNAPSHOT_SAVE)
|
||||||
void ecma_save_literals_append_value (ecma_value_t value, ecma_collection_header_t *lit_pool_p);
|
void ecma_save_literals_append_value (ecma_value_t value, ecma_collection_t *lit_pool_p);
|
||||||
void ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,
|
void ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,
|
||||||
ecma_collection_header_t *lit_pool_p);
|
ecma_collection_t *lit_pool_p);
|
||||||
bool ecma_save_literals_for_snapshot (ecma_collection_header_t *lit_pool_p, uint32_t *buffer_p, size_t buffer_size,
|
bool ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, uint32_t *buffer_p, size_t buffer_size,
|
||||||
size_t *in_out_buffer_offset_p, lit_mem_to_snapshot_id_map_entry_t **out_map_p,
|
size_t *in_out_buffer_offset_p, lit_mem_to_snapshot_id_map_entry_t **out_map_p,
|
||||||
uint32_t *out_map_len_p);
|
uint32_t *out_map_len_p);
|
||||||
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
|
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ ecma_module_create_normalized_path (const uint8_t *char_p, /**< module specifier
|
|||||||
ECMA_MODULE_MAX_PATH,
|
ECMA_MODULE_MAX_PATH,
|
||||||
(char *) module_path_p);
|
(char *) module_path_p);
|
||||||
|
|
||||||
|
|
||||||
if (normalized_size > 0)
|
if (normalized_size > 0)
|
||||||
{
|
{
|
||||||
/* Convert the normalized path to cesu8. */
|
/* Convert the normalized path to cesu8. */
|
||||||
@@ -97,12 +96,13 @@ ecma_module_create_normalized_path (const uint8_t *char_p, /**< module specifier
|
|||||||
} /* ecma_module_create_normalized_path */
|
} /* ecma_module_create_normalized_path */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if we already have a module request in the module list.
|
* Find a module with a specific identifier
|
||||||
*
|
*
|
||||||
* @return pointer to found or newly created module structure
|
* @return pointer to ecma_module_t, if found
|
||||||
|
* NULL, otherwise
|
||||||
*/
|
*/
|
||||||
ecma_module_t *
|
ecma_module_t *
|
||||||
ecma_module_find_or_create_module (ecma_string_t * const path_p) /**< module path */
|
ecma_module_find_module (ecma_string_t *const path_p) /**< module identifier */
|
||||||
{
|
{
|
||||||
ecma_module_t *current_p = JERRY_CONTEXT (ecma_modules_p);
|
ecma_module_t *current_p = JERRY_CONTEXT (ecma_modules_p);
|
||||||
while (current_p != NULL)
|
while (current_p != NULL)
|
||||||
@@ -114,16 +114,59 @@ ecma_module_find_or_create_module (ecma_string_t * const path_p) /**< module pat
|
|||||||
current_p = current_p->next_p;
|
current_p = current_p->next_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_p = (ecma_module_t *) jmem_heap_alloc_block (sizeof (ecma_module_t));
|
|
||||||
memset (current_p, 0, sizeof (ecma_module_t));
|
|
||||||
|
|
||||||
ecma_ref_ecma_string (path_p);
|
|
||||||
current_p->path_p = path_p;
|
|
||||||
current_p->next_p = JERRY_CONTEXT (ecma_modules_p);
|
|
||||||
JERRY_CONTEXT (ecma_modules_p) = current_p;
|
|
||||||
return current_p;
|
return current_p;
|
||||||
|
} /* ecma_module_find_module */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new module
|
||||||
|
*
|
||||||
|
* @return pointer to created module
|
||||||
|
*/
|
||||||
|
static ecma_module_t *
|
||||||
|
ecma_module_create_module (ecma_string_t *const path_p) /**< module identifier */
|
||||||
|
{
|
||||||
|
ecma_module_t *module_p = (ecma_module_t *) jmem_heap_alloc_block (sizeof (ecma_module_t));
|
||||||
|
memset (module_p, 0, sizeof (ecma_module_t));
|
||||||
|
|
||||||
|
module_p->path_p = path_p;
|
||||||
|
module_p->next_p = JERRY_CONTEXT (ecma_modules_p);
|
||||||
|
JERRY_CONTEXT (ecma_modules_p) = module_p;
|
||||||
|
return module_p;
|
||||||
|
} /* ecma_module_create_module */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if we already have a module request in the module list.
|
||||||
|
*
|
||||||
|
* @return pointer to found or newly created module structure
|
||||||
|
*/
|
||||||
|
ecma_module_t *
|
||||||
|
ecma_module_find_or_create_module (ecma_string_t *const path_p) /**< module path */
|
||||||
|
{
|
||||||
|
ecma_module_t *module_p = ecma_module_find_module (path_p);
|
||||||
|
if (module_p)
|
||||||
|
{
|
||||||
|
ecma_deref_ecma_string (path_p);
|
||||||
|
return module_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecma_module_create_module (path_p);
|
||||||
} /* ecma_module_find_or_create_module */
|
} /* ecma_module_find_or_create_module */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new native module
|
||||||
|
*
|
||||||
|
* @return pointer to created module
|
||||||
|
*/
|
||||||
|
ecma_module_t *
|
||||||
|
ecma_module_create_native_module (ecma_string_t *const path_p, /**< module identifier */
|
||||||
|
ecma_object_t *const namespace_p) /**< module namespace */
|
||||||
|
{
|
||||||
|
ecma_module_t *module_p = ecma_module_create_module (path_p);
|
||||||
|
module_p->state = ECMA_MODULE_STATE_NATIVE;
|
||||||
|
module_p->namespace_object_p = namespace_p;
|
||||||
|
return module_p;
|
||||||
|
} /* ecma_module_create_native_module */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a module context.
|
* Creates a module context.
|
||||||
*
|
*
|
||||||
@@ -274,6 +317,30 @@ ecma_module_resolve_export (ecma_module_t * const module_p, /**< base module */
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (current_module_p->state == ECMA_MODULE_STATE_NATIVE)
|
||||||
|
{
|
||||||
|
ecma_object_t *object_p = current_module_p->namespace_object_p;
|
||||||
|
ecma_value_t prop_value = ecma_op_object_find_own (ecma_make_object_value (object_p),
|
||||||
|
object_p,
|
||||||
|
current_export_name_p);
|
||||||
|
if (ecma_is_value_found (prop_value))
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
found_record.module_p = current_module_p;
|
||||||
|
found_record.name_p = current_export_name_p;
|
||||||
|
ecma_free_value (prop_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ecma_compare_ecma_string_to_magic_id (current_export_name_p, LIT_MAGIC_STRING_DEFAULT))
|
||||||
|
{
|
||||||
|
ret_value = ecma_raise_syntax_error (ECMA_ERR_MSG ("No default export in native module."));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_module_resolve_stack_pop (&stack_p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (context_p->local_exports_p != NULL)
|
if (context_p->local_exports_p != NULL)
|
||||||
{
|
{
|
||||||
/* 15.2.1.16.3 / 4 */
|
/* 15.2.1.16.3 / 4 */
|
||||||
@@ -645,25 +712,44 @@ ecma_module_connect_imports (void)
|
|||||||
return ecma_raise_syntax_error (ECMA_ERR_MSG ("Ambiguous import request."));
|
return ecma_raise_syntax_error (ECMA_ERR_MSG ("Ambiguous import request."));
|
||||||
}
|
}
|
||||||
|
|
||||||
result = ecma_module_evaluate (record.module_p);
|
if (record.module_p->state == ECMA_MODULE_STATE_NATIVE)
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (result))
|
|
||||||
{
|
{
|
||||||
return result;
|
ecma_object_t *object_p = record.module_p->namespace_object_p;
|
||||||
|
ecma_value_t prop_value = ecma_op_object_find_own (ecma_make_object_value (object_p),
|
||||||
|
object_p,
|
||||||
|
record.name_p);
|
||||||
|
JERRY_ASSERT (ecma_is_value_found (prop_value));
|
||||||
|
|
||||||
|
ecma_op_create_mutable_binding (local_env_p, import_names_p->local_name_p, true /* is_deletable */);
|
||||||
|
ecma_op_set_mutable_binding (local_env_p,
|
||||||
|
import_names_p->local_name_p,
|
||||||
|
prop_value,
|
||||||
|
false /* is_strict */);
|
||||||
|
|
||||||
|
ecma_free_value (prop_value);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = ecma_module_evaluate (record.module_p);
|
||||||
|
|
||||||
ecma_object_t *ref_base_lex_env_p;
|
if (ECMA_IS_VALUE_ERROR (result))
|
||||||
ecma_value_t prop_value = ecma_op_get_value_lex_env_base (record.module_p->scope_p,
|
{
|
||||||
&ref_base_lex_env_p,
|
return result;
|
||||||
record.name_p);
|
}
|
||||||
|
|
||||||
ecma_op_create_mutable_binding (local_env_p, import_names_p->local_name_p, true /* is_deletable */);
|
ecma_object_t *ref_base_lex_env_p;
|
||||||
ecma_op_set_mutable_binding (local_env_p,
|
ecma_value_t prop_value = ecma_op_get_value_lex_env_base (record.module_p->scope_p,
|
||||||
import_names_p->local_name_p,
|
&ref_base_lex_env_p,
|
||||||
prop_value,
|
record.name_p);
|
||||||
false /* is_strict */);
|
|
||||||
|
|
||||||
ecma_free_value (prop_value);
|
ecma_op_create_mutable_binding (local_env_p, import_names_p->local_name_p, true /* is_deletable */);
|
||||||
|
ecma_op_set_mutable_binding (local_env_p,
|
||||||
|
import_names_p->local_name_p,
|
||||||
|
prop_value,
|
||||||
|
false /* is_strict */);
|
||||||
|
|
||||||
|
ecma_free_value (prop_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
import_names_p = import_names_p->next_p;
|
import_names_p = import_names_p->next_p;
|
||||||
@@ -731,7 +817,7 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
|
|||||||
0,
|
0,
|
||||||
(jerry_char_t *) source_p,
|
(jerry_char_t *) source_p,
|
||||||
source_size,
|
source_size,
|
||||||
JERRY_PARSE_STRICT_MODE,
|
ECMA_PARSE_STRICT_MODE | ECMA_PARSE_MODULE,
|
||||||
&bytecode_data_p);
|
&bytecode_data_p);
|
||||||
|
|
||||||
JERRY_CONTEXT (module_top_context_p) = module_p->context_p->parent_p;
|
JERRY_CONTEXT (module_top_context_p) = module_p->context_p->parent_p;
|
||||||
@@ -820,7 +906,7 @@ ecma_module_check_indirect_exports (void)
|
|||||||
/**
|
/**
|
||||||
* Cleans up a list of module names.
|
* Cleans up a list of module names.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
ecma_module_release_module_names (ecma_module_names_t *module_name_p) /**< first module name */
|
ecma_module_release_module_names (ecma_module_names_t *module_name_p) /**< first module name */
|
||||||
{
|
{
|
||||||
while (module_name_p != NULL)
|
while (module_name_p != NULL)
|
||||||
@@ -838,7 +924,7 @@ ecma_module_release_module_names (ecma_module_names_t *module_name_p) /**< first
|
|||||||
/**
|
/**
|
||||||
* Cleans up a list of module nodes.
|
* Cleans up a list of module nodes.
|
||||||
*/
|
*/
|
||||||
static void
|
void
|
||||||
ecma_module_release_module_nodes (ecma_module_node_t *module_node_p) /**< first module node */
|
ecma_module_release_module_nodes (ecma_module_node_t *module_node_p) /**< first module node */
|
||||||
{
|
{
|
||||||
while (module_node_p != NULL)
|
while (module_node_p != NULL)
|
||||||
@@ -873,6 +959,17 @@ static void
|
|||||||
ecma_module_release_module (ecma_module_t *module_p) /**< module */
|
ecma_module_release_module (ecma_module_t *module_p) /**< module */
|
||||||
{
|
{
|
||||||
ecma_deref_ecma_string (module_p->path_p);
|
ecma_deref_ecma_string (module_p->path_p);
|
||||||
|
|
||||||
|
if (module_p->namespace_object_p != NULL)
|
||||||
|
{
|
||||||
|
ecma_deref_object (module_p->namespace_object_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (module_p->state == ECMA_MODULE_STATE_NATIVE)
|
||||||
|
{
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
|
||||||
if (module_p->state >= ECMA_MODULE_STATE_PARSING)
|
if (module_p->state >= ECMA_MODULE_STATE_PARSING)
|
||||||
{
|
{
|
||||||
ecma_module_release_module_context (module_p->context_p);
|
ecma_module_release_module_context (module_p->context_p);
|
||||||
@@ -889,11 +986,7 @@ ecma_module_release_module (ecma_module_t *module_p) /**< module */
|
|||||||
ecma_bytecode_deref (module_p->compiled_code_p);
|
ecma_bytecode_deref (module_p->compiled_code_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module_p->namespace_object_p != NULL)
|
finished:
|
||||||
{
|
|
||||||
ecma_deref_object (module_p->namespace_object_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
jmem_heap_free_block (module_p, sizeof (ecma_module_t));
|
jmem_heap_free_block (module_p, sizeof (ecma_module_t));
|
||||||
} /* ecma_module_release_module */
|
} /* ecma_module_release_module */
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ typedef enum
|
|||||||
ECMA_MODULE_STATE_PARSED = 2, /**< module has been parsed */
|
ECMA_MODULE_STATE_PARSED = 2, /**< module has been parsed */
|
||||||
ECMA_MODULE_STATE_EVALUATING = 3, /**< module is currently being evaluated */
|
ECMA_MODULE_STATE_EVALUATING = 3, /**< module is currently being evaluated */
|
||||||
ECMA_MODULE_STATE_EVALUATED = 4, /**< module has been evaluated */
|
ECMA_MODULE_STATE_EVALUATED = 4, /**< module has been evaluated */
|
||||||
|
ECMA_MODULE_STATE_NATIVE = 5, /**< module is native */
|
||||||
} ecma_module_state_t;
|
} ecma_module_state_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,24 +117,27 @@ typedef struct ecma_module_resolve_stack
|
|||||||
} ecma_module_resolve_stack_t;
|
} ecma_module_resolve_stack_t;
|
||||||
|
|
||||||
bool ecma_module_resolve_set_insert (ecma_module_resolve_set_t **set_p,
|
bool ecma_module_resolve_set_insert (ecma_module_resolve_set_t **set_p,
|
||||||
ecma_module_t * const module_p,
|
ecma_module_t *const module_p,
|
||||||
ecma_string_t * const export_name_p);
|
ecma_string_t *const export_name_p);
|
||||||
void ecma_module_resolve_set_cleanup (ecma_module_resolve_set_t *set_p);
|
void ecma_module_resolve_set_cleanup (ecma_module_resolve_set_t *set_p);
|
||||||
|
|
||||||
void ecma_module_resolve_stack_push (ecma_module_resolve_stack_t **stack_p,
|
void ecma_module_resolve_stack_push (ecma_module_resolve_stack_t **stack_p,
|
||||||
ecma_module_t * const module_p,
|
ecma_module_t *const module_p,
|
||||||
ecma_string_t * const export_name_p);
|
ecma_string_t *const export_name_p);
|
||||||
void ecma_module_resolve_stack_pop (ecma_module_resolve_stack_t **stack_p);
|
void ecma_module_resolve_stack_pop (ecma_module_resolve_stack_t **stack_p);
|
||||||
|
|
||||||
ecma_string_t *ecma_module_create_normalized_path (const uint8_t *char_p,
|
ecma_string_t *ecma_module_create_normalized_path (const uint8_t *char_p,
|
||||||
prop_length_t size);
|
prop_length_t size);
|
||||||
ecma_module_t *ecma_module_find_or_create_module (ecma_string_t * const path_p);
|
ecma_module_t *ecma_module_find_module (ecma_string_t *const path_p);
|
||||||
|
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_connect_imports (void);
|
||||||
ecma_value_t ecma_module_parse_modules (void);
|
ecma_value_t ecma_module_parse_modules (void);
|
||||||
ecma_value_t ecma_module_check_indirect_exports (void);
|
ecma_value_t ecma_module_check_indirect_exports (void);
|
||||||
|
|
||||||
void ecma_module_release_module_names (ecma_module_names_t *module_name_p);
|
void ecma_module_release_module_nodes (ecma_module_node_t *module_node_p);
|
||||||
void ecma_module_cleanup (void);
|
void ecma_module_cleanup (void);
|
||||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF
|
|||||||
#define ECMA_PROPERTY_HASHMAP_SET_BIT(byte_p, index) \
|
#define ECMA_PROPERTY_HASHMAP_SET_BIT(byte_p, index) \
|
||||||
((byte_p)[(index) >> 3] = (uint8_t) ((byte_p)[(index) >> 3] | (1 << ((index) & 0x7))))
|
((byte_p)[(index) >> 3] = (uint8_t) ((byte_p)[(index) >> 3] | (1 << ((index) & 0x7))))
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new property hashmap for the object.
|
* Create a new property hashmap for the object.
|
||||||
* The object must not have a property hashmap.
|
* The object must not have a property hashmap.
|
||||||
@@ -74,25 +72,23 @@ static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF
|
|||||||
void
|
void
|
||||||
ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
|
||||||
if (JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) != ECMA_PROP_HASHMAP_ALLOC_ON)
|
if (JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) != ECMA_PROP_HASHMAP_ALLOC_ON)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_property_header_t *prop_iter_p = ecma_get_property_list (object_p);
|
jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp;
|
||||||
|
|
||||||
if (prop_iter_p == NULL)
|
if (prop_iter_cp == JMEM_CP_NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
|
||||||
|
|
||||||
uint32_t named_property_count = 0;
|
uint32_t named_property_count = 0;
|
||||||
|
|
||||||
while (prop_iter_p != NULL)
|
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));
|
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||||
|
|
||||||
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
||||||
@@ -104,8 +100,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
|||||||
named_property_count++;
|
named_property_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t,
|
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||||
prop_iter_p->next_property_cp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (named_property_count < (ECMA_PROPERTY_HASMAP_MINIMUM_SIZE / 2))
|
if (named_property_count < (ECMA_PROPERTY_HASMAP_MINIMUM_SIZE / 2))
|
||||||
@@ -134,8 +129,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
|||||||
memset (hashmap_p, 0, total_size);
|
memset (hashmap_p, 0, total_size);
|
||||||
|
|
||||||
hashmap_p->header.types[0] = ECMA_PROPERTY_TYPE_HASHMAP;
|
hashmap_p->header.types[0] = ECMA_PROPERTY_TYPE_HASHMAP;
|
||||||
hashmap_p->header.types[1] = 0;
|
hashmap_p->header.next_property_cp = object_p->u1.property_list_cp;
|
||||||
hashmap_p->header.next_property_cp = object_p->property_list_or_bound_object_cp;
|
|
||||||
hashmap_p->max_property_count = max_property_count;
|
hashmap_p->max_property_count = max_property_count;
|
||||||
hashmap_p->null_count = max_property_count - named_property_count;
|
hashmap_p->null_count = max_property_count - named_property_count;
|
||||||
hashmap_p->unused_count = max_property_count - named_property_count;
|
hashmap_p->unused_count = max_property_count - named_property_count;
|
||||||
@@ -144,21 +138,12 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
|||||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + max_property_count);
|
uint8_t *bits_p = (uint8_t *) (pair_list_p + max_property_count);
|
||||||
uint32_t mask = max_property_count - 1;
|
uint32_t mask = max_property_count - 1;
|
||||||
|
|
||||||
uint8_t shift_counter = 0;
|
prop_iter_cp = object_p->u1.property_list_cp;
|
||||||
|
ECMA_SET_NON_NULL_POINTER (object_p->u1.property_list_cp, hashmap_p);
|
||||||
|
|
||||||
while (max_property_count > LIT_STRING_HASH_LIMIT)
|
while (prop_iter_cp != JMEM_CP_NULL)
|
||||||
{
|
|
||||||
shift_counter++;
|
|
||||||
max_property_count >>= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
hashmap_p->header.types[1] = shift_counter;
|
|
||||||
|
|
||||||
prop_iter_p = ecma_get_property_list (object_p);
|
|
||||||
ECMA_SET_POINTER (object_p->property_list_or_bound_object_cp, hashmap_p);
|
|
||||||
|
|
||||||
while (prop_iter_p != 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));
|
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||||
|
|
||||||
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
||||||
@@ -174,16 +159,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
|||||||
property_pair_p->names_cp[i]);
|
property_pair_p->names_cp[i]);
|
||||||
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
||||||
|
|
||||||
if (mask < LIT_STRING_HASH_LIMIT)
|
entry_index &= mask;
|
||||||
{
|
|
||||||
entry_index &= mask;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry_index <<= shift_counter;
|
|
||||||
JERRY_ASSERT (entry_index <= mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
/* Because max_property_count (power of 2) and step (a prime
|
/* Because max_property_count (power of 2) and step (a prime
|
||||||
* number) are relative primes, all entries of the hasmap are
|
* number) are relative primes, all entries of the hasmap are
|
||||||
@@ -203,7 +179,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
|||||||
#endif /* !JERRY_NDEBUG */
|
#endif /* !JERRY_NDEBUG */
|
||||||
}
|
}
|
||||||
|
|
||||||
ECMA_SET_POINTER (pair_list_p[entry_index], property_pair_p);
|
ECMA_SET_NON_NULL_POINTER (pair_list_p[entry_index], property_pair_p);
|
||||||
|
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
{
|
{
|
||||||
@@ -211,12 +187,8 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t,
|
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||||
prop_iter_p->next_property_cp);
|
|
||||||
}
|
}
|
||||||
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
JERRY_UNUSED (object_p);
|
|
||||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
} /* ecma_property_hashmap_create */
|
} /* ecma_property_hashmap_create */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -226,21 +198,20 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
|||||||
void
|
void
|
||||||
ecma_property_hashmap_free (ecma_object_t *object_p) /**< object */
|
ecma_property_hashmap_free (ecma_object_t *object_p) /**< object */
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
|
||||||
/* Property hash must be exists and must be the first property. */
|
/* Property hash must be exists and must be the first property. */
|
||||||
ecma_property_header_t *property_p = ecma_get_property_list (object_p);
|
JERRY_ASSERT (object_p->u1.property_list_cp != JMEM_CP_NULL);
|
||||||
|
|
||||||
JERRY_ASSERT (property_p != NULL && property_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
ecma_property_header_t *property_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t,
|
||||||
|
object_p->u1.property_list_cp);
|
||||||
|
|
||||||
|
JERRY_ASSERT (property_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
||||||
|
|
||||||
ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) property_p;
|
ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) property_p;
|
||||||
|
|
||||||
object_p->property_list_or_bound_object_cp = property_p->next_property_cp;
|
object_p->u1.property_list_cp = property_p->next_property_cp;
|
||||||
|
|
||||||
jmem_heap_free_block (hashmap_p,
|
jmem_heap_free_block (hashmap_p,
|
||||||
ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (hashmap_p->max_property_count));
|
ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (hashmap_p->max_property_count));
|
||||||
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
JERRY_UNUSED (object_p);
|
|
||||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
} /* ecma_property_hashmap_free */
|
} /* ecma_property_hashmap_free */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -252,9 +223,10 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
|
|||||||
ecma_property_pair_t *property_pair_p, /**< property pair */
|
ecma_property_pair_t *property_pair_p, /**< property pair */
|
||||||
int property_index) /**< property index in the pair (0 or 1) */
|
int property_index) /**< property index in the pair (0 or 1) */
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
JERRY_ASSERT (property_pair_p != NULL);
|
||||||
|
|
||||||
ecma_property_hashmap_t *hashmap_p = ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t,
|
ecma_property_hashmap_t *hashmap_p = ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t,
|
||||||
object_p->property_list_or_bound_object_cp);
|
object_p->u1.property_list_cp);
|
||||||
|
|
||||||
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
||||||
|
|
||||||
@@ -271,15 +243,7 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
|
|||||||
uint32_t entry_index = ecma_string_hash (name_p);
|
uint32_t entry_index = ecma_string_hash (name_p);
|
||||||
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
||||||
uint32_t mask = hashmap_p->max_property_count - 1;
|
uint32_t mask = hashmap_p->max_property_count - 1;
|
||||||
|
entry_index &= mask;
|
||||||
if (mask < LIT_STRING_HASH_LIMIT)
|
|
||||||
{
|
|
||||||
entry_index &= mask;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry_index <<= hashmap_p->header.types[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
/* See the comment for this variable in ecma_property_hashmap_create. */
|
/* See the comment for this variable in ecma_property_hashmap_create. */
|
||||||
@@ -297,7 +261,7 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
|
|||||||
#endif /* !JERRY_NDEBUG */
|
#endif /* !JERRY_NDEBUG */
|
||||||
}
|
}
|
||||||
|
|
||||||
ECMA_SET_POINTER (pair_list_p[entry_index], property_pair_p);
|
ECMA_SET_NON_NULL_POINTER (pair_list_p[entry_index], property_pair_p);
|
||||||
|
|
||||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
||||||
bits_p += (entry_index >> 3);
|
bits_p += (entry_index >> 3);
|
||||||
@@ -322,12 +286,6 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
|
|||||||
{
|
{
|
||||||
*bits_p = (uint8_t) ((*bits_p) | mask);
|
*bits_p = (uint8_t) ((*bits_p) | mask);
|
||||||
}
|
}
|
||||||
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
JERRY_UNUSED (object_p);
|
|
||||||
JERRY_UNUSED (name_p);
|
|
||||||
JERRY_UNUSED (property_pair_p);
|
|
||||||
JERRY_UNUSED (property_index);
|
|
||||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
} /* ecma_property_hashmap_insert */
|
} /* ecma_property_hashmap_insert */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,9 +299,8 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
|
|||||||
jmem_cpointer_t name_cp, /**< property name */
|
jmem_cpointer_t name_cp, /**< property name */
|
||||||
ecma_property_t *property_p) /**< property */
|
ecma_property_t *property_p) /**< property */
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
|
||||||
ecma_property_hashmap_t *hashmap_p = ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t,
|
ecma_property_hashmap_t *hashmap_p = ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t,
|
||||||
object_p->property_list_or_bound_object_cp);
|
object_p->u1.property_list_cp);
|
||||||
|
|
||||||
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
||||||
|
|
||||||
@@ -361,15 +318,7 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
|
|||||||
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
||||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
||||||
|
|
||||||
if (mask < LIT_STRING_HASH_LIMIT)
|
entry_index &= mask;
|
||||||
{
|
|
||||||
entry_index &= mask;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry_index <<= hashmap_p->header.types[1];
|
|
||||||
JERRY_ASSERT (entry_index <= mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
/* See the comment for this variable in ecma_property_hashmap_create. */
|
/* See the comment for this variable in ecma_property_hashmap_create. */
|
||||||
@@ -411,16 +360,8 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
|
|||||||
JERRY_ASSERT (entry_index != start_entry_index);
|
JERRY_ASSERT (entry_index != start_entry_index);
|
||||||
#endif /* !JERRY_NDEBUG */
|
#endif /* !JERRY_NDEBUG */
|
||||||
}
|
}
|
||||||
#else /* !ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
JERRY_UNUSED (object_p);
|
|
||||||
JERRY_UNUSED (name_cp);
|
|
||||||
JERRY_UNUSED (property_p);
|
|
||||||
|
|
||||||
return ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP;
|
|
||||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
|
||||||
} /* ecma_property_hashmap_delete */
|
} /* ecma_property_hashmap_delete */
|
||||||
|
|
||||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
|
||||||
/**
|
/**
|
||||||
* Find a named property.
|
* Find a named property.
|
||||||
*
|
*
|
||||||
@@ -437,11 +378,12 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
|
|||||||
* from both data collection. The following code checks the property
|
* from both data collection. The following code checks the property
|
||||||
* chain, and sets the property_found variable. */
|
* chain, and sets the property_found variable. */
|
||||||
bool property_found = false;
|
bool property_found = false;
|
||||||
ecma_property_header_t *prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t,
|
|
||||||
hashmap_p->header.next_property_cp);
|
|
||||||
|
|
||||||
while (prop_iter_p != NULL && !property_found)
|
jmem_cpointer_t prop_iter_cp = hashmap_p->header.next_property_cp;
|
||||||
|
|
||||||
|
while (prop_iter_cp != JMEM_CP_NULL && !property_found)
|
||||||
{
|
{
|
||||||
|
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));
|
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||||
|
|
||||||
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
||||||
@@ -454,14 +396,14 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
|
|||||||
prop_pair_p->names_cp[i],
|
prop_pair_p->names_cp[i],
|
||||||
name_p))
|
name_p))
|
||||||
{
|
{
|
||||||
|
/* Property is found */
|
||||||
property_found = true;
|
property_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t,
|
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||||
prop_iter_p->next_property_cp);
|
|
||||||
}
|
}
|
||||||
#endif /* !JERRY_NDEBUG */
|
#endif /* !JERRY_NDEBUG */
|
||||||
|
|
||||||
@@ -470,16 +412,7 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
|
|||||||
uint32_t mask = hashmap_p->max_property_count - 1;
|
uint32_t mask = hashmap_p->max_property_count - 1;
|
||||||
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
||||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
||||||
|
entry_index &= mask;
|
||||||
if (mask < LIT_STRING_HASH_LIMIT)
|
|
||||||
{
|
|
||||||
entry_index &= mask;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry_index <<= hashmap_p->header.types[1];
|
|
||||||
JERRY_ASSERT (entry_index <= mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
/* See the comment for this variable in ecma_property_hashmap_create. */
|
/* See the comment for this variable in ecma_property_hashmap_create. */
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
} ecma_property_hashmap_t;
|
} ecma_property_hashmap_t;
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple ecma values
|
* Simple ecma values
|
||||||
*/
|
*/
|
||||||
@@ -70,7 +72,6 @@ void ecma_property_hashmap_insert (ecma_object_t *object_p, ecma_string_t *name_
|
|||||||
ecma_property_hashmap_delete_status ecma_property_hashmap_delete (ecma_object_t *object_p, jmem_cpointer_t name_cp,
|
ecma_property_hashmap_delete_status ecma_property_hashmap_delete (ecma_object_t *object_p, jmem_cpointer_t name_cp,
|
||||||
ecma_property_t *property_p);
|
ecma_property_t *property_p);
|
||||||
|
|
||||||
#if ENABLED (JERRY_PROPRETY_HASHMAP)
|
|
||||||
ecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, ecma_string_t *name_p,
|
ecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, ecma_string_t *name_p,
|
||||||
jmem_cpointer_t *property_real_name_cp);
|
jmem_cpointer_t *property_real_name_cp);
|
||||||
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
|
||||||
|
|||||||
@@ -18,11 +18,7 @@
|
|||||||
#include "ecma-iterator-object.h"
|
#include "ecma-iterator-object.h"
|
||||||
#include "ecma-typedarray-object.h"
|
#include "ecma-typedarray-object.h"
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
#if !ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
|
||||||
#error "Iterator builtin requires ES2015 symbol builtin"
|
|
||||||
#endif /* !ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
|
||||||
|
|
||||||
#define ECMA_BUILTINS_INTERNAL
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
#include "ecma-builtins-internal.h"
|
#include "ecma-builtins-internal.h"
|
||||||
@@ -82,40 +78,14 @@ ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< t
|
|||||||
|
|
||||||
ecma_object_t *array_object_p = ecma_get_object_from_value (iterated_value);
|
ecma_object_t *array_object_p = ecma_get_object_from_value (iterated_value);
|
||||||
|
|
||||||
uint32_t length;
|
|
||||||
|
|
||||||
/* 8 - 9. */
|
/* 8 - 9. */
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
uint32_t length;
|
||||||
if (ecma_is_typedarray (ecma_make_object_value (array_object_p)))
|
ecma_value_t len_value = ecma_op_object_get_length (array_object_p, &length);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (len_value))
|
||||||
{
|
{
|
||||||
length = ecma_typedarray_get_length (array_object_p);
|
return len_value;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
|
||||||
ecma_value_t len_value = ecma_op_object_get (array_object_p,
|
|
||||||
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH));
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (len_value))
|
|
||||||
{
|
|
||||||
return len_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_number_t length_number;
|
|
||||||
ecma_value_t length_value = ecma_get_number (len_value, &length_number);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (length_value))
|
|
||||||
{
|
|
||||||
ecma_free_value (len_value);
|
|
||||||
return length_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
length = ecma_number_to_uint32 (length_number);
|
|
||||||
|
|
||||||
ecma_free_value (len_value);
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
|
||||||
}
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
|
||||||
|
|
||||||
uint32_t index = ext_obj_p->u.pseudo_array.u1.iterator_index;
|
uint32_t index = ext_obj_p->u.pseudo_array.u1.iterator_index;
|
||||||
|
|
||||||
@@ -161,12 +131,8 @@ ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< t
|
|||||||
return ecma_create_iter_result_object (ecma_make_uint32_value (index), ECMA_VALUE_FALSE);
|
return ecma_create_iter_result_object (ecma_make_uint32_value (index), ECMA_VALUE_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 13. */
|
|
||||||
ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index);
|
|
||||||
|
|
||||||
/* 14. */
|
/* 14. */
|
||||||
ecma_value_t get_value = ecma_op_object_get (array_object_p, index_string_p);
|
ecma_value_t get_value = ecma_op_object_get_by_uint32_index (array_object_p, index);
|
||||||
ecma_deref_ecma_string (index_string_p);
|
|
||||||
|
|
||||||
/* 15. */
|
/* 15. */
|
||||||
if (ECMA_IS_VALUE_ERROR (get_value))
|
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||||
@@ -206,4 +172,4 @@ ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< t
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
LIT_MAGIC_STRING_ARRAY_ITERATOR_UL,
|
LIT_MAGIC_STRING_ARRAY_ITERATOR_UL,
|
||||||
@@ -29,6 +29,6 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
|||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
ROUTINE (LIT_MAGIC_STRING_NEXT, ecma_builtin_array_iterator_prototype_object_next, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_NEXT, ecma_builtin_array_iterator_prototype_object_next, 0, 0)
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers.h"
|
||||||
|
#include "ecma-builtins.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
|
#include "ecma-builtins-internal.h"
|
||||||
|
|
||||||
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array-prototype-unscopables.inc.h"
|
||||||
|
#define BUILTIN_UNDERSCORED_ID array_prototype_unscopables
|
||||||
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Array.prototype[@@unscopables] built-in description
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
SIMPLE_VALUE (LIT_MAGIC_STRING_COPY_WITHIN,
|
||||||
|
ECMA_VALUE_TRUE,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE)
|
||||||
|
|
||||||
|
SIMPLE_VALUE (LIT_MAGIC_STRING_ENTRIES,
|
||||||
|
ECMA_VALUE_TRUE,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE)
|
||||||
|
|
||||||
|
SIMPLE_VALUE (LIT_MAGIC_STRING_FILL,
|
||||||
|
ECMA_VALUE_TRUE,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE)
|
||||||
|
|
||||||
|
SIMPLE_VALUE (LIT_MAGIC_STRING_FIND,
|
||||||
|
ECMA_VALUE_TRUE,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE)
|
||||||
|
|
||||||
|
SIMPLE_VALUE (LIT_MAGIC_STRING_FIND_INDEX,
|
||||||
|
ECMA_VALUE_TRUE,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE)
|
||||||
|
|
||||||
|
SIMPLE_VALUE (LIT_MAGIC_STRING_KEYS,
|
||||||
|
ECMA_VALUE_TRUE,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE)
|
||||||
|
|
||||||
|
SIMPLE_VALUE (LIT_MAGIC_STRING_VALUES,
|
||||||
|
ECMA_VALUE_TRUE,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE)
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,13 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
|||||||
ECMA_BUILTIN_ID_ARRAY,
|
ECMA_BUILTIN_ID_ARRAY,
|
||||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
/* ECMA-262 v6, 22.1.3.31 */
|
||||||
|
OBJECT_VALUE (LIT_GLOBAL_SYMBOL_UNSCOPABLES,
|
||||||
|
ECMA_BUILTIN_ID_ARRAY_PROTOTYPE_UNSCOPABLES,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* Number properties:
|
/* Number properties:
|
||||||
* (property name, object pointer getter) */
|
* (property name, object pointer getter) */
|
||||||
|
|
||||||
@@ -60,18 +67,18 @@ ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ECMA_ARRAY_PROTOTYPE_FOR_EACH, 2, 1)
|
|||||||
ROUTINE (LIT_MAGIC_STRING_MAP, ECMA_ARRAY_PROTOTYPE_MAP, 2, 1)
|
ROUTINE (LIT_MAGIC_STRING_MAP, ECMA_ARRAY_PROTOTYPE_MAP, 2, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_FILTER, ECMA_ARRAY_PROTOTYPE_FILTER, 2, 1)
|
ROUTINE (LIT_MAGIC_STRING_FILTER, ECMA_ARRAY_PROTOTYPE_FILTER, 2, 1)
|
||||||
/* Note these 2 routines must be in this order */
|
/* Note these 2 routines must be in this order */
|
||||||
ROUTINE (LIT_MAGIC_STRING_REDUCE, ECMA_ARRAY_PROTOTYPE_REDUCE, NON_FIXED, 1)
|
ROUTINE (LIT_MAGIC_STRING_REDUCE, ECMA_ARRAY_PROTOTYPE_REDUCE, 2, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ECMA_ARRAY_PROTOTYPE_REDUCE_RIGHT, NON_FIXED, 1)
|
ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ECMA_ARRAY_PROTOTYPE_REDUCE_RIGHT, 2, 1)
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ROUTINE (LIT_MAGIC_STRING_FIND, ECMA_ARRAY_PROTOTYPE_FIND, 2, 1)
|
ROUTINE (LIT_MAGIC_STRING_FIND, ECMA_ARRAY_PROTOTYPE_FIND, 2, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_FIND_INDEX, ECMA_ARRAY_PROTOTYPE_FIND_INDEX, 2, 1)
|
ROUTINE (LIT_MAGIC_STRING_FIND_INDEX, ECMA_ARRAY_PROTOTYPE_FIND_INDEX, 2, 1)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
ROUTINE (LIT_MAGIC_STRING_FILL, ECMA_ARRAY_PROTOTYPE_FILL, 3, 1)
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
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_ENTRIES, ECMA_ARRAY_PROTOTYPE_ENTRIES, 0, 0)
|
||||||
ROUTINE (LIT_MAGIC_STRING_VALUES, ECMA_ARRAY_PROTOTYPE_VALUES, 0, 0)
|
|
||||||
ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_ARRAY_PROTOTYPE_KEYS, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_ARRAY_PROTOTYPE_KEYS, 0, 0)
|
||||||
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ECMA_ARRAY_PROTOTYPE_SYMBOL_ITERATOR, 0, 0)
|
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_VALUES, LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
INTRINSIC_PROPERTY (LIT_GLOBAL_SYMBOL_ITERATOR, LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
#endif /* ENABLED (JERRY_BUILTIN_ARRAY) */
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,16 @@
|
|||||||
|
|
||||||
#include "ecma-alloc.h"
|
#include "ecma-alloc.h"
|
||||||
#include "ecma-builtins.h"
|
#include "ecma-builtins.h"
|
||||||
|
#include "ecma-builtin-helpers.h"
|
||||||
#include "ecma-conversion.h"
|
#include "ecma-conversion.h"
|
||||||
#include "ecma-exceptions.h"
|
#include "ecma-exceptions.h"
|
||||||
|
#include "ecma-function-object.h"
|
||||||
#include "ecma-gc.h"
|
#include "ecma-gc.h"
|
||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "ecma-helpers.h"
|
#include "ecma-helpers.h"
|
||||||
|
#include "ecma-iterator-object.h"
|
||||||
#include "ecma-objects.h"
|
#include "ecma-objects.h"
|
||||||
#include "ecma-array-object.h"
|
#include "ecma-array-object.h"
|
||||||
#include "ecma-try-catch-macro.h"
|
|
||||||
#include "jrt.h"
|
#include "jrt.h"
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_ARRAY)
|
#if ENABLED (JERRY_BUILTIN_ARRAY)
|
||||||
@@ -58,20 +60,419 @@ ecma_builtin_array_object_is_array (ecma_value_t this_arg, /**< 'this' argument
|
|||||||
ecma_value_t arg) /**< first argument */
|
ecma_value_t arg) /**< first argument */
|
||||||
{
|
{
|
||||||
JERRY_UNUSED (this_arg);
|
JERRY_UNUSED (this_arg);
|
||||||
ecma_value_t is_array = ECMA_VALUE_FALSE;
|
|
||||||
|
|
||||||
if (ecma_is_value_object (arg))
|
return ecma_make_boolean_value (ecma_is_value_array (arg));
|
||||||
|
} /* ecma_builtin_array_object_is_array */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
/**
|
||||||
|
* The Array object's 'from' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 22.1.2.1
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_array_object_from (ecma_value_t this_arg, /**< 'this' argument */
|
||||||
|
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||||
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
|
{
|
||||||
|
/* 1. */
|
||||||
|
ecma_value_t constructor = this_arg;
|
||||||
|
ecma_value_t call_this_arg = ECMA_VALUE_UNDEFINED;
|
||||||
|
ecma_value_t items = arguments_list_p[0];
|
||||||
|
ecma_value_t mapfn = (arguments_list_len > 1) ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
||||||
|
|
||||||
|
/* 2. */
|
||||||
|
ecma_object_t *mapfn_obj_p = NULL;
|
||||||
|
|
||||||
|
/* 3. */
|
||||||
|
if (!ecma_is_value_undefined (mapfn))
|
||||||
{
|
{
|
||||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
/* 3.a */
|
||||||
|
if (!ecma_op_is_callable (mapfn))
|
||||||
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_ARRAY_UL)
|
|
||||||
{
|
{
|
||||||
is_array = ECMA_VALUE_TRUE;
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Callback function is not callable."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 3.b */
|
||||||
|
if (arguments_list_len > 2)
|
||||||
|
{
|
||||||
|
call_this_arg = arguments_list_p[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 3.c */
|
||||||
|
mapfn_obj_p = ecma_get_object_from_value (mapfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_array;
|
/* 4. */
|
||||||
} /* ecma_builtin_array_object_is_array */
|
ecma_value_t using_iterator = ecma_op_get_method_by_symbol_id (items, LIT_GLOBAL_SYMBOL_ITERATOR);
|
||||||
|
|
||||||
|
/* 5. */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (using_iterator))
|
||||||
|
{
|
||||||
|
return using_iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||||
|
|
||||||
|
/* 6. */
|
||||||
|
if (!ecma_is_value_undefined (using_iterator))
|
||||||
|
{
|
||||||
|
ecma_value_t array;
|
||||||
|
|
||||||
|
/* 6.a */
|
||||||
|
if (ecma_is_constructor (constructor))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (ecma_is_value_undefined (array) || ecma_is_value_null (array))
|
||||||
|
{
|
||||||
|
ecma_free_value (using_iterator);
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot convert undefined or null to object"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* 6.b */
|
||||||
|
array = ecma_op_create_array_object (NULL, 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 6.c */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (array))
|
||||||
|
{
|
||||||
|
ecma_free_value (using_iterator);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *array_obj_p = ecma_get_object_from_value (array);
|
||||||
|
|
||||||
|
/* 6.d */
|
||||||
|
ecma_value_t iterator = ecma_op_get_iterator (items, using_iterator);
|
||||||
|
ecma_free_value (using_iterator);
|
||||||
|
|
||||||
|
/* 6.e */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (iterator))
|
||||||
|
{
|
||||||
|
ecma_free_value (array);
|
||||||
|
return iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 6.f */
|
||||||
|
uint32_t k = 0;
|
||||||
|
|
||||||
|
/* 6.g */
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
/* 6.g.ii */
|
||||||
|
ecma_value_t next = ecma_op_iterator_step (iterator);
|
||||||
|
|
||||||
|
/* 6.g.iii */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (next))
|
||||||
|
{
|
||||||
|
goto iterator_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 6.g.iii */
|
||||||
|
if (ecma_is_value_false (next))
|
||||||
|
{
|
||||||
|
/* 6.g.iv.1 */
|
||||||
|
ecma_value_t len_value = ecma_make_uint32_value (k);
|
||||||
|
ecma_value_t set_status = ecma_op_object_put (array_obj_p,
|
||||||
|
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH),
|
||||||
|
len_value,
|
||||||
|
true);
|
||||||
|
ecma_free_value (len_value);
|
||||||
|
|
||||||
|
/* 6.g.iv.2 */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (set_status))
|
||||||
|
{
|
||||||
|
goto iterator_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_free_value (iterator);
|
||||||
|
/* 6.g.iv.3 */
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 6.g.v */
|
||||||
|
ecma_value_t next_value = ecma_op_iterator_value (next);
|
||||||
|
|
||||||
|
ecma_free_value (next);
|
||||||
|
|
||||||
|
/* 6.g.vi */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (next_value))
|
||||||
|
{
|
||||||
|
goto iterator_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_value_t mapped_value;
|
||||||
|
/* 6.g.vii */
|
||||||
|
if (mapfn_obj_p != NULL)
|
||||||
|
{
|
||||||
|
/* 6.g.vii.1 */
|
||||||
|
ecma_value_t args_p[2] = { next_value, ecma_make_uint32_value (k) };
|
||||||
|
/* 6.g.vii.3 */
|
||||||
|
mapped_value = ecma_op_function_call (mapfn_obj_p, call_this_arg, args_p, 2);
|
||||||
|
ecma_free_value (args_p[1]);
|
||||||
|
ecma_free_value (next_value);
|
||||||
|
|
||||||
|
/* 6.g.vii.2 */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (mapped_value))
|
||||||
|
{
|
||||||
|
ecma_op_iterator_close (iterator);
|
||||||
|
goto iterator_cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* 6.g.viii */
|
||||||
|
mapped_value = next_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 6.g.ix */
|
||||||
|
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||||
|
ecma_value_t set_status = ecma_builtin_helper_def_prop_by_index (array_obj_p, k, mapped_value, flags);
|
||||||
|
|
||||||
|
ecma_free_value (mapped_value);
|
||||||
|
|
||||||
|
/* 6.g.x */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (set_status))
|
||||||
|
{
|
||||||
|
ecma_op_iterator_close (iterator);
|
||||||
|
goto iterator_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 6.g.xi */
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator_cleanup:
|
||||||
|
ecma_free_value (iterator);
|
||||||
|
ecma_free_value (array);
|
||||||
|
|
||||||
|
return ret_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 8. */
|
||||||
|
ecma_value_t array_like = ecma_op_to_object (items);
|
||||||
|
|
||||||
|
/* 9. */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (array_like))
|
||||||
|
{
|
||||||
|
return array_like;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *array_like_obj_p = ecma_get_object_from_value (array_like);
|
||||||
|
|
||||||
|
/* 10. */
|
||||||
|
uint32_t len;
|
||||||
|
ecma_value_t len_value = ecma_op_object_get_length (array_like_obj_p, &len);
|
||||||
|
|
||||||
|
/* 11. */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (len_value))
|
||||||
|
{
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
len_value = ecma_make_uint32_value (len);
|
||||||
|
|
||||||
|
/* 12. */
|
||||||
|
ecma_value_t array;
|
||||||
|
|
||||||
|
/* 12.a */
|
||||||
|
if (ecma_is_constructor (constructor))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (ecma_is_value_undefined (array) || ecma_is_value_null (array))
|
||||||
|
{
|
||||||
|
ecma_free_value (len_value);
|
||||||
|
ecma_raise_type_error (ECMA_ERR_MSG ("Cannot convert undefined or null to object"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* 13.a */
|
||||||
|
array = ecma_op_create_array_object (&len_value, 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_free_value (len_value);
|
||||||
|
|
||||||
|
/* 14. */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (array))
|
||||||
|
{
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *array_obj_p = ecma_get_object_from_value (array);
|
||||||
|
|
||||||
|
/* 15. */
|
||||||
|
uint32_t k = 0;
|
||||||
|
|
||||||
|
/* 16. */
|
||||||
|
while (k < len)
|
||||||
|
{
|
||||||
|
/* 16.b */
|
||||||
|
ecma_value_t k_value = ecma_op_object_get_by_uint32_index (array_like_obj_p, k);
|
||||||
|
|
||||||
|
/* 16.c */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (k_value))
|
||||||
|
{
|
||||||
|
goto construct_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_value_t mapped_value;
|
||||||
|
/* 16.d */
|
||||||
|
if (mapfn_obj_p != NULL)
|
||||||
|
{
|
||||||
|
/* 16.d.i */
|
||||||
|
ecma_value_t args_p[2] = { k_value, ecma_make_uint32_value (k) };
|
||||||
|
mapped_value = ecma_op_function_call (mapfn_obj_p, call_this_arg, args_p, 2);
|
||||||
|
ecma_free_value (args_p[1]);
|
||||||
|
ecma_free_value (k_value);
|
||||||
|
|
||||||
|
/* 16.d.ii */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (mapped_value))
|
||||||
|
{
|
||||||
|
goto construct_cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* 16.e */
|
||||||
|
mapped_value = k_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 16.f */
|
||||||
|
const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||||
|
ecma_value_t set_status = ecma_builtin_helper_def_prop_by_index (array_obj_p, k, mapped_value, flags);
|
||||||
|
|
||||||
|
ecma_free_value (mapped_value);
|
||||||
|
|
||||||
|
/* 16.g */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (set_status))
|
||||||
|
{
|
||||||
|
goto construct_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 16.h */
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 17. */
|
||||||
|
len_value = ecma_make_uint32_value (k);
|
||||||
|
ecma_value_t set_status = ecma_op_object_put (array_obj_p,
|
||||||
|
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH),
|
||||||
|
len_value,
|
||||||
|
true);
|
||||||
|
ecma_free_value (len_value);
|
||||||
|
|
||||||
|
/* 18. */
|
||||||
|
if (ECMA_IS_VALUE_ERROR (set_status))
|
||||||
|
{
|
||||||
|
goto construct_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 19. */
|
||||||
|
ecma_deref_object (array_like_obj_p);
|
||||||
|
return ecma_make_object_value (array_obj_p);
|
||||||
|
|
||||||
|
construct_cleanup:
|
||||||
|
ecma_deref_object (array_obj_p);
|
||||||
|
cleanup:
|
||||||
|
ecma_deref_object (array_like_obj_p);
|
||||||
|
return ret_value;
|
||||||
|
} /* ecma_builtin_array_object_from */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Array object's 'of' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 22.1.2.3
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_array_object_of (ecma_value_t this_arg, /**< 'this' argument */
|
||||||
|
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||||
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
|
{
|
||||||
|
if (!ecma_is_constructor (this_arg))
|
||||||
|
{
|
||||||
|
return ecma_op_create_array_object (arguments_list_p, arguments_list_len, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
&len,
|
||||||
|
1);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (ret_val))
|
||||||
|
{
|
||||||
|
ecma_free_value (len);
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t k = 0;
|
||||||
|
ecma_object_t *obj_p = ecma_get_object_from_value (ret_val);
|
||||||
|
const uint32_t prop_status_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_IS_THROW;
|
||||||
|
|
||||||
|
while (k < arguments_list_len)
|
||||||
|
{
|
||||||
|
ecma_value_t define_status = ecma_builtin_helper_def_prop_by_index (obj_p,
|
||||||
|
k,
|
||||||
|
arguments_list_p[k],
|
||||||
|
prop_status_flags);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (define_status))
|
||||||
|
{
|
||||||
|
ecma_free_value (len);
|
||||||
|
ecma_deref_object (obj_p);
|
||||||
|
return define_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_val = ecma_op_object_put (obj_p,
|
||||||
|
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH),
|
||||||
|
len,
|
||||||
|
true);
|
||||||
|
|
||||||
|
ecma_free_value (len);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (ret_val))
|
||||||
|
{
|
||||||
|
ecma_deref_object (obj_p);
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecma_make_object_value (obj_p);
|
||||||
|
} /* ecma_builtin_array_object_of */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 22.1.2.5 get Array [ @@species ] accessor
|
||||||
|
*
|
||||||
|
* @return ecma_value
|
||||||
|
* returned value must be freed with ecma_free_value
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_builtin_array_species_get (ecma_value_t this_value) /**< This Value */
|
||||||
|
{
|
||||||
|
return ecma_copy_value (this_value);
|
||||||
|
} /* ecma_builtin_array_species_get */
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle calling [[Call]] of built-in Array object
|
* Handle calling [[Call]] of built-in Array object
|
||||||
|
|||||||
@@ -40,6 +40,15 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
|||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ROUTINE (LIT_MAGIC_STRING_FROM, ecma_builtin_array_object_from, NON_FIXED, 1)
|
||||||
|
ROUTINE (LIT_MAGIC_STRING_OF, ecma_builtin_array_object_of, NON_FIXED, 0)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 22.1.2.5 */
|
||||||
|
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
|
||||||
|
ecma_builtin_array_species_get,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#endif /* !(ENABLED (JERRY_BUILTIN_ARRAY)) */
|
#endif /* !(ENABLED (JERRY_BUILTIN_ARRAY)) */
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**
|
|||||||
|
|
||||||
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL))
|
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL))
|
||||||
{
|
{
|
||||||
|
if (ecma_arraybuffer_is_detached (object_p))
|
||||||
|
{
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer has been detached."));
|
||||||
|
}
|
||||||
ecma_length_t len = ecma_arraybuffer_get_length (object_p);
|
ecma_length_t len = ecma_arraybuffer_get_length (object_p);
|
||||||
|
|
||||||
return ecma_make_uint32_value (len);
|
return ecma_make_uint32_value (len);
|
||||||
@@ -96,31 +100,34 @@ ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< thi
|
|||||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an ArrayBuffer object."));
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an ArrayBuffer object."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ecma_arraybuffer_is_detached (object_p))
|
||||||
|
{
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer has been detached."));
|
||||||
|
}
|
||||||
|
|
||||||
ecma_length_t len = ecma_arraybuffer_get_length (object_p);
|
ecma_length_t len = ecma_arraybuffer_get_length (object_p);
|
||||||
|
|
||||||
ecma_length_t start = 0, end = len;
|
ecma_length_t start = 0, end = len;
|
||||||
|
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||||
|
|
||||||
ECMA_OP_TO_NUMBER_TRY_CATCH (start_num,
|
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg1,
|
||||||
arg1,
|
len,
|
||||||
ret_value);
|
&start)))
|
||||||
|
{
|
||||||
start = ecma_builtin_helper_array_index_normalize (start_num, len);
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ecma_is_value_undefined (arg2))
|
if (!ecma_is_value_undefined (arg2))
|
||||||
{
|
{
|
||||||
ECMA_OP_TO_NUMBER_TRY_CATCH (end_num,
|
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg2,
|
||||||
arg2,
|
len,
|
||||||
ret_value);
|
&end)))
|
||||||
|
{
|
||||||
end = ecma_builtin_helper_array_index_normalize (end_num, len);
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
ECMA_OP_TO_NUMBER_FINALIZE (end_num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ECMA_OP_TO_NUMBER_FINALIZE (start_num);
|
|
||||||
|
|
||||||
if (ret_value != ECMA_VALUE_EMPTY)
|
if (ret_value != ECMA_VALUE_EMPTY)
|
||||||
{
|
{
|
||||||
return ret_value;
|
return ret_value;
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
|
|||||||
ecma_builtin_arraybuffer_prototype_bytelength_getter,
|
ecma_builtin_arraybuffer_prototype_bytelength_getter,
|
||||||
ECMA_PROPERTY_FIXED)
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* ECMA-262 v6, 24.1.4.4 */
|
/* ECMA-262 v6, 24.1.4.4 */
|
||||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
|
LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
|
||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
|
|||||||
@@ -19,7 +19,9 @@
|
|||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "ecma-helpers.h"
|
#include "ecma-helpers.h"
|
||||||
#include "ecma-arraybuffer-object.h"
|
#include "ecma-arraybuffer-object.h"
|
||||||
|
#include "ecma-dataview-object.h"
|
||||||
#include "ecma-try-catch-macro.h"
|
#include "ecma-try-catch-macro.h"
|
||||||
|
#include "ecma-typedarray-object.h"
|
||||||
#include "jrt.h"
|
#include "jrt.h"
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
||||||
@@ -55,11 +57,8 @@ ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argu
|
|||||||
ecma_value_t arg) /**< argument 1 */
|
ecma_value_t arg) /**< argument 1 */
|
||||||
{
|
{
|
||||||
JERRY_UNUSED (this_arg);
|
JERRY_UNUSED (this_arg);
|
||||||
JERRY_UNUSED (arg);
|
|
||||||
|
|
||||||
/* TODO: if arg has [[ViewArrayBuffer]], return true */
|
return ecma_make_boolean_value (ecma_is_typedarray (arg) || ecma_is_dataview (arg));
|
||||||
|
|
||||||
return ECMA_VALUE_FALSE;
|
|
||||||
} /* ecma_builtin_arraybuffer_object_is_view */
|
} /* ecma_builtin_arraybuffer_object_is_view */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,6 +93,18 @@ ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_
|
|||||||
return ecma_op_create_arraybuffer_object (arguments_list_p, arguments_list_len);
|
return ecma_op_create_arraybuffer_object (arguments_list_p, arguments_list_len);
|
||||||
} /* ecma_builtin_arraybuffer_dispatch_construct */
|
} /* ecma_builtin_arraybuffer_dispatch_construct */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 24.1.3.3 get ArrayBuffer [ @@species ] accessor
|
||||||
|
*
|
||||||
|
* @return ecma_value
|
||||||
|
* returned value must be freed with ecma_free_value
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_builtin_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */
|
||||||
|
{
|
||||||
|
return ecma_copy_value (this_value);
|
||||||
|
} /* ecma_builtin_arraybuffer_species_get */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
|||||||
/* ES2015 24.1.3.1 */
|
/* ES2015 24.1.3.1 */
|
||||||
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1)
|
||||||
|
|
||||||
|
/* ES2015 24.1.3.3 */
|
||||||
|
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
|
||||||
|
ecma_builtin_arraybuffer_species_get,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ecma-arraybuffer-object.h"
|
||||||
|
#include "ecma-exceptions.h"
|
||||||
#include "ecma-dataview-object.h"
|
#include "ecma-dataview-object.h"
|
||||||
#include "ecma-gc.h"
|
#include "ecma-gc.h"
|
||||||
|
|
||||||
@@ -41,6 +43,7 @@ enum
|
|||||||
ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER,
|
ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER,
|
||||||
ECMA_DATAVIEW_PROTOTYPE_GET_INT8,
|
ECMA_DATAVIEW_PROTOTYPE_GET_INT8,
|
||||||
ECMA_DATAVIEW_PROTOTYPE_GET_UINT8,
|
ECMA_DATAVIEW_PROTOTYPE_GET_UINT8,
|
||||||
|
ECMA_DATAVIEW_PROTOTYPE_GET_UINT8_CLAMPED, /* unused value */
|
||||||
ECMA_DATAVIEW_PROTOTYPE_GET_INT16,
|
ECMA_DATAVIEW_PROTOTYPE_GET_INT16,
|
||||||
ECMA_DATAVIEW_PROTOTYPE_GET_UINT16,
|
ECMA_DATAVIEW_PROTOTYPE_GET_UINT16,
|
||||||
ECMA_DATAVIEW_PROTOTYPE_GET_INT32,
|
ECMA_DATAVIEW_PROTOTYPE_GET_INT32,
|
||||||
@@ -51,6 +54,7 @@ enum
|
|||||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||||
ECMA_DATAVIEW_PROTOTYPE_SET_INT8,
|
ECMA_DATAVIEW_PROTOTYPE_SET_INT8,
|
||||||
ECMA_DATAVIEW_PROTOTYPE_SET_UINT8,
|
ECMA_DATAVIEW_PROTOTYPE_SET_UINT8,
|
||||||
|
ECMA_DATAVIEW_PROTOTYPE_SET_UINT8_CLAMPED, /* unused value */
|
||||||
ECMA_DATAVIEW_PROTOTYPE_SET_INT16,
|
ECMA_DATAVIEW_PROTOTYPE_SET_INT16,
|
||||||
ECMA_DATAVIEW_PROTOTYPE_SET_UINT16,
|
ECMA_DATAVIEW_PROTOTYPE_SET_UINT16,
|
||||||
ECMA_DATAVIEW_PROTOTYPE_SET_INT32,
|
ECMA_DATAVIEW_PROTOTYPE_SET_INT32,
|
||||||
@@ -75,23 +79,6 @@ enum
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Corresponding typedarray mappings for the {get,set}{[U]int, Float}{8, 16, 32, 64} routines
|
|
||||||
*/
|
|
||||||
static const uint8_t ecma_dataview_type_mapping[] =
|
|
||||||
{
|
|
||||||
ECMA_BUILTIN_ID_INT8ARRAY,
|
|
||||||
ECMA_BUILTIN_ID_UINT8ARRAY,
|
|
||||||
ECMA_BUILTIN_ID_INT16ARRAY,
|
|
||||||
ECMA_BUILTIN_ID_UINT16ARRAY,
|
|
||||||
ECMA_BUILTIN_ID_INT32ARRAY,
|
|
||||||
ECMA_BUILTIN_ID_UINT32ARRAY,
|
|
||||||
ECMA_BUILTIN_ID_FLOAT32ARRAY,
|
|
||||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
|
||||||
ECMA_BUILTIN_ID_FLOAT64ARRAY,
|
|
||||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DataView.prototype object's {buffer, byteOffset, byteLength} getters
|
* The DataView.prototype object's {buffer, byteOffset, byteLength} getters
|
||||||
*
|
*
|
||||||
@@ -125,11 +112,20 @@ ecma_builtin_dataview_prototype_object_getters (ecma_value_t this_arg, /**< this
|
|||||||
}
|
}
|
||||||
case ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER:
|
case ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER:
|
||||||
{
|
{
|
||||||
|
if (ecma_arraybuffer_is_detached (obj_p->buffer_p))
|
||||||
|
{
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer has been detached."));
|
||||||
|
}
|
||||||
return ecma_make_uint32_value (obj_p->header.u.class_prop.u.length);
|
return ecma_make_uint32_value (obj_p->header.u.class_prop.u.length);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER);
|
JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER);
|
||||||
|
|
||||||
|
if (ecma_arraybuffer_is_detached (obj_p->buffer_p))
|
||||||
|
{
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer has been detached."));
|
||||||
|
}
|
||||||
return ecma_make_uint32_value (obj_p->byte_offset);
|
return ecma_make_uint32_value (obj_p->byte_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,9 +164,9 @@ ecma_builtin_dataview_prototype_dispatch_routine (uint16_t builtin_routine_id, /
|
|||||||
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT32:
|
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT32:
|
||||||
{
|
{
|
||||||
ecma_value_t little_endian = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_FALSE;
|
ecma_value_t little_endian = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_FALSE;
|
||||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8];
|
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8);
|
||||||
|
|
||||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, ECMA_VALUE_EMPTY, type);
|
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, ECMA_VALUE_EMPTY, id);
|
||||||
}
|
}
|
||||||
case ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32:
|
case ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32:
|
||||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||||
@@ -183,25 +179,25 @@ ecma_builtin_dataview_prototype_dispatch_routine (uint16_t builtin_routine_id, /
|
|||||||
{
|
{
|
||||||
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
||||||
ecma_value_t little_endian = arguments_number > 2 ? arguments_list_p[2] : ECMA_VALUE_FALSE;
|
ecma_value_t little_endian = arguments_number > 2 ? arguments_list_p[2] : ECMA_VALUE_FALSE;
|
||||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8];
|
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8);
|
||||||
|
|
||||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, value_to_set, type);
|
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, value_to_set, id);
|
||||||
}
|
}
|
||||||
case ECMA_DATAVIEW_PROTOTYPE_GET_INT8:
|
case ECMA_DATAVIEW_PROTOTYPE_GET_INT8:
|
||||||
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT8:
|
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT8:
|
||||||
{
|
{
|
||||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8];
|
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8);
|
||||||
|
|
||||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, ECMA_VALUE_EMPTY, type);
|
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, ECMA_VALUE_EMPTY, id);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_INT8
|
JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_INT8
|
||||||
|| builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_UINT8);
|
|| builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_UINT8);
|
||||||
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
||||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8];
|
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8);
|
||||||
|
|
||||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, value_to_set, type);
|
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, value_to_set, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* ecma_builtin_dataview_prototype_dispatch_routine */
|
} /* ecma_builtin_dataview_prototype_dispatch_routine */
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
|||||||
ECMA_BUILTIN_ID_DATAVIEW,
|
ECMA_BUILTIN_ID_DATAVIEW,
|
||||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* ECMA-262 v6, 23.2.4.21 */
|
/* ECMA-262 v6, 23.2.4.21 */
|
||||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
LIT_MAGIC_STRING_DATAVIEW_UL,
|
LIT_MAGIC_STRING_DATAVIEW_UL,
|
||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "ecma-helpers.h"
|
#include "ecma-helpers.h"
|
||||||
#include "ecma-objects.h"
|
#include "ecma-objects.h"
|
||||||
|
#include "ecma-objects-general.h"
|
||||||
#include "ecma-try-catch-macro.h"
|
#include "ecma-try-catch-macro.h"
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_DATE)
|
#if ENABLED (JERRY_BUILTIN_DATE)
|
||||||
@@ -98,6 +99,10 @@ enum
|
|||||||
ECMA_DATE_PROTOTYPE_GET_TIME, /* ECMA-262 v5, 15.9.5.9 */
|
ECMA_DATE_PROTOTYPE_GET_TIME, /* ECMA-262 v5, 15.9.5.9 */
|
||||||
ECMA_DATE_PROTOTYPE_SET_TIME, /* ECMA-262 v5, 15.9.5.27 */
|
ECMA_DATE_PROTOTYPE_SET_TIME, /* ECMA-262 v5, 15.9.5.27 */
|
||||||
ECMA_DATE_PROTOTYPE_TO_JSON, /* ECMA-262 v5, 15.9.5.44 */
|
ECMA_DATE_PROTOTYPE_TO_JSON, /* ECMA-262 v5, 15.9.5.44 */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ECMA_DATE_PROTOTYPE_TO_PRIMITIVE, /* ECMA-262 v6 20.3.4.45 */
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-date-prototype.inc.h"
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-date-prototype.inc.h"
|
||||||
@@ -179,6 +184,46 @@ ecma_builtin_date_prototype_to_json (ecma_value_t this_arg) /**< this argument *
|
|||||||
return ret_value;
|
return ret_value;
|
||||||
} /* ecma_builtin_date_prototype_to_json */
|
} /* ecma_builtin_date_prototype_to_json */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
/**
|
||||||
|
* The Date.prototype object's toPrimitive routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 20.3.4.45
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_date_prototype_to_primitive (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t hint_arg) /**< {"default", "number", "string"} */
|
||||||
|
{
|
||||||
|
if (ecma_is_value_object (this_arg) && ecma_is_value_string (hint_arg))
|
||||||
|
{
|
||||||
|
ecma_string_t *hint_str_p = ecma_get_string_from_value (hint_arg);
|
||||||
|
|
||||||
|
ecma_preferred_type_hint_t hint = ECMA_PREFERRED_TYPE_NUMBER;
|
||||||
|
|
||||||
|
if (hint_str_p == ecma_get_magic_string (LIT_MAGIC_STRING_STRING)
|
||||||
|
|| hint_str_p == ecma_get_magic_string (LIT_MAGIC_STRING_DEFAULT))
|
||||||
|
{
|
||||||
|
hint = ECMA_PREFERRED_TYPE_STRING;
|
||||||
|
}
|
||||||
|
else if (hint_str_p == ecma_get_magic_string (LIT_MAGIC_STRING_NUMBER))
|
||||||
|
{
|
||||||
|
hint = ECMA_PREFERRED_TYPE_NUMBER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hint != ECMA_PREFERRED_TYPE_NO)
|
||||||
|
{
|
||||||
|
return ecma_op_general_object_ordinary_value (ecma_get_object_from_value (this_arg), hint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type in toPrimitive."));
|
||||||
|
} /* ecma_builtin_date_prototype_to_primitive */
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch get date functions
|
* Dispatch get date functions
|
||||||
*
|
*
|
||||||
@@ -560,6 +605,14 @@ ecma_builtin_date_prototype_dispatch_routine (uint16_t builtin_routine_id, /**<
|
|||||||
return ecma_builtin_date_prototype_to_json (this_arg);
|
return ecma_builtin_date_prototype_to_json (this_arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (JERRY_UNLIKELY (builtin_routine_id == ECMA_DATE_PROTOTYPE_TO_PRIMITIVE))
|
||||||
|
{
|
||||||
|
ecma_value_t argument = arguments_number > 0 ? arguments_list[0] : ECMA_VALUE_UNDEFINED;
|
||||||
|
return ecma_builtin_date_prototype_to_primitive (this_arg, argument);
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
if (!ecma_is_value_object (this_arg)
|
if (!ecma_is_value_object (this_arg)
|
||||||
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
|
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ ROUTINE (LIT_MAGIC_STRING_SET_UTC_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_SET_UTC_FULL
|
|||||||
ROUTINE (LIT_MAGIC_STRING_TO_UTC_STRING_UL, ECMA_DATE_PROTOTYPE_TO_UTC_STRING, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_TO_UTC_STRING_UL, ECMA_DATE_PROTOTYPE_TO_UTC_STRING, 0, 0)
|
||||||
ROUTINE (LIT_MAGIC_STRING_TO_ISO_STRING_UL, ECMA_DATE_PROTOTYPE_TO_ISO_STRING, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_TO_ISO_STRING_UL, ECMA_DATE_PROTOTYPE_TO_ISO_STRING, 0, 0)
|
||||||
ROUTINE (LIT_MAGIC_STRING_TO_JSON_UL, ECMA_DATE_PROTOTYPE_TO_JSON, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_TO_JSON_UL, ECMA_DATE_PROTOTYPE_TO_JSON, 1, 1)
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ROUTINE_CONFIGURABLE_ONLY (LIT_GLOBAL_SYMBOL_TO_PRIMITIVE, ECMA_DATE_PROTOTYPE_TO_PRIMITIVE, 1, 1)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_ANNEXB)
|
#if ENABLED (JERRY_BUILTIN_ANNEXB)
|
||||||
|
|
||||||
|
|||||||
@@ -52,22 +52,137 @@
|
|||||||
static ecma_number_t
|
static ecma_number_t
|
||||||
ecma_date_parse_date_chars (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
ecma_date_parse_date_chars (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
||||||
const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */
|
const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */
|
||||||
uint32_t num_of_chars) /**< number of characters to read and convert */
|
uint32_t num_of_chars, /**< number of characters to read and convert */
|
||||||
|
uint32_t min, /**< minimum valid value */
|
||||||
|
uint32_t max) /**< maximum valid value */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (num_of_chars > 0);
|
JERRY_ASSERT (num_of_chars > 0);
|
||||||
const lit_utf8_byte_t *str_start_p = *str_p;
|
const lit_utf8_byte_t *str_start_p = *str_p;
|
||||||
|
|
||||||
while (num_of_chars--)
|
while (num_of_chars--)
|
||||||
{
|
{
|
||||||
if (*str_p >= str_end_p || !lit_char_is_decimal_digit (lit_utf8_read_next (str_p)))
|
if (*str_p >= str_end_p || !lit_char_is_decimal_digit (lit_cesu8_read_next (str_p)))
|
||||||
{
|
{
|
||||||
return ecma_number_make_nan ();
|
return ecma_number_make_nan ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ecma_utf8_string_to_number (str_start_p, (lit_utf8_size_t) (*str_p - str_start_p));
|
ecma_number_t parsed_number = ecma_utf8_string_to_number (str_start_p, (lit_utf8_size_t) (*str_p - str_start_p));
|
||||||
|
|
||||||
|
if (parsed_number < min || parsed_number > max)
|
||||||
|
{
|
||||||
|
return ecma_number_make_nan ();
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed_number;
|
||||||
} /* ecma_date_parse_date_chars */
|
} /* ecma_date_parse_date_chars */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to try to parse a special chracter (+,-,T,Z,:,.) in a date string
|
||||||
|
*
|
||||||
|
* @return true if the first character is same as the expected, false otherwise
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
ecma_date_parse_special_char (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
||||||
|
const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */
|
||||||
|
const lit_utf8_byte_t expected_char) /**< expected character */
|
||||||
|
{
|
||||||
|
if ((*str_p < str_end_p) && (**str_p == expected_char))
|
||||||
|
{
|
||||||
|
(*str_p)++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} /* ecma_date_parse_special_char */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to try to parse a 4-5-6 digit year with optional negative sign in a date string
|
||||||
|
*
|
||||||
|
* Date.prototype.toString() and Date.prototype.toUTCString() emits year
|
||||||
|
* in this format and Date.parse() should parse this format too.
|
||||||
|
*
|
||||||
|
* @return the parsed year or NaN.
|
||||||
|
*/
|
||||||
|
static ecma_number_t
|
||||||
|
ecma_date_parse_year (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
||||||
|
const lit_utf8_byte_t *str_end_p) /**< pointer to the end of the string */
|
||||||
|
{
|
||||||
|
bool is_year_sign_negative = ecma_date_parse_special_char (str_p, str_end_p, '-');
|
||||||
|
const lit_utf8_byte_t *str_start_p = *str_p;
|
||||||
|
int32_t parsed_year = 0;
|
||||||
|
|
||||||
|
while ((str_start_p - *str_p < 6) && (str_start_p < str_end_p) && lit_char_is_decimal_digit (*str_start_p))
|
||||||
|
{
|
||||||
|
parsed_year = 10 * parsed_year + *str_start_p - LIT_CHAR_0;
|
||||||
|
str_start_p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str_start_p - *str_p >=4)
|
||||||
|
{
|
||||||
|
*str_p = str_start_p;
|
||||||
|
if (is_year_sign_negative)
|
||||||
|
{
|
||||||
|
return -parsed_year;
|
||||||
|
}
|
||||||
|
return parsed_year;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecma_number_make_nan ();
|
||||||
|
} /* ecma_date_parse_year */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to try to parse a day name in a date string
|
||||||
|
* Valid day names: Sun, Mon, Tue, Wed, Thu, Fri, Sat
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v9, 20.3.4.41.2 Table 46
|
||||||
|
*
|
||||||
|
* @return true if the string starts with a valid day name, false otherwise
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
ecma_date_parse_day_name (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
||||||
|
const lit_utf8_byte_t *str_end_p) /**< pointer to the end of the string */
|
||||||
|
{
|
||||||
|
if (*str_p + 3 < str_end_p)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
if (!memcmp (day_names_p[i], *str_p, 3))
|
||||||
|
{
|
||||||
|
(*str_p) += 3;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} /* ecma_date_parse_day_name */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to try to parse a month name in a date string
|
||||||
|
* Valid month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v9, 20.3.4.41.2 Table 47
|
||||||
|
*
|
||||||
|
* @return number of the month if the string starts with a valid month name, 0 otherwise
|
||||||
|
*/
|
||||||
|
static uint32_t
|
||||||
|
ecma_date_parse_month_name (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
||||||
|
const lit_utf8_byte_t *str_end_p) /**< pointer to the end of the string */
|
||||||
|
{
|
||||||
|
if (*str_p + 3 < str_end_p)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
if (!memcmp (month_names_p[i], *str_p, 3))
|
||||||
|
{
|
||||||
|
(*str_p) += 3;
|
||||||
|
return (i+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} /* ecma_date_parse_month_name */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)) for Date constructor and UTC
|
* Calculate MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)) for Date constructor and UTC
|
||||||
*
|
*
|
||||||
@@ -169,80 +284,56 @@ ecma_date_construct_helper (const ecma_value_t *args, /**< arguments passed to t
|
|||||||
} /* ecma_date_construct_helper */
|
} /* ecma_date_construct_helper */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Date object's 'parse' routine
|
* Helper function used by ecma_builtin_date_parse
|
||||||
*
|
*
|
||||||
* See also:
|
* See also:
|
||||||
* ECMA-262 v5, 15.9.4.2
|
* ECMA-262 v5, 15.9.4.2 Date.parse (string)
|
||||||
* ECMA-262 v5, 15.9.1.15
|
* ECMA-262 v5, 15.9.1.15 Date Time String Format
|
||||||
*
|
*
|
||||||
* @return ecma value
|
* @return the parsed date as ecma_number_t or NaN otherwise
|
||||||
* Returned value must be freed with ecma_free_value.
|
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
static ecma_number_t
|
||||||
ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
|
ecma_builtin_date_parse_ISO_string_format (const lit_utf8_byte_t *date_str_curr_p,
|
||||||
ecma_value_t arg) /**< string */
|
const lit_utf8_byte_t *date_str_end_p)
|
||||||
{
|
{
|
||||||
JERRY_UNUSED (this_arg);
|
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
|
||||||
ecma_number_t date_num = ecma_number_make_nan ();
|
|
||||||
|
|
||||||
/* Date Time String fromat (ECMA-262 v5, 15.9.1.15) */
|
|
||||||
ECMA_TRY_CATCH (date_str_value,
|
|
||||||
ecma_op_to_string (arg),
|
|
||||||
ret_value);
|
|
||||||
|
|
||||||
ecma_string_t *date_str_p = ecma_get_string_from_value (date_str_value);
|
|
||||||
|
|
||||||
ECMA_STRING_TO_UTF8_STRING (date_str_p, date_start_p, date_start_size);
|
|
||||||
|
|
||||||
const lit_utf8_byte_t *date_str_curr_p = date_start_p;
|
|
||||||
const lit_utf8_byte_t *date_str_end_p = date_start_p + date_start_size;
|
|
||||||
|
|
||||||
/* 1. read year */
|
/* 1. read year */
|
||||||
ecma_number_t year = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 4);
|
|
||||||
|
|
||||||
if (!ecma_number_is_nan (year)
|
uint32_t year_digits = 4;
|
||||||
&& year >= 0)
|
|
||||||
|
bool is_year_sign_negative = ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '-');
|
||||||
|
if (is_year_sign_negative || ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '+'))
|
||||||
|
{
|
||||||
|
year_digits = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t year = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, year_digits,
|
||||||
|
0, (year_digits == 4) ? 9999 : 999999);
|
||||||
|
if (is_year_sign_negative)
|
||||||
|
{
|
||||||
|
year = -year;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_number_is_nan (year))
|
||||||
{
|
{
|
||||||
ecma_number_t month = ECMA_NUMBER_ONE;
|
ecma_number_t month = ECMA_NUMBER_ONE;
|
||||||
ecma_number_t day = ECMA_NUMBER_ONE;
|
ecma_number_t day = ECMA_NUMBER_ONE;
|
||||||
ecma_number_t time = ECMA_NUMBER_ZERO;
|
ecma_number_t time = ECMA_NUMBER_ZERO;
|
||||||
|
|
||||||
/* 2. read month if any */
|
/* 2. read month if any */
|
||||||
if (date_str_curr_p < date_str_end_p
|
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '-'))
|
||||||
&& *date_str_curr_p == '-')
|
|
||||||
{
|
{
|
||||||
/* eat up '-' */
|
month = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 1, 12);
|
||||||
date_str_curr_p++;
|
|
||||||
month = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
|
||||||
|
|
||||||
if (month > 12 || month < 1)
|
|
||||||
{
|
|
||||||
month = ecma_number_make_nan ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 3. read day if any */
|
/* 3. read day if any */
|
||||||
if (date_str_curr_p < date_str_end_p
|
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '-'))
|
||||||
&& *date_str_curr_p == '-')
|
|
||||||
{
|
{
|
||||||
/* eat up '-' */
|
day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 1, 31);
|
||||||
date_str_curr_p++;
|
|
||||||
day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
|
||||||
|
|
||||||
if (day < 1 || day > 31)
|
|
||||||
{
|
|
||||||
day = ecma_number_make_nan ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 4. read time if any */
|
/* 4. read time if any */
|
||||||
if (date_str_curr_p < date_str_end_p
|
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, 'T'))
|
||||||
&& *date_str_curr_p == 'T')
|
|
||||||
{
|
{
|
||||||
/* eat up 'T' */
|
|
||||||
date_str_curr_p++;
|
|
||||||
|
|
||||||
ecma_number_t hours = ECMA_NUMBER_ZERO;
|
ecma_number_t hours = ECMA_NUMBER_ZERO;
|
||||||
ecma_number_t minutes = ECMA_NUMBER_ZERO;
|
ecma_number_t minutes = ECMA_NUMBER_ZERO;
|
||||||
ecma_number_t seconds = ECMA_NUMBER_ZERO;
|
ecma_number_t seconds = ECMA_NUMBER_ZERO;
|
||||||
@@ -254,58 +345,33 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
|
|||||||
if (remaining_length >= 5)
|
if (remaining_length >= 5)
|
||||||
{
|
{
|
||||||
/* 4.1 read hours and minutes */
|
/* 4.1 read hours and minutes */
|
||||||
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 24);
|
||||||
|
|
||||||
if (hours < 0 || hours > 24)
|
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ':'))
|
||||||
{
|
{
|
||||||
hours = ecma_number_make_nan ();
|
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 59);
|
||||||
}
|
|
||||||
else if (hours == 24)
|
|
||||||
{
|
|
||||||
hours = ECMA_NUMBER_ZERO;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (date_str_curr_p < date_str_end_p
|
|
||||||
&& *date_str_curr_p == ':')
|
|
||||||
{
|
|
||||||
/* eat up ':' */
|
|
||||||
date_str_curr_p++;
|
|
||||||
|
|
||||||
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
|
||||||
|
|
||||||
if (minutes < 0 || minutes > 59)
|
|
||||||
{
|
|
||||||
minutes = ecma_number_make_nan ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 4.2 read seconds if any */
|
/* 4.2 read seconds if any */
|
||||||
if (date_str_curr_p < date_str_end_p
|
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ':'))
|
||||||
&& *date_str_curr_p == ':')
|
|
||||||
{
|
{
|
||||||
/* eat up ':' */
|
seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 59);
|
||||||
date_str_curr_p++;
|
|
||||||
seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
|
||||||
|
|
||||||
if (seconds < 0 || seconds > 59)
|
|
||||||
{
|
|
||||||
seconds = ecma_number_make_nan ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 4.3 read milliseconds if any */
|
/* 4.3 read milliseconds if any */
|
||||||
if (date_str_curr_p < date_str_end_p
|
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '.'))
|
||||||
&& *date_str_curr_p == '.')
|
|
||||||
{
|
{
|
||||||
/* eat up '.' */
|
milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 3, 0, 999);
|
||||||
date_str_curr_p++;
|
|
||||||
milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 3);
|
|
||||||
|
|
||||||
if (milliseconds < 0)
|
|
||||||
{
|
|
||||||
milliseconds = ecma_number_make_nan ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
minutes = ecma_number_make_nan ();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hours == 24 && (minutes != 0 || seconds != 0 || milliseconds != 0))
|
||||||
|
{
|
||||||
|
hours = ecma_number_make_nan ();
|
||||||
|
}
|
||||||
|
|
||||||
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
|
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
|
||||||
}
|
}
|
||||||
@@ -315,62 +381,29 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 4.4 read timezone if any */
|
/* 4.4 read timezone if any */
|
||||||
if (date_str_curr_p < date_str_end_p
|
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, 'Z') && !ecma_number_is_nan (time))
|
||||||
&& *date_str_curr_p == 'Z'
|
|
||||||
&& !ecma_number_is_nan (time))
|
|
||||||
{
|
{
|
||||||
date_str_curr_p++;
|
|
||||||
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
|
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
|
||||||
}
|
}
|
||||||
else if (date_str_curr_p < date_str_end_p
|
else
|
||||||
&& (*date_str_curr_p == '+' || *date_str_curr_p == '-'))
|
|
||||||
{
|
{
|
||||||
ecma_length_t remaining_date_length;
|
bool is_timezone_sign_negative;
|
||||||
remaining_date_length = lit_utf8_string_length (date_str_curr_p,
|
if ((lit_utf8_string_length (date_str_curr_p, (lit_utf8_size_t) (date_str_end_p - date_str_curr_p)) == 6)
|
||||||
(lit_utf8_size_t) (date_str_end_p - date_str_curr_p)) - 1;
|
&& ((is_timezone_sign_negative = ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '-'))
|
||||||
|
|| ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '+')))
|
||||||
if (remaining_date_length == 5)
|
|
||||||
{
|
{
|
||||||
bool is_negative = false;
|
|
||||||
|
|
||||||
if (*date_str_curr_p == '-')
|
|
||||||
{
|
|
||||||
is_negative = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eat up '+/-' */
|
|
||||||
date_str_curr_p++;
|
|
||||||
|
|
||||||
/* read hours and minutes */
|
/* read hours and minutes */
|
||||||
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 24);
|
||||||
|
|
||||||
if (hours < 0 || hours > 24)
|
if (hours == 24)
|
||||||
{
|
|
||||||
hours = ecma_number_make_nan ();
|
|
||||||
}
|
|
||||||
else if (hours == 24)
|
|
||||||
{
|
{
|
||||||
hours = ECMA_NUMBER_ZERO;
|
hours = ECMA_NUMBER_ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eat up ':' */
|
ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ':');
|
||||||
date_str_curr_p++;
|
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 59);
|
||||||
|
ecma_number_t timezone_offset = ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO);
|
||||||
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
time += is_timezone_sign_negative ? timezone_offset : -timezone_offset;
|
||||||
|
|
||||||
if (minutes < 0 || minutes > 59)
|
|
||||||
{
|
|
||||||
minutes = ecma_number_make_nan ();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_negative)
|
|
||||||
{
|
|
||||||
time += ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
time -= ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,16 +411,232 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
|
|||||||
if (date_str_curr_p >= date_str_end_p)
|
if (date_str_curr_p >= date_str_end_p)
|
||||||
{
|
{
|
||||||
ecma_number_t date = ecma_date_make_day (year, month - 1, day);
|
ecma_number_t date = ecma_date_make_day (year, month - 1, day);
|
||||||
date_num = ecma_date_make_date (date, time);
|
return ecma_date_make_date (date, time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ecma_number_make_nan ();
|
||||||
|
} /* ecma_builtin_date_parse_ISO_string_format */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function used by ecma_builtin_date_parse
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v5, 15.9.4.2 Date.parse (string)
|
||||||
|
* ECMA-262 v9, 20.3.4.41 Date.prototype.toString ()
|
||||||
|
* ECMA-262 v9, 20.3.4.43 Date.prototype.toUTCString ()
|
||||||
|
*
|
||||||
|
* Used by: ecma_builtin_date_parse
|
||||||
|
*
|
||||||
|
* @return the parsed date as ecma_number_t or NaN otherwise
|
||||||
|
*/
|
||||||
|
static ecma_number_t
|
||||||
|
ecma_builtin_date_parse_toString_formats (const lit_utf8_byte_t *date_str_curr_p,
|
||||||
|
const lit_utf8_byte_t *date_str_end_p)
|
||||||
|
{
|
||||||
|
const ecma_number_t nan = ecma_number_make_nan ();
|
||||||
|
|
||||||
|
if (!ecma_date_parse_day_name (&date_str_curr_p, date_str_end_p))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool is_toUTCString_format = ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ',');
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ' '))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t month = 0;
|
||||||
|
ecma_number_t day = 0;
|
||||||
|
if (is_toUTCString_format)
|
||||||
|
{
|
||||||
|
day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 31);
|
||||||
|
if (ecma_number_is_nan (day))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ' '))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
month = ecma_date_parse_month_name (&date_str_curr_p, date_str_end_p);
|
||||||
|
if (!(int) month)
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
month = ecma_date_parse_month_name (&date_str_curr_p, date_str_end_p);
|
||||||
|
if (!(int) month)
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ' '))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 31);
|
||||||
|
if (ecma_number_is_nan (day))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_value = ecma_make_number_value (date_num);
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ' '))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t year = ecma_date_parse_year (&date_str_curr_p, date_str_end_p);
|
||||||
|
if (ecma_number_is_nan (year))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ' '))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 24);
|
||||||
|
if (ecma_number_is_nan (hours))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ':'))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 59);
|
||||||
|
if (ecma_number_is_nan (minutes))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ':'))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 59);
|
||||||
|
if (ecma_number_is_nan (seconds))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hours == 24 && (minutes != 0 || seconds != 0))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, ' '))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, 'G'))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, 'M'))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, 'T'))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t time = ecma_date_make_time (hours, minutes, seconds, 0);
|
||||||
|
|
||||||
|
if (!is_toUTCString_format)
|
||||||
|
{
|
||||||
|
bool is_timezone_sign_negative = ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '-');
|
||||||
|
if (!is_timezone_sign_negative && !ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, '+'))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 24);
|
||||||
|
if (ecma_number_is_nan (hours))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
if (hours == 24)
|
||||||
|
{
|
||||||
|
hours = ECMA_NUMBER_ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 0, 59);
|
||||||
|
if (ecma_number_is_nan (minutes))
|
||||||
|
{
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t timezone_offset = ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO);
|
||||||
|
time += is_timezone_sign_negative ? timezone_offset : -timezone_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (date_str_curr_p >= date_str_end_p)
|
||||||
|
{
|
||||||
|
ecma_number_t date = ecma_date_make_day (year, month - 1, day);
|
||||||
|
return ecma_date_make_date (date, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nan;
|
||||||
|
} /* ecma_builtin_date_parse_toString_formats */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Date object's 'parse' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v5, 15.9.4.2 Date.parse (string)
|
||||||
|
* ECMA-262 v5, 15.9.1.15 Date Time String Format
|
||||||
|
* ECMA-262 v9, 20.3.4.41 Date.prototype.toString ()
|
||||||
|
* ECMA-262 v9, 20.3.4.43 Date.prototype.toUTCString ()
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t arg) /**< string */
|
||||||
|
{
|
||||||
|
JERRY_UNUSED (this_arg);
|
||||||
|
|
||||||
|
/* Date Time String fromat (ECMA-262 v5, 15.9.1.15) */
|
||||||
|
ecma_string_t *date_str_p = ecma_op_to_string (arg);
|
||||||
|
if (JERRY_UNLIKELY (date_str_p == NULL))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ECMA_STRING_TO_UTF8_STRING (date_str_p, date_start_p, date_start_size);
|
||||||
|
const lit_utf8_byte_t *date_str_curr_p = date_start_p;
|
||||||
|
const lit_utf8_byte_t *date_str_end_p = date_start_p + date_start_size;
|
||||||
|
|
||||||
|
// try to parse date string as ISO string - ECMA-262 v5, 15.9.1.15
|
||||||
|
ecma_number_t ret_value = ecma_builtin_date_parse_ISO_string_format (date_str_curr_p, date_str_end_p);
|
||||||
|
|
||||||
|
if (ecma_number_is_nan (ret_value))
|
||||||
|
{
|
||||||
|
// try to parse date string in Date.prototype.toString() or toUTCString() format
|
||||||
|
ret_value = ecma_builtin_date_parse_toString_formats (date_str_curr_p, date_str_end_p);
|
||||||
|
}
|
||||||
|
|
||||||
ECMA_FINALIZE_UTF8_STRING (date_start_p, date_start_size);
|
ECMA_FINALIZE_UTF8_STRING (date_start_p, date_start_size);
|
||||||
ECMA_FINALIZE (date_str_value);
|
ecma_deref_ecma_string (date_str_p);
|
||||||
|
return ecma_make_number_value (ret_value);
|
||||||
return ret_value;
|
|
||||||
} /* ecma_builtin_date_parse */
|
} /* ecma_builtin_date_parse */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -571,4 +820,7 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef BREAK_IF_FALSE
|
||||||
|
#undef BREAK_IF_NAN
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
|
#endif /* ENABLED (JERRY_BUILTIN_DATE) */
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "ecma-gc.h"
|
#include "ecma-gc.h"
|
||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "ecma-helpers.h"
|
#include "ecma-helpers.h"
|
||||||
|
#include "lit-char-helpers.h"
|
||||||
#include "ecma-objects.h"
|
#include "ecma-objects.h"
|
||||||
#include "ecma-string-object.h"
|
#include "ecma-string-object.h"
|
||||||
#include "ecma-try-catch-macro.h"
|
#include "ecma-try-catch-macro.h"
|
||||||
@@ -43,6 +44,34 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get a property value from an error object
|
||||||
|
*
|
||||||
|
* @return ecma_string_t
|
||||||
|
*/
|
||||||
|
static ecma_string_t *
|
||||||
|
ecma_builtin_error_prototype_object_to_string_helper (ecma_object_t *obj_p, /**< error object */
|
||||||
|
lit_magic_string_id_t property_id, /**< property id */
|
||||||
|
lit_magic_string_id_t default_value) /**< default prop value */
|
||||||
|
{
|
||||||
|
ecma_value_t prop_value = ecma_op_object_get_by_magic_id (obj_p, property_id);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (prop_value))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ecma_is_value_undefined (prop_value))
|
||||||
|
{
|
||||||
|
return ecma_get_magic_string (default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_string_t *ret_str_p = ecma_op_to_string (prop_value);
|
||||||
|
ecma_free_value (prop_value);
|
||||||
|
|
||||||
|
return ret_str_p;
|
||||||
|
} /* ecma_builtin_error_prototype_object_to_string_helper */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Error.prototype object's 'toString' routine
|
* The Error.prototype object's 'toString' routine
|
||||||
*
|
*
|
||||||
@@ -55,125 +84,52 @@
|
|||||||
static ecma_value_t
|
static ecma_value_t
|
||||||
ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
|
ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
|
||||||
{
|
{
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
|
||||||
|
|
||||||
/* 2. */
|
/* 2. */
|
||||||
if (!ecma_is_value_object (this_arg))
|
if (!ecma_is_value_object (this_arg))
|
||||||
{
|
{
|
||||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an object."));
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an object."));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||||
|
|
||||||
|
ecma_string_t *name_string_p = ecma_builtin_error_prototype_object_to_string_helper (obj_p,
|
||||||
|
LIT_MAGIC_STRING_NAME,
|
||||||
|
LIT_MAGIC_STRING_ERROR_UL);
|
||||||
|
|
||||||
|
if (JERRY_UNLIKELY (name_string_p == NULL))
|
||||||
{
|
{
|
||||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
return ECMA_VALUE_ERROR;
|
||||||
|
|
||||||
ECMA_TRY_CATCH (name_get_ret_value,
|
|
||||||
ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_NAME),
|
|
||||||
ret_value);
|
|
||||||
|
|
||||||
ecma_value_t name_to_str_completion;
|
|
||||||
|
|
||||||
if (ecma_is_value_undefined (name_get_ret_value))
|
|
||||||
{
|
|
||||||
name_to_str_completion = ecma_make_magic_string_value (LIT_MAGIC_STRING_ERROR_UL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
name_to_str_completion = ecma_op_to_string (name_get_ret_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (name_to_str_completion)))
|
|
||||||
{
|
|
||||||
ret_value = ecma_copy_value (name_to_str_completion);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ECMA_TRY_CATCH (msg_get_ret_value,
|
|
||||||
ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_MESSAGE),
|
|
||||||
ret_value);
|
|
||||||
|
|
||||||
ecma_value_t msg_to_str_completion;
|
|
||||||
|
|
||||||
if (ecma_is_value_undefined (msg_get_ret_value))
|
|
||||||
{
|
|
||||||
msg_to_str_completion = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg_to_str_completion = ecma_op_to_string (msg_get_ret_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (msg_to_str_completion)))
|
|
||||||
{
|
|
||||||
ret_value = ecma_copy_value (msg_to_str_completion);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ecma_string_t *name_string_p = ecma_get_string_from_value (name_to_str_completion);
|
|
||||||
ecma_string_t *msg_string_p = ecma_get_string_from_value (msg_to_str_completion);
|
|
||||||
|
|
||||||
ecma_string_t *ret_str_p;
|
|
||||||
|
|
||||||
if (ecma_string_is_empty (name_string_p))
|
|
||||||
{
|
|
||||||
ret_str_p = msg_string_p;
|
|
||||||
ecma_ref_ecma_string (ret_str_p);
|
|
||||||
}
|
|
||||||
else if (ecma_string_is_empty (msg_string_p))
|
|
||||||
{
|
|
||||||
ret_str_p = name_string_p;
|
|
||||||
ecma_ref_ecma_string (ret_str_p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const lit_utf8_size_t name_size = ecma_string_get_size (name_string_p);
|
|
||||||
const lit_utf8_size_t msg_size = ecma_string_get_size (msg_string_p);
|
|
||||||
const lit_utf8_size_t colon_size = lit_get_magic_string_size (LIT_MAGIC_STRING_COLON_CHAR);
|
|
||||||
const lit_utf8_size_t space_size = lit_get_magic_string_size (LIT_MAGIC_STRING_SPACE_CHAR);
|
|
||||||
const lit_utf8_size_t size = name_size + msg_size + colon_size + space_size;
|
|
||||||
|
|
||||||
JMEM_DEFINE_LOCAL_ARRAY (ret_str_buffer, size, lit_utf8_byte_t);
|
|
||||||
lit_utf8_byte_t *ret_str_buffer_p = ret_str_buffer;
|
|
||||||
|
|
||||||
lit_utf8_size_t bytes = ecma_string_copy_to_cesu8_buffer (name_string_p, ret_str_buffer_p, name_size);
|
|
||||||
JERRY_ASSERT (bytes == name_size);
|
|
||||||
ret_str_buffer_p = ret_str_buffer_p + bytes;
|
|
||||||
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
|
|
||||||
|
|
||||||
ret_str_buffer_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_COLON_CHAR,
|
|
||||||
ret_str_buffer_p,
|
|
||||||
colon_size);
|
|
||||||
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
|
|
||||||
|
|
||||||
ret_str_buffer_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_SPACE_CHAR,
|
|
||||||
ret_str_buffer_p,
|
|
||||||
space_size);
|
|
||||||
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
|
|
||||||
|
|
||||||
bytes = ecma_string_copy_to_cesu8_buffer (msg_string_p, ret_str_buffer_p, msg_size);
|
|
||||||
JERRY_ASSERT (bytes == msg_size);
|
|
||||||
ret_str_buffer_p = ret_str_buffer_p + bytes;
|
|
||||||
JERRY_ASSERT (ret_str_buffer_p == ret_str_buffer + size);
|
|
||||||
|
|
||||||
ret_str_p = ecma_new_ecma_string_from_utf8 (ret_str_buffer,
|
|
||||||
size);
|
|
||||||
|
|
||||||
JMEM_FINALIZE_LOCAL_ARRAY (ret_str_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_value = ecma_make_string_value (ret_str_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_free_value (msg_to_str_completion);
|
|
||||||
|
|
||||||
ECMA_FINALIZE (msg_get_ret_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_free_value (name_to_str_completion);
|
|
||||||
|
|
||||||
ECMA_FINALIZE (name_get_ret_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_value;
|
ecma_string_t *msg_string_p = ecma_builtin_error_prototype_object_to_string_helper (obj_p,
|
||||||
|
LIT_MAGIC_STRING_MESSAGE,
|
||||||
|
LIT_MAGIC_STRING__EMPTY);
|
||||||
|
|
||||||
|
if (JERRY_UNLIKELY (msg_string_p == NULL))
|
||||||
|
{
|
||||||
|
ecma_deref_ecma_string (name_string_p);
|
||||||
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ecma_string_is_empty (name_string_p))
|
||||||
|
{
|
||||||
|
return ecma_make_string_value (msg_string_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ecma_string_is_empty (msg_string_p))
|
||||||
|
{
|
||||||
|
return ecma_make_string_value (name_string_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (name_string_p);
|
||||||
|
|
||||||
|
ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *)": ", 2);
|
||||||
|
ecma_stringbuilder_append (&builder, msg_string_p);
|
||||||
|
|
||||||
|
ecma_deref_ecma_string (name_string_p);
|
||||||
|
ecma_deref_ecma_string (msg_string_p);
|
||||||
|
|
||||||
|
return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
|
||||||
} /* ecma_builtin_error_prototype_object_to_string */
|
} /* ecma_builtin_error_prototype_object_to_string */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "ecma-objects.h"
|
#include "ecma-objects.h"
|
||||||
#include "ecma-try-catch-macro.h"
|
#include "ecma-try-catch-macro.h"
|
||||||
#include "jrt.h"
|
#include "jrt.h"
|
||||||
|
#include "ecma-builtin-function-prototype.h"
|
||||||
|
|
||||||
#define ECMA_BUILTINS_INTERNAL
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
#include "ecma-builtins-internal.h"
|
#include "ecma-builtins-internal.h"
|
||||||
@@ -44,6 +45,9 @@ enum
|
|||||||
ECMA_FUNCTION_PROTOTYPE_CALL,
|
ECMA_FUNCTION_PROTOTYPE_CALL,
|
||||||
ECMA_FUNCTION_PROTOTYPE_APPLY,
|
ECMA_FUNCTION_PROTOTYPE_APPLY,
|
||||||
ECMA_FUNCTION_PROTOTYPE_BIND,
|
ECMA_FUNCTION_PROTOTYPE_BIND,
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE,
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function-prototype.inc.h"
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function-prototype.inc.h"
|
||||||
@@ -89,7 +93,7 @@ ecma_builtin_function_prototype_object_to_string (void)
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< this argument object */
|
ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< this argument object */
|
||||||
ecma_value_t arg1, /**< first argument */
|
ecma_value_t arg1, /**< first argument */
|
||||||
ecma_value_t arg2) /**< second argument */
|
ecma_value_t arg2) /**< second argument */
|
||||||
@@ -108,27 +112,15 @@ ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< th
|
|||||||
|
|
||||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg2);
|
ecma_object_t *obj_p = ecma_get_object_from_value (arg2);
|
||||||
|
|
||||||
/* 4. */
|
/* 4-5. */
|
||||||
ecma_value_t length_value = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_LENGTH);
|
uint32_t length;
|
||||||
if (ECMA_IS_VALUE_ERROR (length_value))
|
ecma_value_t len_value = ecma_op_object_get_length (obj_p, &length);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (len_value))
|
||||||
{
|
{
|
||||||
return length_value;
|
return len_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_number_t length_number;
|
|
||||||
ecma_value_t get_result = ecma_get_number (length_value, &length_number);
|
|
||||||
|
|
||||||
ecma_free_value (length_value);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (get_result))
|
|
||||||
{
|
|
||||||
return get_result;
|
|
||||||
}
|
|
||||||
JERRY_ASSERT (ecma_is_value_empty (get_result));
|
|
||||||
|
|
||||||
/* 5. */
|
|
||||||
const uint32_t length = ecma_number_to_uint32 (length_number);
|
|
||||||
|
|
||||||
if (length >= ECMA_FUNCTION_APPLY_ARGUMENT_COUNT_LIMIT)
|
if (length >= ECMA_FUNCTION_APPLY_ARGUMENT_COUNT_LIMIT)
|
||||||
{
|
{
|
||||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Too many arguments declared for Function.apply()."));
|
return ecma_raise_range_error (ECMA_ERR_MSG ("Too many arguments declared for Function.apply()."));
|
||||||
@@ -142,9 +134,7 @@ ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< th
|
|||||||
/* 7. */
|
/* 7. */
|
||||||
for (index = 0; index < length; index++)
|
for (index = 0; index < length; index++)
|
||||||
{
|
{
|
||||||
ecma_string_t *curr_idx_str_p = ecma_new_ecma_string_from_uint32 (index);
|
ecma_value_t get_value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||||
ecma_value_t get_value = ecma_op_object_get (obj_p, curr_idx_str_p);
|
|
||||||
ecma_deref_ecma_string (curr_idx_str_p);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (get_value))
|
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||||
{
|
{
|
||||||
@@ -218,7 +208,13 @@ ecma_builtin_function_prototype_object_bind (ecma_object_t *this_arg_obj_p , /**
|
|||||||
ecma_length_t arguments_number) /**< number of arguments */
|
ecma_length_t arguments_number) /**< number of arguments */
|
||||||
{
|
{
|
||||||
/* 4. 11. 18. */
|
/* 4. 11. 18. */
|
||||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
|
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) */
|
||||||
|
prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
ecma_object_t *function_p;
|
ecma_object_t *function_p;
|
||||||
ecma_extended_object_t *ext_function_p;
|
ecma_extended_object_t *ext_function_p;
|
||||||
@@ -350,6 +346,12 @@ ecma_builtin_function_prototype_dispatch_routine (uint16_t builtin_routine_id, /
|
|||||||
{
|
{
|
||||||
return ecma_builtin_function_prototype_object_bind (func_obj_p, arguments_list_p, arguments_number);
|
return ecma_builtin_function_prototype_object_bind (func_obj_p, arguments_list_p, arguments_number);
|
||||||
}
|
}
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
case ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE:
|
||||||
|
{
|
||||||
|
return ecma_op_object_has_instance (func_obj_p, arguments_list_p[0]);
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JERRY_UNREACHABLE ();
|
JERRY_UNREACHABLE ();
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ECMA_BUILTIN_FUNCTION_PROTOTYPE_H
|
||||||
|
#define ECMA_BUILTIN_FUNCTION_PROTOTYPE_H
|
||||||
|
|
||||||
|
ecma_value_t ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p,
|
||||||
|
ecma_value_t arg1,
|
||||||
|
ecma_value_t arg2);
|
||||||
|
|
||||||
|
#endif /* !ECMA_BUILTIN_FUNCTION_PROTOTYPE_H */
|
||||||
@@ -42,4 +42,20 @@ ROUTINE (LIT_MAGIC_STRING_APPLY, ECMA_FUNCTION_PROTOTYPE_APPLY, 2, 2)
|
|||||||
ROUTINE (LIT_MAGIC_STRING_CALL, ECMA_FUNCTION_PROTOTYPE_CALL, NON_FIXED, 1)
|
ROUTINE (LIT_MAGIC_STRING_CALL, ECMA_FUNCTION_PROTOTYPE_CALL, NON_FIXED, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_BIND, ECMA_FUNCTION_PROTOTYPE_BIND, NON_FIXED, 1)
|
ROUTINE (LIT_MAGIC_STRING_BIND, ECMA_FUNCTION_PROTOTYPE_BIND, NON_FIXED, 1)
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
/**
|
||||||
|
* ECMA-262 v6.0 19.2.3.6 @@hasInstance
|
||||||
|
* the property attributes are: { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
|
||||||
|
*/
|
||||||
|
ROUTINE_WITH_FLAGS (LIT_GLOBAL_SYMBOL_HAS_INSTANCE, ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE, 1, 1, 0 /* flags */)
|
||||||
|
ACCESSOR_BUILTIN_FUNCTION (LIT_MAGIC_STRING_ARGUMENTS,
|
||||||
|
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
|
||||||
|
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
ACCESSOR_BUILTIN_FUNCTION (LIT_MAGIC_STRING_CALLER,
|
||||||
|
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
|
||||||
|
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
|
|||||||
@@ -59,60 +59,6 @@ ecma_builtin_function_dispatch_call (const ecma_value_t *arguments_list_p, /**<
|
|||||||
return ecma_builtin_function_dispatch_construct (arguments_list_p, arguments_list_len);
|
return ecma_builtin_function_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||||
} /* ecma_builtin_function_dispatch_call */
|
} /* ecma_builtin_function_dispatch_call */
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to count and convert the arguments for the Function constructor call.
|
|
||||||
*
|
|
||||||
* Performs the operation described in ECMA 262 v5.1 15.3.2.1 steps 5.a-d
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return ecma value - concatenated arguments as a string.
|
|
||||||
* Returned value must be freed with ecma_free_value.
|
|
||||||
*/
|
|
||||||
static ecma_value_t
|
|
||||||
ecma_builtin_function_helper_get_function_arguments (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);
|
|
||||||
|
|
||||||
if (arguments_list_len <= 1)
|
|
||||||
{
|
|
||||||
return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_value_t final_str = ecma_op_to_string (arguments_list_p[0]);
|
|
||||||
|
|
||||||
if (arguments_list_len == 2 || ECMA_IS_VALUE_ERROR (final_str))
|
|
||||||
{
|
|
||||||
return final_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ecma_length_t idx = 1; idx < arguments_list_len - 1; idx++)
|
|
||||||
{
|
|
||||||
ecma_value_t new_str = ecma_op_to_string (arguments_list_p[idx]);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (new_str))
|
|
||||||
{
|
|
||||||
ecma_free_value (final_str);
|
|
||||||
|
|
||||||
/* Return with the error. */
|
|
||||||
final_str = new_str;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_string_t *final_str_p = ecma_get_string_from_value (final_str);
|
|
||||||
final_str_p = ecma_append_magic_string_to_string (final_str_p,
|
|
||||||
LIT_MAGIC_STRING_COMMA_CHAR);
|
|
||||||
|
|
||||||
ecma_string_t *new_str_p = ecma_get_string_from_value (new_str);
|
|
||||||
final_str_p = ecma_concat_ecma_strings (final_str_p, new_str_p);
|
|
||||||
ecma_deref_ecma_string (new_str_p);
|
|
||||||
|
|
||||||
final_str = ecma_make_string_value (final_str_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
return final_str;
|
|
||||||
} /* ecma_builtin_function_helper_get_function_arguments */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle calling [[Construct]] of built-in Function object
|
* Handle calling [[Construct]] of built-in Function object
|
||||||
*
|
*
|
||||||
@@ -125,71 +71,7 @@ ecma_value_t
|
|||||||
ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
return ecma_op_create_dynamic_function (arguments_list_p, arguments_list_len, ECMA_PARSE_NO_OPTS);
|
||||||
|
|
||||||
ecma_value_t arguments_value = ecma_builtin_function_helper_get_function_arguments (arguments_list_p,
|
|
||||||
arguments_list_len);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (arguments_value))
|
|
||||||
{
|
|
||||||
return arguments_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_value_t function_body_value;
|
|
||||||
|
|
||||||
if (arguments_list_len > 0)
|
|
||||||
{
|
|
||||||
function_body_value = ecma_op_to_string (arguments_list_p[arguments_list_len - 1]);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (function_body_value))
|
|
||||||
{
|
|
||||||
ecma_free_value (arguments_value);
|
|
||||||
return function_body_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Very unlikely code path, not optimized. */
|
|
||||||
function_body_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_string_t *arguments_str_p = ecma_get_string_from_value (arguments_value);
|
|
||||||
ecma_string_t *function_body_str_p = ecma_get_string_from_value (function_body_value);
|
|
||||||
|
|
||||||
ECMA_STRING_TO_UTF8_STRING (arguments_str_p, arguments_buffer_p, arguments_buffer_size);
|
|
||||||
ECMA_STRING_TO_UTF8_STRING (function_body_str_p, function_body_buffer_p, function_body_buffer_size);
|
|
||||||
|
|
||||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
|
||||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
|
||||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
|
||||||
|
|
||||||
ecma_compiled_code_t *bytecode_data_p = NULL;
|
|
||||||
|
|
||||||
ecma_value_t ret_value = parser_parse_script (arguments_buffer_p,
|
|
||||||
arguments_buffer_size,
|
|
||||||
function_body_buffer_p,
|
|
||||||
function_body_buffer_size,
|
|
||||||
ECMA_PARSE_NO_OPTS,
|
|
||||||
&bytecode_data_p);
|
|
||||||
|
|
||||||
if (!ECMA_IS_VALUE_ERROR (ret_value))
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (ecma_is_value_true (ret_value));
|
|
||||||
|
|
||||||
ecma_object_t *func_obj_p = ecma_op_create_function_object (ecma_get_global_environment (),
|
|
||||||
bytecode_data_p);
|
|
||||||
|
|
||||||
ecma_bytecode_deref (bytecode_data_p);
|
|
||||||
ret_value = ecma_make_object_value (func_obj_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
ECMA_FINALIZE_UTF8_STRING (function_body_buffer_p, function_body_buffer_size);
|
|
||||||
ECMA_FINALIZE_UTF8_STRING (arguments_buffer_p, arguments_buffer_size);
|
|
||||||
|
|
||||||
ecma_deref_ecma_string (arguments_str_p);
|
|
||||||
ecma_deref_ecma_string (function_body_str_p);
|
|
||||||
|
|
||||||
return ret_value;
|
|
||||||
} /* ecma_builtin_function_dispatch_construct */
|
} /* ecma_builtin_function_dispatch_construct */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/* 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-globals.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
|
#include "ecma-builtins-internal.h"
|
||||||
|
#include "ecma-function-object.h"
|
||||||
|
|
||||||
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-generator-function.inc.h"
|
||||||
|
#define BUILTIN_UNDERSCORED_ID generator_function
|
||||||
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
|
|
||||||
|
/** \addtogroup ecma ECMA
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup ecmabuiltins
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup generator ECMA GeneratorFunction object built-in
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle calling [[Call]] of built-in GeneratorFunction object
|
||||||
|
*
|
||||||
|
* @return constructed generator function object - if success
|
||||||
|
* raised error otherwise
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_builtin_generator_function_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||||
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||||
|
|
||||||
|
return ecma_op_create_dynamic_function (arguments_list_p, arguments_list_len, ECMA_PARSE_GENERATOR_FUNCTION);
|
||||||
|
} /* ecma_builtin_generator_function_dispatch_call */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle calling [[Construct]] of built-in GeneratorFunction object
|
||||||
|
*
|
||||||
|
* @return constructed generator function object - if success
|
||||||
|
* raised error otherwise
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_builtin_generator_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||||
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
|
{
|
||||||
|
return ecma_builtin_generator_function_dispatch_call (arguments_list_p, arguments_list_len);
|
||||||
|
} /* ecma_builtin_generator_function_dispatch_construct */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* %GeneratorFunction% built-in description
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.2.2 */
|
||||||
|
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||||
|
LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.2.2 */
|
||||||
|
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||||
|
1,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.2.2.2 */
|
||||||
|
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||||
|
ECMA_BUILTIN_ID_GENERATOR,
|
||||||
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
@@ -0,0 +1,250 @@
|
|||||||
|
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecma-builtins.h"
|
||||||
|
#include "ecma-exceptions.h"
|
||||||
|
#include "ecma-gc.h"
|
||||||
|
#include "ecma-globals.h"
|
||||||
|
#include "ecma-helpers.h"
|
||||||
|
#include "ecma-iterator-object.h"
|
||||||
|
#include "jcontext.h"
|
||||||
|
#include "opcodes.h"
|
||||||
|
#include "vm-defines.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
|
#include "ecma-builtins-internal.h"
|
||||||
|
|
||||||
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-generator-prototype.inc.h"
|
||||||
|
#define BUILTIN_UNDERSCORED_ID generator_prototype
|
||||||
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
|
|
||||||
|
/** \addtogroup ecma ECMA
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup ecmabuiltins
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup generator ECMA Generator.prototype object built-in
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Byte code sequence which returns from the generator.
|
||||||
|
*/
|
||||||
|
static const uint8_t ecma_builtin_generator_prototype_return[2] =
|
||||||
|
{
|
||||||
|
CBC_EXT_OPCODE, CBC_EXT_RETURN
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Byte code sequence which throws an exception.
|
||||||
|
*/
|
||||||
|
static const uint8_t ecma_builtin_generator_prototype_throw[1] =
|
||||||
|
{
|
||||||
|
CBC_THROW
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for next / return / throw
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_generator_prototype_object_do (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t arg, /**< argument */
|
||||||
|
ecma_iterator_command_type_t resume_mode) /**< resume mode */
|
||||||
|
{
|
||||||
|
vm_executable_object_t *executable_object_p = NULL;
|
||||||
|
|
||||||
|
if (ecma_is_value_object (this_arg))
|
||||||
|
{
|
||||||
|
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
|
||||||
|
|
||||||
|
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_CLASS)
|
||||||
|
{
|
||||||
|
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||||
|
|
||||||
|
if (ext_object_p->u.class_prop.class_id == LIT_MAGIC_STRING_GENERATOR_UL)
|
||||||
|
{
|
||||||
|
executable_object_p = (vm_executable_object_t *) ext_object_p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (executable_object_p == NULL)
|
||||||
|
{
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a generator object."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (executable_object_p->extended_object.u.class_prop.extra_info & ECMA_EXECUTABLE_OBJECT_RUNNING)
|
||||||
|
{
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Generator is currently under execution."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (executable_object_p->extended_object.u.class_prop.extra_info & ECMA_EXECUTABLE_OBJECT_COMPLETED)
|
||||||
|
{
|
||||||
|
return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = ecma_copy_value (arg);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (executable_object_p->extended_object.u.class_prop.extra_info & ECMA_GENERATOR_ITERATE_AND_YIELD)
|
||||||
|
{
|
||||||
|
ecma_value_t iterator = executable_object_p->extended_object.u.class_prop.u.value;
|
||||||
|
|
||||||
|
bool done = false;
|
||||||
|
ecma_value_t result = ecma_op_iterator_do (resume_mode, iterator, arg, &done);
|
||||||
|
ecma_free_value (arg);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (result))
|
||||||
|
{
|
||||||
|
arg = result;
|
||||||
|
}
|
||||||
|
else if (done)
|
||||||
|
{
|
||||||
|
arg = ecma_op_iterator_value (result);
|
||||||
|
ecma_free_value (result);
|
||||||
|
if (resume_mode == ECMA_ITERATOR_THROW)
|
||||||
|
{
|
||||||
|
/* This part is changed in the newest ECMAScript standard.
|
||||||
|
* It was ECMA_ITERATOR_RETURN in ES2015, but I think it was a typo. */
|
||||||
|
resume_mode = ECMA_ITERATOR_NEXT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
executable_object_p->extended_object.u.class_prop.extra_info &= (uint16_t) ~ECMA_GENERATOR_ITERATE_AND_YIELD;
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (arg))
|
||||||
|
{
|
||||||
|
arg = jcontext_take_exception ();
|
||||||
|
resume_mode = ECMA_ITERATOR_THROW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resume_mode == ECMA_ITERATOR_RETURN)
|
||||||
|
{
|
||||||
|
executable_object_p->frame_ctx.byte_code_p = ecma_builtin_generator_prototype_return;
|
||||||
|
}
|
||||||
|
else if (resume_mode == ECMA_ITERATOR_THROW)
|
||||||
|
{
|
||||||
|
executable_object_p->frame_ctx.byte_code_p = ecma_builtin_generator_prototype_throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_value_t value = opfunc_resume_executable_object (executable_object_p, arg);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool done = (executable_object_p->extended_object.u.class_prop.extra_info & ECMA_EXECUTABLE_OBJECT_COMPLETED);
|
||||||
|
|
||||||
|
if (!done)
|
||||||
|
{
|
||||||
|
const uint8_t *byte_code_p = executable_object_p->frame_ctx.byte_code_p;
|
||||||
|
|
||||||
|
JERRY_ASSERT (byte_code_p[-2] == CBC_EXT_OPCODE
|
||||||
|
&& (byte_code_p[-1] == CBC_EXT_YIELD || byte_code_p[-1] == CBC_EXT_YIELD_ITERATOR));
|
||||||
|
|
||||||
|
if (byte_code_p[-1] == CBC_EXT_YIELD_ITERATOR)
|
||||||
|
{
|
||||||
|
ecma_value_t iterator = ecma_op_get_iterator (value, ECMA_VALUE_EMPTY);
|
||||||
|
ecma_free_value (value);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (iterator))
|
||||||
|
{
|
||||||
|
resume_mode = ECMA_ITERATOR_THROW;
|
||||||
|
arg = jcontext_take_exception ();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_deref_object (ecma_get_object_from_value (iterator));
|
||||||
|
executable_object_p->extended_object.u.class_prop.extra_info |= ECMA_GENERATOR_ITERATE_AND_YIELD;
|
||||||
|
executable_object_p->extended_object.u.class_prop.u.value = iterator;
|
||||||
|
arg = ECMA_VALUE_UNDEFINED;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_value_t result = ecma_create_iter_result_object (value, ecma_make_boolean_value (done));
|
||||||
|
ecma_fast_free_value (value);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} /* ecma_builtin_generator_prototype_object_do */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Generator.prototype object's 'next' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 25.3.1.2
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_generator_prototype_object_next (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t next_arg) /**< next argument */
|
||||||
|
{
|
||||||
|
return ecma_builtin_generator_prototype_object_do (this_arg, next_arg, ECMA_ITERATOR_NEXT);
|
||||||
|
} /* ecma_builtin_generator_prototype_object_next */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Generator.prototype object's 'return' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 25.3.1.3
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_generator_prototype_object_return (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t return_arg) /**< return argument */
|
||||||
|
{
|
||||||
|
return ecma_builtin_generator_prototype_object_do (this_arg, return_arg, ECMA_ITERATOR_RETURN);
|
||||||
|
} /* ecma_builtin_generator_prototype_object_return */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Generator.prototype object's 'throw' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 25.3.1.4
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_generator_prototype_object_throw (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t throw_arg) /**< throw argument */
|
||||||
|
{
|
||||||
|
return ecma_builtin_generator_prototype_object_do (this_arg, throw_arg, ECMA_ITERATOR_THROW);
|
||||||
|
} /* ecma_builtin_generator_prototype_object_throw */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generator.prototype built-in description
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
/* Object properties:
|
||||||
|
* (property name, object pointer getter) */
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.3.1.5 */
|
||||||
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
|
LIT_MAGIC_STRING_GENERATOR_UL,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.2.3.1 */
|
||||||
|
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||||
|
ECMA_BUILTIN_ID_GENERATOR,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
|
/* Routine properties:
|
||||||
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
|
ROUTINE (LIT_MAGIC_STRING_NEXT, ecma_builtin_generator_prototype_object_next, 1, 1)
|
||||||
|
ROUTINE (LIT_MAGIC_STRING_RETURN, ecma_builtin_generator_prototype_object_return, 1, 1)
|
||||||
|
ROUTINE (LIT_MAGIC_STRING_THROW, ecma_builtin_generator_prototype_object_throw, 1, 1)
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/* 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-globals.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
|
#include "ecma-builtins-internal.h"
|
||||||
|
|
||||||
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-generator.inc.h"
|
||||||
|
#define BUILTIN_UNDERSCORED_ID generator
|
||||||
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
|
|
||||||
|
/** \addtogroup ecma ECMA
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup ecmabuiltins
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup generator ECMA Generator object built-in
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* %Generator% built-in description (GeneratorFunction.prototype)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.3.2.3.1 */
|
||||||
|
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||||
|
ECMA_BUILTIN_ID_GENERATOR_FUNCTION,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.3.2.3.2 */
|
||||||
|
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||||
|
ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 25.3.2.3.3 */
|
||||||
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
|
LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
@@ -100,42 +100,17 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument *
|
|||||||
parse_opts |= ECMA_PARSE_STRICT_MODE;
|
parse_opts |= ECMA_PARSE_STRICT_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_CLASS)
|
#if ENABLED (JERRY_ES2015)
|
||||||
if (vm_is_direct_eval_form_call ())
|
if (vm_is_direct_eval_form_call ())
|
||||||
{
|
{
|
||||||
parse_opts |= ECMA_GET_SUPER_EVAL_PARSER_OPTS ();
|
parse_opts |= ECMA_GET_SUPER_EVAL_PARSER_OPTS ();
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* steps 2 to 8 */
|
/* steps 2 to 8 */
|
||||||
return ecma_op_eval (ecma_get_string_from_value (x), parse_opts);
|
return ecma_op_eval (ecma_get_string_from_value (x), parse_opts);
|
||||||
} /* ecma_builtin_global_object_eval */
|
} /* ecma_builtin_global_object_eval */
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function for trimming leading whitespaces
|
|
||||||
* for the Global object's 'parseInt' and 'parseFloat' routines
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
ecma_builtin_global_remove_leading_white_spaces (const lit_utf8_byte_t **string_curr_p, /**< [in, out] current string
|
|
||||||
* position */
|
|
||||||
const lit_utf8_byte_t *string_end_p, /**< end of the string buffer */
|
|
||||||
const lit_utf8_byte_t **start_p) /**< [in, out] start position of the
|
|
||||||
* trimmed string */
|
|
||||||
{
|
|
||||||
while (*string_curr_p < string_end_p)
|
|
||||||
{
|
|
||||||
ecma_char_t current_char = lit_utf8_read_next (string_curr_p);
|
|
||||||
|
|
||||||
if (!lit_char_is_white_space (current_char)
|
|
||||||
&& !lit_char_is_line_terminator (current_char))
|
|
||||||
{
|
|
||||||
lit_utf8_decr (string_curr_p);
|
|
||||||
*start_p = *string_curr_p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} /* ecma_builtin_global_remove_leading_white_spaces */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Global object's 'parseInt' routine
|
* The Global object's 'parseInt' routine
|
||||||
*
|
*
|
||||||
@@ -158,13 +133,13 @@ ecma_builtin_global_object_parse_int (const lit_utf8_byte_t *string_buff, /**< r
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lit_utf8_byte_t *string_curr_p = string_buff;
|
const lit_utf8_byte_t *string_curr_p = string_buff;
|
||||||
const lit_utf8_byte_t *string_end_p = string_buff + string_buff_size;
|
|
||||||
|
|
||||||
/* 2. Remove leading whitespace. */
|
/* 2. Remove leading whitespace. */
|
||||||
const lit_utf8_byte_t *start_p = string_end_p;
|
ecma_string_trim_helper (&string_curr_p, &string_buff_size);
|
||||||
const lit_utf8_byte_t *end_p = start_p;
|
|
||||||
|
|
||||||
ecma_builtin_global_remove_leading_white_spaces (&string_curr_p, string_end_p, &start_p);
|
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)
|
if (string_curr_p >= string_end_p)
|
||||||
{
|
{
|
||||||
@@ -175,7 +150,7 @@ ecma_builtin_global_object_parse_int (const lit_utf8_byte_t *string_buff, /**< r
|
|||||||
int sign = 1;
|
int sign = 1;
|
||||||
|
|
||||||
/* 4. */
|
/* 4. */
|
||||||
ecma_char_t current = lit_utf8_read_next (&string_curr_p);
|
ecma_char_t current = lit_cesu8_read_next (&string_curr_p);
|
||||||
if (current == LIT_CHAR_MINUS)
|
if (current == LIT_CHAR_MINUS)
|
||||||
{
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
@@ -187,7 +162,7 @@ ecma_builtin_global_object_parse_int (const lit_utf8_byte_t *string_buff, /**< r
|
|||||||
start_p = string_curr_p;
|
start_p = string_curr_p;
|
||||||
if (string_curr_p < string_end_p)
|
if (string_curr_p < string_end_p)
|
||||||
{
|
{
|
||||||
current = lit_utf8_read_next (&string_curr_p);
|
current = lit_cesu8_read_next (&string_curr_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,14 +311,14 @@ ecma_builtin_global_object_parse_float (const lit_utf8_byte_t *string_buff, /**<
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lit_utf8_byte_t *str_curr_p = string_buff;
|
const lit_utf8_byte_t *str_curr_p = string_buff;
|
||||||
const lit_utf8_byte_t *str_end_p = string_buff + string_buff_size;
|
|
||||||
|
|
||||||
const lit_utf8_byte_t *start_p = str_end_p;
|
/* 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;
|
const lit_utf8_byte_t *end_p = str_end_p;
|
||||||
|
|
||||||
/* 2. Find first non whitespace char and set starting position. */
|
|
||||||
ecma_builtin_global_remove_leading_white_spaces (&str_curr_p, str_end_p, &start_p);
|
|
||||||
|
|
||||||
bool sign = false;
|
bool sign = false;
|
||||||
ecma_char_t current;
|
ecma_char_t current;
|
||||||
|
|
||||||
@@ -412,7 +387,6 @@ ecma_builtin_global_object_parse_float (const lit_utf8_byte_t *string_buff, /**<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Set end position to the end of whole part. */
|
/* Set end position to the end of whole part. */
|
||||||
end_p = str_curr_p;
|
end_p = str_curr_p;
|
||||||
if (str_curr_p < str_end_p)
|
if (str_curr_p < str_end_p)
|
||||||
@@ -450,7 +424,6 @@ ecma_builtin_global_object_parse_float (const lit_utf8_byte_t *string_buff, /**<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (str_curr_p < str_end_p)
|
if (str_curr_p < str_end_p)
|
||||||
{
|
{
|
||||||
current = *str_curr_p++;
|
current = *str_curr_p++;
|
||||||
@@ -995,7 +968,7 @@ ecma_builtin_global_object_escape (lit_utf8_byte_t *input_start_p, /**< routine'
|
|||||||
|
|
||||||
while (input_curr_p < input_end_p)
|
while (input_curr_p < input_end_p)
|
||||||
{
|
{
|
||||||
ecma_char_t chr = lit_utf8_read_next (&input_curr_p);
|
ecma_char_t chr = lit_cesu8_read_next (&input_curr_p);
|
||||||
|
|
||||||
if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
||||||
{
|
{
|
||||||
@@ -1030,7 +1003,7 @@ ecma_builtin_global_object_escape (lit_utf8_byte_t *input_start_p, /**< routine'
|
|||||||
|
|
||||||
while (input_curr_p < input_end_p)
|
while (input_curr_p < input_end_p)
|
||||||
{
|
{
|
||||||
ecma_char_t chr = lit_utf8_read_next (&input_curr_p);
|
ecma_char_t chr = lit_cesu8_read_next (&input_curr_p);
|
||||||
|
|
||||||
if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
||||||
{
|
{
|
||||||
@@ -1116,7 +1089,7 @@ ecma_builtin_global_object_unescape (lit_utf8_byte_t *input_start_p, /**< routin
|
|||||||
while (input_curr_p < input_end_p)
|
while (input_curr_p < input_end_p)
|
||||||
{
|
{
|
||||||
/* 6. */
|
/* 6. */
|
||||||
ecma_char_t chr = lit_utf8_read_next (&input_curr_p);
|
ecma_char_t chr = lit_cesu8_read_next (&input_curr_p);
|
||||||
|
|
||||||
/* 7-8. */
|
/* 7-8. */
|
||||||
if (status == 0 && chr == LIT_CHAR_PERCENT)
|
if (status == 0 && chr == LIT_CHAR_PERCENT)
|
||||||
@@ -1210,15 +1183,13 @@ ecma_builtin_global_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
|
|||||||
return ecma_builtin_global_object_is_finite (arg_num);
|
return ecma_builtin_global_object_is_finite (arg_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_t string_value = ecma_op_to_string (routine_arg_1);
|
ecma_string_t *str_p = ecma_op_to_string (routine_arg_1);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (string_value))
|
if (JERRY_UNLIKELY (str_p == NULL))
|
||||||
{
|
{
|
||||||
return string_value;
|
return ECMA_VALUE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_string_t *str_p = ecma_get_string_from_value (string_value);
|
|
||||||
|
|
||||||
ecma_value_t ret_value;
|
ecma_value_t ret_value;
|
||||||
|
|
||||||
if (builtin_routine_id <= ECMA_GLOBAL_PARSE_FLOAT)
|
if (builtin_routine_id <= ECMA_GLOBAL_PARSE_FLOAT)
|
||||||
|
|||||||
@@ -139,6 +139,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_MATH_UL,
|
|||||||
ECMA_BUILTIN_ID_MATH,
|
ECMA_BUILTIN_ID_MATH,
|
||||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_MATH) */
|
#endif /* ENABLED (JERRY_BUILTIN_MATH) */
|
||||||
|
#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT)
|
||||||
|
/* ECMA-262 v6, 26.1 */
|
||||||
|
OBJECT_VALUE (LIT_MAGIC_STRING_REFLECT_UL,
|
||||||
|
ECMA_BUILTIN_ID_REFLECT,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_REFLECT) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_JSON)
|
#if ENABLED (JERRY_BUILTIN_JSON)
|
||||||
/* ECMA-262 v5, 15.1.5.2 */
|
/* ECMA-262 v5, 15.1.5.2 */
|
||||||
@@ -212,12 +218,26 @@ OBJECT_VALUE (LIT_MAGIC_STRING_SET_UL,
|
|||||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKMAP)
|
||||||
|
/* ECMA-262 v6, 23.1.1.1 */
|
||||||
|
OBJECT_VALUE (LIT_MAGIC_STRING_WEAKMAP_UL,
|
||||||
|
ECMA_BUILTIN_ID_WEAKMAP,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015_BUILTIN_WEAKSET)
|
||||||
|
/* ECMA-262 v6, 23.1.1.1 */
|
||||||
|
OBJECT_VALUE (LIT_MAGIC_STRING_WEAKSET_UL,
|
||||||
|
ECMA_BUILTIN_ID_WEAKSET,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* ECMA-262 v6, 19.4.1.1 */
|
/* ECMA-262 v6, 19.4.1.1 */
|
||||||
OBJECT_VALUE (LIT_MAGIC_STRING_SYMBOL_UL,
|
OBJECT_VALUE (LIT_MAGIC_STRING_SYMBOL_UL,
|
||||||
ECMA_BUILTIN_ID_SYMBOL,
|
ECMA_BUILTIN_ID_SYMBOL,
|
||||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
|
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
|
||||||
/* ECMA-262 v6, 23.1.1.1 */
|
/* ECMA-262 v6, 23.1.1.1 */
|
||||||
|
|||||||
@@ -33,6 +33,16 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const char day_names_p[7][3] =
|
||||||
|
{
|
||||||
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char month_names_p[12][3] =
|
||||||
|
{
|
||||||
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get day number from time value.
|
* Helper function to get day number from time value.
|
||||||
*
|
*
|
||||||
@@ -41,7 +51,7 @@
|
|||||||
*
|
*
|
||||||
* @return time value for day number
|
* @return time value for day number
|
||||||
*/
|
*/
|
||||||
inline ecma_number_t JERRY_ATTR_ALWAYS_INLINE
|
extern inline ecma_number_t JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_date_day (ecma_number_t time) /**< time value */
|
ecma_date_day (ecma_number_t time) /**< time value */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (!ecma_number_is_nan (time));
|
JERRY_ASSERT (!ecma_number_is_nan (time));
|
||||||
@@ -57,7 +67,7 @@ ecma_date_day (ecma_number_t time) /**< time value */
|
|||||||
*
|
*
|
||||||
* @return time value within the day
|
* @return time value within the day
|
||||||
*/
|
*/
|
||||||
inline ecma_number_t JERRY_ATTR_ALWAYS_INLINE
|
extern inline ecma_number_t JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_date_time_within_day (ecma_number_t time) /**< time value */
|
ecma_date_time_within_day (ecma_number_t time) /**< time value */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (!ecma_number_is_nan (time));
|
JERRY_ASSERT (!ecma_number_is_nan (time));
|
||||||
@@ -577,17 +587,7 @@ static ecma_value_t
|
|||||||
ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */
|
ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */
|
||||||
const char *format_p) /**< format buffer */
|
const char *format_p) /**< format buffer */
|
||||||
{
|
{
|
||||||
static const char * const day_names_p[8] =
|
const uint32_t date_buffer_length = 37;
|
||||||
{
|
|
||||||
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char * const month_names_p[13] =
|
|
||||||
{
|
|
||||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint32_t date_buffer_length = 34;
|
|
||||||
JERRY_VLA (lit_utf8_byte_t, date_buffer, date_buffer_length);
|
JERRY_VLA (lit_utf8_byte_t, date_buffer, date_buffer_length);
|
||||||
|
|
||||||
lit_utf8_byte_t *dest_p = date_buffer;
|
lit_utf8_byte_t *dest_p = date_buffer;
|
||||||
@@ -611,7 +611,32 @@ ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */
|
|||||||
case LIT_CHAR_UPPERCASE_Y: /* Year. */
|
case LIT_CHAR_UPPERCASE_Y: /* Year. */
|
||||||
{
|
{
|
||||||
number = (int32_t) ecma_date_year_from_time (datetime_number);
|
number = (int32_t) ecma_date_year_from_time (datetime_number);
|
||||||
number_length = 4;
|
|
||||||
|
if (number >= 100000 || number <= -100000)
|
||||||
|
{
|
||||||
|
number_length = 6;
|
||||||
|
}
|
||||||
|
else if (number >= 10000 || number <= -10000)
|
||||||
|
{
|
||||||
|
number_length = 5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
number_length = 4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LIT_CHAR_LOWERCASE_Y: /* ISO Year: -000001, 0000, 0001, 9999, +012345 */
|
||||||
|
{
|
||||||
|
number = (int32_t) ecma_date_year_from_time (datetime_number);
|
||||||
|
if (0 <= number && number <= 9999)
|
||||||
|
{
|
||||||
|
number_length = 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
number_length = 6;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LIT_CHAR_UPPERCASE_M: /* Month. */
|
case LIT_CHAR_UPPERCASE_M: /* Month. */
|
||||||
@@ -671,7 +696,7 @@ ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */
|
|||||||
number_length = 3;
|
number_length = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LIT_CHAR_LOWERCASE_Z: /* Time zone minutes part. */
|
case LIT_CHAR_LOWERCASE_Z: /* Time zone hours part. */
|
||||||
{
|
{
|
||||||
int32_t time_zone = (int32_t) ecma_date_local_time_zone_adjustment (datetime_number);
|
int32_t time_zone = (int32_t) ecma_date_local_time_zone_adjustment (datetime_number);
|
||||||
|
|
||||||
@@ -691,7 +716,7 @@ ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (*format_p == LIT_CHAR_UPPERCASE_Z); /* Time zone seconds part. */
|
JERRY_ASSERT (*format_p == LIT_CHAR_UPPERCASE_Z); /* Time zone minutes part. */
|
||||||
|
|
||||||
int32_t time_zone = (int32_t) ecma_date_local_time_zone_adjustment (datetime_number);
|
int32_t time_zone = (int32_t) ecma_date_local_time_zone_adjustment (datetime_number);
|
||||||
|
|
||||||
@@ -700,7 +725,7 @@ ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */
|
|||||||
time_zone = -time_zone;
|
time_zone = -time_zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
number = time_zone % (int32_t) ECMA_DATE_MS_PER_HOUR;
|
number = time_zone % (int32_t) ECMA_DATE_MS_PER_HOUR / (int32_t) ECMA_DATE_MS_PER_MINUTE;
|
||||||
number_length = 2;
|
number_length = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -710,19 +735,26 @@ ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */
|
|||||||
|
|
||||||
if (str_p != NULL)
|
if (str_p != NULL)
|
||||||
{
|
{
|
||||||
/* Print string values. */
|
/* Print string values: month or day name which is always 3 characters */
|
||||||
do
|
memcpy (dest_p, str_p, 3);
|
||||||
{
|
dest_p += 3;
|
||||||
*dest_p++ = (lit_utf8_byte_t) *str_p++;
|
|
||||||
}
|
|
||||||
while (*str_p != LIT_CHAR_NULL);
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print right aligned number values. */
|
/* Print right aligned number values. */
|
||||||
JERRY_ASSERT (number_length > 0);
|
JERRY_ASSERT (number_length > 0);
|
||||||
|
|
||||||
|
if (number < 0)
|
||||||
|
{
|
||||||
|
number = -number;
|
||||||
|
*dest_p++ = '-';
|
||||||
|
}
|
||||||
|
else if (*(format_p - 1) == LIT_CHAR_LOWERCASE_Y && number_length == 6)
|
||||||
|
{
|
||||||
|
/* positive sign is compulsory for extended years */
|
||||||
|
*dest_p++ = '+';
|
||||||
|
}
|
||||||
|
|
||||||
dest_p += number_length;
|
dest_p += number_length;
|
||||||
lit_utf8_byte_t *buffer_p = dest_p;
|
lit_utf8_byte_t *buffer_p = dest_p;
|
||||||
|
|
||||||
@@ -755,7 +787,7 @@ ecma_value_t
|
|||||||
ecma_date_value_to_string (ecma_number_t datetime_number) /**< datetime */
|
ecma_date_value_to_string (ecma_number_t datetime_number) /**< datetime */
|
||||||
{
|
{
|
||||||
datetime_number += ecma_date_local_time_zone_adjustment (datetime_number);
|
datetime_number += ecma_date_local_time_zone_adjustment (datetime_number);
|
||||||
return ecma_date_to_string_format (datetime_number, "$W $M $D $Y $h:$m:$s GMT$z:$Z");
|
return ecma_date_to_string_format (datetime_number, "$W $M $D $Y $h:$m:$s GMT$z$Z");
|
||||||
} /* ecma_date_value_to_string */
|
} /* ecma_date_value_to_string */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -785,7 +817,7 @@ ecma_date_value_to_utc_string (ecma_number_t datetime_number) /**< datetime */
|
|||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_date_value_to_iso_string (ecma_number_t datetime_number) /**<datetime */
|
ecma_date_value_to_iso_string (ecma_number_t datetime_number) /**<datetime */
|
||||||
{
|
{
|
||||||
return ecma_date_to_string_format (datetime_number, "$Y-$O-$DT$h:$m:$s.$iZ");
|
return ecma_date_to_string_format (datetime_number, "$y-$O-$DT$h:$m:$s.$iZ");
|
||||||
} /* ecma_date_value_to_iso_string */
|
} /* ecma_date_value_to_iso_string */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,20 +47,18 @@ ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**<
|
|||||||
if (arguments_list_len != 0
|
if (arguments_list_len != 0
|
||||||
&& !ecma_is_value_undefined (arguments_list_p[0]))
|
&& !ecma_is_value_undefined (arguments_list_p[0]))
|
||||||
{
|
{
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
ecma_string_t *message_string_p = ecma_op_to_string (arguments_list_p[0]);
|
||||||
|
|
||||||
ECMA_TRY_CATCH (msg_str_value,
|
if (JERRY_UNLIKELY (message_string_p == NULL))
|
||||||
ecma_op_to_string (arguments_list_p[0]),
|
{
|
||||||
ret_value);
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
|
|
||||||
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (error_type,
|
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (error_type,
|
||||||
message_string_p);
|
message_string_p);
|
||||||
ret_value = ecma_make_object_value (new_error_object_p);
|
|
||||||
|
|
||||||
ECMA_FINALIZE (msg_str_value);
|
ecma_deref_ecma_string (message_string_p);
|
||||||
|
return ecma_make_object_value (new_error_object_p);
|
||||||
return ret_value;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -74,4 +72,3 @@ ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**<
|
|||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -63,165 +63,23 @@ ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, /**< s
|
|||||||
* @return true, if the string is already in the collection.
|
* @return true, if the string is already in the collection.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
ecma_has_string_value_in_collection (ecma_collection_header_t *collection_p, /**< collection */
|
ecma_has_string_value_in_collection (ecma_collection_t *collection_p, /**< collection */
|
||||||
ecma_value_t string_value) /**< string value */
|
ecma_string_t *string_p) /**< string */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (ecma_is_value_string (string_value));
|
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||||
|
|
||||||
ecma_string_t *string_p = ecma_get_string_from_value (string_value);
|
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (collection_p);
|
|
||||||
|
|
||||||
while (ecma_value_p != NULL)
|
|
||||||
{
|
{
|
||||||
ecma_string_t *current_p = ecma_get_string_from_value (*ecma_value_p);
|
ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]);
|
||||||
|
|
||||||
if (ecma_compare_ecma_strings (current_p, string_p))
|
if (ecma_compare_ecma_strings (current_p, string_p))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} /* ecma_has_string_value_in_collection*/
|
} /* ecma_has_string_value_in_collection */
|
||||||
|
|
||||||
/**
|
|
||||||
* Common function to concatenate key-value pairs into an ecma-string.
|
|
||||||
*
|
|
||||||
* See also:
|
|
||||||
* ECMA-262 v5, 15.12.3
|
|
||||||
*
|
|
||||||
* Used by:
|
|
||||||
* - ecma_builtin_helper_json_create_formatted_json step 10.b.ii
|
|
||||||
* - ecma_builtin_helper_json_create_non_formatted_json step 10.a.i
|
|
||||||
*
|
|
||||||
* @return pointer to ecma-string
|
|
||||||
* Returned value must be freed with ecma_deref_ecma_string.
|
|
||||||
*/
|
|
||||||
static ecma_string_t *
|
|
||||||
ecma_builtin_helper_json_create_separated_properties (ecma_collection_header_t *partial_p, /**< key-value pairs*/
|
|
||||||
ecma_string_t *separator_p) /**< separator*/
|
|
||||||
{
|
|
||||||
ecma_string_t *properties_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (partial_p);
|
|
||||||
|
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
while (ecma_value_p != NULL)
|
|
||||||
{
|
|
||||||
ecma_string_t *current_p = ecma_get_string_from_value (*ecma_value_p);
|
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
|
|
||||||
if (JERRY_LIKELY (!first))
|
|
||||||
{
|
|
||||||
properties_str_p = ecma_concat_ecma_strings (properties_str_p, separator_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
properties_str_p = ecma_concat_ecma_strings (properties_str_p, current_p);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return properties_str_p;
|
|
||||||
} /* ecma_builtin_helper_json_create_separated_properties */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common function to create a formatted JSON string.
|
|
||||||
*
|
|
||||||
* See also:
|
|
||||||
* ECMA-262 v5, 15.12.3
|
|
||||||
*
|
|
||||||
* Used by:
|
|
||||||
* - ecma_builtin_json_object step 10.b
|
|
||||||
* - ecma_builtin_json_array step 10.b
|
|
||||||
*
|
|
||||||
* @return ecma value
|
|
||||||
* Returned value must be freed with ecma_free_value.
|
|
||||||
*/
|
|
||||||
ecma_value_t
|
|
||||||
ecma_builtin_helper_json_create_formatted_json (lit_utf8_byte_t left_bracket, /**< left bracket character */
|
|
||||||
lit_utf8_byte_t right_bracket, /**< right bracket character */
|
|
||||||
ecma_string_t *stepback_p, /**< stepback*/
|
|
||||||
ecma_collection_header_t *partial_p, /**< key-value pairs*/
|
|
||||||
ecma_json_stringify_context_t *context_p) /**< context*/
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (left_bracket < LIT_UTF8_1_BYTE_CODE_POINT_MAX
|
|
||||||
&& right_bracket < LIT_UTF8_1_BYTE_CODE_POINT_MAX);
|
|
||||||
|
|
||||||
/* 10.b.i */
|
|
||||||
lit_utf8_byte_t chars[2] = { LIT_CHAR_COMMA, LIT_CHAR_LF };
|
|
||||||
|
|
||||||
ecma_string_t *separator_p = ecma_new_ecma_string_from_utf8 (chars, 2);
|
|
||||||
|
|
||||||
separator_p = ecma_concat_ecma_strings (separator_p, context_p->indent_str_p);
|
|
||||||
|
|
||||||
/* 10.b.ii */
|
|
||||||
ecma_string_t *properties_str_p = ecma_builtin_helper_json_create_separated_properties (partial_p, separator_p);
|
|
||||||
ecma_deref_ecma_string (separator_p);
|
|
||||||
|
|
||||||
/* 10.b.iii */
|
|
||||||
chars[0] = left_bracket;
|
|
||||||
|
|
||||||
ecma_string_t *final_str_p = ecma_new_ecma_string_from_utf8 (chars, 2);
|
|
||||||
|
|
||||||
final_str_p = ecma_concat_ecma_strings (final_str_p, context_p->indent_str_p);
|
|
||||||
|
|
||||||
final_str_p = ecma_concat_ecma_strings (final_str_p, properties_str_p);
|
|
||||||
ecma_deref_ecma_string (properties_str_p);
|
|
||||||
|
|
||||||
chars[0] = LIT_CHAR_LF;
|
|
||||||
final_str_p = ecma_append_chars_to_string (final_str_p, chars, 1, 1);
|
|
||||||
|
|
||||||
final_str_p = ecma_concat_ecma_strings (final_str_p, stepback_p);
|
|
||||||
|
|
||||||
chars[0] = right_bracket;
|
|
||||||
final_str_p = ecma_append_chars_to_string (final_str_p, chars, 1, 1);
|
|
||||||
|
|
||||||
return ecma_make_string_value (final_str_p);
|
|
||||||
} /* ecma_builtin_helper_json_create_formatted_json */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common function to create a non-formatted JSON string.
|
|
||||||
*
|
|
||||||
* See also:
|
|
||||||
* ECMA-262 v5, 15.12.3
|
|
||||||
*
|
|
||||||
* Used by:
|
|
||||||
* - ecma_builtin_json_object step 10.a
|
|
||||||
* - ecma_builtin_json_array step 10.a
|
|
||||||
*
|
|
||||||
* @return ecma value
|
|
||||||
* Returned value must be freed with ecma_free_value.
|
|
||||||
*/
|
|
||||||
ecma_value_t
|
|
||||||
ecma_builtin_helper_json_create_non_formatted_json (lit_utf8_byte_t left_bracket, /**< left bracket character */
|
|
||||||
lit_utf8_byte_t right_bracket, /**< right bracket character */
|
|
||||||
ecma_collection_header_t *partial_p) /**< key-value pairs */
|
|
||||||
{
|
|
||||||
JERRY_ASSERT (left_bracket < LIT_UTF8_1_BYTE_CODE_POINT_MAX
|
|
||||||
&& right_bracket < LIT_UTF8_1_BYTE_CODE_POINT_MAX);
|
|
||||||
|
|
||||||
/* 10.a */
|
|
||||||
ecma_string_t *comma_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_COMMA_CHAR);
|
|
||||||
ecma_string_t *properties_str_p;
|
|
||||||
|
|
||||||
/* 10.a.i */
|
|
||||||
properties_str_p = ecma_builtin_helper_json_create_separated_properties (partial_p, comma_str_p);
|
|
||||||
|
|
||||||
/* 10.a.ii */
|
|
||||||
ecma_string_t *result_str_p = ecma_new_ecma_string_from_code_unit (left_bracket);
|
|
||||||
|
|
||||||
result_str_p = ecma_concat_ecma_strings (result_str_p, properties_str_p);
|
|
||||||
ecma_deref_ecma_string (properties_str_p);
|
|
||||||
|
|
||||||
lit_utf8_byte_t chars[1] = { right_bracket };
|
|
||||||
|
|
||||||
result_str_p = ecma_append_chars_to_string (result_str_p, chars, 1, 1);
|
|
||||||
|
|
||||||
return ecma_make_string_value (result_str_p);
|
|
||||||
} /* ecma_builtin_helper_json_create_non_formatted_json */
|
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,19 @@
|
|||||||
#define STRING_VALUE(name, magic_string_id, prop_attributes)
|
#define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||||
#endif /* !STRING_VALUE */
|
#endif /* !STRING_VALUE */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
#ifndef SYMBOL_VALUE
|
#ifndef SYMBOL_VALUE
|
||||||
#define SYMBOL_VALUE(name, desc_string_id)
|
#define SYMBOL_VALUE(symbol, desc_magic_string_id)
|
||||||
#endif /* !SYMBOL_VALUE */
|
#endif /* !SYMBOL_VALUE */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
|
||||||
|
#ifndef INTRINSIC_PROPERTY
|
||||||
|
#define INTRINSIC_PROPERTY(name, magic_string_id)
|
||||||
|
#endif /* !INTRINSIC_PROPERTY */
|
||||||
|
|
||||||
|
#ifndef ACCESSOR_BUILTIN_FUNCTION_OBJECT
|
||||||
|
#define ACCESSOR_BUILTIN_FUNCTION_OBJECT(name, getter_builtin_id, setter_builtin_id, prop_attributes)
|
||||||
|
#endif /* !ACCESSOR_BUILTIN_FUNCTION_OBJECT */
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#ifndef OBJECT_VALUE
|
#ifndef OBJECT_VALUE
|
||||||
#define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
#define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||||
@@ -43,6 +51,10 @@
|
|||||||
#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value)
|
#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value)
|
||||||
#endif /* !ROUTINE_CONFIGURABLE_ONLY */
|
#endif /* !ROUTINE_CONFIGURABLE_ONLY */
|
||||||
|
|
||||||
|
#ifndef ROUTINE_WITH_FLAGS
|
||||||
|
#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags)
|
||||||
|
#endif /* !ROUTINE_WITH_FLAGS */
|
||||||
|
|
||||||
#ifndef ACCESSOR_READ_WRITE
|
#ifndef ACCESSOR_READ_WRITE
|
||||||
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes)
|
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes)
|
||||||
#endif /* !ACCESSOR_READ_WRITE */
|
#endif /* !ACCESSOR_READ_WRITE */
|
||||||
|
|||||||
@@ -16,11 +16,14 @@
|
|||||||
#undef SIMPLE_VALUE
|
#undef SIMPLE_VALUE
|
||||||
#undef NUMBER_VALUE
|
#undef NUMBER_VALUE
|
||||||
#undef STRING_VALUE
|
#undef STRING_VALUE
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
#undef SYMBOL_VALUE
|
#undef SYMBOL_VALUE
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#undef INTRINSIC_PROPERTY
|
||||||
|
#undef ACCESSOR_BUILTIN_FUNCTION_OBJECT
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
#undef OBJECT_VALUE
|
#undef OBJECT_VALUE
|
||||||
#undef ROUTINE
|
#undef ROUTINE
|
||||||
#undef ROUTINE_CONFIGURABLE_ONLY
|
#undef ROUTINE_CONFIGURABLE_ONLY
|
||||||
|
#undef ROUTINE_WITH_FLAGS
|
||||||
#undef ACCESSOR_READ_WRITE
|
#undef ACCESSOR_READ_WRITE
|
||||||
#undef ACCESSOR_READ_ONLY
|
#undef ACCESSOR_READ_ONLY
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "ecma-objects.h"
|
#include "ecma-objects.h"
|
||||||
#include "ecma-try-catch-macro.h"
|
#include "ecma-try-catch-macro.h"
|
||||||
#include "lit-magic-strings.h"
|
#include "lit-magic-strings.h"
|
||||||
|
#include "lit-char-helpers.h"
|
||||||
|
|
||||||
/** \addtogroup ecma ECMA
|
/** \addtogroup ecma ECMA
|
||||||
* @{
|
* @{
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/**
|
/**
|
||||||
* Helper function for Object.prototype.toString routine when
|
* Helper function for Object.prototype.toString routine when
|
||||||
* the @@toStringTag property is present
|
* the @@toStringTag property is present
|
||||||
@@ -96,7 +97,7 @@ ecma_builtin_helper_object_to_string_tag_helper (ecma_value_t tag_value) /**< st
|
|||||||
|
|
||||||
return ecma_make_string_value (ret_string_p);
|
return ecma_make_string_value (ret_string_p);
|
||||||
} /* ecma_builtin_helper_object_to_string_tag_helper */
|
} /* ecma_builtin_helper_object_to_string_tag_helper */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common implementation of the Object.prototype.toString routine
|
* Common implementation of the Object.prototype.toString routine
|
||||||
@@ -140,8 +141,8 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg
|
|||||||
|
|
||||||
type_string = ecma_object_get_class_name (obj_p);
|
type_string = ecma_object_get_class_name (obj_p);
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ecma_value_t tag_value = ecma_op_object_get_by_symbol_id (obj_p, LIT_MAGIC_STRING_TO_STRING_TAG);
|
ecma_value_t tag_value = ecma_op_object_get_by_symbol_id (obj_p, LIT_GLOBAL_SYMBOL_TO_STRING_TAG);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (tag_value))
|
if (ECMA_IS_VALUE_ERROR (tag_value))
|
||||||
{
|
{
|
||||||
@@ -156,7 +157,7 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg
|
|||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_value (tag_value);
|
ecma_free_value (tag_value);
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
ecma_deref_object (obj_p);
|
ecma_deref_object (obj_p);
|
||||||
}
|
}
|
||||||
@@ -201,63 +202,68 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
ecma_value_t
|
ecma_string_t *
|
||||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< this object */
|
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< this object */
|
||||||
uint32_t index) /**< array index */
|
uint32_t index) /**< array index */
|
||||||
{
|
{
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
ecma_value_t index_value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||||
ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index);
|
|
||||||
|
|
||||||
ECMA_TRY_CATCH (index_value,
|
if (ECMA_IS_VALUE_ERROR (index_value))
|
||||||
ecma_op_object_get (obj_p, index_string_p),
|
{
|
||||||
ret_value);
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (ecma_is_value_undefined (index_value) || ecma_is_value_null (index_value))
|
if (ecma_is_value_undefined (index_value) || ecma_is_value_null (index_value))
|
||||||
{
|
{
|
||||||
ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
|
return ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
ecma_value_t index_obj_value = ecma_op_to_object (index_value);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (index_obj_value))
|
||||||
{
|
{
|
||||||
ECMA_TRY_CATCH (index_obj_value,
|
ecma_free_value (index_value);
|
||||||
ecma_op_to_object (index_value),
|
return NULL;
|
||||||
ret_value);
|
|
||||||
|
|
||||||
ecma_object_t *index_obj_p = ecma_get_object_from_value (index_obj_value);
|
|
||||||
|
|
||||||
ECMA_TRY_CATCH (to_locale_value,
|
|
||||||
ecma_op_object_get_by_magic_id (index_obj_p, LIT_MAGIC_STRING_TO_LOCALE_STRING_UL),
|
|
||||||
ret_value);
|
|
||||||
|
|
||||||
if (ecma_op_is_callable (to_locale_value))
|
|
||||||
{
|
|
||||||
ecma_object_t *locale_func_obj_p = ecma_get_object_from_value (to_locale_value);
|
|
||||||
ECMA_TRY_CATCH (call_value,
|
|
||||||
ecma_op_function_call (locale_func_obj_p,
|
|
||||||
ecma_make_object_value (index_obj_p),
|
|
||||||
NULL,
|
|
||||||
0),
|
|
||||||
ret_value);
|
|
||||||
ret_value = ecma_op_to_string (call_value);
|
|
||||||
ECMA_FINALIZE (call_value);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("'toLocaleString' is missing or not a function."));
|
|
||||||
}
|
|
||||||
|
|
||||||
ECMA_FINALIZE (to_locale_value);
|
|
||||||
ECMA_FINALIZE (index_obj_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ECMA_FINALIZE (index_value);
|
ecma_string_t *ret_string_p = NULL;
|
||||||
|
ecma_object_t *index_obj_p = ecma_get_object_from_value (index_obj_value);
|
||||||
|
ecma_value_t to_locale_value = ecma_op_object_get_by_magic_id (index_obj_p, LIT_MAGIC_STRING_TO_LOCALE_STRING_UL);
|
||||||
|
|
||||||
ecma_deref_ecma_string (index_string_p);
|
if (ECMA_IS_VALUE_ERROR (to_locale_value))
|
||||||
|
{
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
return ret_value;
|
if (!ecma_op_is_callable (to_locale_value))
|
||||||
|
{
|
||||||
|
ecma_free_value (to_locale_value);
|
||||||
|
ecma_raise_type_error (ECMA_ERR_MSG ("'toLocaleString' is missing or not a function."));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *locale_func_obj_p = ecma_get_object_from_value (to_locale_value);
|
||||||
|
ecma_value_t call_value = ecma_op_function_call (locale_func_obj_p,
|
||||||
|
index_obj_value,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
|
ecma_deref_object (locale_func_obj_p);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (call_value))
|
||||||
|
{
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_string_p = ecma_op_to_string (call_value);
|
||||||
|
ecma_free_value (call_value);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
ecma_deref_object (index_obj_p);
|
||||||
|
ecma_free_value (index_value);
|
||||||
|
|
||||||
|
return ret_string_p;
|
||||||
} /* ecma_builtin_helper_get_to_locale_string_at_index */
|
} /* ecma_builtin_helper_get_to_locale_string_at_index */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Object.keys and Object.getOwnPropertyNames routine's common part.
|
* The Object.keys and Object.getOwnPropertyNames routine's common part.
|
||||||
*
|
*
|
||||||
@@ -278,32 +284,22 @@ ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
|
|||||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array));
|
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array));
|
||||||
ecma_object_t *new_array_p = ecma_get_object_from_value (new_array);
|
ecma_object_t *new_array_p = ecma_get_object_from_value (new_array);
|
||||||
|
|
||||||
uint32_t index = 0;
|
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
||||||
|
|
||||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
if (props_p->item_count == 0)
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
|
||||||
|
|
||||||
while (ecma_value_p != NULL)
|
|
||||||
{
|
{
|
||||||
ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index);
|
ecma_collection_destroy (props_p);
|
||||||
|
return new_array;
|
||||||
ecma_value_t completion = ecma_builtin_helper_def_prop (new_array_p,
|
|
||||||
index_string_p,
|
|
||||||
*ecma_value_p,
|
|
||||||
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
|
|
||||||
false); /* Failure handling */
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_value_true (completion));
|
|
||||||
|
|
||||||
ecma_deref_ecma_string (index_string_p);
|
|
||||||
|
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_values_collection (props_p, 0);
|
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);
|
||||||
|
|
||||||
return new_array;
|
return new_array;
|
||||||
} /* ecma_builtin_helper_object_get_properties */
|
} /* ecma_builtin_helper_object_get_properties */
|
||||||
@@ -311,76 +307,49 @@ ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
|
|||||||
/**
|
/**
|
||||||
* Helper function to normalizing an array index
|
* Helper function to normalizing an array index
|
||||||
*
|
*
|
||||||
* This function clamps the given index to the [0, length] range.
|
|
||||||
* If the index is negative, it is used as the offset from the end of the array,
|
|
||||||
* to compute normalized index.
|
|
||||||
* If the index is greater than the length of the array, the normalized index will be the length of the array.
|
|
||||||
*
|
|
||||||
* See also:
|
* See also:
|
||||||
* ECMA-262 v5, 15.4.4.10 steps 5-6, 7 (part 2) and 8
|
* ECMA-262 v5, 15.4.4.10 steps 5, 6, 7 part 2, 8
|
||||||
* ECMA-262 v5, 15.4.4.12 steps 5-6
|
* ECMA-262 v5, 15.4.4.12 steps 5, 6
|
||||||
* ECMA-262 v5, 15.4.4.14 steps 5
|
* ECMA-262 v5, 15.5.4.13 steps 4 - 7
|
||||||
* ECMA-262 v5, 15.5.4.13 steps 4, 5 (part 2) and 6-7
|
* ECMA-262 v6, 22.1.3.6 steps 5 - 7, 8 part 2, 9, 10
|
||||||
|
* ECMA-262 v6, 22.1.3.3 steps 5 - 10, 11 part 2, 12, 13
|
||||||
|
* ECMA-262 v6, 22.2.3.5 steps 5 - 10, 11 part 2, 12, 13
|
||||||
|
* ECMA-262 v6, 22.2.3.23 steps 5 - 10
|
||||||
|
* ECMA-262 v6, 24.1.4.3 steps 6 - 8, 9 part 2, 10, 11
|
||||||
|
* ECMA-262 v6, 22.2.3.26 steps 7 - 9, 10 part 2, 11, 12
|
||||||
|
* ECMA-262 v6, 22.2.3.8 steps 5 - 7, 8 part 2, 9, 10
|
||||||
*
|
*
|
||||||
* Used by:
|
* Used by:
|
||||||
* - The Array.prototype.slice routine.
|
* - The Array.prototype.slice routine.
|
||||||
* - The Array.prototype.splice routine.
|
* - The Array.prototype.splice routine.
|
||||||
* - The Array.prototype.indexOf routine.
|
|
||||||
* - The String.prototype.slice routine.
|
* - The String.prototype.slice routine.
|
||||||
|
* - The Array.prototype.fill routine.
|
||||||
|
* - The Array.prototype.copyWithin routine.
|
||||||
|
* - The TypedArray.prototype.copyWithin routine.
|
||||||
|
* - The TypedArray.prototype.slice routine.
|
||||||
|
* - The ArrayBuffer.prototype.slice routine.
|
||||||
|
* - The TypedArray.prototype.subarray routine.
|
||||||
|
* - The TypedArray.prototype.fill routine.
|
||||||
*
|
*
|
||||||
* @return uint32_t - the normalized value of the index
|
* @return ECMA_VALUE_EMPTY if successful
|
||||||
|
* conversion error otherwise
|
||||||
*/
|
*/
|
||||||
uint32_t
|
uint32_t
|
||||||
ecma_builtin_helper_array_index_normalize (ecma_number_t index, /**< index */
|
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, /**< index */
|
||||||
uint32_t length) /**< array's length */
|
uint32_t length, /**< array's length */
|
||||||
|
uint32_t *number_p) /**< [out] uint32_t */
|
||||||
{
|
{
|
||||||
uint32_t norm_index;
|
ecma_number_t to_int;
|
||||||
|
|
||||||
if (!ecma_number_is_nan (index))
|
if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arg, &to_int)))
|
||||||
{
|
{
|
||||||
|
return ECMA_VALUE_ERROR;
|
||||||
if (ecma_number_is_zero (index))
|
|
||||||
{
|
|
||||||
norm_index = 0;
|
|
||||||
}
|
|
||||||
else if (ecma_number_is_infinity (index))
|
|
||||||
{
|
|
||||||
norm_index = ecma_number_is_negative (index) ? 0 : length;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ecma_number_is_negative (index))
|
|
||||||
{
|
|
||||||
ecma_number_t index_neg = -index;
|
|
||||||
|
|
||||||
if (index_neg > length)
|
|
||||||
{
|
|
||||||
norm_index = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
norm_index = length - ecma_number_to_uint32 (index_neg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (index > length)
|
|
||||||
{
|
|
||||||
norm_index = length;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
norm_index = ecma_number_to_uint32 (index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
norm_index = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return norm_index;
|
*number_p = ((to_int < 0) ? (uint32_t) JERRY_MAX ((length + to_int), 0)
|
||||||
|
: (uint32_t) JERRY_MIN (to_int, length));
|
||||||
|
|
||||||
|
return ECMA_VALUE_EMPTY;
|
||||||
} /* ecma_builtin_helper_array_index_normalize */
|
} /* ecma_builtin_helper_array_index_normalize */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -396,88 +365,80 @@ ecma_builtin_helper_array_index_normalize (ecma_number_t index, /**< index */
|
|||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, /**< array */
|
ecma_builtin_helper_array_concat_value (ecma_object_t *array_obj_p, /**< array */
|
||||||
uint32_t *length_p, /**< [in,out] array's length */
|
uint32_t *length_p, /**< [in,out] array's length */
|
||||||
ecma_value_t value) /**< value to concat */
|
ecma_value_t value) /**< value to concat */
|
||||||
{
|
{
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
|
||||||
|
|
||||||
/* 5.b */
|
/* 5.b */
|
||||||
if (ecma_is_value_object (value)
|
#if ENABLED (JERRY_ES2015)
|
||||||
&& (ecma_object_get_class_name (ecma_get_object_from_value (value)) == LIT_MAGIC_STRING_ARRAY_UL))
|
ecma_value_t is_spreadable = ecma_op_is_concat_spreadable (value);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (is_spreadable))
|
||||||
{
|
{
|
||||||
/* 5.b.ii */
|
return is_spreadable;
|
||||||
ECMA_TRY_CATCH (arg_len_value,
|
}
|
||||||
ecma_op_object_get_by_magic_id (ecma_get_object_from_value (value),
|
|
||||||
LIT_MAGIC_STRING_LENGTH),
|
|
||||||
ret_value);
|
|
||||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_len_number, arg_len_value, ret_value);
|
|
||||||
|
|
||||||
uint32_t arg_len = ecma_number_to_uint32 (arg_len_number);
|
bool spread_object = is_spreadable == ECMA_VALUE_TRUE;
|
||||||
|
#else /* !ENABLED (JERRY_ES2015) */
|
||||||
|
bool spread_object = ecma_is_value_array (value);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* 5.b.iii */
|
if (spread_object)
|
||||||
for (uint32_t array_index = 0;
|
{
|
||||||
array_index < arg_len && ecma_is_value_empty (ret_value);
|
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||||
array_index++)
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
uint32_t arg_len;
|
||||||
|
ecma_value_t error = ecma_op_object_get_length (obj_p, &arg_len);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (error))
|
||||||
|
{
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
#else /* !ENABLED (JERRY_ES2015) */
|
||||||
|
/* 5.b.ii */
|
||||||
|
uint32_t arg_len = ecma_array_get_length (obj_p);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
/* 5.b.iii */
|
||||||
|
for (uint32_t array_index = 0; array_index < arg_len; array_index++)
|
||||||
{
|
{
|
||||||
ecma_string_t *array_index_string_p = ecma_new_ecma_string_from_uint32 (array_index);
|
|
||||||
|
|
||||||
/* 5.b.iii.2 */
|
/* 5.b.iii.2 */
|
||||||
ECMA_TRY_CATCH (get_value,
|
ecma_value_t get_value = ecma_op_object_find_by_uint32_index (obj_p, array_index);
|
||||||
ecma_op_object_find (ecma_get_object_from_value (value),
|
|
||||||
array_index_string_p),
|
|
||||||
ret_value);
|
|
||||||
|
|
||||||
if (ecma_is_value_found (get_value))
|
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||||
{
|
{
|
||||||
/* 5.b.iii.3.a */
|
return get_value;
|
||||||
ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 (*length_p + array_index);
|
|
||||||
|
|
||||||
/* 5.b.iii.3.b */
|
|
||||||
/* This will always be a simple value since 'is_throw' is false, so no need to free. */
|
|
||||||
ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p,
|
|
||||||
new_array_index_string_p,
|
|
||||||
get_value,
|
|
||||||
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
|
|
||||||
false); /* Failure handling */
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_value_true (put_comp));
|
|
||||||
ecma_deref_ecma_string (new_array_index_string_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ECMA_FINALIZE (get_value);
|
if (!ecma_is_value_found (get_value))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ecma_deref_ecma_string (array_index_string_p);
|
/* 5.b.iii.3.b */
|
||||||
|
/* This will always be a simple value since 'is_throw' is false, so no need to free. */
|
||||||
|
ecma_value_t put_comp = ecma_builtin_helper_def_prop_by_index (array_obj_p,
|
||||||
|
*length_p + array_index,
|
||||||
|
get_value,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE);
|
||||||
|
|
||||||
|
JERRY_ASSERT (ecma_is_value_true (put_comp));
|
||||||
|
ecma_free_value (get_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
*length_p += arg_len;
|
*length_p += arg_len;
|
||||||
|
return ECMA_VALUE_EMPTY;
|
||||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_len_number);
|
|
||||||
ECMA_FINALIZE (arg_len_value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 ((*length_p)++);
|
|
||||||
|
|
||||||
/* 5.c.i */
|
|
||||||
/* This will always be a simple value since 'is_throw' is false, so no need to free. */
|
|
||||||
ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p,
|
|
||||||
new_array_index_string_p,
|
|
||||||
value,
|
|
||||||
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
|
|
||||||
false); /* Failure handling */
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_value_true (put_comp));
|
|
||||||
|
|
||||||
ecma_deref_ecma_string (new_array_index_string_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ecma_is_value_empty (ret_value))
|
/* 5.c.i */
|
||||||
{
|
/* This will always be a simple value since 'is_throw' is false, so no need to free. */
|
||||||
ret_value = ECMA_VALUE_TRUE;
|
ecma_value_t put_comp = ecma_builtin_helper_def_prop_by_index (array_obj_p,
|
||||||
}
|
(*length_p)++,
|
||||||
|
value,
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE);
|
||||||
|
JERRY_ASSERT (ecma_is_value_true (put_comp));
|
||||||
|
|
||||||
return ret_value;
|
return ECMA_VALUE_EMPTY;
|
||||||
} /* ecma_builtin_helper_array_concat_value */
|
} /* ecma_builtin_helper_array_concat_value */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -560,31 +521,48 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_st
|
|||||||
/* 5 (indexOf) -- 6 (lastIndexOf) */
|
/* 5 (indexOf) -- 6 (lastIndexOf) */
|
||||||
const ecma_length_t original_len = ecma_string_get_length (original_str_p);
|
const ecma_length_t original_len = ecma_string_get_length (original_str_p);
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* 4, 6 (startsWith, includes, endsWith) */
|
/* 4, 6 (startsWith, includes, endsWith) */
|
||||||
if (mode >= ECMA_STRING_STARTS_WITH
|
if (mode >= ECMA_STRING_STARTS_WITH)
|
||||||
&& (ecma_is_value_object (arg1)
|
|
||||||
&& ecma_object_class_is (ecma_get_object_from_value (arg1), LIT_MAGIC_STRING_REGEXP_UL)))
|
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (ECMA_STRING_LAST_INDEX_OF < mode && mode <= ECMA_STRING_ENDS_WITH);
|
ecma_value_t regexp = ecma_op_is_regexp (arg1);
|
||||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Search string can't be of type: RegExp"));
|
|
||||||
}
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
|
||||||
|
|
||||||
/* 3 */
|
if (ECMA_IS_VALUE_ERROR (regexp))
|
||||||
ecma_value_t search_str_val = ecma_op_to_string (arg1);
|
{
|
||||||
|
return regexp;
|
||||||
|
}
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (search_str_val))
|
if (regexp == ECMA_VALUE_TRUE)
|
||||||
{
|
{
|
||||||
return search_str_val;
|
JERRY_ASSERT (ECMA_STRING_LAST_INDEX_OF < mode && mode <= ECMA_STRING_ENDS_WITH);
|
||||||
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Search string can't be of type: RegExp"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* 7, 8 */
|
/* 7, 8 */
|
||||||
ecma_string_t *search_str_p = ecma_get_string_from_value (search_str_val);
|
ecma_string_t *search_str_p = ecma_op_to_string (arg1);
|
||||||
|
|
||||||
|
if (JERRY_UNLIKELY (search_str_p == NULL))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* 4 (indexOf, lastIndexOf), 9 (startsWith, includes), 10 (endsWith) */
|
/* 4 (indexOf, lastIndexOf), 9 (startsWith, includes), 10 (endsWith) */
|
||||||
ecma_number_t pos_num;
|
ecma_number_t pos_num;
|
||||||
ecma_value_t ret_value = ecma_get_number (arg2, &pos_num);
|
ecma_value_t ret_value;
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (mode > ECMA_STRING_LAST_INDEX_OF)
|
||||||
|
{
|
||||||
|
ret_value = ecma_op_to_integer (arg2, &pos_num);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
ret_value = ecma_get_number (arg2, &pos_num);
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* 10 (startsWith, includes), 11 (endsWith) */
|
/* 10 (startsWith, includes), 11 (endsWith) */
|
||||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||||
@@ -606,7 +584,7 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_st
|
|||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
case ECMA_STRING_STARTS_WITH:
|
case ECMA_STRING_STARTS_WITH:
|
||||||
{
|
{
|
||||||
if (pos_num + start > original_len)
|
if (pos_num + start > original_len)
|
||||||
@@ -657,7 +635,7 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_st
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
case ECMA_STRING_INDEX_OF:
|
case ECMA_STRING_INDEX_OF:
|
||||||
case ECMA_STRING_LAST_INDEX_OF:
|
case ECMA_STRING_LAST_INDEX_OF:
|
||||||
@@ -733,7 +711,7 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
|
|||||||
|
|
||||||
/* iterate original string and try to match at each position */
|
/* iterate original string and try to match at each position */
|
||||||
bool searching = true;
|
bool searching = true;
|
||||||
ecma_char_t first_char = lit_utf8_read_next (&search_str_curr_p);
|
ecma_char_t first_char = lit_cesu8_read_next (&search_str_curr_p);
|
||||||
while (searching)
|
while (searching)
|
||||||
{
|
{
|
||||||
/* match as long as possible */
|
/* match as long as possible */
|
||||||
@@ -742,14 +720,14 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
|
|||||||
|
|
||||||
if (match_len < search_len &&
|
if (match_len < search_len &&
|
||||||
index + match_len < original_len &&
|
index + match_len < original_len &&
|
||||||
lit_utf8_read_next (&original_str_curr_p) == first_char)
|
lit_cesu8_read_next (&original_str_curr_p) == first_char)
|
||||||
{
|
{
|
||||||
const lit_utf8_byte_t *nested_search_str_curr_p = search_str_curr_p;
|
const lit_utf8_byte_t *nested_search_str_curr_p = search_str_curr_p;
|
||||||
match_len++;
|
match_len++;
|
||||||
|
|
||||||
while (match_len < search_len &&
|
while (match_len < search_len &&
|
||||||
index + match_len < original_len &&
|
index + match_len < original_len &&
|
||||||
lit_utf8_read_next (&original_str_curr_p) == lit_utf8_read_next (&nested_search_str_curr_p))
|
lit_cesu8_read_next (&original_str_curr_p) == lit_cesu8_read_next (&nested_search_str_curr_p))
|
||||||
{
|
{
|
||||||
match_len++;
|
match_len++;
|
||||||
}
|
}
|
||||||
@@ -795,6 +773,38 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
|
|||||||
return match_found;
|
return match_found;
|
||||||
} /* ecma_builtin_helper_string_find_index */
|
} /* ecma_builtin_helper_string_find_index */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for using [[DefineOwnProperty]] specialized for indexed property names
|
||||||
|
*
|
||||||
|
* Note: this method falls back to the general ecma_builtin_helper_def_prop
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, /**< object */
|
||||||
|
uint32_t index, /**< property index */
|
||||||
|
ecma_value_t value, /**< value */
|
||||||
|
uint32_t opts) /**< any combination of ecma_property_flag_t bits */
|
||||||
|
{
|
||||||
|
if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM))
|
||||||
|
{
|
||||||
|
return ecma_builtin_helper_def_prop (obj_p,
|
||||||
|
ECMA_CREATE_DIRECT_UINT32_STRING (index),
|
||||||
|
value,
|
||||||
|
opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_string_t *index_str_p = ecma_new_non_direct_string_from_uint32 (index);
|
||||||
|
ecma_value_t ret_value = ecma_builtin_helper_def_prop (obj_p,
|
||||||
|
index_str_p,
|
||||||
|
value,
|
||||||
|
opts);
|
||||||
|
ecma_deref_ecma_string (index_str_p);
|
||||||
|
|
||||||
|
return ret_value;
|
||||||
|
} /* ecma_builtin_helper_def_prop_by_index */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for using [[DefineOwnProperty]].
|
* Helper function for using [[DefineOwnProperty]].
|
||||||
*
|
*
|
||||||
@@ -809,29 +819,199 @@ ecma_value_t
|
|||||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, /**< object */
|
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, /**< object */
|
||||||
ecma_string_t *index_p, /**< index string */
|
ecma_string_t *index_p, /**< index string */
|
||||||
ecma_value_t value, /**< value */
|
ecma_value_t value, /**< value */
|
||||||
uint32_t opts, /**< any combination of ecma_property_flag_t bits */
|
uint32_t opts) /**< any combination of ecma_property_flag_t bits
|
||||||
bool is_throw) /**< is_throw */
|
* with the optional ECMA_IS_THROW flag */
|
||||||
{
|
{
|
||||||
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
|
ecma_property_descriptor_t prop_desc;
|
||||||
|
|
||||||
|
prop_desc.flags = (uint16_t) (ECMA_NAME_DATA_PROPERTY_DESCRIPTOR_BITS | opts);
|
||||||
|
|
||||||
prop_desc.is_value_defined = true;
|
|
||||||
prop_desc.value = value;
|
prop_desc.value = value;
|
||||||
|
|
||||||
prop_desc.is_writable_defined = true;
|
|
||||||
prop_desc.is_writable = (opts & ECMA_PROPERTY_FLAG_WRITABLE) != 0;
|
|
||||||
|
|
||||||
prop_desc.is_enumerable_defined = true;
|
|
||||||
prop_desc.is_enumerable = (opts & ECMA_PROPERTY_FLAG_ENUMERABLE) != 0;
|
|
||||||
|
|
||||||
prop_desc.is_configurable_defined = true;
|
|
||||||
prop_desc.is_configurable = (opts & ECMA_PROPERTY_FLAG_CONFIGURABLE) != 0;
|
|
||||||
|
|
||||||
return ecma_op_object_define_own_property (obj_p,
|
return ecma_op_object_define_own_property (obj_p,
|
||||||
index_p,
|
index_p,
|
||||||
&prop_desc,
|
&prop_desc);
|
||||||
is_throw);
|
|
||||||
} /* ecma_builtin_helper_def_prop */
|
} /* ecma_builtin_helper_def_prop */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetSubstitution abstract operation
|
||||||
|
*
|
||||||
|
* See:
|
||||||
|
* ECMA-262 v6.0 21.1.3.14.1
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecma_builtin_replace_substitute (ecma_replace_context_t *ctx_p) /**< replace context */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (ctx_p->string_p != NULL);
|
||||||
|
JERRY_ASSERT (ctx_p->matched_p == NULL
|
||||||
|
|| (ctx_p->matched_p >= ctx_p->string_p
|
||||||
|
&& ctx_p->matched_p <= ctx_p->string_p + ctx_p->string_size));
|
||||||
|
|
||||||
|
lit_utf8_size_t replace_size;
|
||||||
|
uint8_t replace_flags = ECMA_STRING_FLAG_IS_ASCII;
|
||||||
|
const lit_utf8_byte_t *replace_buf_p = ecma_string_get_chars (ctx_p->replace_str_p,
|
||||||
|
&replace_size,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&replace_flags);
|
||||||
|
|
||||||
|
const lit_utf8_byte_t *const replace_end_p = replace_buf_p + replace_size;
|
||||||
|
const lit_utf8_byte_t *curr_p = replace_buf_p;
|
||||||
|
const lit_utf8_byte_t *last_inserted_end_p = replace_buf_p;
|
||||||
|
|
||||||
|
while (curr_p < replace_end_p)
|
||||||
|
{
|
||||||
|
if (*curr_p++ == LIT_CHAR_DOLLAR_SIGN)
|
||||||
|
{
|
||||||
|
ecma_stringbuilder_append_raw (&(ctx_p->builder),
|
||||||
|
last_inserted_end_p,
|
||||||
|
(lit_utf8_size_t) (curr_p - last_inserted_end_p - 1));
|
||||||
|
if (curr_p >= replace_end_p)
|
||||||
|
{
|
||||||
|
last_inserted_end_p = curr_p - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lit_utf8_byte_t c = *curr_p++;
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case LIT_CHAR_DOLLAR_SIGN:
|
||||||
|
{
|
||||||
|
ecma_stringbuilder_append_byte (&(ctx_p->builder), LIT_CHAR_DOLLAR_SIGN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LIT_CHAR_AMPERSAND:
|
||||||
|
{
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (JERRY_UNLIKELY (ctx_p->matched_p == NULL))
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (ctx_p->capture_count == 0);
|
||||||
|
JERRY_ASSERT (ctx_p->u.collection_p != NULL);
|
||||||
|
JERRY_ASSERT (ctx_p->u.collection_p->item_count > 0);
|
||||||
|
const ecma_value_t match_value = ctx_p->u.collection_p->buffer_p[0];
|
||||||
|
|
||||||
|
JERRY_ASSERT (ecma_is_value_string (match_value));
|
||||||
|
ecma_stringbuilder_append (&(ctx_p->builder), ecma_get_string_from_value (match_value));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
JERRY_ASSERT (ctx_p->matched_p != NULL);
|
||||||
|
ecma_stringbuilder_append_raw (&(ctx_p->builder), ctx_p->matched_p, ctx_p->matched_size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LIT_CHAR_GRAVE_ACCENT:
|
||||||
|
{
|
||||||
|
ecma_stringbuilder_append_raw (&(ctx_p->builder), ctx_p->string_p, ctx_p->match_byte_pos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LIT_CHAR_SINGLE_QUOTE:
|
||||||
|
{
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (JERRY_UNLIKELY (ctx_p->matched_p == NULL))
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (ctx_p->capture_count == 0);
|
||||||
|
JERRY_ASSERT (ctx_p->u.collection_p != NULL);
|
||||||
|
JERRY_ASSERT (ctx_p->u.collection_p->item_count > 0);
|
||||||
|
const ecma_value_t match_value = ctx_p->u.collection_p->buffer_p[0];
|
||||||
|
|
||||||
|
JERRY_ASSERT (ecma_is_value_string (match_value));
|
||||||
|
const ecma_string_t *const matched_p = ecma_get_string_from_value (match_value);
|
||||||
|
const lit_utf8_size_t match_size = ecma_string_get_size (matched_p);
|
||||||
|
const lit_utf8_byte_t *const begin_p = ctx_p->string_p + ctx_p->match_byte_pos + match_size;
|
||||||
|
|
||||||
|
ecma_stringbuilder_append_raw (&(ctx_p->builder),
|
||||||
|
begin_p,
|
||||||
|
(lit_utf8_size_t) (ctx_p->string_p + ctx_p->string_size - begin_p));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
JERRY_ASSERT (ctx_p->matched_p != NULL);
|
||||||
|
ecma_stringbuilder_append_raw (&(ctx_p->builder),
|
||||||
|
ctx_p->matched_p + ctx_p->matched_size,
|
||||||
|
ctx_p->string_size - ctx_p->match_byte_pos - ctx_p->matched_size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
const lit_utf8_byte_t *const number_begin_p = curr_p - 1;
|
||||||
|
|
||||||
|
if (lit_char_is_decimal_digit (c))
|
||||||
|
{
|
||||||
|
uint32_t capture_count = ctx_p->capture_count;
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (capture_count == 0 && ctx_p->u.collection_p != NULL)
|
||||||
|
{
|
||||||
|
capture_count = ctx_p->u.collection_p->item_count;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
uint8_t idx = (uint8_t) (c - LIT_CHAR_0);
|
||||||
|
if (curr_p < replace_end_p && lit_char_is_decimal_digit (*(curr_p)))
|
||||||
|
{
|
||||||
|
uint8_t two_digit_index = (uint8_t) (idx * 10 + (uint8_t) (*(curr_p) - LIT_CHAR_0));
|
||||||
|
if (two_digit_index < capture_count)
|
||||||
|
{
|
||||||
|
idx = two_digit_index;
|
||||||
|
curr_p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idx > 0 && idx < capture_count)
|
||||||
|
{
|
||||||
|
if (ctx_p->capture_count > 0)
|
||||||
|
{
|
||||||
|
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||||
|
JERRY_ASSERT (ctx_p->u.captures_p != NULL);
|
||||||
|
const ecma_regexp_capture_t *const capture_p = ctx_p->u.captures_p + idx;
|
||||||
|
|
||||||
|
if (ECMA_RE_IS_CAPTURE_DEFINED (capture_p))
|
||||||
|
{
|
||||||
|
ecma_stringbuilder_append_raw (&(ctx_p->builder),
|
||||||
|
capture_p->begin_p,
|
||||||
|
(lit_utf8_size_t) (capture_p->end_p - capture_p->begin_p));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||||
|
}
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
else if (ctx_p->u.collection_p != NULL)
|
||||||
|
{
|
||||||
|
const ecma_value_t capture_value = ctx_p->u.collection_p->buffer_p[idx];
|
||||||
|
if (!ecma_is_value_undefined (capture_value))
|
||||||
|
{
|
||||||
|
ecma_stringbuilder_append (&(ctx_p->builder), ecma_get_string_from_value (capture_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_stringbuilder_append_byte (&(ctx_p->builder), LIT_CHAR_DOLLAR_SIGN);
|
||||||
|
curr_p = number_begin_p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last_inserted_end_p = curr_p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_stringbuilder_append_raw (&(ctx_p->builder),
|
||||||
|
last_inserted_end_p,
|
||||||
|
(lit_utf8_size_t) (replace_end_p - last_inserted_end_p));
|
||||||
|
|
||||||
|
if (replace_flags & ECMA_STRING_FLAG_MUST_BE_FREED)
|
||||||
|
{
|
||||||
|
jmem_heap_free_block ((void *) replace_buf_p, replace_size);
|
||||||
|
}
|
||||||
|
} /* ecma_builtin_replace_substitute */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include "ecma-globals.h"
|
#include "ecma-globals.h"
|
||||||
#include "ecma-exceptions.h"
|
#include "ecma-exceptions.h"
|
||||||
|
#include "ecma-helpers.h"
|
||||||
|
#include "ecma-regexp-object.h"
|
||||||
|
|
||||||
/** \addtogroup ecma ECMA
|
/** \addtogroup ecma ECMA
|
||||||
* @{
|
* @{
|
||||||
@@ -32,8 +34,8 @@
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
/** These routines must be in this order */
|
/** These routines must be in this order */
|
||||||
ECMA_STRING_INDEX_OF, /**< String.indexOf: ECMA-262 v5, 15.5.4.7 */
|
|
||||||
ECMA_STRING_LAST_INDEX_OF, /**< String.lastIndexOf: ECMA-262 v5, 15.5.4.8 */
|
ECMA_STRING_LAST_INDEX_OF, /**< String.lastIndexOf: ECMA-262 v5, 15.5.4.8 */
|
||||||
|
ECMA_STRING_INDEX_OF, /**< String.indexOf: ECMA-262 v5, 15.5.4.7 */
|
||||||
ECMA_STRING_STARTS_WITH, /**< String.startsWith: ECMA-262 v6, 21.1.3.18 */
|
ECMA_STRING_STARTS_WITH, /**< String.startsWith: ECMA-262 v6, 21.1.3.18 */
|
||||||
ECMA_STRING_INCLUDES, /**< String.includes: ECMA-262 v6, 21.1.3.7 */
|
ECMA_STRING_INCLUDES, /**< String.includes: ECMA-262 v6, 21.1.3.7 */
|
||||||
ECMA_STRING_ENDS_WITH /**< String.includes: ECMA-262 v6, 21.1.3.6 */
|
ECMA_STRING_ENDS_WITH /**< String.includes: ECMA-262 v6, 21.1.3.6 */
|
||||||
@@ -41,14 +43,14 @@ typedef enum
|
|||||||
|
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_helper_object_to_string (const ecma_value_t this_arg);
|
ecma_builtin_helper_object_to_string (const ecma_value_t this_arg);
|
||||||
ecma_value_t
|
ecma_string_t *
|
||||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, uint32_t index);
|
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, uint32_t index);
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, uint32_t opts);
|
ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, uint32_t opts);
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, uint32_t *length_p, ecma_value_t value);
|
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, uint32_t *length_p, ecma_value_t value);
|
||||||
uint32_t
|
uint32_t
|
||||||
ecma_builtin_helper_array_index_normalize (ecma_number_t index, uint32_t length);
|
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, uint32_t length, uint32_t *number_p);
|
||||||
uint32_t
|
uint32_t
|
||||||
ecma_builtin_helper_string_index_normalize (ecma_number_t index, uint32_t length, bool nan_to_zero);
|
ecma_builtin_helper_string_index_normalize (ecma_number_t index, uint32_t length, bool nan_to_zero);
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
@@ -58,8 +60,46 @@ bool
|
|||||||
ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, ecma_string_t *search_str_p, bool first_index,
|
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_length_t start_pos, ecma_length_t *ret_index_p);
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, ecma_string_t *index_p, ecma_value_t value,
|
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, ecma_string_t *index_p, ecma_value_t value, uint32_t opts);
|
||||||
uint32_t opts, bool is_throw);
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context for replace substitutions
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ecma_stringbuilder_t builder; /**< result string builder */
|
||||||
|
const lit_utf8_byte_t *string_p; /**< source string */
|
||||||
|
lit_utf8_size_t string_size; /**< source string size */
|
||||||
|
const lit_utf8_byte_t *matched_p; /**< matched string */
|
||||||
|
lit_utf8_size_t matched_size; /**< matcehd string size */
|
||||||
|
lit_utf8_size_t match_byte_pos; /**< byte position of the match in the source string */
|
||||||
|
ecma_length_t index; /**< current match index */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capture results
|
||||||
|
*/
|
||||||
|
union
|
||||||
|
{
|
||||||
|
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||||
|
const ecma_regexp_capture_t *captures_p; /**< array of regexp capturing groups */
|
||||||
|
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||||
|
const ecma_collection_t *collection_p; /**< collection of captured substrings */
|
||||||
|
} u;
|
||||||
|
|
||||||
|
uint32_t capture_count; /**< number of captures in the capturing group array */
|
||||||
|
ecma_string_t *replace_str_p; /**< replacement string */
|
||||||
|
} ecma_replace_context_t;
|
||||||
|
|
||||||
|
void
|
||||||
|
ecma_builtin_replace_substitute (ecma_replace_context_t *ctx_p);
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
bool
|
||||||
|
ecma_builtin_is_regexp_exec (ecma_extended_object_t *obj_p);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_DATE)
|
#if ENABLED (JERRY_BUILTIN_DATE)
|
||||||
|
|
||||||
@@ -107,6 +147,9 @@ typedef enum
|
|||||||
} ecma_date_timezone_t;
|
} ecma_date_timezone_t;
|
||||||
|
|
||||||
/* ecma-builtin-helpers-date.c */
|
/* ecma-builtin-helpers-date.c */
|
||||||
|
extern const char day_names_p[7][3];
|
||||||
|
extern const char month_names_p[12][3];
|
||||||
|
|
||||||
ecma_number_t ecma_date_day (ecma_number_t time);
|
ecma_number_t ecma_date_day (ecma_number_t time);
|
||||||
ecma_number_t ecma_date_time_within_day (ecma_number_t time);
|
ecma_number_t ecma_date_time_within_day (ecma_number_t time);
|
||||||
ecma_number_t ecma_date_year_from_time (ecma_number_t time);
|
ecma_number_t ecma_date_year_from_time (ecma_number_t time);
|
||||||
@@ -151,34 +194,33 @@ typedef struct struct_ecma_json_occurence_stack_item_t
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/** Collection for property keys. */
|
/** Collection for property keys. */
|
||||||
ecma_collection_header_t *property_list_p;
|
ecma_collection_t *property_list_p;
|
||||||
|
|
||||||
/** Collection for traversing objects. */
|
/** Collection for traversing objects. */
|
||||||
ecma_json_occurence_stack_item_t *occurence_stack_last_p;
|
ecma_json_occurence_stack_item_t *occurence_stack_last_p;
|
||||||
|
|
||||||
/** The actual indentation text. */
|
/** The actual indentation text. */
|
||||||
ecma_string_t *indent_str_p;
|
ecma_stringbuilder_t indent_builder;
|
||||||
|
|
||||||
/** The indentation text. */
|
/** The indentation text. */
|
||||||
ecma_string_t *gap_str_p;
|
ecma_string_t *gap_str_p;
|
||||||
|
|
||||||
/** The replacer function. */
|
/** The replacer function. */
|
||||||
ecma_object_t *replacer_function_p;
|
ecma_object_t *replacer_function_p;
|
||||||
|
|
||||||
|
/** Result string builder. */
|
||||||
|
ecma_stringbuilder_t result_builder;
|
||||||
} ecma_json_stringify_context_t;
|
} ecma_json_stringify_context_t;
|
||||||
|
|
||||||
ecma_value_t ecma_builtin_json_parse_buffer (const lit_utf8_byte_t * str_start_p,
|
ecma_value_t ecma_builtin_json_parse_buffer (const lit_utf8_byte_t * str_start_p,
|
||||||
lit_utf8_size_t string_size);
|
lit_utf8_size_t string_size);
|
||||||
ecma_value_t ecma_builtin_json_string_from_object (const ecma_value_t arg1);
|
ecma_value_t ecma_builtin_json_string_from_object (const ecma_value_t arg1);
|
||||||
bool ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, ecma_object_t *object_p);
|
bool ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, ecma_object_t *object_p);
|
||||||
bool ecma_has_string_value_in_collection (ecma_collection_header_t *collection_p, ecma_value_t string_value);
|
bool ecma_has_string_value_in_collection (ecma_collection_t *collection_p, ecma_string_t *string_p);
|
||||||
|
|
||||||
ecma_value_t
|
|
||||||
ecma_builtin_helper_json_create_formatted_json (lit_utf8_byte_t left_bracket, lit_utf8_byte_t right_bracket,
|
|
||||||
ecma_string_t *stepback_p, ecma_collection_header_t *partial_p,
|
|
||||||
ecma_json_stringify_context_t *context_p);
|
|
||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_helper_json_create_non_formatted_json (lit_utf8_byte_t left_bracket, lit_utf8_byte_t right_bracket,
|
ecma_builtin_helper_json_create_non_formatted_json (lit_utf8_byte_t left_bracket, lit_utf8_byte_t right_bracket,
|
||||||
ecma_collection_header_t *partial_p);
|
ecma_collection_t *partial_p);
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
||||||
|
|
||||||
/* ecma-builtin-helper-error.c */
|
/* ecma-builtin-helper-error.c */
|
||||||
|
|||||||
@@ -45,6 +45,8 @@
|
|||||||
static ecma_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
static ecma_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
||||||
#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \
|
#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \
|
||||||
static ecma_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
static ecma_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
||||||
|
#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \
|
||||||
|
static ecma_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
||||||
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
||||||
static ecma_value_t c_getter_func_name (ROUTINE_ARG_LIST_0); \
|
static ecma_value_t c_getter_func_name (ROUTINE_ARG_LIST_0); \
|
||||||
static ecma_value_t c_setter_func_name (ROUTINE_ARG_LIST_1);
|
static ecma_value_t c_setter_func_name (ROUTINE_ARG_LIST_1);
|
||||||
@@ -68,6 +70,8 @@ enum
|
|||||||
ECMA_ROUTINE_ ## name ## c_function_name,
|
ECMA_ROUTINE_ ## name ## c_function_name,
|
||||||
#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \
|
#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \
|
||||||
ECMA_ROUTINE_ ## name ## c_function_name,
|
ECMA_ROUTINE_ ## name ## c_function_name,
|
||||||
|
#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \
|
||||||
|
ECMA_ROUTINE_ ## name ## c_function_name,
|
||||||
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
||||||
ECMA_ACCESSOR_ ## name ## c_getter_func_name, \
|
ECMA_ACCESSOR_ ## name ## c_getter_func_name, \
|
||||||
ECMA_ACCESSOR_ ## name ## c_setter_func_name,
|
ECMA_ACCESSOR_ ## name ## c_setter_func_name,
|
||||||
@@ -98,6 +102,13 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
|||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE, \
|
ECMA_PROPERTY_FLAG_CONFIGURABLE, \
|
||||||
ECMA_ROUTINE_VALUE (ECMA_ROUTINE_ ## name ## c_function_name, length_prop_value) \
|
ECMA_ROUTINE_VALUE (ECMA_ROUTINE_ ## name ## c_function_name, length_prop_value) \
|
||||||
},
|
},
|
||||||
|
#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \
|
||||||
|
{ \
|
||||||
|
name, \
|
||||||
|
ECMA_BUILTIN_PROPERTY_ROUTINE, \
|
||||||
|
flags, \
|
||||||
|
ECMA_ROUTINE_VALUE (ECMA_ROUTINE_ ## name ## c_function_name, length_prop_value) \
|
||||||
|
},
|
||||||
#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \
|
#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \
|
||||||
{ \
|
{ \
|
||||||
name, \
|
name, \
|
||||||
@@ -120,6 +131,13 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
|||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE, \
|
ECMA_PROPERTY_FLAG_CONFIGURABLE, \
|
||||||
ECMA_ROUTINE_VALUE (c_function_name, length_prop_value) \
|
ECMA_ROUTINE_VALUE (c_function_name, length_prop_value) \
|
||||||
},
|
},
|
||||||
|
#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \
|
||||||
|
{ \
|
||||||
|
name, \
|
||||||
|
ECMA_BUILTIN_PROPERTY_ROUTINE, \
|
||||||
|
flags, \
|
||||||
|
ECMA_ROUTINE_VALUE (c_function_name, length_prop_value) \
|
||||||
|
},
|
||||||
#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \
|
#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \
|
||||||
{ \
|
{ \
|
||||||
name, \
|
name, \
|
||||||
@@ -156,15 +174,29 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
|||||||
prop_attributes, \
|
prop_attributes, \
|
||||||
magic_string_id \
|
magic_string_id \
|
||||||
},
|
},
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
#define SYMBOL_VALUE(name, desc_string_id) \
|
#define SYMBOL_VALUE(symbol, desc_magic_string_id) \
|
||||||
{ \
|
{ \
|
||||||
name, \
|
symbol, \
|
||||||
ECMA_BUILTIN_PROPERTY_SYMBOL, \
|
ECMA_BUILTIN_PROPERTY_SYMBOL, \
|
||||||
ECMA_PROPERTY_FIXED, \
|
ECMA_PROPERTY_FIXED, \
|
||||||
desc_string_id \
|
desc_magic_string_id \
|
||||||
},
|
},
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#define INTRINSIC_PROPERTY(name, magic_string_id) \
|
||||||
|
{ \
|
||||||
|
name, \
|
||||||
|
ECMA_BUILTIN_PROPERTY_INTRINSIC_PROPERTY, \
|
||||||
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE, \
|
||||||
|
magic_string_id \
|
||||||
|
},
|
||||||
|
#define ACCESSOR_BUILTIN_FUNCTION(name, getter_builtin_id, setter_builtin_id, prop_attributes) \
|
||||||
|
{ \
|
||||||
|
name, \
|
||||||
|
ECMA_BUILTIN_PROPERTY_ACCESSOR_BUILTIN_FUNCTION, \
|
||||||
|
prop_attributes, \
|
||||||
|
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) \
|
#define ACCESSOR_READ_WRITE(name, c_getter_name, c_setter_name, prop_attributes) \
|
||||||
{ \
|
{ \
|
||||||
name, \
|
name, \
|
||||||
@@ -222,6 +254,11 @@ DISPATCH_ROUTINE_ROUTINE_NAME (uint16_t builtin_routine_id, /**< built-in wide r
|
|||||||
{ \
|
{ \
|
||||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||||
}
|
}
|
||||||
|
#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \
|
||||||
|
case ECMA_ROUTINE_ ## name ## c_function_name: \
|
||||||
|
{ \
|
||||||
|
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||||
|
}
|
||||||
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \
|
||||||
case ECMA_ACCESSOR_ ## name ## c_getter_func_name: \
|
case ECMA_ACCESSOR_ ## name ## c_getter_func_name: \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/* 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-array-object.h"
|
||||||
|
#include "ecma-gc.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
|
#include "ecma-builtins-internal.h"
|
||||||
|
|
||||||
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-intrinsic.inc.h"
|
||||||
|
#define BUILTIN_UNDERSCORED_ID intrinsic
|
||||||
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
|
|
||||||
|
/** \addtogroup ecma ECMA
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup ecmabuiltins
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup intrinsic ECMA Intrinsic object built-in
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The %ArrayProto_values% intrinsic routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v5, 15.4.4.4
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_intrinsic_array_prototype_values (ecma_value_t this_value) /**< this argument */
|
||||||
|
{
|
||||||
|
ecma_value_t this_obj = ecma_op_to_object (this_value);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (this_obj))
|
||||||
|
{
|
||||||
|
return this_obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *this_obj_p = ecma_get_object_from_value (this_obj);
|
||||||
|
|
||||||
|
ecma_value_t ret_value = ecma_op_create_array_iterator (this_obj_p, ECMA_ITERATOR_VALUES);
|
||||||
|
|
||||||
|
ecma_deref_object (this_obj_p);
|
||||||
|
|
||||||
|
return ret_value;
|
||||||
|
} /* ecma_builtin_intrinsic_array_prototype_values */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Intrinsic built-in description
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.2 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_HAS_INSTANCE,
|
||||||
|
LIT_MAGIC_STRING_HAS_INSTANCE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.3 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE,
|
||||||
|
LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.4 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_ITERATOR,
|
||||||
|
LIT_MAGIC_STRING_ITERATOR)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.6 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_MATCH,
|
||||||
|
LIT_MAGIC_STRING_MATCH)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.8 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_REPLACE,
|
||||||
|
LIT_MAGIC_STRING_REPLACE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.9 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_SEARCH,
|
||||||
|
LIT_MAGIC_STRING_SEARCH)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.10 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_SPECIES,
|
||||||
|
LIT_MAGIC_STRING_SPECIES)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.11 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_SPLIT,
|
||||||
|
LIT_MAGIC_STRING_SPLIT)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.12 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_TO_PRIMITIVE,
|
||||||
|
LIT_MAGIC_STRING_TO_PRIMITIVE)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 19.4.2.13 */
|
||||||
|
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
|
LIT_MAGIC_STRING_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)
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
#include "ecma-builtins.h"
|
#include "ecma-builtins.h"
|
||||||
#include "ecma-iterator-object.h"
|
#include "ecma-iterator-object.h"
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
#define ECMA_BUILTINS_INTERNAL
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
#include "ecma-builtins-internal.h"
|
#include "ecma-builtins-internal.h"
|
||||||
@@ -60,4 +60,4 @@ ecma_builtin_iterator_prototype_object_iterator (ecma_value_t this_val) /**< thi
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|||||||
@@ -19,12 +19,12 @@
|
|||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ecma_builtin_iterator_prototype_object_iterator, 0, 0)
|
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ecma_builtin_iterator_prototype_object_iterator, 0, 0)
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -21,12 +21,12 @@
|
|||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_JSON)
|
#if ENABLED (JERRY_BUILTIN_JSON)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* ECMA-262 v6, 24.3.3 */
|
/* ECMA-262 v6, 24.3.3 */
|
||||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
LIT_MAGIC_STRING_JSON_U,
|
LIT_MAGIC_STRING_JSON_U,
|
||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
|
|||||||
@@ -19,10 +19,6 @@
|
|||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
#if ENABLED (JERRY_ES2015_BUILTIN_MAP)
|
||||||
|
|
||||||
#if !ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
|
||||||
#error "Map iterator builtin requires ES2015 iterator builtin"
|
|
||||||
#endif /* !ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
|
||||||
|
|
||||||
#define ECMA_BUILTINS_INTERNAL
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
#include "ecma-builtins-internal.h"
|
#include "ecma-builtins-internal.h"
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ static ecma_value_t
|
|||||||
ecma_builtin_map_prototype_object_get (ecma_value_t this_arg, /**< this argument */
|
ecma_builtin_map_prototype_object_get (ecma_value_t this_arg, /**< this argument */
|
||||||
ecma_value_t key_arg) /**< key argument */
|
ecma_value_t key_arg) /**< key argument */
|
||||||
{
|
{
|
||||||
return ecma_op_container_get (this_arg, key_arg);
|
return ecma_op_container_get (this_arg, key_arg, LIT_MAGIC_STRING_MAP_UL);
|
||||||
} /* ecma_builtin_map_prototype_object_get */
|
} /* ecma_builtin_map_prototype_object_get */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,7 +147,8 @@ ecma_builtin_map_prototype_object_size_getter (ecma_value_t this_arg) /**< this
|
|||||||
return ecma_op_container_size (this_arg, LIT_MAGIC_STRING_MAP_UL);
|
return ecma_op_container_size (this_arg, LIT_MAGIC_STRING_MAP_UL);
|
||||||
} /* ecma_builtin_map_prototype_object_size_getter */
|
} /* ecma_builtin_map_prototype_object_size_getter */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Map.prototype object's 'entries' routine
|
* The Map.prototype object's 'entries' routine
|
||||||
*
|
*
|
||||||
@@ -205,7 +206,7 @@ ecma_builtin_map_prototype_object_values (ecma_value_t this_arg) /**< this argum
|
|||||||
ECMA_PSEUDO_MAP_ITERATOR);
|
ECMA_PSEUDO_MAP_ITERATOR);
|
||||||
} /* ecma_builtin_map_prototype_object_values */
|
} /* ecma_builtin_map_prototype_object_values */
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
|||||||
ECMA_BUILTIN_ID_MAP,
|
ECMA_BUILTIN_ID_MAP,
|
||||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* ECMA-262 v6, 23.1.3.13 */
|
/* ECMA-262 v6, 23.1.3.13 */
|
||||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
LIT_MAGIC_STRING_MAP_UL,
|
LIT_MAGIC_STRING_MAP_UL,
|
||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
@@ -44,12 +44,12 @@ ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ecma_builtin_map_prototype_object_foreach
|
|||||||
ROUTINE (LIT_MAGIC_STRING_GET, ecma_builtin_map_prototype_object_get, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_GET, ecma_builtin_map_prototype_object_get, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_HAS, ecma_builtin_map_prototype_object_has, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_HAS, ecma_builtin_map_prototype_object_has, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_SET, ecma_builtin_map_prototype_object_set, 2, 2)
|
ROUTINE (LIT_MAGIC_STRING_SET, ecma_builtin_map_prototype_object_set, 2, 2)
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_ITERATOR)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ROUTINE (LIT_MAGIC_STRING_ENTRIES, ecma_builtin_map_prototype_object_entries, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_ENTRIES, ecma_builtin_map_prototype_object_entries, 0, 0)
|
||||||
ROUTINE (LIT_MAGIC_STRING_VALUES, ecma_builtin_map_prototype_object_values, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_VALUES, ecma_builtin_map_prototype_object_values, 0, 0)
|
||||||
ROUTINE (LIT_MAGIC_STRING_KEYS, ecma_builtin_map_prototype_object_keys, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_KEYS, ecma_builtin_map_prototype_object_keys, 0, 0)
|
||||||
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ecma_builtin_map_prototype_object_values, 0, 0)
|
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ecma_builtin_map_prototype_object_entries, 0, 0)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* ECMA-262 v6, 23.1.3.10 */
|
/* ECMA-262 v6, 23.1.3.10 */
|
||||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE,
|
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE,
|
||||||
|
|||||||
@@ -65,6 +65,18 @@ ecma_builtin_map_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
|
|||||||
ECMA_BUILTIN_ID_MAP_PROTOTYPE);
|
ECMA_BUILTIN_ID_MAP_PROTOTYPE);
|
||||||
} /* ecma_builtin_map_dispatch_construct */
|
} /* ecma_builtin_map_dispatch_construct */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 23.1.2.2 get Map [ @@species ] accessor
|
||||||
|
*
|
||||||
|
* @return ecma_value
|
||||||
|
* returned value must be freed with ecma_free_value
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_builtin_map_species_get (ecma_value_t this_value) /**< This Value */
|
||||||
|
{
|
||||||
|
return ecma_copy_value (this_value);
|
||||||
|
} /* ecma_builtin_map_species_get */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
|||||||
ECMA_BUILTIN_ID_MAP_PROTOTYPE,
|
ECMA_BUILTIN_ID_MAP_PROTOTYPE,
|
||||||
ECMA_PROPERTY_FIXED)
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 23.1.2.2 */
|
||||||
|
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
|
||||||
|
ecma_builtin_map_species_get,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */
|
||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ enum
|
|||||||
ECMA_MATH_OBJECT_EXP, /* ECMA-262 v5, 15.8.2.8 */
|
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_FLOOR, /* ECMA-262 v5, 15.8.2.9 */
|
||||||
ECMA_MATH_OBJECT_LOG, /* ECMA-262 v5, 15.8.2.10 */
|
ECMA_MATH_OBJECT_LOG, /* ECMA-262 v5, 15.8.2.10 */
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ECMA_MATH_OBJECT_TRUNC, /* ECMA-262 v6, 20.2.2.35 */
|
ECMA_MATH_OBJECT_TRUNC, /* ECMA-262 v6, 20.2.2.35 */
|
||||||
ECMA_MATH_OBJECT_SIGN, /* ECMA-262 v6, 20.2.2.29 */
|
ECMA_MATH_OBJECT_SIGN, /* ECMA-262 v6, 20.2.2.29 */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
ECMA_MATH_OBJECT_ROUND, /* ECMA-262 v5, 15.8.2.15 */
|
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_SIN, /* ECMA-262 v5, 15.8.2.16 */
|
||||||
ECMA_MATH_OBJECT_SQRT, /* ECMA-262 v5, 15.8.2.17 */
|
ECMA_MATH_OBJECT_SQRT, /* ECMA-262 v5, 15.8.2.17 */
|
||||||
@@ -103,6 +103,7 @@ ecma_builtin_math_object_max_min (bool is_max, /**< 'max' or 'min' operation */
|
|||||||
ecma_length_t args_number) /**< number of arguments */
|
ecma_length_t args_number) /**< number of arguments */
|
||||||
{
|
{
|
||||||
ecma_number_t result_num = ecma_number_make_infinity (is_max);
|
ecma_number_t result_num = ecma_number_make_infinity (is_max);
|
||||||
|
bool nan_found = false;
|
||||||
|
|
||||||
while (args_number > 0)
|
while (args_number > 0)
|
||||||
{
|
{
|
||||||
@@ -126,10 +127,13 @@ ecma_builtin_math_object_max_min (bool is_max, /**< 'max' or 'min' operation */
|
|||||||
ecma_fast_free_value (value);
|
ecma_fast_free_value (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JERRY_UNLIKELY (ecma_number_is_nan (arg_num)))
|
arg++;
|
||||||
|
args_number--;
|
||||||
|
|
||||||
|
if (JERRY_UNLIKELY (nan_found || ecma_number_is_nan (arg_num)))
|
||||||
{
|
{
|
||||||
result_num = arg_num;
|
nan_found = true;
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ecma_number_is_zero (arg_num)
|
if (ecma_number_is_zero (arg_num)
|
||||||
@@ -149,15 +153,18 @@ ecma_builtin_math_object_max_min (bool is_max, /**< 'max' or 'min' operation */
|
|||||||
result_num = arg_num;
|
result_num = arg_num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arg++;
|
if (JERRY_UNLIKELY (nan_found))
|
||||||
args_number--;
|
{
|
||||||
|
result_num = ecma_number_make_nan ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ecma_make_number_value (result_num);
|
return ecma_make_number_value (result_num);
|
||||||
} /* ecma_builtin_math_object_max_min */
|
} /* ecma_builtin_math_object_max_min */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Math object's 'trunc' routine
|
* The Math object's 'trunc' routine
|
||||||
*
|
*
|
||||||
@@ -176,12 +183,12 @@ ecma_builtin_math_object_trunc (ecma_number_t arg)
|
|||||||
|
|
||||||
if ((arg > 0) && (arg < 1))
|
if ((arg > 0) && (arg < 1))
|
||||||
{
|
{
|
||||||
return (ecma_number_t) 0;
|
return (ecma_number_t) 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((arg < 0) && (arg > -1))
|
if ((arg < 0) && (arg > -1))
|
||||||
{
|
{
|
||||||
return (ecma_number_t) -0;
|
return (ecma_number_t) -0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ecma_number_t) arg - fmod (arg, 1);
|
return (ecma_number_t) arg - fmod (arg, 1);
|
||||||
@@ -210,7 +217,8 @@ ecma_builtin_math_object_sign (ecma_number_t arg)
|
|||||||
|
|
||||||
return (ecma_number_t) 1.0;
|
return (ecma_number_t) 1.0;
|
||||||
} /* ecma_builtin_math_object_sign */
|
} /* ecma_builtin_math_object_sign */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Math object's 'random' routine.
|
* The Math object's 'random' routine.
|
||||||
@@ -341,7 +349,7 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
|||||||
x = DOUBLE_TO_ECMA_NUMBER_T (log (x));
|
x = DOUBLE_TO_ECMA_NUMBER_T (log (x));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
case ECMA_MATH_OBJECT_TRUNC:
|
case ECMA_MATH_OBJECT_TRUNC:
|
||||||
{
|
{
|
||||||
x = ecma_builtin_math_object_trunc (x);
|
x = ecma_builtin_math_object_trunc (x);
|
||||||
@@ -352,12 +360,13 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
|||||||
x = ecma_builtin_math_object_sign (x);
|
x = ecma_builtin_math_object_sign (x);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
case ECMA_MATH_OBJECT_ROUND:
|
case ECMA_MATH_OBJECT_ROUND:
|
||||||
{
|
{
|
||||||
if (ecma_number_is_nan (x)
|
if (ecma_number_is_nan (x)
|
||||||
|| ecma_number_is_zero (x)
|
|| ecma_number_is_zero (x)
|
||||||
|| ecma_number_is_infinity (x))
|
|| ecma_number_is_infinity (x)
|
||||||
|
|| fmod (x, 1.0) == 0)
|
||||||
{
|
{
|
||||||
/* Do nothing. */
|
/* Do nothing. */
|
||||||
}
|
}
|
||||||
@@ -435,7 +444,6 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
|||||||
arguments_number);
|
arguments_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JERRY_ASSERT (builtin_routine_id == ECMA_MATH_OBJECT_RANDOM);
|
JERRY_ASSERT (builtin_routine_id == ECMA_MATH_OBJECT_RANDOM);
|
||||||
|
|
||||||
return ecma_builtin_math_object_random ();
|
return ecma_builtin_math_object_random ();
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ NUMBER_VALUE (LIT_MAGIC_STRING_SQRT2_U,
|
|||||||
ECMA_BUILTIN_NUMBER_SQRT2,
|
ECMA_BUILTIN_NUMBER_SQRT2,
|
||||||
ECMA_PROPERTY_FIXED)
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* ECMA-262 v6, 20.2.1.9 */
|
/* ECMA-262 v6, 20.2.1.9 */
|
||||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
LIT_MAGIC_STRING_MATH_UL,
|
LIT_MAGIC_STRING_MATH_UL,
|
||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
@@ -91,10 +91,10 @@ ROUTINE (LIT_MAGIC_STRING_ROUND, ECMA_MATH_OBJECT_ROUND, 1, 1)
|
|||||||
ROUTINE (LIT_MAGIC_STRING_SIN, ECMA_MATH_OBJECT_SIN, 1, 1)
|
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_SQRT, ECMA_MATH_OBJECT_SQRT, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_TAN, ECMA_MATH_OBJECT_TAN, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_TAN, ECMA_MATH_OBJECT_TAN, 1, 1)
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ROUTINE (LIT_MAGIC_STRING_SIGN, ECMA_MATH_OBJECT_SIGN, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_SIGN, ECMA_MATH_OBJECT_SIGN, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_TRUNC, ECMA_MATH_OBJECT_TRUNC, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_TRUNC, ECMA_MATH_OBJECT_TRUNC, 1, 1)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_MATH) */
|
#endif /* ENABLED (JERRY_BUILTIN_MATH) */
|
||||||
|
|
||||||
|
|||||||
@@ -249,16 +249,6 @@ ecma_builtin_number_prototype_object_to_string (ecma_number_t this_arg_number, /
|
|||||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
{
|
{
|
||||||
|
|
||||||
if (arguments_list_len == 0
|
|
||||||
|| ecma_number_is_nan (this_arg_number)
|
|
||||||
|| ecma_number_is_infinity (this_arg_number)
|
|
||||||
|| ecma_number_is_zero (this_arg_number)
|
|
||||||
|| (arguments_list_len > 0 && ecma_is_value_undefined (arguments_list_p[0])))
|
|
||||||
{
|
|
||||||
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
|
|
||||||
return ecma_make_string_value (ret_str_p);
|
|
||||||
}
|
|
||||||
static const lit_utf8_byte_t digit_chars[36] =
|
static const lit_utf8_byte_t digit_chars[36] =
|
||||||
{
|
{
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||||
@@ -267,27 +257,33 @@ ecma_builtin_number_prototype_object_to_string (ecma_number_t this_arg_number, /
|
|||||||
'u', 'v', 'w', 'x', 'y', 'z'
|
'u', 'v', 'w', 'x', 'y', 'z'
|
||||||
};
|
};
|
||||||
|
|
||||||
ecma_number_t arg_num;
|
uint32_t radix = 10;
|
||||||
ecma_value_t radix_num = ecma_get_number (arguments_list_p[0], &arg_num);
|
if (arguments_list_len > 0 && !ecma_is_value_undefined (arguments_list_p[0]))
|
||||||
|
|
||||||
if (!ecma_is_value_empty (radix_num))
|
|
||||||
{
|
{
|
||||||
return radix_num;
|
ecma_number_t arg_num;
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arguments_list_p[0], &arg_num)))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
radix = ecma_number_to_uint32 (arg_num);
|
||||||
|
|
||||||
|
if (radix < 2 || radix > 36)
|
||||||
|
{
|
||||||
|
return ecma_raise_range_error (ECMA_ERR_MSG ("Radix must be between 2 and 36."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radix = ecma_number_to_uint32 (arg_num);
|
if (ecma_number_is_nan (this_arg_number)
|
||||||
|
|| ecma_number_is_infinity (this_arg_number)
|
||||||
if (radix < 2 || radix > 36)
|
|| ecma_number_is_zero (this_arg_number)
|
||||||
{
|
|| radix == 10)
|
||||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Radix must be between 2 and 36."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radix == 10)
|
|
||||||
{
|
{
|
||||||
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
|
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
|
||||||
|
|
||||||
return ecma_make_string_value (ret_str_p);
|
return ecma_make_string_value (ret_str_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
int buff_size = 0;
|
int buff_size = 0;
|
||||||
|
|
||||||
bool is_number_negative = false;
|
bool is_number_negative = false;
|
||||||
@@ -373,14 +369,14 @@ ecma_builtin_number_prototype_object_to_string (ecma_number_t this_arg_number, /
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < magnitude; i++)
|
for (int i = 0; i < magnitude; i++)
|
||||||
{
|
{
|
||||||
this_arg_number /= (ecma_number_t) radix;
|
this_arg_number /= radix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (exponent < 0)
|
else if (exponent < 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < magnitude; i++)
|
for (int i = 0; i < magnitude; i++)
|
||||||
{
|
{
|
||||||
this_arg_number *= (ecma_number_t) radix;
|
this_arg_number *= radix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +439,7 @@ ecma_builtin_number_prototype_object_to_string (ecma_number_t this_arg_number, /
|
|||||||
/* Calculate digits for fractional part. */
|
/* Calculate digits for fractional part. */
|
||||||
while (buff_index < required_digits)
|
while (buff_index < required_digits)
|
||||||
{
|
{
|
||||||
fraction *= (ecma_number_t) radix;
|
fraction *= radix;
|
||||||
lit_utf8_byte_t digit = (lit_utf8_byte_t) floor (fraction);
|
lit_utf8_byte_t digit = (lit_utf8_byte_t) floor (fraction);
|
||||||
|
|
||||||
buff[buff_index++] = digit;
|
buff[buff_index++] = digit;
|
||||||
@@ -596,9 +592,9 @@ ecma_builtin_number_prepare_conversion (ecma_number_t *this_num_p, /**< [out] th
|
|||||||
JERRY_ASSERT (mode < NUMBER_ROUTINE__COUNT);
|
JERRY_ASSERT (mode < NUMBER_ROUTINE__COUNT);
|
||||||
|
|
||||||
ecma_number_t arg_num;
|
ecma_number_t arg_num;
|
||||||
arg_1 = ecma_get_number (arg_1, &arg_num);
|
arg_1 = ecma_op_to_integer (arg_1, &arg_num);
|
||||||
|
|
||||||
if (!ecma_is_value_empty (arg_1))
|
if (ECMA_IS_VALUE_ERROR (arg_1))
|
||||||
{
|
{
|
||||||
return arg_1;
|
return arg_1;
|
||||||
}
|
}
|
||||||
@@ -632,9 +628,9 @@ ecma_builtin_number_prepare_conversion (ecma_number_t *this_num_p, /**< [out] th
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mode == NUMBER_ROUTINE_TO_PRECISION &&
|
if (mode == NUMBER_ROUTINE_TO_PRECISION &&
|
||||||
(arg_num < 1 || arg_num >= 22))
|
(ecma_number_is_nan (arg_num) || arg_num < 1 || arg_num >= 22))
|
||||||
{
|
{
|
||||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Precision digits must be between 0 and 21."));
|
return ecma_raise_range_error (ECMA_ERR_MSG ("Precision digits must be between 1 and 21."));
|
||||||
}
|
}
|
||||||
|
|
||||||
*arg_1_int32_p = ecma_number_to_int32 (arg_num);
|
*arg_1_int32_p = ecma_number_to_int32 (arg_num);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "ecma-alloc.h"
|
#include "ecma-alloc.h"
|
||||||
#include "ecma-builtins.h"
|
#include "ecma-builtins.h"
|
||||||
#include "ecma-conversion.h"
|
#include "ecma-conversion.h"
|
||||||
@@ -91,6 +93,137 @@ ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
|||||||
}
|
}
|
||||||
} /* ecma_builtin_number_dispatch_construct */
|
} /* ecma_builtin_number_dispatch_construct */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Number object 'isFinite' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 20.1.2.2
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_number_object_is_finite (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t arg) /**< routine's argument */
|
||||||
|
{
|
||||||
|
JERRY_UNUSED (this_arg);
|
||||||
|
|
||||||
|
if (ecma_is_value_number (arg))
|
||||||
|
{
|
||||||
|
ecma_number_t num = ecma_get_number_from_value (arg);
|
||||||
|
if (!(ecma_number_is_nan (num) || ecma_number_is_infinity (num)))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
} /* ecma_builtin_number_object_is_finite */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Number object 'isNan' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 20.1.2.4
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_number_object_is_nan (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t arg) /**< routine's argument */
|
||||||
|
{
|
||||||
|
JERRY_UNUSED (this_arg);
|
||||||
|
|
||||||
|
if (ecma_is_value_number (arg))
|
||||||
|
{
|
||||||
|
ecma_number_t num_val = ecma_get_number_from_value (arg);
|
||||||
|
|
||||||
|
if (ecma_number_is_nan (num_val))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
} /* ecma_builtin_number_object_is_nan */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Number object 'isInteger' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 20.1.2.3
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_number_object_is_integer (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t arg) /**< routine's argument */
|
||||||
|
{
|
||||||
|
JERRY_UNUSED (this_arg);
|
||||||
|
if (!ecma_is_value_number (arg))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t num = ecma_get_number_from_value (arg);
|
||||||
|
|
||||||
|
if (ecma_number_is_nan (num) || ecma_number_is_infinity (num))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t int_num;
|
||||||
|
ecma_op_to_integer (arg, &int_num);
|
||||||
|
|
||||||
|
if (int_num != num)
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ECMA_VALUE_TRUE;
|
||||||
|
} /* ecma_builtin_number_object_is_integer */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Number object 'isSafeInteger' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 20.1.2.3
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_number_object_is_safe_integer (ecma_value_t this_arg, /**< this argument */
|
||||||
|
ecma_value_t arg) /**< routine's argument */
|
||||||
|
{
|
||||||
|
JERRY_UNUSED (this_arg);
|
||||||
|
|
||||||
|
if (!ecma_is_value_number (arg))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t num = ecma_get_number_from_value (arg);
|
||||||
|
|
||||||
|
if (ecma_number_is_nan (num) || ecma_number_is_infinity (num))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t int_num = ecma_number_trunc (num);
|
||||||
|
|
||||||
|
if (int_num == num && fabs (int_num) <= ECMA_NUMBER_MAX_SAFE_INTEGER)
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ECMA_VALUE_FALSE;
|
||||||
|
} /* ecma_builtin_number_object_is_safe_integer */
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -54,6 +54,25 @@ NUMBER_VALUE (LIT_MAGIC_STRING_NEGATIVE_INFINITY_U,
|
|||||||
ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY,
|
ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY,
|
||||||
ECMA_PROPERTY_FIXED)
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 20.1.2.1 */
|
||||||
|
NUMBER_VALUE (LIT_MAGIC_STRING_EPSILON_U,
|
||||||
|
ECMA_BUILTIN_NUMBER_EPSILON,
|
||||||
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 20.1.2.6 */
|
||||||
|
NUMBER_VALUE (LIT_MAGIC_STRING_MAX_SAFE_INTEGER_U,
|
||||||
|
ECMA_BUILTIN_NUMBER_MAX_SAFE_INTEGER,
|
||||||
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
|
/* ECMA-262 v6, 20.1.2.8 */
|
||||||
|
NUMBER_VALUE (LIT_MAGIC_STRING_MIN_SAFE_INTEGER_U,
|
||||||
|
ECMA_BUILTIN_NUMBER_MIN_SAFE_INTEGER,
|
||||||
|
ECMA_PROPERTY_FIXED)
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/* Object properties:
|
/* Object properties:
|
||||||
* (property name, object pointer getter) */
|
* (property name, object pointer getter) */
|
||||||
|
|
||||||
@@ -64,4 +83,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
|||||||
|
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
#endif /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
||||||
|
|
||||||
|
/* Routine properties:
|
||||||
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
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)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ enum
|
|||||||
ECMA_OBJECT_PROTOTYPE_PROPERTY_IS_ENUMERABLE,
|
ECMA_OBJECT_PROTOTYPE_PROPERTY_IS_ENUMERABLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object-prototype.inc.h"
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object-prototype.inc.h"
|
||||||
#define BUILTIN_UNDERSCORED_ID object_prototype
|
#define BUILTIN_UNDERSCORED_ID object_prototype
|
||||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "ecma-objects.h"
|
#include "ecma-objects.h"
|
||||||
#include "ecma-objects-general.h"
|
#include "ecma-objects-general.h"
|
||||||
#include "jrt.h"
|
#include "jrt.h"
|
||||||
|
#include "ecma-builtin-object.h"
|
||||||
|
|
||||||
#define ECMA_BUILTINS_INTERNAL
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
#include "ecma-builtins-internal.h"
|
#include "ecma-builtins-internal.h"
|
||||||
@@ -39,22 +40,32 @@
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ECMA_OBJECT_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1,
|
ECMA_OBJECT_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1,
|
||||||
ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY,
|
|
||||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR,
|
|
||||||
ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES,
|
|
||||||
ECMA_OBJECT_ROUTINE_CREATE,
|
ECMA_OBJECT_ROUTINE_CREATE,
|
||||||
ECMA_OBJECT_ROUTINE_SEAL,
|
ECMA_OBJECT_ROUTINE_IS,
|
||||||
ECMA_OBJECT_ROUTINE_FREEZE,
|
ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF,
|
||||||
ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS,
|
|
||||||
ECMA_OBJECT_ROUTINE_IS_SEALED,
|
/* These should be in this order. */
|
||||||
ECMA_OBJECT_ROUTINE_IS_FROZEN,
|
ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY,
|
||||||
ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE,
|
ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES,
|
||||||
|
|
||||||
|
/* These should be in this order. */
|
||||||
|
ECMA_OBJECT_ROUTINE_ASSIGN,
|
||||||
|
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR,
|
||||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES,
|
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES,
|
||||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS,
|
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS,
|
||||||
ECMA_OBJECT_ROUTINE_KEYS,
|
|
||||||
ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF,
|
ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF,
|
||||||
ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF,
|
ECMA_OBJECT_ROUTINE_KEYS,
|
||||||
ECMA_OBJECT_ROUTINE_ASSIGN,
|
|
||||||
|
/* These should be in this order. */
|
||||||
|
ECMA_OBJECT_ROUTINE_FREEZE,
|
||||||
|
ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS,
|
||||||
|
ECMA_OBJECT_ROUTINE_SEAL,
|
||||||
|
|
||||||
|
/* These should be in this order. */
|
||||||
|
ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE,
|
||||||
|
ECMA_OBJECT_ROUTINE_IS_FROZEN,
|
||||||
|
ECMA_OBJECT_ROUTINE_IS_SEALED,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object.inc.h"
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object.inc.h"
|
||||||
@@ -122,50 +133,23 @@ ecma_builtin_object_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_object_object_get_prototype_of (ecma_value_t arg) /**< routine's argument */
|
ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p) /**< routine's argument */
|
||||||
{
|
{
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
jmem_cpointer_t prototype_cp = obj_p->u2.prototype_cp;
|
||||||
bool was_object = ecma_is_value_object (arg);
|
|
||||||
|
|
||||||
/* 1. */
|
if (prototype_cp != JMEM_CP_NULL)
|
||||||
if (!was_object)
|
|
||||||
{
|
{
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
ecma_object_t *prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, prototype_cp);
|
||||||
arg = ecma_op_to_object (arg);
|
|
||||||
if (ECMA_IS_VALUE_ERROR (arg))
|
|
||||||
{
|
|
||||||
return arg;
|
|
||||||
}
|
|
||||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN) */
|
|
||||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object."));
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
|
||||||
}
|
|
||||||
/* 2. */
|
|
||||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
|
||||||
ecma_object_t *prototype_p = ecma_get_object_prototype (obj_p);
|
|
||||||
|
|
||||||
if (prototype_p)
|
|
||||||
{
|
|
||||||
ret_value = ecma_make_object_value (prototype_p);
|
|
||||||
ecma_ref_object (prototype_p);
|
ecma_ref_object (prototype_p);
|
||||||
}
|
return ecma_make_object_value (prototype_p);
|
||||||
else
|
|
||||||
{
|
|
||||||
ret_value = ECMA_VALUE_NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
return ECMA_VALUE_NULL;
|
||||||
if (!was_object)
|
|
||||||
{
|
|
||||||
ecma_deref_object (obj_p);
|
|
||||||
}
|
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
|
||||||
|
|
||||||
return ret_value;
|
|
||||||
} /* ecma_builtin_object_object_get_prototype_of */
|
} /* ecma_builtin_object_object_get_prototype_of */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [[SetPrototypeOf]]
|
* [[SetPrototypeOf]]
|
||||||
*
|
*
|
||||||
@@ -184,10 +168,20 @@ ecma_set_prototype_of (ecma_value_t o_value, /**< O */
|
|||||||
JERRY_ASSERT (ecma_is_value_object (v_value) || ecma_is_value_null (v_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);
|
ecma_object_t *o_p = ecma_get_object_from_value (o_value);
|
||||||
ecma_object_t *v_p = ecma_is_value_null (v_value) ? NULL : ecma_get_object_from_value (v_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. */
|
/* 3., 4. */
|
||||||
if (v_p == ecma_get_object_prototype (o_p))
|
if (v_cp == o_p->u2.prototype_cp)
|
||||||
{
|
{
|
||||||
ecma_ref_object (o_p);
|
ecma_ref_object (o_p);
|
||||||
return ecma_make_object_value (o_p);
|
return ecma_make_object_value (o_p);
|
||||||
@@ -200,14 +194,10 @@ ecma_set_prototype_of (ecma_value_t o_value, /**< O */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 6., 7., 8. */
|
/* 6., 7., 8. */
|
||||||
ecma_object_t *p_p = v_p;
|
jmem_cpointer_t p_cp = v_cp;
|
||||||
while (true)
|
while (p_cp != JMEM_CP_NULL)
|
||||||
{
|
{
|
||||||
/* a. */
|
ecma_object_t *p_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, p_cp);
|
||||||
if (p_p == NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* b. */
|
/* b. */
|
||||||
if (p_p == o_p)
|
if (p_p == o_p)
|
||||||
@@ -219,11 +209,11 @@ ecma_set_prototype_of (ecma_value_t o_value, /**< O */
|
|||||||
* [[GetPrototypeOf]] internal method */
|
* [[GetPrototypeOf]] internal method */
|
||||||
|
|
||||||
/* c.ii. */
|
/* c.ii. */
|
||||||
p_p = ecma_get_object_prototype (p_p);
|
p_cp = p_p->u2.prototype_cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 9. */
|
/* 9. */
|
||||||
ECMA_SET_POINTER (o_p->prototype_or_outer_reference_cp, v_p);
|
o_p->u2.prototype_cp = v_cp;
|
||||||
|
|
||||||
/* 10. */
|
/* 10. */
|
||||||
ecma_ref_object (o_p);
|
ecma_ref_object (o_p);
|
||||||
@@ -239,7 +229,7 @@ ecma_set_prototype_of (ecma_value_t o_value, /**< O */
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's first argument */
|
ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's first argument */
|
||||||
ecma_value_t arg2) /**< routine's second argument */
|
ecma_value_t arg2) /**< routine's second argument */
|
||||||
{
|
{
|
||||||
@@ -267,7 +257,8 @@ ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's f
|
|||||||
/* 5-8. */
|
/* 5-8. */
|
||||||
return ecma_set_prototype_of (arg1, arg2);
|
return ecma_set_prototype_of (arg1, arg2);
|
||||||
} /* ecma_builtin_object_object_set_prototype_of */
|
} /* ecma_builtin_object_object_set_prototype_of */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Object object's 'getOwnPropertyNames' routine
|
* The Object object's 'getOwnPropertyNames' routine
|
||||||
@@ -284,7 +275,8 @@ ecma_builtin_object_object_get_own_property_names (ecma_object_t *obj_p) /**< ro
|
|||||||
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_NO_OPTS);
|
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_NO_OPTS);
|
||||||
} /* ecma_builtin_object_object_get_own_property_names */
|
} /* ecma_builtin_object_object_get_own_property_names */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Object object's 'getOwnPropertySymbols' routine
|
* The Object object's 'getOwnPropertySymbols' routine
|
||||||
*
|
*
|
||||||
@@ -297,9 +289,10 @@ ecma_builtin_object_object_get_own_property_names (ecma_object_t *obj_p) /**< ro
|
|||||||
static ecma_value_t
|
static ecma_value_t
|
||||||
ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**< routine's argument */
|
ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**< routine's argument */
|
||||||
{
|
{
|
||||||
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_SYMBOLS);
|
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_SYMBOLS_ONLY);
|
||||||
} /* ecma_builtin_object_object_get_own_property_symbols */
|
} /* ecma_builtin_object_object_get_own_property_symbols */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Object object's 'seal' routine
|
* The Object object's 'seal' routine
|
||||||
@@ -313,14 +306,13 @@ ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**<
|
|||||||
static ecma_value_t
|
static ecma_value_t
|
||||||
ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument */
|
ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument */
|
||||||
{
|
{
|
||||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||||
|
|
||||||
while (ecma_value_p != NULL)
|
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||||
{
|
{
|
||||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
|
|
||||||
/* 2.a */
|
/* 2.a */
|
||||||
ecma_property_descriptor_t prop_desc;
|
ecma_property_descriptor_t prop_desc;
|
||||||
@@ -331,26 +323,26 @@ ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument *
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 2.b */
|
/* 2.b */
|
||||||
prop_desc.is_configurable = false;
|
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||||
|
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||||
|
|
||||||
/* 2.c */
|
/* 2.c */
|
||||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||||
property_name_p,
|
property_name_p,
|
||||||
&prop_desc,
|
&prop_desc);
|
||||||
true);
|
|
||||||
|
|
||||||
ecma_free_property_descriptor (&prop_desc);
|
ecma_free_property_descriptor (&prop_desc);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||||
{
|
{
|
||||||
ecma_free_values_collection (props_p, 0);
|
ecma_collection_free (props_p);
|
||||||
return define_own_prop_ret;
|
return define_own_prop_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_value (define_own_prop_ret);
|
ecma_free_value (define_own_prop_ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_values_collection (props_p, 0);
|
ecma_collection_free (props_p);
|
||||||
|
|
||||||
/* 3. */
|
/* 3. */
|
||||||
ecma_set_object_extensible (obj_p, false);
|
ecma_set_object_extensible (obj_p, false);
|
||||||
@@ -372,14 +364,13 @@ ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument *
|
|||||||
static ecma_value_t
|
static ecma_value_t
|
||||||
ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument */
|
ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument */
|
||||||
{
|
{
|
||||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||||
|
|
||||||
while (ecma_value_p != NULL)
|
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||||
{
|
{
|
||||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
|
|
||||||
/* 2.a */
|
/* 2.a */
|
||||||
ecma_property_descriptor_t prop_desc;
|
ecma_property_descriptor_t prop_desc;
|
||||||
@@ -390,32 +381,33 @@ ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 2.b */
|
/* 2.b */
|
||||||
if (prop_desc.is_writable_defined && prop_desc.is_writable)
|
if ((prop_desc.flags & (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
|
||||||
|
== (ECMA_PROP_IS_WRITABLE_DEFINED | ECMA_PROP_IS_WRITABLE))
|
||||||
{
|
{
|
||||||
prop_desc.is_writable = false;
|
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_WRITABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2.c */
|
/* 2.c */
|
||||||
prop_desc.is_configurable = false;
|
prop_desc.flags &= (uint16_t) ~ECMA_PROP_IS_CONFIGURABLE;
|
||||||
|
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||||
|
|
||||||
/* 2.d */
|
/* 2.d */
|
||||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||||
property_name_p,
|
property_name_p,
|
||||||
&prop_desc,
|
&prop_desc);
|
||||||
true);
|
|
||||||
|
|
||||||
ecma_free_property_descriptor (&prop_desc);
|
ecma_free_property_descriptor (&prop_desc);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||||
{
|
{
|
||||||
ecma_free_values_collection (props_p, 0);
|
ecma_collection_free (props_p);
|
||||||
return define_own_prop_ret;
|
return define_own_prop_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_value (define_own_prop_ret);
|
ecma_free_value (define_own_prop_ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_values_collection (props_p, 0);
|
ecma_collection_free (props_p);
|
||||||
|
|
||||||
/* 3. */
|
/* 3. */
|
||||||
ecma_set_object_extensible (obj_p, false);
|
ecma_set_object_extensible (obj_p, false);
|
||||||
@@ -434,7 +426,7 @@ ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routine's argument */
|
ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routine's argument */
|
||||||
{
|
{
|
||||||
ecma_set_object_extensible (obj_p, false);
|
ecma_set_object_extensible (obj_p, false);
|
||||||
@@ -469,14 +461,13 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
|||||||
ecma_value_t ret_value = ECMA_VALUE_TRUE;
|
ecma_value_t ret_value = ECMA_VALUE_TRUE;
|
||||||
|
|
||||||
/* 2. */
|
/* 2. */
|
||||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||||
|
|
||||||
while (ecma_value_p != NULL)
|
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||||
{
|
{
|
||||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
|
|
||||||
/* 2.a */
|
/* 2.a */
|
||||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
||||||
@@ -501,7 +492,7 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_values_collection (props_p, 0);
|
ecma_collection_free (props_p);
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
} /* ecma_builtin_object_frozen_or_sealed_helper */
|
} /* ecma_builtin_object_frozen_or_sealed_helper */
|
||||||
@@ -515,7 +506,7 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p) /**< routine's argument */
|
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));
|
return ecma_make_boolean_value (ecma_get_object_extensible (obj_p));
|
||||||
@@ -545,7 +536,7 @@ ecma_builtin_object_object_keys (ecma_object_t *obj_p) /**< routine's argument *
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, /**< routine's first argument */
|
ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, /**< routine's first argument */
|
||||||
ecma_string_t *name_str_p) /**< routine's second argument */
|
ecma_string_t *name_str_p) /**< routine's second argument */
|
||||||
{
|
{
|
||||||
@@ -588,20 +579,20 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
|||||||
|
|
||||||
ecma_object_t *props_p = ecma_get_object_from_value (props);
|
ecma_object_t *props_p = ecma_get_object_from_value (props);
|
||||||
/* 3. */
|
/* 3. */
|
||||||
ecma_collection_header_t *prop_names_p = ecma_op_object_get_property_names (props_p, ECMA_LIST_ENUMERABLE);
|
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (props_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||||
uint32_t property_number = prop_names_p->item_count;
|
| ECMA_LIST_ENUMERABLE);
|
||||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
ecma_value_t *buffer_p = prop_names_p->buffer_p;
|
||||||
|
|
||||||
/* 4. */
|
/* 4. */
|
||||||
JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, property_number, ecma_property_descriptor_t);
|
JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, prop_names_p->item_count, ecma_property_descriptor_t);
|
||||||
uint32_t property_descriptor_number = 0;
|
uint32_t property_descriptor_number = 0;
|
||||||
|
|
||||||
while (ecma_value_p != NULL)
|
for (uint32_t i = 0; i < prop_names_p->item_count; i++)
|
||||||
{
|
{
|
||||||
/* 5.a */
|
/* 5.a */
|
||||||
ecma_value_t desc_obj = ecma_op_object_get (props_p, ecma_get_string_from_value (*ecma_value_p));
|
ecma_value_t desc_obj = ecma_op_object_get (props_p, ecma_get_string_from_value (buffer_p[i]));
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (desc_obj))
|
if (ECMA_IS_VALUE_ERROR (desc_obj))
|
||||||
{
|
{
|
||||||
@@ -612,6 +603,8 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
|||||||
ecma_value_t conv_result = ecma_op_to_property_descriptor (desc_obj,
|
ecma_value_t conv_result = ecma_op_to_property_descriptor (desc_obj,
|
||||||
&property_descriptors[property_descriptor_number]);
|
&property_descriptors[property_descriptor_number]);
|
||||||
|
|
||||||
|
property_descriptors[property_descriptor_number].flags |= ECMA_PROP_IS_THROW;
|
||||||
|
|
||||||
ecma_free_value (desc_obj);
|
ecma_free_value (desc_obj);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (conv_result))
|
if (ECMA_IS_VALUE_ERROR (conv_result))
|
||||||
@@ -622,27 +615,22 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
|||||||
property_descriptor_number++;
|
property_descriptor_number++;
|
||||||
|
|
||||||
ecma_free_value (conv_result);
|
ecma_free_value (conv_result);
|
||||||
|
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 6. */
|
/* 6. */
|
||||||
ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
buffer_p = prop_names_p->buffer_p;
|
||||||
|
|
||||||
for (uint32_t index = 0; index < property_number; index++)
|
for (uint32_t i = 0; i < prop_names_p->item_count; i++)
|
||||||
{
|
{
|
||||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||||
ecma_get_string_from_value (*ecma_value_p),
|
ecma_get_string_from_value (buffer_p[i]),
|
||||||
&property_descriptors[index],
|
&property_descriptors[i]);
|
||||||
true);
|
|
||||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||||
{
|
{
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_free_value (define_own_prop_ret);
|
ecma_free_value (define_own_prop_ret);
|
||||||
|
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_ref_object (obj_p);
|
ecma_ref_object (obj_p);
|
||||||
@@ -659,7 +647,7 @@ cleanup:
|
|||||||
|
|
||||||
JMEM_FINALIZE_LOCAL_ARRAY (property_descriptors);
|
JMEM_FINALIZE_LOCAL_ARRAY (property_descriptors);
|
||||||
|
|
||||||
ecma_free_values_collection (prop_names_p, 0);
|
ecma_collection_free (prop_names_p);
|
||||||
|
|
||||||
ecma_deref_object (props_p);
|
ecma_deref_object (props_p);
|
||||||
|
|
||||||
@@ -721,7 +709,7 @@ ecma_builtin_object_object_create (ecma_value_t arg1, /**< routine's first argum
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's first argument */
|
ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's first argument */
|
||||||
ecma_string_t *name_str_p, /**< routine's second argument */
|
ecma_string_t *name_str_p, /**< routine's second argument */
|
||||||
ecma_value_t arg3) /**< routine's third argument */
|
ecma_value_t arg3) /**< routine's third argument */
|
||||||
@@ -735,10 +723,11 @@ ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's
|
|||||||
return conv_result;
|
return conv_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prop_desc.flags |= ECMA_PROP_IS_THROW;
|
||||||
|
|
||||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||||
name_str_p,
|
name_str_p,
|
||||||
&prop_desc,
|
&prop_desc);
|
||||||
true);
|
|
||||||
|
|
||||||
ecma_free_property_descriptor (&prop_desc);
|
ecma_free_property_descriptor (&prop_desc);
|
||||||
ecma_free_value (conv_result);
|
ecma_free_value (conv_result);
|
||||||
@@ -754,8 +743,8 @@ ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's
|
|||||||
return ecma_make_object_value (obj_p);
|
return ecma_make_object_value (obj_p);
|
||||||
} /* ecma_builtin_object_object_define_property */
|
} /* ecma_builtin_object_object_define_property */
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
|
||||||
/**
|
/**
|
||||||
* The Object object's 'assign' routine
|
* The Object object's 'assign' routine
|
||||||
*
|
*
|
||||||
@@ -766,31 +755,14 @@ ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's
|
|||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
static ecma_value_t
|
||||||
ecma_builtin_object_object_assign (const ecma_value_t arguments_list_p[], /**< arguments list */
|
ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object */
|
||||||
|
const ecma_value_t arguments_list_p[], /**< arguments list */
|
||||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
{
|
{
|
||||||
ecma_value_t target = arguments_list_len > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
|
|
||||||
|
|
||||||
/* 1. */
|
|
||||||
ecma_value_t to_value = ecma_op_to_object (target);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (to_value))
|
|
||||||
{
|
|
||||||
return to_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_object_t *to_obj_p = ecma_get_object_from_value (to_value);
|
|
||||||
|
|
||||||
/* 2. */
|
|
||||||
if (arguments_list_len == 1)
|
|
||||||
{
|
|
||||||
return to_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||||
|
|
||||||
/* 4-5. */
|
/* 4-5. */
|
||||||
for (uint32_t i = 1; i < arguments_list_len && ecma_is_value_empty (ret_value); i++)
|
for (uint32_t i = 0; i < arguments_list_len && ecma_is_value_empty (ret_value); i++)
|
||||||
{
|
{
|
||||||
ecma_value_t next_source = arguments_list_p[i];
|
ecma_value_t next_source = arguments_list_p[i];
|
||||||
|
|
||||||
@@ -808,14 +780,15 @@ ecma_builtin_object_object_assign (const ecma_value_t arguments_list_p[], /**< a
|
|||||||
ecma_object_t *from_obj_p = ecma_get_object_from_value (from_value);
|
ecma_object_t *from_obj_p = ecma_get_object_from_value (from_value);
|
||||||
|
|
||||||
/* 5.b.iii */
|
/* 5.b.iii */
|
||||||
/* TODO: extends this collection if symbols will be supported */
|
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_ENUMERABLE);
|
| ECMA_LIST_ENUMERABLE
|
||||||
|
| ECMA_LIST_SYMBOLS);
|
||||||
|
|
||||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||||
|
|
||||||
while (ecma_value_p != NULL && ecma_is_value_empty (ret_value))
|
for (uint32_t j = 0; (j < props_p->item_count) && ecma_is_value_empty (ret_value); j++)
|
||||||
{
|
{
|
||||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[j]);
|
||||||
|
|
||||||
/* 5.c.i-ii */
|
/* 5.c.i-ii */
|
||||||
ecma_property_descriptor_t prop_desc;
|
ecma_property_descriptor_t prop_desc;
|
||||||
@@ -826,9 +799,9 @@ ecma_builtin_object_object_assign (const ecma_value_t arguments_list_p[], /**< a
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 5.c.iii */
|
/* 5.c.iii */
|
||||||
if (prop_desc.is_enumerable
|
if ((prop_desc.flags & ECMA_PROP_IS_ENUMERABLE)
|
||||||
&& ((prop_desc.is_value_defined && !ecma_is_value_undefined (prop_desc.value))
|
&& (((prop_desc.flags & ECMA_PROP_IS_VALUE_DEFINED) && !ecma_is_value_undefined (prop_desc.value))
|
||||||
|| prop_desc.is_get_defined))
|
|| (prop_desc.flags & ECMA_PROP_IS_GET_DEFINED)))
|
||||||
{
|
{
|
||||||
/* 5.c.iii.1 */
|
/* 5.c.iii.1 */
|
||||||
ecma_value_t prop_value = ecma_op_object_get (from_obj_p, property_name_p);
|
ecma_value_t prop_value = ecma_op_object_get (from_obj_p, property_name_p);
|
||||||
@@ -841,7 +814,7 @@ ecma_builtin_object_object_assign (const ecma_value_t arguments_list_p[], /**< a
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 5.c.iii.3 */
|
/* 5.c.iii.3 */
|
||||||
ecma_value_t status = ecma_op_object_put (to_obj_p, property_name_p, prop_value, true);
|
ecma_value_t status = ecma_op_object_put (target_p, property_name_p, prop_value, true);
|
||||||
|
|
||||||
/* 5.c.iii.4 */
|
/* 5.c.iii.4 */
|
||||||
if (ECMA_IS_VALUE_ERROR (status))
|
if (ECMA_IS_VALUE_ERROR (status))
|
||||||
@@ -853,24 +826,39 @@ ecma_builtin_object_object_assign (const ecma_value_t arguments_list_p[], /**< a
|
|||||||
ecma_free_value (prop_value);
|
ecma_free_value (prop_value);
|
||||||
ecma_free_property_descriptor (&prop_desc);
|
ecma_free_property_descriptor (&prop_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_deref_object (from_obj_p);
|
ecma_deref_object (from_obj_p);
|
||||||
ecma_free_values_collection (props_p, 0);
|
ecma_collection_free (props_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 6. */
|
/* 6. */
|
||||||
if (ecma_is_value_empty (ret_value))
|
if (ecma_is_value_empty (ret_value))
|
||||||
{
|
{
|
||||||
return to_value;
|
ecma_ref_object (target_p);
|
||||||
|
return ecma_make_object_value (target_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_deref_object (to_obj_p);
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
} /* ecma_builtin_object_object_assign */
|
} /* ecma_builtin_object_object_assign */
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
|
||||||
|
/**
|
||||||
|
* The Object object's 'is' routine
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v6, 19.1.2.10
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
static ecma_value_t
|
||||||
|
ecma_builtin_object_object_is (ecma_value_t arg1, /**< routine's first argument */
|
||||||
|
ecma_value_t arg2) /**< routine's second argument */
|
||||||
|
{
|
||||||
|
return ecma_op_same_value (arg1, arg2) ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
|
||||||
|
} /* ecma_builtin_object_object_is */
|
||||||
|
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatcher of the built-in's routines
|
* Dispatcher of the built-in's routines
|
||||||
@@ -900,103 +888,185 @@ ecma_builtin_object_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
|
|||||||
{
|
{
|
||||||
return ecma_builtin_object_object_create (arg1, arg2);
|
return ecma_builtin_object_object_create (arg1, arg2);
|
||||||
}
|
}
|
||||||
case ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF:
|
#if ENABLED (JERRY_ES2015)
|
||||||
{
|
|
||||||
return ecma_builtin_object_object_get_prototype_of (arg1);
|
|
||||||
}
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
|
||||||
case ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF:
|
case ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF:
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_object_set_prototype_of (arg1, arg2);
|
return ecma_builtin_object_object_set_prototype_of (arg1, arg2);
|
||||||
}
|
}
|
||||||
case ECMA_OBJECT_ROUTINE_ASSIGN:
|
case ECMA_OBJECT_ROUTINE_IS:
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_object_assign (arguments_list_p, arguments_number);
|
return ecma_builtin_object_object_is (arg1, arg2);
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ecma_object_t *obj_p;
|
||||||
|
#if !ENABLED (JERRY_ES2015)
|
||||||
if (!ecma_is_value_object (arg1))
|
if (!ecma_is_value_object (arg1))
|
||||||
{
|
{
|
||||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object."));
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object."));
|
||||||
}
|
}
|
||||||
|
#endif /* !ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
|
if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES)
|
||||||
|
|
||||||
if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR)
|
|
||||||
{
|
{
|
||||||
ecma_string_t *prop_name_p = ecma_op_to_prop_name (arg2);
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (!ecma_is_value_object (arg1))
|
||||||
if (prop_name_p == NULL)
|
|
||||||
{
|
{
|
||||||
return ECMA_VALUE_ERROR;
|
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object."));
|
||||||
}
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
ecma_value_t ret_value;
|
obj_p = ecma_get_object_from_value (arg1);
|
||||||
|
|
||||||
if (builtin_routine_id == ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY)
|
if (builtin_routine_id == ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY)
|
||||||
{
|
{
|
||||||
ret_value = ecma_builtin_object_object_define_property (obj_p, prop_name_p, arguments_list_p[2]);
|
ecma_string_t *prop_name_p = ecma_op_to_prop_name (arg2);
|
||||||
}
|
|
||||||
else
|
if (prop_name_p == NULL)
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (builtin_routine_id == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR);
|
return ECMA_VALUE_ERROR;
|
||||||
ret_value = ecma_builtin_object_object_get_own_property_descriptor (obj_p, prop_name_p);
|
}
|
||||||
|
|
||||||
|
ecma_value_t result = ecma_builtin_object_object_define_property (obj_p, prop_name_p, arguments_list_p[2]);
|
||||||
|
|
||||||
|
ecma_deref_ecma_string (prop_name_p);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_deref_ecma_string (prop_name_p);
|
JERRY_ASSERT (builtin_routine_id == ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES);
|
||||||
return ret_value;
|
return ecma_builtin_object_object_define_properties (obj_p, arg2);
|
||||||
}
|
}
|
||||||
|
else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_KEYS)
|
||||||
switch (builtin_routine_id)
|
|
||||||
{
|
{
|
||||||
case ECMA_OBJECT_ROUTINE_SEAL:
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ecma_value_t object = ecma_op_to_object (arg1);
|
||||||
|
if (ECMA_IS_VALUE_ERROR (object))
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_object_seal (obj_p);
|
return object;
|
||||||
}
|
}
|
||||||
case ECMA_OBJECT_ROUTINE_FREEZE:
|
|
||||||
|
obj_p = ecma_get_object_from_value (object);
|
||||||
|
#else /* !ENABLED (JERRY_ES2015) */
|
||||||
|
obj_p = ecma_get_object_from_value (arg1);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
ecma_value_t result;
|
||||||
|
switch (builtin_routine_id)
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_object_freeze (obj_p);
|
case ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF:
|
||||||
|
{
|
||||||
|
result = ecma_builtin_object_object_get_prototype_of (obj_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES:
|
||||||
|
{
|
||||||
|
result = ecma_builtin_object_object_get_own_property_names (obj_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
case ECMA_OBJECT_ROUTINE_ASSIGN:
|
||||||
|
{
|
||||||
|
result = ecma_builtin_object_object_assign (obj_p, arguments_list_p + 1, arguments_number - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS:
|
||||||
|
{
|
||||||
|
result = ecma_builtin_object_object_get_own_property_symbols (obj_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
case ECMA_OBJECT_ROUTINE_KEYS:
|
||||||
|
{
|
||||||
|
result = ecma_builtin_object_object_keys (obj_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR:
|
||||||
|
{
|
||||||
|
ecma_string_t *prop_name_p = ecma_op_to_prop_name (arg2);
|
||||||
|
|
||||||
|
if (prop_name_p == NULL)
|
||||||
|
{
|
||||||
|
result = ECMA_VALUE_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = ecma_builtin_object_object_get_own_property_descriptor (obj_p, prop_name_p);
|
||||||
|
ecma_deref_ecma_string (prop_name_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
JERRY_UNREACHABLE ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS:
|
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ecma_deref_object (obj_p);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_SEAL)
|
||||||
|
{
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (!ecma_is_value_object (arg1))
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_object_prevent_extensions (obj_p);
|
return ecma_copy_value (arg1);
|
||||||
}
|
}
|
||||||
case ECMA_OBJECT_ROUTINE_IS_SEALED:
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
case ECMA_OBJECT_ROUTINE_IS_FROZEN:
|
|
||||||
|
obj_p = ecma_get_object_from_value (arg1);
|
||||||
|
switch (builtin_routine_id)
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_frozen_or_sealed_helper (obj_p,
|
case ECMA_OBJECT_ROUTINE_SEAL:
|
||||||
builtin_routine_id);
|
{
|
||||||
|
return ecma_builtin_object_object_seal (obj_p);
|
||||||
|
}
|
||||||
|
case ECMA_OBJECT_ROUTINE_FREEZE:
|
||||||
|
{
|
||||||
|
return ecma_builtin_object_object_freeze (obj_p);
|
||||||
|
}
|
||||||
|
case ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS:
|
||||||
|
{
|
||||||
|
return ecma_builtin_object_object_prevent_extensions (obj_p);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
JERRY_UNREACHABLE ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE:
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (builtin_routine_id <= ECMA_OBJECT_ROUTINE_IS_SEALED);
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
if (!ecma_is_value_object (arg1))
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_object_is_extensible (obj_p);
|
return ecma_make_boolean_value (builtin_routine_id != ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE);
|
||||||
}
|
}
|
||||||
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES:
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
|
obj_p = ecma_get_object_from_value (arg1);
|
||||||
|
switch (builtin_routine_id)
|
||||||
{
|
{
|
||||||
return ecma_builtin_object_object_get_own_property_names (obj_p);
|
case ECMA_OBJECT_ROUTINE_IS_SEALED:
|
||||||
}
|
case ECMA_OBJECT_ROUTINE_IS_FROZEN:
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
{
|
||||||
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS:
|
return ecma_builtin_object_frozen_or_sealed_helper (obj_p,
|
||||||
{
|
builtin_routine_id);
|
||||||
return ecma_builtin_object_object_get_own_property_symbols (obj_p);
|
}
|
||||||
}
|
case ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE:
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
{
|
||||||
case ECMA_OBJECT_ROUTINE_KEYS:
|
return ecma_builtin_object_object_is_extensible (obj_p);
|
||||||
{
|
}
|
||||||
return ecma_builtin_object_object_keys (obj_p);
|
default:
|
||||||
}
|
{
|
||||||
case ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES:
|
JERRY_UNREACHABLE ();
|
||||||
{
|
}
|
||||||
return ecma_builtin_object_object_define_properties (obj_p, arg2);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
JERRY_UNREACHABLE ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* ecma_builtin_object_dispatch_routine */
|
} /* ecma_builtin_object_dispatch_routine */
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
#ifndef ECMA_BUILTIN_OBJECT_H
|
||||||
|
#define ECMA_BUILTIN_OBJECT_H
|
||||||
|
|
||||||
|
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_prevent_extensions (ecma_object_t *obj_p);
|
||||||
|
|
||||||
|
ecma_value_t ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p);
|
||||||
|
|
||||||
|
ecma_value_t ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p,
|
||||||
|
ecma_string_t *name_str_p);
|
||||||
|
ecma_value_t ecma_builtin_object_object_define_property (ecma_object_t *obj_p,
|
||||||
|
ecma_string_t *name_str_p,
|
||||||
|
ecma_value_t arg3);
|
||||||
|
|
||||||
|
#endif /* !ECMA_BUILTIN_OBJECT_H */
|
||||||
@@ -39,9 +39,9 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
|||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (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)
|
ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES, 1, 1)
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_SYMBOLS_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_SYMBOLS_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS, 1, 1)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
ROUTINE (LIT_MAGIC_STRING_SEAL, ECMA_OBJECT_ROUTINE_SEAL, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_SEAL, ECMA_OBJECT_ROUTINE_SEAL, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_FREEZE, ECMA_OBJECT_ROUTINE_FREEZE, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_FREEZE, ECMA_OBJECT_ROUTINE_FREEZE, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS, 1, 1)
|
||||||
@@ -54,9 +54,10 @@ ROUTINE (LIT_MAGIC_STRING_CREATE, ECMA_OBJECT_ROUTINE_CREATE, 2, 2)
|
|||||||
ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL, ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES, 2, 2)
|
ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL, ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES, 2, 2)
|
||||||
ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY, 3, 3)
|
ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY, 3, 3)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ROUTINE (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF, 2, 2)
|
ROUTINE (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF, 2, 2)
|
||||||
ROUTINE (LIT_MAGIC_STRING_ASSIGN, ECMA_OBJECT_ROUTINE_ASSIGN, NON_FIXED, 2)
|
ROUTINE (LIT_MAGIC_STRING_ASSIGN, ECMA_OBJECT_ROUTINE_ASSIGN, NON_FIXED, 2)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
|
ROUTINE (LIT_MAGIC_STRING_IS, ECMA_OBJECT_ROUTINE_IS, 2, 2)
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
|||||||
1,
|
1,
|
||||||
ECMA_PROPERTY_FLAG_WRITABLE)
|
ECMA_PROPERTY_FLAG_WRITABLE)
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL)
|
#if ENABLED (JERRY_ES2015)
|
||||||
/* ECMA-262 v6, 25.4.5.4 */
|
/* ECMA-262 v6, 25.4.5.4 */
|
||||||
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
||||||
LIT_MAGIC_STRING_PROMISE_UL,
|
LIT_MAGIC_STRING_PROMISE_UL,
|
||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
ROUTINE (LIT_MAGIC_STRING_THEN, ecma_builtin_promise_prototype_then, 2, 2)
|
ROUTINE (LIT_MAGIC_STRING_THEN, ecma_builtin_promise_prototype_then, 2, 2)
|
||||||
ROUTINE (LIT_MAGIC_STRING_CATCH, ecma_builtin_promise_prototype_catch, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_CATCH, ecma_builtin_promise_prototype_catch, 1, 1)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user