mirror of
https://github.com/bellard/quickjs.git
synced 2025-11-15 10:12:14 +03:00
optimized global variable access
This commit is contained in:
@@ -123,17 +123,14 @@ DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern a
|
|||||||
DEF( get_super, 1, 1, 1, none)
|
DEF( get_super, 1, 1, 1, none)
|
||||||
DEF( import, 1, 2, 1, none) /* dynamic module import */
|
DEF( import, 1, 2, 1, none) /* dynamic module import */
|
||||||
|
|
||||||
DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */
|
DEF( get_var_undef, 3, 0, 1, var_ref) /* push undefined if the variable does not exist */
|
||||||
DEF( get_var, 5, 0, 1, atom) /* throw an exception if the variable does not exist */
|
DEF( get_var, 3, 0, 1, var_ref) /* throw an exception if the variable does not exist */
|
||||||
DEF( put_var, 5, 1, 0, atom) /* must come after get_var */
|
DEF( put_var, 3, 1, 0, var_ref) /* must come after get_var */
|
||||||
DEF( put_var_init, 5, 1, 0, atom) /* must come after put_var. Used to initialize a global lexical variable */
|
DEF( put_var_init, 3, 1, 0, var_ref) /* must come after put_var. Used to initialize a global lexical variable */
|
||||||
|
|
||||||
DEF( get_ref_value, 1, 2, 3, none)
|
DEF( get_ref_value, 1, 2, 3, none)
|
||||||
DEF( put_ref_value, 1, 3, 0, none)
|
DEF( put_ref_value, 1, 3, 0, none)
|
||||||
|
|
||||||
DEF( define_var, 6, 0, 0, atom_u8)
|
|
||||||
DEF(check_define_var, 6, 0, 0, atom_u8)
|
|
||||||
DEF( define_func, 6, 1, 0, atom_u8)
|
|
||||||
DEF( get_field, 5, 1, 1, atom)
|
DEF( get_field, 5, 1, 1, atom)
|
||||||
DEF( get_field2, 5, 1, 2, atom)
|
DEF( get_field2, 5, 1, 2, atom)
|
||||||
DEF( put_field, 5, 2, 0, atom)
|
DEF( put_field, 5, 2, 0, atom)
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ function test_template_skip()
|
|||||||
|
|
||||||
function test_object_literal()
|
function test_object_literal()
|
||||||
{
|
{
|
||||||
var x = 0, get = 1, set = 2; async = 3;
|
var x = 0, get = 1, set = 2, async = 3;
|
||||||
a = { get: 2, set: 3, async: 4, get a(){ return this.get} };
|
a = { get: 2, set: 3, async: 4, get a(){ return this.get} };
|
||||||
assert(JSON.stringify(a), '{"get":2,"set":3,"async":4,"a":2}');
|
assert(JSON.stringify(a), '{"get":2,"set":3,"async":4,"a":2}');
|
||||||
assert(a.a === 2);
|
assert(a.a === 2);
|
||||||
@@ -628,6 +628,33 @@ function test_unicode_ident()
|
|||||||
assert(typeof õ, "undefined");
|
assert(typeof õ, "undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check global variable optimization */
|
||||||
|
function test_global_var_opt()
|
||||||
|
{
|
||||||
|
var v2;
|
||||||
|
(1, eval)('var gvar1'); /* create configurable global variables */
|
||||||
|
|
||||||
|
gvar1 = 1;
|
||||||
|
Object.defineProperty(globalThis, "gvar1", { writable: false });
|
||||||
|
gvar1 = 2;
|
||||||
|
assert(gvar1, 1);
|
||||||
|
|
||||||
|
Object.defineProperty(globalThis, "gvar1", { get: function() { return "hello" },
|
||||||
|
set: function(v) { v2 = v; } });
|
||||||
|
assert(gvar1, "hello");
|
||||||
|
gvar1 = 3;
|
||||||
|
assert(v2, 3);
|
||||||
|
|
||||||
|
Object.defineProperty(globalThis, "gvar1", { value: 4, writable: true, configurable: true });
|
||||||
|
assert(gvar1, 4);
|
||||||
|
gvar1 = 6;
|
||||||
|
|
||||||
|
delete gvar1;
|
||||||
|
assert_throws(ReferenceError, function() { return gvar1 });
|
||||||
|
gvar1 = 5;
|
||||||
|
assert(gvar1, 5);
|
||||||
|
}
|
||||||
|
|
||||||
test_op1();
|
test_op1();
|
||||||
test_cvt();
|
test_cvt();
|
||||||
test_eq();
|
test_eq();
|
||||||
@@ -652,3 +679,4 @@ test_parse_semicolon();
|
|||||||
test_optional_chaining();
|
test_optional_chaining();
|
||||||
test_parse_arrow_function();
|
test_parse_arrow_function();
|
||||||
test_unicode_ident();
|
test_unicode_ident();
|
||||||
|
test_global_var_opt();
|
||||||
|
|||||||
Reference in New Issue
Block a user