mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
Stage 1-4: Update tests
This commit is contained in:
parent
f2622bd19f
commit
5676f63f41
23 changed files with 434 additions and 63 deletions
|
|
@ -29,12 +29,12 @@ function run_test_with_server(server, cb) {
|
|||
addSources(debuggee);
|
||||
|
||||
threadClient.getSources(Task.async(function* (res) {
|
||||
do_check_true(res.sources.length === 3, "3 sources exist");
|
||||
do_check_eq(res.sources.length, 3, "3 sources exist");
|
||||
|
||||
yield threadClient.reconfigure({ useSourceMaps: false });
|
||||
|
||||
threadClient.getSources(function(res) {
|
||||
do_check_true(res.sources.length === 1, "1 source exist");
|
||||
do_check_eq(res.sources.length, 1, "1 source exist");
|
||||
client.close().then(cb);
|
||||
});
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -48,14 +48,14 @@ assertEq(g.toString(), funcBody2);
|
|||
assertEq(g.toSource(), '(' + funcBody2 + ')');
|
||||
|
||||
f0 = new Function(bodyOnly);
|
||||
assertEq(f0.toString(), "function anonymous() {\n" + bodyOnly + "\n}");
|
||||
assertEq(f0.toSource(), "(function anonymous() {\n" + bodyOnly + "\n})");
|
||||
assertEq(f0.toString(), "function anonymous(\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(f0.toSource(), "(function anonymous(\n) {\n" + bodyOnly + "\n})");
|
||||
|
||||
if (isAsmJSCompilationAvailable() && isCachingEnabled()) {
|
||||
var m = new Function(bodyOnly);
|
||||
assertEq(isAsmJSModuleLoadedFromCache(m), true);
|
||||
assertEq(m.toString(), "function anonymous() {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous() {\n" + bodyOnly + "\n})");
|
||||
assertEq(m.toString(), "function anonymous(\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous(\n) {\n" + bodyOnly + "\n})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -107,14 +107,14 @@ assertEq(g.toString(), funcBody2);
|
|||
assertEq(g.toSource(), '(' + funcBody2 + ')');
|
||||
|
||||
f1 = new Function('glob', bodyOnly);
|
||||
assertEq(f1.toString(), "function anonymous(glob) {\n" + bodyOnly + "\n}");
|
||||
assertEq(f1.toSource(), "(function anonymous(glob) {\n" + bodyOnly + "\n})");
|
||||
assertEq(f1.toString(), "function anonymous(glob\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(f1.toSource(), "(function anonymous(glob\n) {\n" + bodyOnly + "\n})");
|
||||
|
||||
if (isAsmJSCompilationAvailable() && isCachingEnabled()) {
|
||||
var m = new Function('glob', bodyOnly);
|
||||
assertEq(isAsmJSModuleLoadedFromCache(m), true);
|
||||
assertEq(m.toString(), "function anonymous(glob) {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous(glob) {\n" + bodyOnly + "\n})");
|
||||
assertEq(m.toString(), "function anonymous(glob\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous(glob\n) {\n" + bodyOnly + "\n})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -167,14 +167,14 @@ assertEq(g.toString(), funcBody2);
|
|||
assertEq(g.toSource(), '(' + funcBody2 + ')');
|
||||
|
||||
f2 = new Function('glob', 'ffi', bodyOnly);
|
||||
assertEq(f2.toString(), "function anonymous(glob, ffi) {\n" + bodyOnly + "\n}");
|
||||
assertEq(f2.toSource(), "(function anonymous(glob, ffi) {\n" + bodyOnly + "\n})");
|
||||
assertEq(f2.toString(), "function anonymous(glob,ffi\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(f2.toSource(), "(function anonymous(glob,ffi\n) {\n" + bodyOnly + "\n})");
|
||||
|
||||
if (isAsmJSCompilationAvailable() && isCachingEnabled()) {
|
||||
var m = new Function('glob', 'ffi', bodyOnly);
|
||||
assertEq(isAsmJSModuleLoadedFromCache(m), true);
|
||||
assertEq(m.toString(), "function anonymous(glob, ffi) {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous(glob, ffi) {\n" + bodyOnly + "\n})");
|
||||
assertEq(m.toString(), "function anonymous(glob,ffi\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous(glob,ffi\n) {\n" + bodyOnly + "\n})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -227,14 +227,14 @@ assertEq(g.toString(), funcBody2);
|
|||
assertEq(g.toSource(), '(' + funcBody2 + ')');
|
||||
|
||||
f3 = new Function('glob', 'ffi', 'heap', bodyOnly);
|
||||
assertEq(f3.toString(), "function anonymous(glob, ffi, heap) {\n" + bodyOnly + "\n}");
|
||||
assertEq(f3.toSource(), "(function anonymous(glob, ffi, heap) {\n" + bodyOnly + "\n})");
|
||||
assertEq(f3.toString(), "function anonymous(glob,ffi,heap\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(f3.toSource(), "(function anonymous(glob,ffi,heap\n) {\n" + bodyOnly + "\n})");
|
||||
|
||||
if (isAsmJSCompilationAvailable() && isCachingEnabled()) {
|
||||
var m = new Function('glob', 'ffi', 'heap', bodyOnly);
|
||||
assertEq(isAsmJSModuleLoadedFromCache(m), true);
|
||||
assertEq(m.toString(), "function anonymous(glob, ffi, heap) {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous(glob, ffi, heap) {\n" + bodyOnly + "\n})");
|
||||
assertEq(m.toString(), "function anonymous(glob,ffi,heap\n) {\n" + bodyOnly + "\n}");
|
||||
assertEq(m.toSource(), "(function anonymous(glob,ffi,heap\n) {\n" + bodyOnly + "\n})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -252,7 +252,7 @@ var funcSource =
|
|||
var f4 = eval("\"use strict\";\n(" + funcSource + ")");
|
||||
|
||||
var expectedToString = funcSource;
|
||||
var expectedToSource = '(' + expectedToString + ')'
|
||||
var expectedToSource = '(' + expectedToString + ')';
|
||||
|
||||
assertEq(f4.toString(), expectedToString);
|
||||
assertEq(f4.toSource(), expectedToSource);
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ for (var i=0; i<400; ++i) {
|
|||
x += String.fromCharCode(i * 289);
|
||||
}
|
||||
var s = "'" + x + "'";
|
||||
assertEq(Function("evt", s).toString(), "function anonymous(evt) {\n" + s + "\n}");
|
||||
assertEq(Function("evt", s).toString(), "function anonymous(evt\n) {\n" + s + "\n}");
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
var f = Function("a", "b", "return a + b;");
|
||||
assertEq(f.toString(), "function anonymous(a, b) {\nreturn a + b;\n}");
|
||||
assertEq(f.toSource(), "(function anonymous(a, b) {\nreturn a + b;\n})");
|
||||
assertEq(f.toString(), "function anonymous(a,b\n) {\nreturn a + b;\n}");
|
||||
assertEq(f.toSource(), "(function anonymous(a,b\n) {\nreturn a + b;\n})");
|
||||
assertEq(decompileFunction(f), f.toString());
|
||||
f = Function("a", "...rest", "return rest[42] + b;");
|
||||
assertEq(f.toString(), "function anonymous(a, ...rest) {\nreturn rest[42] + b;\n}");
|
||||
assertEq(f.toSource(), "(function anonymous(a, ...rest) {\nreturn rest[42] + b;\n})")
|
||||
assertEq(f.toString(), "function anonymous(a,...rest\n) {\nreturn rest[42] + b;\n}");
|
||||
assertEq(f.toSource(), "(function anonymous(a,...rest\n) {\nreturn rest[42] + b;\n})")
|
||||
assertEq(decompileFunction(f), f.toString());
|
||||
f = Function("");
|
||||
assertEq(f.toString(), "function anonymous() {\n\n}");
|
||||
assertEq(f.toString(), "function anonymous(\n) {\n\n}");
|
||||
f = Function("", "(abc)");
|
||||
assertEq(f.toString(), "function anonymous() {\n(abc)\n}");
|
||||
assertEq(f.toString(), "function anonymous(\n) {\n(abc)\n}");
|
||||
f = Function("", "return function (a,b) a + b;")();
|
||||
assertEq(f.toString(), "function (a,b) a + b");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var o = {get prop() a + b, set prop(x) a + b};
|
||||
var prop = Object.getOwnPropertyDescriptor(o, "prop");
|
||||
assertEq(prop.get.toString(), "function get prop() a + b");
|
||||
assertEq(prop.get.toSource(), "(function get prop() a + b)");
|
||||
assertEq(prop.set.toString(), "function set prop(x) a + b");
|
||||
assertEq(prop.set.toSource(), "(function set prop(x) a + b)");
|
||||
assertEq(o.toSource(), "({get prop () a + b, set prop (x) a + b})");
|
||||
assertEq(prop.get.toString(), "get prop() { a + b; }");
|
||||
assertEq(prop.get.toSource(), "get prop() { a + b; }");
|
||||
assertEq(prop.set.toString(), "set prop(x) { a + b; }");
|
||||
assertEq(prop.set.toSource(), "set prop(x) { a + b; }");
|
||||
assertEq(o.toSource(), "({get prop() { a + b; }, set prop(x) { a + b; }})");
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ function test(str, arg, result)
|
|||
var fun = new Function('x', str);
|
||||
|
||||
var got = fun.toSource();
|
||||
var expect = '(function anonymous(x) {\n' + str + '\n})';
|
||||
var expect = '(function anonymous(x\n) {\n' + str + '\n})';
|
||||
if (got !== expect) {
|
||||
print("GOT: " + got);
|
||||
print("EXPECT: " + expect);
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ assertEq(arr.length, 10);
|
|||
gc();
|
||||
|
||||
for (var i = 0; i < arr.length; i++)
|
||||
assertEq(arr[i].lineCount, 3);
|
||||
assertEq(arr[i].lineCount, 4);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ assertEq(arr.length, 100);
|
|||
gc(g);
|
||||
|
||||
for (var i = 0; i < arr.length; i++)
|
||||
assertEq(arr[i].lineCount, 3);
|
||||
assertEq(arr[i].lineCount, 4);
|
||||
|
||||
gc();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,6 @@ function test(string, range) {
|
|||
}
|
||||
|
||||
test("eval('2 * 3')", [0, 5]);
|
||||
test("new Function('2 * 3')", [0, 12]);
|
||||
test("new Function('x', 'x * x')", [0, 13]);
|
||||
test("new Function('2 * 3')", [0, 31]);
|
||||
test("new Function('x', 'x * x')", [0, 32]);
|
||||
assertEq(count, 6);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
let g = newGlobal();
|
||||
let dbg = new Debugger(g);
|
||||
|
||||
var text;
|
||||
var count = 0;
|
||||
dbg.onNewScript = function (script) {
|
||||
++count;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ assertEq(o.toSource(), '({get prop () { return "\\u1200"; }, set prop () { retur
|
|||
var ff = function() { return 10; };
|
||||
ff.toSource = function() { return "((11))"; }
|
||||
Object.defineProperty(o, "prop", {get: ff, set: ff, enumerable: true});
|
||||
assertEq(o.toSource(), "({prop:((11)), prop:((11))})");
|
||||
assertEq(o.toSource(), "({get prop(11), set prop(11)})");
|
||||
|
||||
// XDR
|
||||
load(libdir + 'bytecode-cache.js');
|
||||
|
|
|
|||
370
js/src/tests/ecma_2017/Function/Object-toSource.js
Normal file
370
js/src/tests/ecma_2017/Function/Object-toSource.js
Normal file
|
|
@ -0,0 +1,370 @@
|
|||
var BUGNUMBER = 1317400;
|
||||
var summary = "Function string representation in Object.prototype.toSource";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
// Methods.
|
||||
|
||||
assertEq(({ foo(){} }).toSource(),
|
||||
"({foo(){}})");
|
||||
assertEq(({ *foo(){} }).toSource(),
|
||||
"({*foo(){}})");
|
||||
assertEq(({ async foo(){} }).toSource(),
|
||||
"({async foo(){}})");
|
||||
|
||||
assertEq(({ 1(){} }).toSource(),
|
||||
"({1(){}})");
|
||||
|
||||
// Methods with more spacing.
|
||||
// Spacing is kept.
|
||||
|
||||
assertEq(({ foo (){} }).toSource(),
|
||||
"({foo (){}})");
|
||||
assertEq(({ foo () {} }).toSource(),
|
||||
"({foo () {}})");
|
||||
|
||||
// Methods with computed name.
|
||||
// Method syntax is composed.
|
||||
|
||||
let name = "foo";
|
||||
assertEq(({ [name](){} }).toSource(),
|
||||
"({foo(){}})");
|
||||
assertEq(({ *[name](){} }).toSource(),
|
||||
"({*foo(){}})");
|
||||
assertEq(({ async [name](){} }).toSource(),
|
||||
"({async foo(){}})");
|
||||
|
||||
assertEq(({ [ Symbol.iterator ](){} }).toSource(),
|
||||
"({[Symbol.iterator](){}})");
|
||||
|
||||
// Accessors.
|
||||
|
||||
assertEq(({ get foo(){} }).toSource(),
|
||||
"({get foo(){}})");
|
||||
assertEq(({ set foo(v){} }).toSource(),
|
||||
"({set foo(v){}})");
|
||||
|
||||
// Accessors with computed name.
|
||||
// Method syntax is composed.
|
||||
|
||||
assertEq(({ get [name](){} }).toSource(),
|
||||
"({get foo(){}})");
|
||||
assertEq(({ set [name](v){} }).toSource(),
|
||||
"({set foo(v){}})");
|
||||
|
||||
assertEq(({ get [ Symbol.iterator ](){} }).toSource(),
|
||||
"({get [Symbol.iterator](){}})");
|
||||
assertEq(({ set [ Symbol.iterator ](v){} }).toSource(),
|
||||
"({set [Symbol.iterator](v){}})");
|
||||
|
||||
// Getter and setter with same name.
|
||||
// Getter always comes before setter.
|
||||
|
||||
assertEq(({ get foo(){}, set foo(v){} }).toSource(),
|
||||
"({get foo(){}, set foo(v){}})");
|
||||
assertEq(({ set foo(v){}, get foo(){} }).toSource(),
|
||||
"({get foo(){}, set foo(v){}})");
|
||||
|
||||
// Normal properties.
|
||||
|
||||
assertEq(({ foo: function(){} }).toSource(),
|
||||
"({foo:(function(){})})");
|
||||
assertEq(({ foo: function bar(){} }).toSource(),
|
||||
"({foo:(function bar(){})})");
|
||||
assertEq(({ foo: function*(){} }).toSource(),
|
||||
"({foo:(function*(){})})");
|
||||
assertEq(({ foo: async function(){} }).toSource(),
|
||||
"({foo:(async function(){})})");
|
||||
|
||||
// Normal properties with computed name.
|
||||
|
||||
assertEq(({ [ Symbol.iterator ]: function(){} }).toSource(),
|
||||
"({[Symbol.iterator]:(function(){})})");
|
||||
|
||||
// Dynamically defined properties with function expression.
|
||||
// Never become a method syntax.
|
||||
|
||||
let obj = {};
|
||||
obj.foo = function() {};
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:(function() {})})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: function() {}});
|
||||
assertEq(obj.toSource(),
|
||||
"({})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: function() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:(function() {})})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: function bar() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:(function bar() {})})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, Symbol.iterator, {value: function() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({[Symbol.iterator]:(function() {})})");
|
||||
|
||||
// Dynamically defined property with other object's method.
|
||||
// Method syntax is composed.
|
||||
|
||||
let method = ({foo() {}}).foo;
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: method, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({foo() {}})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "bar", {value: method, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({bar() {}})");
|
||||
|
||||
method = ({*foo() {}}).foo;
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "bar", {value: method, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({*bar() {}})");
|
||||
|
||||
method = ({async foo() {}}).foo;
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "bar", {value: method, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({async bar() {}})");
|
||||
|
||||
// Dynamically defined accessors.
|
||||
// Accessor syntax is composed.
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: function() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo() {}})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: function() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo() {}})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, Symbol.iterator, {get: function() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get [Symbol.iterator]() {}})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, Symbol.iterator, {set: function() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set [Symbol.iterator]() {}})");
|
||||
|
||||
// Dynamically defined accessors with other object's accessors.
|
||||
// Accessor syntax is composed.
|
||||
|
||||
let accessor = Object.getOwnPropertyDescriptor({ get foo() {} }, "foo").get;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo() {}})");
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ get bar() {} }, "bar").get;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo() {}})");
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ set foo(v) {} }, "foo").set;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo(v) {}})");
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ set bar(v) {} }, "bar").set;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo(v) {}})");
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ get foo() {} }, "foo").get;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo() {}})");
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ get bar() {} }, "bar").get;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo() {}})");
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ set foo(v) {} }, "foo").set;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo(v) {}})");
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ set bar(v) {} }, "bar").set;
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo(v) {}})");
|
||||
|
||||
// Methods with proxy.
|
||||
// Treated as normal property.
|
||||
|
||||
method = ({foo() {}}).foo;
|
||||
let handler = {
|
||||
get(that, name) {
|
||||
if (name == "toSource") {
|
||||
return function() {
|
||||
return that.toSource();
|
||||
};
|
||||
}
|
||||
return that[name];
|
||||
}
|
||||
};
|
||||
let proxy = new Proxy(method, handler);
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: proxy, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:foo() {}})");
|
||||
|
||||
// Accessors with proxy.
|
||||
// Accessor syntax is composed.
|
||||
|
||||
accessor = Object.getOwnPropertyDescriptor({ get foo() {} }, "foo").get;
|
||||
proxy = new Proxy(accessor, handler);
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: proxy, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo() {}})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: proxy, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo() {}})");
|
||||
|
||||
// Methods from other global.
|
||||
// Treated as normal property.
|
||||
|
||||
let g = newGlobal();
|
||||
|
||||
method = g.eval("({ foo() {} }).foo");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: method, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:foo() {}})");
|
||||
|
||||
// Accessors from other global.
|
||||
// Accessor syntax is composed.
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ get foo() {} }, 'foo').get");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo() {}})");
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ get bar() {} }, 'bar').get");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo() {}})");
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ set foo(v) {} }, 'foo').set");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo(v) {}})");
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ set bar(v) {} }, 'bar').set");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo(v) {}})");
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ get foo() {} }, 'foo').get");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo() {}})");
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ get bar() {} }, 'bar').get");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo() {}})");
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ set foo(v) {} }, 'foo').set");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo(v) {}})");
|
||||
|
||||
accessor = g.eval("Object.getOwnPropertyDescriptor({ set bar(v) {} }, 'bar').set");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: accessor, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo(v) {}})");
|
||||
|
||||
// **** Some weird cases ****
|
||||
|
||||
// Accessors with generator or async.
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {get: function*() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({get foo() {}})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {set: async function() {}, enumerable: true});
|
||||
assertEq(obj.toSource(),
|
||||
"({set foo() {}})");
|
||||
|
||||
// Modified toSource.
|
||||
|
||||
obj = { foo() {} };
|
||||
obj.foo.toSource = () => "hello";
|
||||
assertEq(obj.toSource(),
|
||||
"({hello})");
|
||||
|
||||
obj = { foo() {} };
|
||||
obj.foo.toSource = () => "bar() {}";
|
||||
assertEq(obj.toSource(),
|
||||
"({bar() {}})");
|
||||
|
||||
// Modified toSource with different method name.
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: function bar() {}, enumerable: true});
|
||||
obj.foo.toSource = () => "hello";
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:hello})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: function* bar() {}, enumerable: true});
|
||||
obj.foo.toSource = () => "hello";
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:hello})");
|
||||
|
||||
obj = {};
|
||||
Object.defineProperty(obj, "foo", {value: async function bar() {}, enumerable: true});
|
||||
obj.foo.toSource = () => "hello";
|
||||
assertEq(obj.toSource(),
|
||||
"({foo:hello})");
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
0
js/src/tests/ecma_2017/Function/browser.js
Normal file
0
js/src/tests/ecma_2017/Function/browser.js
Normal file
0
js/src/tests/ecma_2017/Function/shell.js
Normal file
0
js/src/tests/ecma_2017/Function/shell.js
Normal file
|
|
@ -109,7 +109,7 @@ function TestGeneratorFunction() {
|
|||
// Doesn't matter particularly what string gets serialized, as long
|
||||
// as it contains "function*" and "yield 10".
|
||||
assertEq(GeneratorFunction('yield 10').toString(),
|
||||
"function* anonymous() {\nyield 10\n}");
|
||||
"function* anonymous(\n) {\nyield 10\n}");
|
||||
}
|
||||
TestGeneratorFunction();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue