mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Check if there is really an old bytecode when recompiling a regexp
Fixes #612 JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
This commit is contained in:
parent
0d6568db18
commit
98fc4098e8
@ -124,8 +124,6 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
|
||||
/* Get bytecode property. */
|
||||
ecma_property_t *bc_prop_p = ecma_get_internal_property (this_obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
|
||||
re_bytecode_t *old_bc_p = ECMA_GET_NON_NULL_POINTER (re_bytecode_t,
|
||||
bc_prop_p->u.internal_property.value);
|
||||
|
||||
FIXME ("We currently have to re-compile the bytecode, because we can't copy it without knowing its length.")
|
||||
re_bytecode_t *new_bc_p = NULL;
|
||||
@ -133,7 +131,13 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
|
||||
/* Should always succeed, since we're compiling from a source that has been compiled previously. */
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (bc_comp));
|
||||
|
||||
mem_heap_free_block (old_bc_p);
|
||||
re_bytecode_t *old_bc_p = ECMA_GET_POINTER (re_bytecode_t,
|
||||
bc_prop_p->u.internal_property.value);
|
||||
if (old_bc_p != NULL)
|
||||
{
|
||||
mem_heap_free_block (old_bc_p);
|
||||
}
|
||||
|
||||
ECMA_SET_POINTER (bc_prop_p->u.internal_property.value, new_bc_p);
|
||||
|
||||
re_initialize_props (this_obj_p, pattern_string_p, flags);
|
||||
@ -184,15 +188,20 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
|
||||
{
|
||||
ecma_property_t *bc_prop_p = ecma_get_internal_property (this_obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
|
||||
re_bytecode_t *old_bc_p = ECMA_GET_NON_NULL_POINTER (re_bytecode_t,
|
||||
bc_prop_p->u.internal_property.value);
|
||||
|
||||
/* Try to compile bytecode from new source. */
|
||||
re_bytecode_t *new_bc_p = NULL;
|
||||
ECMA_TRY_CATCH (bc_dummy, re_compile_bytecode (&new_bc_p, pattern_string_p, flags), ret_value);
|
||||
|
||||
/* Replace old bytecode with new one. */
|
||||
mem_heap_free_block (old_bc_p);
|
||||
|
||||
re_bytecode_t *old_bc_p = ECMA_GET_POINTER (re_bytecode_t,
|
||||
bc_prop_p->u.internal_property.value);
|
||||
|
||||
if (old_bc_p != NULL)
|
||||
{
|
||||
/* Replace old bytecode with new one. */
|
||||
mem_heap_free_block (old_bc_p);
|
||||
}
|
||||
|
||||
ECMA_SET_POINTER (bc_prop_p->u.internal_property.value, new_bc_p);
|
||||
re_initialize_props (this_obj_p, pattern_string_p, flags);
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
|
||||
|
||||
17
tests/jerry/regression-test-issue-612.js
Normal file
17
tests/jerry/regression-test-issue-612.js
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// 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 result = RegExp.prototype.compile([]);
|
||||
assert(result === undefined);
|
||||
Loading…
x
Reference in New Issue
Block a user