-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ECMA262 RegExp builtin object and RegExp engine #169
Changes from all commits
6511f0e
d0e9edc
50b64bf
1f9add4
4ffcb4d
f992f5d
e027b4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -455,6 +455,54 @@ ecma_init_ecma_string_from_magic_string_ex_id (ecma_string_t *string_p, /**< des | |
string_p->u.magic_string_ex_id = magic_string_ex_id; | ||
} /* ecma_init_ecma_string_from_magic_string_ex_id */ | ||
|
||
/** | ||
* Allocate new ecma-string and fill it with specified number of characters from specified buffer | ||
* | ||
* @return pointer to ecma-string descriptor | ||
*/ | ||
ecma_string_t* | ||
ecma_new_ecma_string (const ecma_char_t *string_p, /**< input string */ | ||
const ecma_length_t length) /**< number of characters */ | ||
{ | ||
JERRY_ASSERT (string_p != NULL); | ||
JERRY_ASSERT (length > 0 && length <= ecma_zt_string_length (string_p)); | ||
|
||
if (length != ecma_zt_string_length (string_p)) | ||
{ | ||
/* FIXME: update this when 'ecma_is_charset_magic' interface is added */ | ||
ecma_char_t *zt_str_p = (ecma_char_t *) mem_heap_alloc_block ((size_t) (length + 1), MEM_HEAP_ALLOC_SHORT_TERM); | ||
memcpy (zt_str_p, string_p, length * sizeof (ecma_char_t)); | ||
zt_str_p[length] = 0; | ||
|
||
ecma_magic_string_id_t magic_string_id; | ||
if (ecma_is_zt_string_magic (zt_str_p, &magic_string_id)) | ||
{ | ||
mem_heap_free_block (zt_str_p); | ||
return ecma_get_magic_string (magic_string_id); | ||
} | ||
|
||
ecma_magic_string_ex_id_t magic_string_ex_id; | ||
if (ecma_is_zt_ex_string_magic (zt_str_p, &magic_string_ex_id)) | ||
{ | ||
mem_heap_free_block (zt_str_p); | ||
return ecma_get_magic_string_ex (magic_string_ex_id); | ||
} | ||
mem_heap_free_block (zt_str_p); | ||
} | ||
|
||
ecma_string_t *string_desc_p = ecma_alloc_string (); | ||
string_desc_p->refs = 1; | ||
string_desc_p->is_stack_var = false; | ||
string_desc_p->container = ECMA_STRING_CONTAINER_HEAP_CHUNKS; | ||
string_desc_p->hash = ecma_chars_buffer_calc_hash_last_chars (string_p, length); | ||
string_desc_p->u.common_field = 0; | ||
|
||
ecma_collection_header_t *collection_p = ecma_new_chars_collection (string_p, length); | ||
ECMA_SET_NON_NULL_POINTER (string_desc_p->u.collection_cp, collection_p); | ||
|
||
return string_desc_p; | ||
} /* ecma_new_ecma_string */ | ||
|
||
/** | ||
* Allocate new ecma-string and fill it with characters from specified buffer | ||
* | ||
|
@@ -485,19 +533,7 @@ ecma_new_ecma_string (const ecma_char_t *string_p) /**< zero-terminated string * | |
length++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, remove the above checks on equality to a magic string, as they are now performed in function, called from there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my first thought too. :) I didn't want to do the string duplication when the whole string is magic string. But I see the problem now. When we create an ecma_string_t from the whole zero-terminated string, then these checks will be evaluated twice and there will be an unnecessary string duplication too. I should clean this up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is fixed now. We don't copy and check again when the whole zero terminated string is converted to ecma_string_t. |
||
} | ||
|
||
JERRY_ASSERT (length > 0); | ||
|
||
ecma_string_t* string_desc_p = ecma_alloc_string (); | ||
string_desc_p->refs = 1; | ||
string_desc_p->is_stack_var = false; | ||
string_desc_p->container = ECMA_STRING_CONTAINER_HEAP_CHUNKS; | ||
string_desc_p->hash = ecma_chars_buffer_calc_hash_last_chars (string_p, length); | ||
|
||
string_desc_p->u.common_field = 0; | ||
ecma_collection_header_t *collection_p = ecma_new_chars_collection (string_p, length); | ||
ECMA_SET_NON_NULL_POINTER (string_desc_p->u.collection_cp, collection_p); | ||
|
||
return string_desc_p; | ||
return ecma_new_ecma_string (string_p, length); | ||
} /* ecma_new_ecma_string */ | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -809,6 +809,11 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */ | |
{ | ||
JERRY_UNREACHABLE (); | ||
} | ||
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE: | ||
{ | ||
void *bytecode_p = ECMA_GET_NON_NULL_POINTER (void, property_value); | ||
mem_heap_free_block (bytecode_p); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had to introduce a new type of internal property to store the bytecode of RegExp. This property store a compressed pointer to the start of the bytecode container. The compiled bytecode should be exist until RegExp object exists. When the object is freed and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. |
||
} | ||
} | ||
|
||
ecma_dealloc_property (property_p); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing new line ^_^