Mark target_function of bound objects. (#1707)

Fixes #1621.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2017-04-03 13:05:29 +02:00
committed by GitHub
parent a5b90ed858
commit 1aec439869
3 changed files with 68 additions and 18 deletions
+7
View File
@@ -294,6 +294,13 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
ecma_extended_object_t *ext_function_p = (ecma_extended_object_t *) object_p;
ecma_object_t *target_func_obj_p;
target_func_obj_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
ext_function_p->u.bound_function.target_function);
ecma_gc_set_object_visited (target_func_obj_p, true);
ecma_length_t args_length = ext_function_p->u.bound_function.args_length;
ecma_value_t *args_p = (ecma_value_t *) (ext_function_p + 1);
+44 -18
View File
@@ -107,6 +107,21 @@ assert_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< f
}
} /* assert_handler */
/**
* Provide the 'gc' implementation for the engine.
*
* @return undefined.
*/
static jerry_value_t
gc_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< function object */
const jerry_value_t this_p __attribute__((unused)), /**< this arg */
const jerry_value_t args_p[] __attribute__((unused)), /**< function arguments */
const jerry_length_t args_cnt __attribute__((unused))) /**< number of function arguments */
{
jerry_gc ();
return jerry_create_undefined ();
} /* gc_handler */
static void
print_usage (char *name)
{
@@ -334,6 +349,32 @@ print_unhandled_exception (jerry_value_t error_value) /**< error value */
jerry_release_value (err_str_val);
} /* print_unhandled_exception */
/**
* Register a JavaScript function in the global object.
*/
static void
register_js_function (const char *name_p, /**< name of the function */
jerry_external_handler_t handler_p) /**< function callback */
{
jerry_value_t global_obj_val = jerry_get_global_object ();
jerry_value_t function_val = jerry_create_external_function (handler_p);
jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) name_p);
jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val);
jerry_release_value (function_name_val);
jerry_release_value (function_val);
jerry_release_value (global_obj_val);
if (jerry_value_has_error_flag (result_val))
{
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register '%s' method.", name_p);
print_unhandled_exception (result_val);
}
jerry_release_value (result_val);
} /* register_js_function */
int
main (int argc,
char **argv)
@@ -609,25 +650,10 @@ main (int argc,
jerry_init (flags);
jerry_value_t global_obj_val = jerry_get_global_object ();
jerry_value_t assert_value = jerry_create_external_function (assert_handler);
register_js_function ("assert", assert_handler);
register_js_function ("gc", gc_handler);
jerry_value_t assert_func_name_val = jerry_create_string ((jerry_char_t *) "assert");
jerry_value_t ret_value = jerry_set_property (global_obj_val, assert_func_name_val, assert_value);
jerry_release_value (assert_func_name_val);
jerry_release_value (assert_value);
jerry_release_value (global_obj_val);
if (jerry_value_has_error_flag (ret_value))
{
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register 'assert' method.");
print_unhandled_exception (ret_value);
}
jerry_release_value (ret_value);
ret_value = jerry_create_undefined ();
jerry_value_t ret_value = jerry_create_undefined ();
if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC))
{
+17
View File
@@ -0,0 +1,17 @@
// 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.
var eval = eval.bind()
gc();
eval("1");