remove module eval branches
This commit is contained in:
@@ -1671,11 +1671,6 @@ JSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id)
|
||||
return JS_DupValue(ctx, ctx->class_proto[class_id]);
|
||||
}
|
||||
|
||||
typedef enum JSFreeModuleEnum {
|
||||
JS_FREE_MODULE_ALL,
|
||||
JS_FREE_MODULE_NOT_RESOLVED,
|
||||
} JSFreeModuleEnum;
|
||||
|
||||
JSContext *JS_DupContext(JSContext *ctx)
|
||||
{
|
||||
ctx->header.ref_count++;
|
||||
@@ -15346,8 +15341,6 @@ typedef struct JSParseState {
|
||||
|
||||
/* current function code */
|
||||
JSFunctionDef *cur_func;
|
||||
BOOL is_module; /* parsing a module */
|
||||
BOOL allow_html_comments;
|
||||
BOOL ext_json; /* true if accepting JSON superset */
|
||||
GetLineColCache get_line_col_cache;
|
||||
} JSParseState;
|
||||
@@ -16255,13 +16248,6 @@ static __exception int next_token(JSParseState *s)
|
||||
p += 2;
|
||||
s->token.val = TOK_MINUS_ASSIGN;
|
||||
} else if (p[1] == '-') {
|
||||
if (s->allow_html_comments && p[2] == '>' &&
|
||||
(s->got_lf || s->last_ptr == s->buf_start)) {
|
||||
/* Annex B: `-->` at beginning of line is an html comment end.
|
||||
It extends to the end of the line.
|
||||
*/
|
||||
goto skip_line_comment;
|
||||
}
|
||||
p += 2;
|
||||
s->token.val = TOK_DEC;
|
||||
} else {
|
||||
@@ -16280,10 +16266,6 @@ static __exception int next_token(JSParseState *s)
|
||||
p += 2;
|
||||
s->token.val = TOK_SHL;
|
||||
}
|
||||
} else if (s->allow_html_comments &&
|
||||
p[1] == '!' && p[2] == '-' && p[3] == '-') {
|
||||
/* Annex B: handle `<!--` single line html comments */
|
||||
goto skip_line_comment;
|
||||
} else {
|
||||
goto def_token;
|
||||
}
|
||||
@@ -17432,8 +17414,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
|
||||
}
|
||||
|
||||
if (fd->is_eval &&
|
||||
(fd->eval_type == JS_EVAL_TYPE_GLOBAL ||
|
||||
fd->eval_type == JS_EVAL_TYPE_MODULE) &&
|
||||
fd->eval_type == JS_EVAL_TYPE_GLOBAL &&
|
||||
fd->scope_level == fd->body_scope) {
|
||||
JSGlobalVar *hf;
|
||||
hf = add_global_var(s->ctx, fd, name);
|
||||
@@ -17473,10 +17454,6 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
|
||||
if (fd->is_global_var) {
|
||||
JSGlobalVar *hf;
|
||||
hf = find_global_var(fd, name);
|
||||
if (hf && hf->is_lexical && hf->scope_level == fd->scope_level &&
|
||||
fd->eval_type == JS_EVAL_TYPE_MODULE) {
|
||||
goto invalid_lexical_redefinition;
|
||||
}
|
||||
hf = add_global_var(s->ctx, fd, name);
|
||||
if (!hf)
|
||||
return -1;
|
||||
@@ -18553,8 +18530,6 @@ static BOOL need_var_reference(JSParseState *s, int tok)
|
||||
if (fd->js_mode & JS_MODE_STRICT) {
|
||||
if (!fd->is_global_var)
|
||||
return FALSE; /* local definitions in strict mode in function or direct eval */
|
||||
if (s->is_module)
|
||||
return FALSE; /* in a module global variables are like closure variables */
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -25248,39 +25223,23 @@ static __exception int js_parse_function_decl2(JSParseState *s,
|
||||
if (next_token(s))
|
||||
return -1;
|
||||
|
||||
if (s->token.val == TOK_IDENT && s->token.u.ident.is_reserved) {
|
||||
return js_parse_error_reserved_identifier(s);
|
||||
}
|
||||
if (s->token.val == TOK_IDENT ||
|
||||
(((s->token.val == TOK_YIELD && !(fd->js_mode & JS_MODE_STRICT)) ||
|
||||
(s->token.val == TOK_AWAIT && !s->is_module)) &&
|
||||
func_type == JS_PARSE_FUNC_EXPR)) {
|
||||
func_name = JS_DupAtom(ctx, s->token.u.ident.atom);
|
||||
if (next_token(s)) {
|
||||
if (s->token.val == TOK_IDENT) {
|
||||
if (s->token.u.ident.is_reserved)
|
||||
return js_parse_error_reserved_identifier(s);
|
||||
func_name = JS_DupAtom(ctx, s->token.u.ident.atom);
|
||||
if (next_token(s)) {
|
||||
JS_FreeAtom(ctx, func_name);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (func_type != JS_PARSE_FUNC_EXPR) {
|
||||
}
|
||||
} else {
|
||||
if (func_type != JS_PARSE_FUNC_EXPR)
|
||||
return js_parse_error(s, "function name expected");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (func_type != JS_PARSE_FUNC_ARROW) {
|
||||
func_name = JS_DupAtom(ctx, func_name);
|
||||
}
|
||||
|
||||
if (fd->is_eval && fd->eval_type == JS_EVAL_TYPE_MODULE &&
|
||||
(func_type == JS_PARSE_FUNC_STATEMENT || func_type == JS_PARSE_FUNC_VAR)) {
|
||||
JSGlobalVar *hf;
|
||||
hf = find_global_var(fd, func_name);
|
||||
/* XXX: should check scope chain */
|
||||
if (hf && hf->scope_level == fd->scope_level) {
|
||||
js_parse_error(s, "invalid redefinition of global identifier in module code");
|
||||
JS_FreeAtom(ctx, func_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (func_type == JS_PARSE_FUNC_VAR) {
|
||||
if (!(fd->js_mode & JS_MODE_STRICT)
|
||||
&& find_lexical_decl(ctx, fd, func_name, fd->scope_first, FALSE) < 0
|
||||
@@ -25290,8 +25249,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
|
||||
/* Create the lexical name here so that the function closure
|
||||
contains it */
|
||||
if (fd->is_eval &&
|
||||
(fd->eval_type == JS_EVAL_TYPE_GLOBAL ||
|
||||
fd->eval_type == JS_EVAL_TYPE_MODULE) &&
|
||||
fd->eval_type == JS_EVAL_TYPE_GLOBAL &&
|
||||
fd->scope_level == fd->body_scope) {
|
||||
/* avoid creating a lexical variable in the global
|
||||
scope. XXX: check annex B */
|
||||
@@ -25736,29 +25694,22 @@ static __exception int js_parse_program(JSParseState *s)
|
||||
return -1;
|
||||
|
||||
fd->is_global_var = (fd->eval_type == JS_EVAL_TYPE_GLOBAL) ||
|
||||
(fd->eval_type == JS_EVAL_TYPE_MODULE) ||
|
||||
!(fd->js_mode & JS_MODE_STRICT);
|
||||
|
||||
if (!s->is_module) {
|
||||
/* hidden variable for the return value */
|
||||
fd->eval_ret_idx = idx = add_var(s->ctx, fd, JS_ATOM__ret_);
|
||||
if (idx < 0)
|
||||
return -1;
|
||||
}
|
||||
/* hidden variable for the return value */
|
||||
fd->eval_ret_idx = idx = add_var(s->ctx, fd, JS_ATOM__ret_);
|
||||
if (idx < 0)
|
||||
return -1;
|
||||
|
||||
while (s->token.val != TOK_EOF) {
|
||||
if (js_parse_source_element(s))
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!s->is_module) {
|
||||
/* return the value of the hidden variable eval_ret_idx */
|
||||
emit_op(s, OP_get_loc);
|
||||
emit_u16(s, fd->eval_ret_idx);
|
||||
emit_return(s, TRUE);
|
||||
} else {
|
||||
emit_return(s, FALSE);
|
||||
}
|
||||
/* return the value of the hidden variable eval_ret_idx */
|
||||
emit_op(s, OP_get_loc);
|
||||
emit_u16(s, fd->eval_ret_idx);
|
||||
emit_return(s, TRUE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -25857,8 +25808,6 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
s->allow_html_comments = !s->is_module;
|
||||
|
||||
push_scope(s); /* body scope */
|
||||
fd->body_scope = fd->scope_level;
|
||||
|
||||
@@ -25933,8 +25882,7 @@ JSValue JS_EvalThis(JSContext *ctx, JSValueConst this_obj,
|
||||
int eval_type = eval_flags & JS_EVAL_TYPE_MASK;
|
||||
JSValue ret;
|
||||
|
||||
assert(eval_type == JS_EVAL_TYPE_GLOBAL ||
|
||||
eval_type == JS_EVAL_TYPE_MODULE);
|
||||
assert(eval_type == JS_EVAL_TYPE_GLOBAL);
|
||||
ret = JS_EvalInternal(ctx, this_obj, input, input_len, filename,
|
||||
eval_flags, -1);
|
||||
return ret;
|
||||
|
||||
@@ -309,7 +309,6 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
|
||||
|
||||
/* JS_Eval() flags */
|
||||
#define JS_EVAL_TYPE_GLOBAL (0 << 0) /* global code (default) */
|
||||
#define JS_EVAL_TYPE_MODULE (1 << 0) /* module code */
|
||||
#define JS_EVAL_TYPE_DIRECT (2 << 0) /* direct call (internal use) */
|
||||
#define JS_EVAL_TYPE_INDIRECT (3 << 0) /* indirect call (internal use) */
|
||||
#define JS_EVAL_TYPE_MASK (3 << 0)
|
||||
|
||||
Reference in New Issue
Block a user