Index: test/mjsunit/strong/literals.js |
diff --git a/test/mjsunit/strong/literals.js b/test/mjsunit/strong/literals.js |
index a810dcc8cbb7a3f55972f23f38e5b880154b7d46..3a6bbdd208d70904cbb30076aa5f06b8a660e0a6 100644 |
--- a/test/mjsunit/strong/literals.js |
+++ b/test/mjsunit/strong/literals.js |
@@ -4,36 +4,44 @@ |
// Flags: --strong-mode --allow-natives-syntax |
// Flags: --harmony-arrow-functions --harmony-rest-parameters |
-// Flags: --harmony-destructuring |
+// Flags: --harmony-destructuring --harmony-spread-arrays |
'use strict'; |
(function WeakObjectLiterals() { |
- assertTrue(!%IsStrong({})); |
- assertTrue(!%IsStrong({a: 0, b: 0})); |
- assertTrue(!%IsStrong({a: [], b: {}})); |
- assertTrue(!%IsStrong({a: [], b: {}}.a)); |
- assertTrue(!%IsStrong({a: [], b: {}}.b)); |
- assertTrue(!%IsStrong({a: {b: {c: {}}}}.a)); |
- assertTrue(!%IsStrong({a: {b: {c: {}}}}.a.b)); |
- assertTrue(!%IsStrong({a: {b: {c: {}}}}.a.b.c)); |
- assertTrue(!%IsStrong({f: function(){}})); |
- assertTrue(!%IsStrong(Realm.eval(Realm.current(), |
- "({f: function(){}})"))); |
+ function assertWeakObject(x) { |
+ assertFalse(%IsStrong(x)); |
+ assertSame(Object.prototype, Object.getPrototypeOf(x)); |
+ } |
+ assertWeakObject({}); |
+ assertWeakObject({a: 0, b: 0}); |
+ assertWeakObject({a: [], b: {}}); |
+ assertWeakObject({a: [], b: {}}.b); |
+ assertWeakObject({a: {b: {c: {}}}}.a); |
+ assertWeakObject({a: {b: {c: {}}}}.a.b); |
+ assertWeakObject({a: {b: {c: {}}}}.a.b.c); |
+ assertWeakObject([[1], {}, [[3]]][1]); |
+ assertWeakObject({f: function(){}}); |
+ assertWeakObject( |
+ Realm.eval(Realm.current(), "({f: function(){}})")); |
})(); |
(function StrongObjectLiterals() { |
'use strong'; |
- assertTrue(%IsStrong({})); |
- assertTrue(%IsStrong({a: 0, b: 0})); |
- assertTrue(%IsStrong({a: [], b: {}})); |
- assertTrue(%IsStrong({a: [], b: {}}.a)); |
- assertTrue(%IsStrong({a: [], b: {}}.b)); |
- assertTrue(%IsStrong({a: {b: {c: {}}}}.a)); |
- assertTrue(%IsStrong({a: {b: {c: {}}}}.a.b)); |
- assertTrue(%IsStrong({a: {b: {c: {}}}}.a.b.c)); |
+ function assertStrongObject(x) { |
+ assertTrue(%IsStrong(x)); |
+ // TODO(rossberg) |
+ // assertSame(Object.prototype, Object.getPrototypeOf(x)); |
+ } |
+ assertStrongObject({}); |
+ assertStrongObject({a: 0, b: 0}); |
+ assertStrongObject({a: [], b: {}}); |
+ assertStrongObject({a: [], b: {}}.b); |
+ assertStrongObject({a: {b: {c: {}}}}.a); |
+ assertStrongObject({a: {b: {c: {}}}}.a.b); |
+ assertStrongObject({a: {b: {c: {}}}}.a.b.c); |
// Maps for literals with too many properties are not cached. |
- assertTrue(%IsStrong({ |
+ assertStrongObject({ |
x001: 0, x002: 0, x003: 0, x004: 0, x005: 0, |
x006: 0, x007: 0, x008: 0, x009: 0, x010: 0, |
x011: 0, x012: 0, x013: 0, x014: 0, x015: 0, |
@@ -74,177 +82,226 @@ |
x186: 0, x187: 0, x188: 0, x189: 0, x190: 0, |
x191: 0, x192: 0, x193: 0, x194: 0, x195: 0, |
x196: 0, x197: 0, x198: 0, x199: 0, x200: 0, |
- })); |
- assertTrue(%IsStrong({__proto__: {}, get a() {}, set b(x) {}})); |
- assertTrue(%IsStrong({[Date() + ""]: 0, [Symbol()]: 0})); |
- assertTrue(%IsStrong({m() { super.m() }})); |
+ }); |
+ assertStrongObject([[1], {}, [[3]]][1]); |
+ assertStrongObject({__proto__: {}, get a() {}, set b(x) {}}); |
+ assertStrongObject({[Date() + ""]: 0, [Symbol()]: 0}); |
+ assertStrongObject({m() { super.m() }}); |
// Object literals with constant functions are treated specially, |
// but currently only on the toplevel (using Realm.eval to emulate that). |
- assertTrue(%IsStrong({f: function(){}})); |
- assertTrue(%IsStrong(Realm.eval(Realm.current(), |
- "'use strong'; ({f: function(){}})"))); |
+ assertStrongObject({f: function(){}}); |
+ assertStrongObject( |
+ Realm.eval(Realm.current(), "'use strong'; ({f: function(){}})")); |
})(); |
(function WeakArrayLiterals(...args) { |
+ function assertWeakArray(x) { |
+ assertFalse(%IsStrong(x)); |
+ assertSame(Array.prototype, Object.getPrototypeOf(x)); |
+ } |
let [...r] = []; |
- assertTrue(!%IsStrong(args)); |
- assertTrue(!%IsStrong(r)); |
- assertTrue(!%IsStrong([])); |
- assertTrue(!%IsStrong([1, 2, 3])); |
- assertTrue(!%IsStrong([[[]]])); |
- assertTrue(!%IsStrong([[1], {}, [[3]]])); |
- assertTrue(!%IsStrong([[1], {}, [[3]]][0])); |
- assertTrue(!%IsStrong([[1], {}, [[3]]][1])); |
- assertTrue(!%IsStrong([[1], {}, [[3]]][2])); |
- assertTrue(!%IsStrong([[1], {}, [[3]]][2][0])); |
+ assertWeakArray(args); |
+ assertWeakArray(r); |
+ assertWeakArray([]); |
+ assertWeakArray([1, 2, 3]); |
+ assertWeakArray([1, 2, ...[3, 4], 5]); |
+ assertWeakArray([[[]]]); |
+ assertWeakArray([[1], {}, [[3]]]); |
+ assertWeakArray([[1], {}, [[3]]][0]); |
+ assertWeakArray([[1], {}, [[3]]][2]); |
+ assertWeakArray([[1], {}, [[3]]][2][0]); |
+ assertWeakArray({a: [], b: {}}.a); |
})(); |
(function StrongArrayLiterals(...args) { |
'use strong'; |
+ function assertStrongArray(x) { |
+ assertTrue(%IsStrong(x)); |
+ assertSame(Array.prototype, Object.getPrototypeOf(x)); |
+ } |
let [...r] = []; |
- // TODO(rossberg): teach strongness to FastCloneShallowArrayStub |
- // assertTrue(%IsStrong(args)); |
- // assertTrue(%IsStrong(r)); |
- // assertTrue(%IsStrong([])); |
- // assertTrue(%IsStrong([1, 2, 3])); |
- // assertTrue(%IsStrong([1, 2, ...[3, 4], 5])); |
- assertTrue(%IsStrong([[[]]])); |
- assertTrue(%IsStrong([[1], {}, [[3]]])); |
- assertTrue(%IsStrong([[1], {}, [[3]]][0])); |
- assertTrue(%IsStrong([[1], {}, [[3]]][1])); |
- assertTrue(%IsStrong([[1], {}, [[3]]][2])); |
- assertTrue(%IsStrong([[1], {}, [[3]]][2][0])); |
+ assertStrongArray(args); |
+ assertStrongArray(r); |
+ assertStrongArray([]); |
+ assertStrongArray([1, 2, 3]); |
+ assertStrongArray([1, 2, ...[3, 4], 5]); |
+ assertStrongArray([[[]]]); |
+ assertStrongArray([[1], {}, [[3]]]); |
+ assertStrongArray([[1], {}, [[3]]][0]); |
+ assertStrongArray([[1], {}, [[3]]][2]); |
+ assertStrongArray([[1], {}, [[3]]][2][0]); |
+ assertStrongArray({a: [], b: {}}.a); |
})(); |
(function WeakFunctionLiterals() { |
+ function assertWeakFunction(x) { |
+ assertFalse(%IsStrong(x)); |
+ assertFalse(%IsStrong(x.prototype)); |
+ assertSame(Function.prototype, Object.getPrototypeOf(x)); |
+ } |
function f() {} |
- assertTrue(!%IsStrong(f)); |
- assertTrue(!%IsStrong(function(){})); |
- assertTrue(!%IsStrong(function f(){})); |
- assertTrue(!%IsStrong(() => {})); |
- assertTrue(!%IsStrong(x => x)); |
- assertTrue(!%IsStrong({m(){}}.m)); |
- assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
- {get a(){}}, 'a').get)); |
- assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
- {set a(x){}}, 'a').set)); |
- assertTrue(!%IsStrong((class {static m(){}}).m)); |
- assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
- class {static get a(){}}, 'a').get)); |
- assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
- class {static set a(x){}}, 'a').set)); |
- assertTrue(!%IsStrong((new class {m(){}}).m)); |
- assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
- (class {get a(){}}).prototype, 'a').get)); |
- assertTrue(!%IsStrong(Object.getOwnPropertyDescriptor( |
- (class {set a(x){}}).prototype, 'a').set)); |
+ assertWeakFunction(f); |
+ assertWeakFunction(function(){}); |
+ assertWeakFunction(function f(){}); |
+ assertWeakFunction(() => {}); |
+ assertWeakFunction(x => x); |
+ assertWeakFunction({m(){}}.m); |
+ assertWeakFunction(Object.getOwnPropertyDescriptor( |
+ {get a(){}}, 'a').get); |
+ assertWeakFunction(Object.getOwnPropertyDescriptor( |
+ {set a(x){}}, 'a').set); |
+ assertWeakFunction((class {static m(){}}).m); |
+ assertWeakFunction(Object.getOwnPropertyDescriptor( |
+ class {static get a(){}}, 'a').get); |
+ assertWeakFunction(Object.getOwnPropertyDescriptor( |
+ class {static set a(x){}}, 'a').set); |
+ assertWeakFunction((new class {m(){}}).m); |
+ assertWeakFunction(Object.getOwnPropertyDescriptor( |
+ (class {get a(){}}).prototype, 'a').get); |
+ assertWeakFunction(Object.getOwnPropertyDescriptor( |
+ (class {set a(x){}}).prototype, 'a').set); |
})(); |
(function StrongFunctionLiterals() { |
'use strong'; |
+ function assertStrongFunction(x) { |
+ assertTrue(%IsStrong(x)); |
+ assertFalse('prototype' in x); |
+ assertSame(Function.prototype, Object.getPrototypeOf(x)); |
+ } |
function f() {} |
- assertTrue(%IsStrong(f)); |
- assertTrue(%IsStrong(function(){})); |
- assertTrue(%IsStrong(function f(){})); |
- assertTrue(%IsStrong(() => {})); |
- assertTrue(%IsStrong(x => x)); |
- assertTrue(%IsStrong({m(){}}.m)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- {get a(){}}, 'a').get)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- {set a(x){}}, 'a').set)); |
- assertTrue(%IsStrong((class {static m(){}}).m)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- class {static get a(){}}, 'a').get)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- class {static set a(x){}}, 'a').set)); |
- assertTrue(%IsStrong((new class {m(){}}).m)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- (class {get a(){}}).prototype, 'a').get)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- (class {set a(x){}}).prototype, 'a').set)); |
+ assertStrongFunction(f); |
+ assertStrongFunction(function(){}); |
+ assertStrongFunction(function f(){}); |
+ assertStrongFunction(() => {}); |
+ assertStrongFunction(x => x); |
+ assertStrongFunction({m(){}}.m); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ {get a(){}}, 'a').get); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ {set a(x){}}, 'a').set); |
+ assertStrongFunction((class {static m(){}}).m); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ class {static get a(){}}, 'a').get); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ class {static set a(x){}}, 'a').set); |
+ assertStrongFunction((new class {m(){}}).m); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ (class {get a(){}}).prototype, 'a').get); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ (class {set a(x){}}).prototype, 'a').set); |
})(); |
(function SelfStrongFunctionLiterals() { |
+ function assertStrongFunction(x) { |
+ assertTrue(%IsStrong(x)); |
+ assertFalse('prototype' in x); |
+ assertSame(Function.prototype, Object.getPrototypeOf(x)); |
+ } |
function f() {'use strong'} |
- assertTrue(%IsStrong(f)); |
- assertTrue(%IsStrong(function(){'use strong'})); |
- assertTrue(%IsStrong(function f(){'use strong'})); |
- assertTrue(%IsStrong(() => {'use strong'})); |
- assertTrue(%IsStrong(x => {'use strong'})); |
- assertTrue(%IsStrong({m(){'use strong'}}.m)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- {get a(){'use strong'}}, 'a').get)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- {set a(x){'use strong'}}, 'a').set)); |
- assertTrue(%IsStrong((class {static m(){'use strong'}}).m)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- class {static get a(){'use strong'}}, 'a').get)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- class {static set a(x){'use strong'}}, 'a').set)); |
- assertTrue(%IsStrong((new class {m(){'use strong'}}).m)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- (class {get a(){'use strong'}}).prototype, 'a').get)); |
- assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( |
- (class {set a(x){'use strong'}}).prototype, 'a').set)); |
+ assertStrongFunction(f); |
+ assertStrongFunction(function(){'use strong'}); |
+ assertStrongFunction(function f(){'use strong'}); |
+ assertStrongFunction(() => {'use strong'}); |
+ assertStrongFunction(x => {'use strong'}); |
+ assertStrongFunction({m(){'use strong'}}.m); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ {get a(){'use strong'}}, 'a').get); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ {set a(x){'use strong'}}, 'a').set); |
+ assertStrongFunction((class {static m(){'use strong'}}).m); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ class {static get a(){'use strong'}}, 'a').get); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ class {static set a(x){'use strong'}}, 'a').set); |
+ assertStrongFunction((new class {m(){'use strong'}}).m); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ (class {get a(){'use strong'}}).prototype, 'a').get); |
+ assertStrongFunction(Object.getOwnPropertyDescriptor( |
+ (class {set a(x){'use strong'}}).prototype, 'a').set); |
})(); |
+let GeneratorPrototype = (function*(){}).__proto__; |
+ |
(function WeakGeneratorLiterals() { |
+ function assertWeakGenerator(x) { |
+ assertFalse(%IsStrong(x)); |
+ assertFalse(%IsStrong(x.prototype)); |
+ assertSame(GeneratorPrototype, Object.getPrototypeOf(x)); |
+ assertFalse(%IsStrong(x())); |
+ } |
function* g() {} |
- assertTrue(!%IsStrong(g)); |
- assertTrue(!%IsStrong(function*(){})); |
- assertTrue(!%IsStrong(function* g(){})); |
- assertTrue(!%IsStrong({*m(){}}.m)); |
- assertTrue(!%IsStrong((class {static *m(){}}).m)); |
- assertTrue(!%IsStrong((new class {*m(){}}).m)); |
+ assertWeakGenerator(g); |
+ assertWeakGenerator(function*(){}); |
+ assertWeakGenerator(function* g(){}); |
+ assertWeakGenerator({*m(){}}.m); |
+ assertWeakGenerator((class {static *m(){}}).m); |
+ assertWeakGenerator((new class {*m(){}}).m); |
})(); |
(function StrongGeneratorLiterals() { |
'use strong'; |
+ function assertStrongGenerator(x) { |
+ assertTrue(%IsStrong(x)); |
+ // TODO(rossberg): strongify generator prototypes |
+ // assertTrue(%IsStrong(x.prototype)); |
+ assertSame(GeneratorPrototype, Object.getPrototypeOf(x)); |
+ // TODO(rossberg): strongify generator instances |
+ // assertTrue(%IsStrong(x())); |
+ } |
function* g() {} |
- assertTrue(%IsStrong(g)); |
- assertTrue(%IsStrong(function*(){})); |
- assertTrue(%IsStrong(function* g(){})); |
- assertTrue(%IsStrong({*m(){}}.m)); |
- assertTrue(%IsStrong((class {static *m(){}}).m)); |
- assertTrue(%IsStrong((new class {*m(){}}).m)); |
+ assertStrongGenerator(g); |
+ assertStrongGenerator(function*(){}); |
+ assertStrongGenerator(function* g(){}); |
+ assertStrongGenerator({*m(){}}.m); |
+ assertStrongGenerator((class {static *m(){}}).m); |
+ assertStrongGenerator((new class {*m(){}}).m); |
})(); |
(function SelfStrongGeneratorLiterals() { |
+ function assertStrongGenerator(x) { |
+ assertTrue(%IsStrong(x)); |
+ // TODO(rossberg): strongify generator prototypes |
+ // assertTrue(%IsStrong(x.prototype)); |
+ assertSame(GeneratorPrototype, Object.getPrototypeOf(x)); |
+ // TODO(rossberg): strongify generator instances |
+ // assertTrue(%IsStrong(x())); |
+ } |
function* g() {'use strong'} |
- assertTrue(%IsStrong(g)); |
- assertTrue(%IsStrong(function*(){'use strong'})); |
- assertTrue(%IsStrong(function* g(){'use strong'})); |
- assertTrue(%IsStrong({*m(){'use strong'}}.m)); |
- assertTrue(%IsStrong((class {static *m(){'use strong'}}).m)); |
- assertTrue(%IsStrong((new class {*m(){'use strong'}}).m)); |
+ assertStrongGenerator(g); |
+ assertStrongGenerator(function*(){'use strong'}); |
+ assertStrongGenerator(function* g(){'use strong'}); |
+ assertStrongGenerator({*m(){'use strong'}}.m); |
+ assertStrongGenerator((class {static *m(){'use strong'}}).m); |
+ assertStrongGenerator((new class {*m(){'use strong'}}).m); |
})(); |
(function WeakClassLiterals() { |
- function assertWeakClass(C) { |
- assertTrue(!%IsStrong(C)); |
- assertTrue(!%IsStrong(C.prototype)); |
+ function assertWeakClass(x) { |
+ assertFalse(%IsStrong(x)); |
+ assertFalse(%IsStrong(x.prototype)); |
+ assertFalse(%IsStrong(new x)); |
} |
class C {}; |
class D extends C {}; |
class E extends Object {}; |
- class F extends null {}; |
+ // class F extends null {}; |
const S = (() => {'use strong'; return class {}})(); |
class G extends S {}; |
assertWeakClass(C); |
assertWeakClass(D); |
assertWeakClass(E); |
- assertWeakClass(F); |
+ // assertWeakClass(F); |
assertWeakClass(G); |
assertWeakClass(class {}); |
assertWeakClass(class extends Object {}); |
- assertWeakClass(class extends null {}); |
+ // assertWeakClass(class extends null {}); |
assertWeakClass(class extends C {}); |
assertWeakClass(class extends S {}); |
assertWeakClass(class extends class {} {}); |
assertWeakClass(class C {}); |
assertWeakClass(class D extends Object {}); |
- assertWeakClass(class D extends null {}); |
+ // assertWeakClass(class D extends null {}); |
assertWeakClass(class D extends C {}); |
assertWeakClass(class D extends S {}); |
assertWeakClass(class D extends class {} {}); |
@@ -252,42 +309,45 @@ |
(function StrongClassLiterals() { |
'use strong'; |
- function assertStrongClass(C) { |
- assertTrue(%IsStrong(C)); |
- // TODO(rossberg): prototype object is not yet strongified |
- // assertTrue(%IsStrong(C.prototype)); |
+ function assertStrongClass(x) { |
+ assertTrue(%IsStrong(x)); |
+ // TODO(rossberg): strongify class prototype and instance |
+ // assertTrue(%IsStrong(x.prototype)); |
+ // assertTrue(%IsStrong(new x)); |
} |
class C {}; |
class D extends C {}; |
class E extends Object {}; |
- class F extends null {}; |
const W = (1, eval)(() => {'use strict'; return class {}})(); |
class G extends W {}; |
assertStrongClass(C); |
assertStrongClass(D); |
assertStrongClass(E); |
- assertStrongClass(F); |
assertStrongClass(G); |
assertStrongClass(class {}); |
assertStrongClass(class extends Object {}); |
- assertStrongClass(class extends null {}); |
assertStrongClass(class extends C {}); |
assertStrongClass(class extends W {}); |
assertStrongClass(class extends class {} {}); |
assertStrongClass(class C {}); |
assertStrongClass(class D extends Object {}); |
- assertStrongClass(class D extends null {}); |
assertStrongClass(class D extends C {}); |
assertStrongClass(class D extends W {}); |
assertStrongClass(class D extends class {} {}); |
})(); |
(function WeakRegExpLiterals() { |
- assertTrue(!%IsStrong(/abc/)); |
+ function assertWeakRegExp(x) { |
+ assertFalse(%IsStrong(x)); |
+ } |
+ assertWeakRegExp(/abc/); |
})(); |
(function StrongRegExpLiterals() { |
'use strong'; |
- // TODO(rossberg): implement strong regexp literals |
- // assertTrue(%IsStrong(/abc/)); |
+ function assertStrongRegExp(x) { |
+ // TODO(rossberg): strongify regexps |
+ // assertTrue(%IsStrong(x)); |
+ } |
+ assertStrongRegExp(/abc/); |
})(); |