Browse Source

Treat all \xFF strings as internal (also user)

This allows user code to create internal properties too, so that the
internal properties are not returned by e.g. getOwnPropertyNames().

Prior to this change, a user string beginning with \xFF would not be
treated as internal - unless it happened to be a string already used
by Duktape for its own purposes.  This is quite confusing.
pull/30/head
Sami Vaarala 10 years ago
parent
commit
ea7b123832
  1. 10
      src/duk_heap_alloc.c
  2. 11
      src/duk_heap_stringtable.c

10
src/duk_heap_alloc.c

@ -318,11 +318,11 @@ static int duk__init_heap_strings(duk_heap *heap) {
goto error;
}
/* special flags */
if (len > 0 && tmp[0] == (duk_uint8_t) 0xff) {
DUK_HSTRING_SET_INTERNAL(h);
}
/* Special flags checks. Since these strings are always
* reachable and a string cannot appear twice in the string
* table, there's no need to check/set these flags elsewhere.
* The 'internal' flag is set by string intern code.
*/
if (i == DUK_STRIDX_EVAL || i == DUK_STRIDX_LC_ARGUMENTS) {
DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(h);
}

11
src/duk_heap_stringtable.c

@ -44,6 +44,17 @@ static duk_hstring *duk__alloc_init_hstring(duk_heap *heap,
DUK_HSTRING_SET_ARRIDX(res);
}
/* All strings beginning with 0xff are treated as "internal",
* even strings interned by the user. This allows user code to
* create internal properties too, and makes behavior consistent
* in case user code happens to use a string also used by Duktape
* (such as string has already been interned and has the 'internal'
* flag set).
*/
if (blen > 0 && str[0] == (duk_uint8_t) 0xff) {
DUK_HSTRING_SET_INTERNAL(res);
}
res->hash = strhash;
res->blen = blen;
res->clen = (duk_uint32_t) duk_unicode_unvalidated_utf8_length(str, (duk_size_t) blen); /* clen <= blen */

Loading…
Cancel
Save