Commit 092acb2b authored by conradw's avatar conradw Committed by Commit bot

[strong] fix strong array, object prototypes

Strong Object/Array literals are currently being created with incorrect
internal prototypes. This CL fixes this and extends the test suite to check.

BUG=
LOG=N

Review URL: https://codereview.chromium.org/1158933002

Cr-Commit-Position: refs/heads/master@{#28655}
parent 4d6f1abb
...@@ -534,7 +534,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { ...@@ -534,7 +534,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
// Allocate initial strong object map. // Allocate initial strong object map.
Handle<Map> strong_object_map = Handle<Map> strong_object_map =
Map::Copy(object_function_map, "EmptyStrongObject"); Map::Copy(Handle<Map>(object_fun->initial_map()), "EmptyStrongObject");
strong_object_map->set_is_strong(); strong_object_map->set_is_strong();
native_context()->set_js_object_strong_map(*strong_object_map); native_context()->set_js_object_strong_map(*strong_object_map);
} }
......
...@@ -10368,8 +10368,7 @@ void JSFunction::SetInstancePrototype(Handle<JSFunction> function, ...@@ -10368,8 +10368,7 @@ void JSFunction::SetInstancePrototype(Handle<JSFunction> function,
if (array_function->IsJSFunction() && if (array_function->IsJSFunction() &&
*function == JSFunction::cast(*array_function)) { *function == JSFunction::cast(*array_function)) {
CacheInitialJSArrayMaps(native_context, new_map); CacheInitialJSArrayMaps(native_context, new_map);
Handle<Map> new_strong_map = Handle<Map> new_strong_map = Map::Copy(new_map, "SetInstancePrototype");
Map::Copy(initial_map, "SetInstancePrototype");
new_strong_map->set_is_strong(); new_strong_map->set_is_strong();
CacheInitialJSArrayMaps(native_context, new_strong_map); CacheInitialJSArrayMaps(native_context, new_strong_map);
} }
......
...@@ -8,6 +8,28 @@ ...@@ -8,6 +8,28 @@
'use strict'; 'use strict';
let GeneratorFunctionPrototype = (function*(){}).__proto__;
function assertStrongObject(o) {
assertTrue(%IsStrong(o));
assertSame(Object.prototype, o.__proto__);
}
function assertStrongArray(a) {
assertTrue(%IsStrong(a));
assertSame(Array.prototype, a.__proto__);
}
function assertStrongFunction(f) {
assertTrue(%IsStrong(f));
assertSame(Function.prototype, f.__proto__);
}
function assertStrongGenerator(g) {
assertTrue(%IsStrong(g));
assertSame(GeneratorFunctionPrototype, g.__proto__);
}
(function WeakObjectLiterals() { (function WeakObjectLiterals() {
assertTrue(!%IsStrong({})); assertTrue(!%IsStrong({}));
assertTrue(!%IsStrong({a: 0, b: 0})); assertTrue(!%IsStrong({a: 0, b: 0}));
...@@ -24,16 +46,16 @@ ...@@ -24,16 +46,16 @@
(function StrongObjectLiterals() { (function StrongObjectLiterals() {
'use strong'; 'use strong';
assertTrue(%IsStrong({})); assertStrongObject({});
assertTrue(%IsStrong({a: 0, b: 0})); assertStrongObject({a: 0, b: 0});
assertTrue(%IsStrong({a: [], b: {}})); assertStrongObject({a: [], b: {}});
assertTrue(%IsStrong({a: [], b: {}}.a)); assertStrongArray({a: [], b: {}}.a);
assertTrue(%IsStrong({a: [], b: {}}.b)); assertStrongObject({a: [], b: {}}.b);
assertTrue(%IsStrong({a: {b: {c: {}}}}.a)); assertStrongObject({a: {b: {c: {}}}}.a);
assertTrue(%IsStrong({a: {b: {c: {}}}}.a.b)); assertStrongObject({a: {b: {c: {}}}}.a.b);
assertTrue(%IsStrong({a: {b: {c: {}}}}.a.b.c)); assertStrongObject({a: {b: {c: {}}}}.a.b.c);
// Maps for literals with too many properties are not cached. // Maps for literals with too many properties are not cached.
assertTrue(%IsStrong({ assertStrongObject({
x001: 0, x002: 0, x003: 0, x004: 0, x005: 0, x001: 0, x002: 0, x003: 0, x004: 0, x005: 0,
x006: 0, x007: 0, x008: 0, x009: 0, x010: 0, x006: 0, x007: 0, x008: 0, x009: 0, x010: 0,
x011: 0, x012: 0, x013: 0, x014: 0, x015: 0, x011: 0, x012: 0, x013: 0, x014: 0, x015: 0,
...@@ -74,15 +96,15 @@ ...@@ -74,15 +96,15 @@
x186: 0, x187: 0, x188: 0, x189: 0, x190: 0, x186: 0, x187: 0, x188: 0, x189: 0, x190: 0,
x191: 0, x192: 0, x193: 0, x194: 0, x195: 0, x191: 0, x192: 0, x193: 0, x194: 0, x195: 0,
x196: 0, x197: 0, x198: 0, x199: 0, x200: 0, x196: 0, x197: 0, x198: 0, x199: 0, x200: 0,
})); });
assertTrue(%IsStrong({__proto__: {}, get a() {}, set b(x) {}})); assertStrongObject({[Date() + ""]: 0, [Symbol()]: 0});
assertTrue(%IsStrong({[Date() + ""]: 0, [Symbol()]: 0})); assertStrongObject({m() { super.m() }});
assertTrue(%IsStrong({m() { super.m() }}));
// Object literals with constant functions are treated specially, // Object literals with constant functions are treated specially,
// but currently only on the toplevel (using Realm.eval to emulate that). // but currently only on the toplevel (using Realm.eval to emulate that).
assertTrue(%IsStrong({f: function(){}})); assertStrongObject({f: function(){}});
assertTrue(%IsStrong(Realm.eval(Realm.current(), assertStrongObject(Realm.eval(Realm.current(),
"'use strong'; ({f: function(){}})"))); "'use strong'; ({f: function(){}})"));
assertTrue(%IsStrong({__proto__: {}, get a() {}, set b(x) {}}));
})(); })();
(function WeakArrayLiterals(...args) { (function WeakArrayLiterals(...args) {
...@@ -108,12 +130,12 @@ ...@@ -108,12 +130,12 @@
// assertTrue(%IsStrong([])); // assertTrue(%IsStrong([]));
// assertTrue(%IsStrong([1, 2, 3])); // assertTrue(%IsStrong([1, 2, 3]));
// assertTrue(%IsStrong([1, 2, ...[3, 4], 5])); // assertTrue(%IsStrong([1, 2, ...[3, 4], 5]));
assertTrue(%IsStrong([[[]]])); assertStrongArray([[[]]]);
assertTrue(%IsStrong([[1], {}, [[3]]])); assertStrongArray([[1], {}, [[3]]]);
assertTrue(%IsStrong([[1], {}, [[3]]][0])); assertStrongArray([[1], {}, [[3]]][0]);
assertTrue(%IsStrong([[1], {}, [[3]]][1])); assertStrongObject([[1], {}, [[3]]][1]);
assertTrue(%IsStrong([[1], {}, [[3]]][2])); assertStrongArray([[1], {}, [[3]]][2]);
assertTrue(%IsStrong([[1], {}, [[3]]][2][0])); assertStrongArray([[1], {}, [[3]]][2][0]);
})(); })();
(function WeakFunctionLiterals() { (function WeakFunctionLiterals() {
...@@ -143,50 +165,50 @@ ...@@ -143,50 +165,50 @@
(function StrongFunctionLiterals() { (function StrongFunctionLiterals() {
'use strong'; 'use strong';
function f() {} function f() {}
assertTrue(%IsStrong(f)); assertStrongFunction(f);
assertTrue(%IsStrong(function(){})); assertStrongFunction(function(){});
assertTrue(%IsStrong(function f(){})); assertStrongFunction(function f(){});
assertTrue(%IsStrong(() => {})); assertStrongFunction(() => {});
assertTrue(%IsStrong(x => x)); assertStrongFunction(x => x);
assertTrue(%IsStrong({m(){}}.m)); assertStrongFunction({m(){}}.m);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
{get a(){}}, 'a').get)); {get a(){}}, 'a').get);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
{set a(x){}}, 'a').set)); {set a(x){}}, 'a').set);
assertTrue(%IsStrong((class {static m(){}}).m)); assertStrongFunction((class {static m(){}}).m);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
class {static get a(){}}, 'a').get)); class {static get a(){}}, 'a').get);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
class {static set a(x){}}, 'a').set)); class {static set a(x){}}, 'a').set);
assertTrue(%IsStrong((new class {m(){}}).m)); assertStrongFunction((new class {m(){}}).m);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
(class {get a(){}}).prototype, 'a').get)); (class {get a(){}}).prototype, 'a').get);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
(class {set a(x){}}).prototype, 'a').set)); (class {set a(x){}}).prototype, 'a').set);
})(); })();
(function SelfStrongFunctionLiterals() { (function SelfStrongFunctionLiterals() {
function f() {'use strong'} function f() {'use strong'}
assertTrue(%IsStrong(f)); assertStrongFunction(f);
assertTrue(%IsStrong(function(){'use strong'})); assertStrongFunction(function(){'use strong'});
assertTrue(%IsStrong(function f(){'use strong'})); assertStrongFunction(function f(){'use strong'});
assertTrue(%IsStrong(() => {'use strong'})); assertStrongFunction(() => {'use strong'});
assertTrue(%IsStrong(x => {'use strong'})); assertStrongFunction(x => {'use strong'});
assertTrue(%IsStrong({m(){'use strong'}}.m)); assertStrongFunction({m(){'use strong'}}.m);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
{get a(){'use strong'}}, 'a').get)); {get a(){'use strong'}}, 'a').get);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
{set a(x){'use strong'}}, 'a').set)); {set a(x){'use strong'}}, 'a').set);
assertTrue(%IsStrong((class {static m(){'use strong'}}).m)); assertStrongFunction((class {static m(){'use strong'}}).m);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
class {static get a(){'use strong'}}, 'a').get)); class {static get a(){'use strong'}}, 'a').get);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
class {static set a(x){'use strong'}}, 'a').set)); class {static set a(x){'use strong'}}, 'a').set);
assertTrue(%IsStrong((new class {m(){'use strong'}}).m)); assertStrongFunction((new class {m(){'use strong'}}).m);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
(class {get a(){'use strong'}}).prototype, 'a').get)); (class {get a(){'use strong'}}).prototype, 'a').get);
assertTrue(%IsStrong(Object.getOwnPropertyDescriptor( assertStrongFunction(Object.getOwnPropertyDescriptor(
(class {set a(x){'use strong'}}).prototype, 'a').set)); (class {set a(x){'use strong'}}).prototype, 'a').set);
})(); })();
(function WeakGeneratorLiterals() { (function WeakGeneratorLiterals() {
...@@ -202,22 +224,22 @@ ...@@ -202,22 +224,22 @@
(function StrongGeneratorLiterals() { (function StrongGeneratorLiterals() {
'use strong'; 'use strong';
function* g() {} function* g() {}
assertTrue(%IsStrong(g)); assertStrongGenerator(g);
assertTrue(%IsStrong(function*(){})); assertStrongGenerator(function*(){});
assertTrue(%IsStrong(function* g(){})); assertStrongGenerator(function* g(){});
assertTrue(%IsStrong({*m(){}}.m)); assertStrongGenerator({*m(){}}.m);
assertTrue(%IsStrong((class {static *m(){}}).m)); assertStrongGenerator((class {static *m(){}}).m);
assertTrue(%IsStrong((new class {*m(){}}).m)); assertStrongGenerator((new class {*m(){}}).m);
})(); })();
(function SelfStrongGeneratorLiterals() { (function SelfStrongGeneratorLiterals() {
function* g() {'use strong'} function* g() {'use strong'}
assertTrue(%IsStrong(g)); assertStrongGenerator(g);
assertTrue(%IsStrong(function*(){'use strong'})); assertStrongGenerator(function*(){'use strong'});
assertTrue(%IsStrong(function* g(){'use strong'})); assertStrongGenerator(function* g(){'use strong'});
assertTrue(%IsStrong({*m(){'use strong'}}.m)); assertStrongGenerator({*m(){'use strong'}}.m);
assertTrue(%IsStrong((class {static *m(){'use strong'}}).m)); assertStrongGenerator((class {static *m(){'use strong'}}).m);
assertTrue(%IsStrong((new class {*m(){'use strong'}}).m)); assertStrongGenerator((new class {*m(){'use strong'}}).m);
})(); })();
(function WeakClassLiterals() { (function WeakClassLiterals() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment