mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 00:38:39 +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
|
|
@ -24,7 +24,7 @@ var inputTests = [
|
|||
{
|
||||
input: "(function() { return 42; })",
|
||||
output: "function ()",
|
||||
printOutput: "function () { return 42; }",
|
||||
printOutput: "function() { return 42; }",
|
||||
suppressClick: true
|
||||
},
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ var inputTests = [
|
|||
{
|
||||
input: "testobj1.testfn2",
|
||||
output: "function testfn2()",
|
||||
printOutput: "function () { return 42; }",
|
||||
printOutput: "function() { return 42; }",
|
||||
suppressClick: true
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ var f0 = function() {
|
|||
|
||||
}
|
||||
|
||||
funcBody1 = funcBody.replace('function f0','function ');
|
||||
funcBody1 = funcBody.replace('function f0','function');
|
||||
assertEq(f0.toString(), funcBody1);
|
||||
assertEq(f0.toSource(), '(' + funcBody1 + ')');
|
||||
|
||||
|
|
@ -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})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -91,7 +91,7 @@ f1 = function(glob) {
|
|||
|
||||
}
|
||||
|
||||
funcBody1 = funcBody.replace('function f1', 'function ');
|
||||
funcBody1 = funcBody.replace('function f1', 'function');
|
||||
assertEq(f1.toString(), funcBody1);
|
||||
assertEq(f1.toSource(), '(' + funcBody1 + ')');
|
||||
|
||||
|
|
@ -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})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -144,14 +144,14 @@ var funcBody = 'function f2(glob, ffi) {\n\
|
|||
assertEq(f2.toString(), funcBody);
|
||||
assertEq(f2.toSource(), funcBody);
|
||||
|
||||
f2 = function (glob, ffi) {
|
||||
f2 = function(glob, ffi) {
|
||||
"use asm";
|
||||
function g() {}
|
||||
return g;
|
||||
|
||||
}
|
||||
|
||||
funcBody1 = funcBody.replace('function f2', 'function ');
|
||||
funcBody1 = funcBody.replace('function f2', 'function');
|
||||
assertEq(f2.toString(), funcBody1);
|
||||
assertEq(f2.toSource(), '(' + funcBody1 + ')');
|
||||
|
||||
|
|
@ -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})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -204,14 +204,14 @@ var funcBody = 'function f3(glob, ffi, heap) {\n\
|
|||
assertEq(f3.toString(), funcBody);
|
||||
assertEq(f3.toSource(), funcBody);
|
||||
|
||||
f3 = function (glob, ffi, heap) {
|
||||
f3 = function(glob, ffi, heap) {
|
||||
"use asm";
|
||||
function g() {}
|
||||
return g;
|
||||
|
||||
}
|
||||
|
||||
funcBody1 = funcBody.replace('function f3', 'function ');
|
||||
funcBody1 = funcBody.replace('function f3', 'function');
|
||||
assertEq(f3.toString(), funcBody1);
|
||||
assertEq(f3.toSource(), '(' + funcBody1 + ')');
|
||||
|
||||
|
|
@ -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})");
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -243,7 +243,7 @@ if (isAsmJSCompilationAvailable() && isCachingEnabled()) {
|
|||
(function() {
|
||||
|
||||
var funcSource =
|
||||
`function (glob, ffi, heap) {
|
||||
`function(glob, ffi, heap) {
|
||||
"use asm";
|
||||
function g() {}
|
||||
return g;
|
||||
|
|
@ -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}");
|
||||
f = Function("", "return function (a, b) a + b;")();
|
||||
assertEq(f.toString(), "function (a, b) a + b");
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@ var o = {};
|
|||
Object.defineProperty(o, "prop", {get: function() { return 1; },
|
||||
set: function() { return 2; },
|
||||
enumerable: true, configurable: true});
|
||||
assertEq(o.toSource(), "({get prop () { return 1; }, set prop () { return 2; }})");
|
||||
assertEq(o.toSource(), "({get prop() { return 1; }, set prop() { return 2; }})");
|
||||
|
||||
// obj.toSource TwoByte
|
||||
Object.defineProperty(o, "prop", {get: function() { return "\u1200"; },
|
||||
set: function() { return "\u1200"; },
|
||||
enumerable: true});
|
||||
assertEq(o.toSource(), '({get prop () { return "\\u1200"; }, set prop () { return "\\u1200"; }})');
|
||||
assertEq(o.toSource(), '({get prop() { return "\\u1200"; }, set prop() { return "\\u1200"; }})');
|
||||
|
||||
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');
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ function test() {
|
|||
|
||||
var f = Function(arg1TwoByte, arg2Latin1, bodyLatin1);
|
||||
assertEq(f(10, 20), 60);
|
||||
assertEq(f.toSource().includes("arg1\u1200, arg2"), true);
|
||||
assertEq(f.toSource().includes("arg1\u1200,arg2"), true);
|
||||
|
||||
var bodyTwoByte = "return arg1\u1200 + arg2;";
|
||||
f = Function(arg1TwoByte, arg2Latin1, bodyTwoByte);
|
||||
assertEq(f(30, 40), 70);
|
||||
assertEq(f.toSource().includes("arg1\u1200, arg2"), true);
|
||||
assertEq(f.toSource().includes("arg1\u1200,arg2"), true);
|
||||
}
|
||||
test();
|
||||
|
|
|
|||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ with (x)
|
|||
}
|
||||
status = inSection(5);
|
||||
actual = x.g.toString();
|
||||
expect = (function () {}).toString();
|
||||
expect = (function() {}).toString();
|
||||
addThis();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 354945;
|
||||
var summary = 'Do not crash with new Iterator';
|
||||
var expect = 'TypeError: trap __iterator__ for ({__iterator__:(function (){ })}) returned a primitive value';
|
||||
var expect = 'TypeError: trap __iterator__ for ({__iterator__:(function(){ })}) returned a primitive value';
|
||||
var actual;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function test()
|
|||
printBugNumber(BUGNUMBER);
|
||||
printStatus (summary);
|
||||
|
||||
expect = 'TypeError: trap __iterator__ for ({__iterator__:(function (){ })}) returned a primitive value';
|
||||
expect = 'TypeError: trap __iterator__ for ({__iterator__:(function(){ })}) returned a primitive value';
|
||||
var obj = {};
|
||||
obj.__iterator__ = function(){ };
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
var actual;
|
||||
var expect = "function f() { ff (); }";
|
||||
var expect = "function f () { ff (); }";
|
||||
function fun() {
|
||||
(new Function ("function ff () { actual = '' + ff. caller; } function f () { ff (); } f ();")) ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,21 +22,21 @@
|
|||
storage.b = 0;
|
||||
assert_equals(storage.b, "0");
|
||||
storage.c = function(){};
|
||||
assert_equals(storage.c, "function (){}");
|
||||
assert_equals(storage.c, "function(){}");
|
||||
|
||||
storage.setItem('d', null);
|
||||
assert_equals(storage.d, "null");
|
||||
storage.setItem('e', 0);
|
||||
assert_equals(storage.e, "0");
|
||||
storage.setItem('f', function(){});
|
||||
assert_equals(storage.f, "function (){}");
|
||||
assert_equals(storage.f, "function(){}");
|
||||
|
||||
storage['g'] = null;
|
||||
assert_equals(storage.g, "null");
|
||||
storage['h'] = 0;
|
||||
assert_equals(storage.h, "0");
|
||||
storage['i'] = function(){};
|
||||
assert_equals(storage.f, "function (){}");
|
||||
assert_equals(storage.f, "function(){}");
|
||||
|
||||
}, name + " only stores strings");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -381,12 +381,12 @@ add_task(function* log_message_with_params() {
|
|||
ob = function() {};
|
||||
ob.toJSON = function() {throw "oh noes JSON"};
|
||||
do_check_eq(formatMessage("Fail is ${sub}", {sub: ob}),
|
||||
'Fail is (function () {})');
|
||||
'Fail is (function() {})');
|
||||
|
||||
// Fall back to .toString if both .toJSON and .toSource fail.
|
||||
ob.toSource = function() {throw "oh noes SOURCE"};
|
||||
do_check_eq(formatMessage("Fail is ${sub}", {sub: ob}),
|
||||
'Fail is function () {}');
|
||||
'Fail is function() {}');
|
||||
|
||||
// Fall back to '[object]' if .toJSON, .toSource and .toString fail.
|
||||
ob.toString = function() {throw "oh noes STRING"};
|
||||
|
|
@ -450,7 +450,7 @@ add_task(function* log_message_with_params() {
|
|||
// doesn't cause the logger to fail.
|
||||
let vOf = {a: 1, valueOf: function() {throw "oh noes valueOf"}};
|
||||
do_check_eq(formatMessage("Broken valueOf ${}", vOf),
|
||||
'Broken valueOf ({a:1, valueOf:(function () {throw "oh noes valueOf"})})');
|
||||
'Broken valueOf ({a:1, valueOf:(function() {throw "oh noes valueOf"})})');
|
||||
|
||||
// Test edge cases of bad data to formatter:
|
||||
// If 'params' is not an object, format it as a basic type.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue