Skip to content

Commit bffc911

Browse files
author
bence gabor kis
committed
Add support test262 $262 global object support
Few test-cases in test262 uses a $262 object to run a few method (for example detachedArrayBuffer) JerryScript-DCO-1.0-Signed-off-by: bence gabor kis [email protected]
1 parent 25bb508 commit bffc911

File tree

8 files changed

+162
-188
lines changed

8 files changed

+162
-188
lines changed

.github/workflows/gh-actions.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,3 @@ jobs:
144144
run: sudo apt-get install gcc-multilib
145145
- name: UBSAN - jerry-tests
146146
run: $RUNNER --jerry-tests $SKIP_LIST $BUILD_OPTIONS -q
147-

docs/01.CONFIGURATION.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ This option is disabled by default.
255255
| CMake: | `-DJERRY_SYSTEM_ALLOCATOR=ON/OFF` |
256256
| Python: | `--system-allocator=ON/OFF` |
257257

258+
### Test262
259+
260+
This option enables the use of $262 object.
261+
This option is disabled by default.
262+
263+
| Options | |
264+
|---------|----------------------------------------------|
265+
| C: | `-DJERRY_TEST262=0/1` |
266+
| CMake: | `-DJERRY_TEST262=ON/OFF` |
267+
| Python: | `--test262=ON/OFF` |
268+
258269
### Valgrind support
259270

260271
This option enables valgrind support for the internal allocator. When enabled, valgrind will be able to properly identify allocated memory regions, and report leaks or out-of-bounds memory accesses.

jerry-core/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ set(JERRY_REGEXP_DUMP_BYTE_CODE OFF CACHE BOOL "Enable regexp byt
3636
set(JERRY_SNAPSHOT_EXEC OFF CACHE BOOL "Enable executing snapshot files?")
3737
set(JERRY_SNAPSHOT_SAVE OFF CACHE BOOL "Enable saving snapshot files?")
3838
set(JERRY_SYSTEM_ALLOCATOR OFF CACHE BOOL "Enable system allocator?")
39+
set(JERRY_TEST262 OFF CACHE BOOL "Enable test262 support?")
3940
set(JERRY_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
4041
set(JERRY_VM_EXEC_STOP OFF CACHE BOOL "Enable VM execution stopping?")
4142
set(JERRY_GLOBAL_HEAP_SIZE "(512)" CACHE STRING "Size of memory heap, in kilobytes")
@@ -100,6 +101,7 @@ message(STATUS "JERRY_REGEXP_DUMP_BYTE_CODE " ${JERRY_REGEXP_DUMP_BYTE_CODE})
100101
message(STATUS "JERRY_SNAPSHOT_EXEC " ${JERRY_SNAPSHOT_EXEC} ${JERRY_SNAPSHOT_EXEC_MESSAGE})
101102
message(STATUS "JERRY_SNAPSHOT_SAVE " ${JERRY_SNAPSHOT_SAVE} ${JERRY_SNAPSHOT_SAVE_MESSAGE})
102103
message(STATUS "JERRY_SYSTEM_ALLOCATOR " ${JERRY_SYSTEM_ALLOCATOR})
104+
message(STATUS "JERRY_TEST262 " ${JERRY_TEST262})
103105
message(STATUS "JERRY_VALGRIND " ${JERRY_VALGRIND})
104106
message(STATUS "JERRY_VM_EXEC_STOP " ${JERRY_VM_EXEC_STOP})
105107
message(STATUS "JERRY_GLOBAL_HEAP_SIZE " ${JERRY_GLOBAL_HEAP_SIZE})
@@ -296,6 +298,9 @@ jerry_add_define01(JERRY_SNAPSHOT_SAVE)
296298
# Enable system allocator
297299
jerry_add_define01(JERRY_SYSTEM_ALLOCATOR)
298300

301+
# Enable test262
302+
jerry_add_define01(JERRY_TEST262)
303+
299304
# Valgrind
300305
jerry_add_define01(JERRY_VALGRIND)
301306
if(JERRY_VALGRIND)

jerry-core/config.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,19 @@
432432
# define JERRY_VM_EXEC_STOP 0
433433
#endif /* !defined (JERRY_VM_EXEC_STOP) */
434434

435+
/**
436+
* Enable/Disable test262 support
437+
*
438+
* Allowed values:
439+
* 0: Disable test262 support.
440+
* 1: Enable test262 support.
441+
*
442+
* Default value: 0
443+
*/
444+
#ifndef JERRY_TEST262
445+
# define JERRY_TEST262 0
446+
#endif /* JERRY_TEST262 */
447+
435448
/**
436449
* Advanced section configurations.
437450
*/
@@ -682,6 +695,10 @@
682695
|| ((JERRY_VM_EXEC_STOP != 0) && (JERRY_VM_EXEC_STOP != 1))
683696
# error "Invalid value for 'JERRY_VM_EXEC_STOP' macro."
684697
#endif
698+
#if !defined (JERRY_TEST262) \
699+
|| ((JERRY_TEST262 != 0) && (JERRY_TEST262 != 1))
700+
# error "Invalid value for 'JERRY_TEST262' macro."
701+
#endif
685702

686703
#define ENABLED(FEATURE) ((FEATURE) == 1)
687704
#define DISABLED(FEATURE) ((FEATURE) != 1)

jerry-main/main-utils.c

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,126 @@ main_register_global_function (const char *name_p, /**< name of the function */
4444
jerry_release_value (result_val);
4545
} /* main_register_global_function */
4646

47+
#if defined (JERRY_TEST262) && (JERRY_TEST262 == 1)
48+
49+
static void
50+
test262_register_function (jerry_value_t test262_obj, /** $262 object */
51+
const char *name_p, /**< name of the function */
52+
jerry_external_handler_t handler_p) /**< function callback */
53+
{
54+
jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) name_p);
55+
jerry_value_t function_val = jerry_create_external_function (handler_p);
56+
57+
jerry_value_t result_val = jerry_set_property (test262_obj, function_name_val, function_val);
58+
59+
jerry_release_value (function_val);
60+
jerry_release_value (function_name_val);
61+
62+
assert (!jerry_value_is_error (result_val));
63+
jerry_release_value (result_val);
64+
} /* test262_register_function */
65+
66+
/**
67+
* $262.detachArrayBuffer
68+
*
69+
* A function which implements the DetachArrayBuffer abstract operation
70+
*
71+
* @return null value - if success
72+
* value marked with error flag - otherwise
73+
*/
74+
static jerry_value_t
75+
test262_detach_array_buffer (const jerry_value_t func_obj_val, /**< function object */
76+
const jerry_value_t this_p, /**< this arg */
77+
const jerry_value_t args_p[], /**< function arguments */
78+
const jerry_length_t args_cnt) /**< number of function arguments */
79+
{
80+
(void) func_obj_val; /* unused */
81+
(void) this_p; /* unused */
82+
83+
if (args_cnt < 1 || !jerry_value_is_arraybuffer (args_p[0]))
84+
{
85+
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Expected an ArrayBuffer object");
86+
}
87+
88+
/* TODO: support the optional 'key' argument */
89+
90+
return jerry_detach_arraybuffer (args_p[0]);
91+
} /* test262_detach_array_buffer */
92+
93+
/**
94+
* $262.evalScript
95+
*
96+
* A function which accepts a string value as its first argument and executes it
97+
*
98+
* @return completion of the script parsing and execution.
99+
*/
100+
static jerry_value_t
101+
test262_eval_script (const jerry_value_t func_obj_val, /**< function object */
102+
const jerry_value_t this_p, /**< this arg */
103+
const jerry_value_t args_p[], /**< function arguments */
104+
const jerry_length_t args_cnt) /**< number of function arguments */
105+
{
106+
(void) func_obj_val; /* unused */
107+
(void) this_p; /* unused */
108+
109+
if (args_cnt < 1 || !jerry_value_is_string (args_p[0]))
110+
{
111+
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Expected a string");
112+
}
113+
114+
jerry_size_t str_size = jerry_get_utf8_string_size (args_p[0]);
115+
jerry_char_t *str_buf_p = malloc (str_size * sizeof (jerry_char_t));
116+
117+
if (str_buf_p == NULL || jerry_string_to_utf8_char_buffer (args_p[0], str_buf_p, str_size) != str_size)
118+
{
119+
return jerry_create_error (JERRY_ERROR_RANGE, (jerry_char_t *) "Internal error");
120+
}
121+
122+
jerry_value_t ret_value = jerry_parse (NULL, 0, str_buf_p, str_size, JERRY_PARSE_NO_OPTS);
123+
124+
if (!jerry_value_is_error (ret_value))
125+
{
126+
jerry_value_t func_val = ret_value;
127+
ret_value = jerry_run (func_val);
128+
jerry_release_value (func_val);
129+
}
130+
131+
free (str_buf_p);
132+
133+
return ret_value;
134+
} /* test262_eval_script */
135+
136+
/**
137+
* Init the $262 object
138+
*/
139+
static void
140+
register_test262 (void)
141+
{
142+
jerry_value_t global_obj = jerry_get_global_object ();
143+
jerry_value_t test262_object = jerry_create_object ();
144+
145+
test262_register_function (test262_object, "detachArrayBuffer", test262_detach_array_buffer);
146+
test262_register_function (test262_object, "evalScript", test262_eval_script);
147+
test262_register_function (test262_object, "gc", jerryx_handler_gc);
148+
149+
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "global");
150+
jerry_value_t result = jerry_set_property (test262_object, prop_name, global_obj);
151+
152+
jerry_release_value (prop_name);
153+
assert (!jerry_value_is_error (result));
154+
155+
prop_name = jerry_create_string ((const jerry_char_t *) "$262");
156+
result = jerry_set_property (global_obj, prop_name, test262_object);
157+
158+
assert (!jerry_value_is_error (result));
159+
jerry_release_value (prop_name);
160+
161+
jerry_release_value (global_obj);
162+
jerry_release_value (test262_object);
163+
jerry_release_value (result);
164+
} /* register_test262 */
165+
#endif /* defined (JERRY_TEST262) && (JERRY_TEST262 == 1) */
166+
47167
/**
48168
* Inits the engine and the debugger
49169
*/
@@ -81,6 +201,9 @@ main_init_engine (main_args_t *arguments_p) /** main arguments */
81201
main_register_global_function ("gc", jerryx_handler_gc);
82202
main_register_global_function ("print", jerryx_handler_print);
83203
main_register_global_function ("resourceName", jerryx_handler_resource_name);
204+
#if defined (JERRY_TEST262) && (JERRY_TEST262 == 1)
205+
register_test262 ();
206+
#endif /* defined (JERRY_TEST262) && (JERRY_TEST262 == 1) */
84207
} /* main_init_engine */
85208

86209
/**

0 commit comments

Comments
 (0)