remove all private stuff
This commit is contained in:
@@ -249,8 +249,6 @@ DEF(SyntaxError, "SyntaxError")
|
||||
DEF(TypeError, "TypeError")
|
||||
DEF(URIError, "URIError")
|
||||
DEF(InternalError, "InternalError")
|
||||
/* private symbols */
|
||||
DEF(Private_brand, "<brand>")
|
||||
/* symbols */
|
||||
DEF(Symbol_toPrimitive, "Symbol.toPrimitive")
|
||||
DEF(Symbol_iterator, "Symbol.iterator")
|
||||
|
||||
@@ -129,9 +129,6 @@ DEF( define_func, 6, 1, 0, atom_u8)
|
||||
DEF( get_field, 5, 1, 1, atom)
|
||||
DEF( get_field2, 5, 1, 2, atom)
|
||||
DEF( put_field, 5, 2, 0, atom)
|
||||
DEF( get_private_field, 1, 2, 1, none) /* obj prop -> value */
|
||||
DEF( put_private_field, 1, 3, 0, none) /* obj value prop -> */
|
||||
DEF(define_private_field, 1, 3, 1, none) /* obj prop value -> obj */
|
||||
DEF( get_array_el, 1, 2, 1, none)
|
||||
DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */
|
||||
DEF( get_array_el3, 1, 2, 3, none) /* obj prop -> obj prop1 value */
|
||||
@@ -251,10 +248,6 @@ def( scope_make_ref, 11, 0, 2, atom_label_u16) /* emitted in phase 1, removed in
|
||||
def( scope_get_ref, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||
def(scope_put_var_init, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||
def(scope_get_var_checkthis, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2, only used to return 'this' in derived class constructors */
|
||||
def(scope_get_private_field, 7, 1, 1, atom_u16) /* obj -> value, emitted in phase 1, removed in phase 2 */
|
||||
def(scope_get_private_field2, 7, 1, 2, atom_u16) /* obj -> obj value, emitted in phase 1, removed in phase 2 */
|
||||
def(scope_put_private_field, 7, 2, 0, atom_u16) /* obj value ->, emitted in phase 1, removed in phase 2 */
|
||||
def(scope_in_private_field, 7, 1, 1, atom_u16) /* obj -> res emitted in phase 1, removed in phase 2 */
|
||||
def(get_field_opt_chain, 5, 1, 1, atom) /* emitted in phase 1, removed in phase 2 */
|
||||
def(get_array_el_opt_chain, 1, 2, 1, none) /* emitted in phase 1, removed in phase 2 */
|
||||
def( set_class_name, 5, 1, 1, u32) /* emitted in phase 1, removed in phase 2 */
|
||||
|
||||
189
source/quickjs.c
189
source/quickjs.c
@@ -371,17 +371,14 @@ enum {
|
||||
JS_ATOM_TYPE_STRING = 1,
|
||||
JS_ATOM_TYPE_GLOBAL_SYMBOL,
|
||||
JS_ATOM_TYPE_SYMBOL,
|
||||
JS_ATOM_TYPE_PRIVATE,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
JS_ATOM_KIND_STRING,
|
||||
JS_ATOM_KIND_SYMBOL,
|
||||
JS_ATOM_KIND_PRIVATE,
|
||||
} JSAtomKindEnum;
|
||||
|
||||
#define JS_ATOM_HASH_MASK ((1 << 30) - 1)
|
||||
#define JS_ATOM_HASH_PRIVATE JS_ATOM_HASH_MASK
|
||||
|
||||
struct JSString {
|
||||
JSRefCountHeader header; /* must come first, 32-bit */
|
||||
@@ -442,11 +439,6 @@ typedef enum {
|
||||
function declaration */
|
||||
JS_VAR_CATCH,
|
||||
JS_VAR_FUNCTION_NAME, /* function expression name */
|
||||
JS_VAR_PRIVATE_FIELD,
|
||||
JS_VAR_PRIVATE_METHOD,
|
||||
JS_VAR_PRIVATE_GETTER,
|
||||
JS_VAR_PRIVATE_SETTER, /* must come after JS_VAR_PRIVATE_GETTER */
|
||||
JS_VAR_PRIVATE_GETTER_SETTER, /* must come after JS_VAR_PRIVATE_SETTER */
|
||||
} JSVarKindEnum;
|
||||
|
||||
/* XXX: could use a different structure in bytecode functions to save
|
||||
@@ -1527,15 +1519,9 @@ void JS_FreeRuntime(JSRuntime *rt)
|
||||
printf(")");
|
||||
break;
|
||||
case JS_ATOM_TYPE_SYMBOL:
|
||||
if (p->hash != JS_ATOM_HASH_PRIVATE) {
|
||||
printf("Symbol(");
|
||||
JS_DumpString(rt, p);
|
||||
printf(")");
|
||||
} else {
|
||||
printf("Private(");
|
||||
JS_DumpString(rt, p);
|
||||
printf(")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (rt->rt_info) {
|
||||
@@ -2051,9 +2037,7 @@ static int JS_InitAtoms(JSRuntime *rt)
|
||||
|
||||
p = js_atom_init;
|
||||
for(i = 1; i < JS_ATOM_END; i++) {
|
||||
if (i == JS_ATOM_Private_brand)
|
||||
atom_type = JS_ATOM_TYPE_PRIVATE;
|
||||
else if (i >= JS_ATOM_Symbol_toPrimitive)
|
||||
if (i >= JS_ATOM_Symbol_toPrimitive)
|
||||
atom_type = JS_ATOM_TYPE_SYMBOL;
|
||||
else
|
||||
atom_type = JS_ATOM_TYPE_STRING;
|
||||
@@ -2104,9 +2088,6 @@ static JSAtomKindEnum JS_AtomGetKind(JSContext *ctx, JSAtom v)
|
||||
case JS_ATOM_TYPE_GLOBAL_SYMBOL:
|
||||
return JS_ATOM_KIND_SYMBOL;
|
||||
case JS_ATOM_TYPE_SYMBOL:
|
||||
if (p->hash == JS_ATOM_HASH_PRIVATE)
|
||||
return JS_ATOM_KIND_PRIVATE;
|
||||
else
|
||||
return JS_ATOM_KIND_SYMBOL;
|
||||
default:
|
||||
abort();
|
||||
@@ -2175,13 +2156,8 @@ static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type)
|
||||
i = p->hash_next;
|
||||
}
|
||||
} else {
|
||||
h1 = 0; /* avoid warning */
|
||||
if (atom_type == JS_ATOM_TYPE_SYMBOL) {
|
||||
h = 0;
|
||||
} else {
|
||||
h = JS_ATOM_HASH_PRIVATE;
|
||||
atom_type = JS_ATOM_TYPE_SYMBOL;
|
||||
}
|
||||
h1 = 0;
|
||||
}
|
||||
|
||||
if (rt->atom_free_index == 0) {
|
||||
@@ -2370,8 +2346,7 @@ static void JS_FreeAtomStruct(JSRuntime *rt, JSAtomStruct *p)
|
||||
#ifdef DUMP_LEAKS
|
||||
list_del(&p->link);
|
||||
#endif
|
||||
if (p->atom_type == JS_ATOM_TYPE_SYMBOL &&
|
||||
p->hash != JS_ATOM_HASH_PRIVATE && p->hash != 0) {
|
||||
if (p->atom_type == JS_ATOM_TYPE_SYMBOL && p->hash != 0) {
|
||||
/* live weak references are still present on this object: keep
|
||||
it */
|
||||
} else {
|
||||
@@ -2690,8 +2665,7 @@ static BOOL JS_AtomSymbolHasDescription(JSContext *ctx, JSAtom v)
|
||||
if (__JS_AtomIsTaggedInt(v))
|
||||
return FALSE;
|
||||
p = rt->atom_array[v];
|
||||
return (((p->atom_type == JS_ATOM_TYPE_SYMBOL &&
|
||||
p->hash != JS_ATOM_HASH_PRIVATE) ||
|
||||
return ((p->atom_type == JS_ATOM_TYPE_SYMBOL ||
|
||||
p->atom_type == JS_ATOM_TYPE_GLOBAL_SYMBOL) &&
|
||||
!(p->len == 0 && p->is_wide_char != 0));
|
||||
}
|
||||
@@ -6853,102 +6827,6 @@ JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
|
||||
}
|
||||
}
|
||||
|
||||
static JSValue JS_ThrowTypeErrorPrivateNotFound(JSContext *ctx, JSAtom atom)
|
||||
{
|
||||
return JS_ThrowTypeErrorAtom(ctx, "private class field '%s' does not exist",
|
||||
atom);
|
||||
}
|
||||
|
||||
/* Private fields can be added even on non extensible objects or
|
||||
Proxies */
|
||||
static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,
|
||||
JSValueConst name, JSValue val)
|
||||
{
|
||||
JSObject *p;
|
||||
JSShapeProperty *prs;
|
||||
JSProperty *pr;
|
||||
JSAtom prop;
|
||||
|
||||
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) {
|
||||
JS_ThrowTypeErrorNotAnObject(ctx);
|
||||
goto fail;
|
||||
}
|
||||
/* safety check */
|
||||
if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL)) {
|
||||
JS_ThrowTypeErrorNotASymbol(ctx);
|
||||
goto fail;
|
||||
}
|
||||
prop = js_symbol_to_atom(ctx, (JSValue)name);
|
||||
p = JS_VALUE_GET_OBJ(obj);
|
||||
prs = find_own_property(&pr, p, prop);
|
||||
if (prs) {
|
||||
JS_ThrowTypeErrorAtom(ctx, "private class field '%s' already exists",
|
||||
prop);
|
||||
goto fail;
|
||||
}
|
||||
pr = add_property(ctx, p, prop, JS_PROP_C_W_E);
|
||||
if (unlikely(!pr)) {
|
||||
fail:
|
||||
JS_FreeValue(ctx, val);
|
||||
return -1;
|
||||
}
|
||||
pr->u.value = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj,
|
||||
JSValueConst name)
|
||||
{
|
||||
JSObject *p;
|
||||
JSShapeProperty *prs;
|
||||
JSProperty *pr;
|
||||
JSAtom prop;
|
||||
|
||||
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))
|
||||
return JS_ThrowTypeErrorNotAnObject(ctx);
|
||||
/* safety check */
|
||||
if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL))
|
||||
return JS_ThrowTypeErrorNotASymbol(ctx);
|
||||
prop = js_symbol_to_atom(ctx, (JSValue)name);
|
||||
p = JS_VALUE_GET_OBJ(obj);
|
||||
prs = find_own_property(&pr, p, prop);
|
||||
if (!prs) {
|
||||
JS_ThrowTypeErrorPrivateNotFound(ctx, prop);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
return JS_DupValue(ctx, pr->u.value);
|
||||
}
|
||||
|
||||
static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj,
|
||||
JSValueConst name, JSValue val)
|
||||
{
|
||||
JSObject *p;
|
||||
JSShapeProperty *prs;
|
||||
JSProperty *pr;
|
||||
JSAtom prop;
|
||||
|
||||
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) {
|
||||
JS_ThrowTypeErrorNotAnObject(ctx);
|
||||
goto fail;
|
||||
}
|
||||
/* safety check */
|
||||
if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL)) {
|
||||
JS_ThrowTypeErrorNotASymbol(ctx);
|
||||
goto fail;
|
||||
}
|
||||
prop = js_symbol_to_atom(ctx, (JSValue)name);
|
||||
p = JS_VALUE_GET_OBJ(obj);
|
||||
prs = find_own_property(&pr, p, prop);
|
||||
if (!prs) {
|
||||
JS_ThrowTypeErrorPrivateNotFound(ctx, prop);
|
||||
fail:
|
||||
JS_FreeValue(ctx, val);
|
||||
return -1;
|
||||
}
|
||||
set_value(ctx, &pr->u.value, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t js_string_obj_get_length(JSContext *ctx,
|
||||
JSValueConst obj)
|
||||
{
|
||||
@@ -14030,43 +13908,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
}
|
||||
BREAK;
|
||||
|
||||
CASE(OP_get_private_field):
|
||||
{
|
||||
JSValue val;
|
||||
|
||||
val = JS_GetPrivateField(ctx, sp[-2], sp[-1]);
|
||||
JS_FreeValue(ctx, sp[-1]);
|
||||
JS_FreeValue(ctx, sp[-2]);
|
||||
sp[-2] = val;
|
||||
sp--;
|
||||
if (unlikely(JS_IsException(val)))
|
||||
goto exception;
|
||||
}
|
||||
BREAK;
|
||||
|
||||
CASE(OP_put_private_field):
|
||||
{
|
||||
int ret;
|
||||
ret = JS_SetPrivateField(ctx, sp[-3], sp[-1], sp[-2]);
|
||||
JS_FreeValue(ctx, sp[-3]);
|
||||
JS_FreeValue(ctx, sp[-1]);
|
||||
sp -= 3;
|
||||
if (unlikely(ret < 0))
|
||||
goto exception;
|
||||
}
|
||||
BREAK;
|
||||
|
||||
CASE(OP_define_private_field):
|
||||
{
|
||||
int ret;
|
||||
ret = JS_DefinePrivateField(ctx, sp[-3], sp[-2], sp[-1]);
|
||||
JS_FreeValue(ctx, sp[-2]);
|
||||
sp -= 2;
|
||||
if (unlikely(ret < 0))
|
||||
goto exception;
|
||||
}
|
||||
BREAK;
|
||||
|
||||
CASE(OP_define_field):
|
||||
{
|
||||
int ret;
|
||||
@@ -16140,7 +15981,7 @@ static void reparse_ident_token(JSParseState *s)
|
||||
|
||||
/* 'c' is the first character. Return JS_ATOM_NULL in case of error */
|
||||
static JSAtom parse_ident(JSParseState *s, const uint8_t **pp,
|
||||
BOOL *pident_has_escape, int c, BOOL is_private)
|
||||
BOOL *pident_has_escape, int c)
|
||||
{
|
||||
const uint8_t *p, *p1;
|
||||
char ident_buf[128], *buf;
|
||||
@@ -16151,8 +15992,6 @@ static JSAtom parse_ident(JSParseState *s, const uint8_t **pp,
|
||||
buf = ident_buf;
|
||||
ident_size = sizeof(ident_buf);
|
||||
ident_pos = 0;
|
||||
if (is_private)
|
||||
buf[ident_pos++] = '#';
|
||||
for(;;) {
|
||||
p1 = p;
|
||||
|
||||
@@ -16331,7 +16170,7 @@ static __exception int next_token(JSParseState *s)
|
||||
p++;
|
||||
ident_has_escape = FALSE;
|
||||
has_ident:
|
||||
atom = parse_ident(s, &p, &ident_has_escape, c, FALSE);
|
||||
atom = parse_ident(s, &p, &ident_has_escape, c);
|
||||
if (atom == JS_ATOM_NULL)
|
||||
goto fail;
|
||||
s->token.u.ident.atom = atom;
|
||||
@@ -17819,8 +17658,6 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc)
|
||||
#define PROP_TYPE_GET 2
|
||||
#define PROP_TYPE_SET 3
|
||||
|
||||
#define PROP_TYPE_PRIVATE (1 << 4)
|
||||
|
||||
static BOOL token_is_ident(int tok)
|
||||
{
|
||||
/* Accept keywords and reserved words as property names */
|
||||
@@ -17832,10 +17669,8 @@ static BOOL token_is_ident(int tok)
|
||||
/* if the property is an expression, name = JS_ATOM_NULL */
|
||||
static int __exception js_parse_property_name(JSParseState *s,
|
||||
JSAtom *pname,
|
||||
BOOL allow_method, BOOL allow_var,
|
||||
BOOL allow_private)
|
||||
BOOL allow_method, BOOL allow_var)
|
||||
{
|
||||
int is_private = 0;
|
||||
BOOL is_non_reserved_ident;
|
||||
JSAtom name;
|
||||
int prop_type;
|
||||
@@ -17847,7 +17682,7 @@ static int __exception js_parse_property_name(JSParseState *s,
|
||||
is a field name */
|
||||
if ((token_is_pseudo_keyword(s, JS_ATOM_get) ||
|
||||
token_is_pseudo_keyword(s, JS_ATOM_set)) &&
|
||||
(!allow_private || peek_token(s, TRUE) != '\n')) {
|
||||
(peek_token(s, TRUE) != '\n')) {
|
||||
/* get x(), set x() */
|
||||
name = JS_DupAtom(s->ctx, s->token.u.ident.atom);
|
||||
if (next_token(s))
|
||||
@@ -17855,7 +17690,7 @@ static int __exception js_parse_property_name(JSParseState *s,
|
||||
if (s->token.val == ':' || s->token.val == ',' ||
|
||||
s->token.val == '}' || s->token.val == '(' ||
|
||||
s->token.val == '=' ||
|
||||
(s->token.val == ';' && allow_private)) {
|
||||
(s->token.val == ';')) {
|
||||
is_non_reserved_ident = TRUE;
|
||||
goto ident_found;
|
||||
}
|
||||
@@ -17913,7 +17748,7 @@ static int __exception js_parse_property_name(JSParseState *s,
|
||||
goto fail;
|
||||
}
|
||||
*pname = name;
|
||||
return prop_type | is_private;
|
||||
return prop_type;
|
||||
fail1:
|
||||
JS_FreeAtom(s->ctx, name);
|
||||
fail:
|
||||
@@ -18177,7 +18012,7 @@ static __exception int js_parse_object_literal(JSParseState *s)
|
||||
goto next;
|
||||
}
|
||||
|
||||
prop_type = js_parse_property_name(s, &name, TRUE, TRUE, FALSE);
|
||||
prop_type = js_parse_property_name(s, &name, TRUE, TRUE);
|
||||
if (prop_type < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -18844,7 +18679,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
|
||||
emit_u8(s, 0 | ((depth_lvalue + 1) << 2) | ((depth_lvalue + 2) << 5));
|
||||
goto set_val;
|
||||
}
|
||||
prop_type = js_parse_property_name(s, &prop_name, FALSE, TRUE, FALSE);
|
||||
prop_type = js_parse_property_name(s, &prop_name, FALSE, TRUE);
|
||||
if (prop_type < 0)
|
||||
return -1;
|
||||
var_name = JS_ATOM_NULL;
|
||||
|
||||
Reference in New Issue
Block a user