зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1505574 - Remove Unboxed Objects Test code r=iain
Differential Revision: https://phabricator.services.mozilla.com/D24049 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
872e0839a3
Коммит
0f83342537
|
@ -1,85 +0,0 @@
|
|||
load(libdir + "asserts.js");
|
||||
|
||||
function Unboxed() {
|
||||
this.a = 0;
|
||||
this.b = true;
|
||||
}
|
||||
|
||||
function tryCreateUnboxedObject() {
|
||||
var obj;
|
||||
for (var i = 0; i < 1000; ++i) {
|
||||
obj = new Unboxed();
|
||||
}
|
||||
if (unboxedObjectsEnabled())
|
||||
assertEq(isUnboxedObject(obj), true);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function basic() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
|
||||
var target = {};
|
||||
Object.assign(target, unboxed);
|
||||
assertDeepEq(target, {a: 0, b: true});
|
||||
|
||||
target = {a: 1, c: 3};
|
||||
Object.assign(target, unboxed);
|
||||
assertDeepEq(target, {a: 0, c: 3, b: true});
|
||||
}
|
||||
|
||||
function expando() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
unboxed.c = 3.5;
|
||||
|
||||
var target = {};
|
||||
Object.assign(target, unboxed);
|
||||
assertDeepEq(target, {a: 0, b: true, c: 3.5});
|
||||
|
||||
target = {a: 1, d: 3};
|
||||
Object.assign(target, unboxed);
|
||||
assertDeepEq(target, {a: 0, d: 3, b: true, c: 3.5});
|
||||
}
|
||||
|
||||
function addExpando() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
|
||||
function setA(value) {
|
||||
assertEq(value, 0);
|
||||
unboxed.c = 3.5;
|
||||
}
|
||||
|
||||
var target = {};
|
||||
Object.defineProperty(target, "a", {set: setA});
|
||||
|
||||
var reference = {};
|
||||
Object.defineProperty(reference, "a", {set: setA});
|
||||
Object.defineProperty(reference, "b", {value: true, enumerable: true, configurable: true, writable: true});
|
||||
|
||||
Object.assign(target, unboxed);
|
||||
assertDeepEq(target, reference);
|
||||
}
|
||||
|
||||
function makeNative() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
|
||||
function setA(value) {
|
||||
assertEq(value, 0);
|
||||
Object.defineProperty(unboxed, "a", {writable: false});
|
||||
}
|
||||
|
||||
var target = {};
|
||||
Object.defineProperty(target, "a", {set: setA});
|
||||
|
||||
var reference = {};
|
||||
Object.defineProperty(reference, "a", {set: setA});
|
||||
Object.defineProperty(reference, "b", {value: true, enumerable: true, configurable: true, writable: true});
|
||||
|
||||
Object.assign(target, unboxed);
|
||||
assertDeepEq(target, reference);
|
||||
}
|
||||
|
||||
|
||||
basic();
|
||||
expando();
|
||||
addExpando();
|
||||
makeNative();
|
|
@ -1,44 +0,0 @@
|
|||
load(libdir + "asserts.js");
|
||||
|
||||
function Unboxed() {
|
||||
this.a = 0;
|
||||
this.b = true;
|
||||
}
|
||||
|
||||
function tryCreateUnboxedObject() {
|
||||
var obj;
|
||||
for (var i = 0; i < 1000; ++i) {
|
||||
obj = new Unboxed();
|
||||
}
|
||||
if (unboxedObjectsEnabled())
|
||||
assertEq(isUnboxedObject(obj), true);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function basic() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
|
||||
var {...target} = unboxed;
|
||||
assertDeepEq(target, {a: 0, b: true});
|
||||
|
||||
var {a, c, ...target} = unboxed;
|
||||
assertDeepEq(a, 0);
|
||||
assertDeepEq(c, undefined);
|
||||
assertDeepEq(target, {b: true});
|
||||
}
|
||||
|
||||
function expando() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
unboxed.c = 3.5;
|
||||
|
||||
var {...target} = unboxed;
|
||||
assertDeepEq(target, {a: 0, b: true, c: 3.5});
|
||||
|
||||
var {a, d, ...target} = unboxed;
|
||||
assertDeepEq(a, 0);
|
||||
assertDeepEq(d, undefined);
|
||||
assertDeepEq(target, {b: true, c: 3.5});
|
||||
}
|
||||
|
||||
basic();
|
||||
expando();
|
|
@ -1,40 +0,0 @@
|
|||
load(libdir + "asserts.js");
|
||||
|
||||
function Unboxed() {
|
||||
this.a = 0;
|
||||
this.b = true;
|
||||
}
|
||||
|
||||
function tryCreateUnboxedObject() {
|
||||
var obj;
|
||||
for (var i = 0; i < 1000; ++i) {
|
||||
obj = new Unboxed();
|
||||
}
|
||||
if (unboxedObjectsEnabled())
|
||||
assertEq(isUnboxedObject(obj), true);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function basic() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
|
||||
var target = {...unboxed};
|
||||
assertDeepEq(target, {a: 0, b: true});
|
||||
|
||||
target = {a: 1, c: 3, ...unboxed};
|
||||
assertDeepEq(target, {a: 0, c: 3, b: true});
|
||||
}
|
||||
|
||||
function expando() {
|
||||
var unboxed = tryCreateUnboxedObject();
|
||||
unboxed.c = 3.5;
|
||||
|
||||
var target = {...unboxed};
|
||||
assertDeepEq(target, {a: 0, b: true, c: 3.5});
|
||||
|
||||
target = {a: 1, d: 3, ...unboxed};
|
||||
assertDeepEq(target, {a: 0, d: 3, b: true, c: 3.5});
|
||||
}
|
||||
|
||||
basic();
|
||||
expando();
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
function Foo(a, b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
function invalidate_foo() {
|
||||
var a = [];
|
||||
var counter = 0;
|
||||
for (var i = 0; i < 50; i++)
|
||||
a.push(new Foo(i, i + 1));
|
||||
Object.defineProperty(Foo.prototype, "a", {configurable: true, set: function() { counter++; }});
|
||||
for (var i = 0; i < 50; i++)
|
||||
a.push(new Foo(i, i + 1));
|
||||
delete Foo.prototype.a;
|
||||
var total = 0;
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
assertEq('a' in a[i], i < 50);
|
||||
total += a[i].b;
|
||||
}
|
||||
assertEq(total, 2550);
|
||||
assertEq(counter, 50);
|
||||
}
|
||||
invalidate_foo();
|
||||
|
||||
function Bar(a, b, fn) {
|
||||
this.a = a;
|
||||
if (b == 30)
|
||||
Object.defineProperty(Bar.prototype, "b", {configurable: true, set: fn});
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
function invalidate_bar() {
|
||||
var a = [];
|
||||
var counter = 0;
|
||||
function fn() { counter++; }
|
||||
for (var i = 0; i < 50; i++)
|
||||
a.push(new Bar(i, i + 1, fn));
|
||||
delete Bar.prototype.b;
|
||||
var total = 0;
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
assertEq('a' in a[i], true);
|
||||
assertEq('b' in a[i], i < 29);
|
||||
total += a[i].a;
|
||||
}
|
||||
assertEq(total, 1225);
|
||||
assertEq(counter, 21);
|
||||
}
|
||||
invalidate_bar();
|
|
@ -1,47 +0,0 @@
|
|||
|
||||
// Test various ways of converting an unboxed object to native.
|
||||
|
||||
function Foo(a, b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
var proxyObj = {
|
||||
get: function(recipient, name) {
|
||||
return recipient[name] + 2;
|
||||
}
|
||||
};
|
||||
|
||||
function f() {
|
||||
var a = [];
|
||||
for (var i = 0; i < 50; i++)
|
||||
a.push(new Foo(i, i + 1));
|
||||
|
||||
var prop = "a";
|
||||
|
||||
i = 0;
|
||||
for (; i < 5; i++)
|
||||
a[i].c = i;
|
||||
for (; i < 10; i++)
|
||||
Object.defineProperty(a[i], 'c', {value: i});
|
||||
for (; i < 15; i++)
|
||||
a[i] = new Proxy(a[i], proxyObj);
|
||||
for (; i < 20; i++)
|
||||
a[i].a = 3.5;
|
||||
for (; i < 25; i++)
|
||||
delete a[i].b;
|
||||
for (; i < 30; i++)
|
||||
a[prop] = 4;
|
||||
|
||||
var total = 0;
|
||||
for (i = 0; i < a.length; i++) {
|
||||
if ('a' in a[i])
|
||||
total += a[i].a;
|
||||
if ('b' in a[i])
|
||||
total += a[i].b;
|
||||
if ('c' in a[i])
|
||||
total += a[i].c;
|
||||
}
|
||||
assertEq(total, 2382.5);
|
||||
}
|
||||
f();
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
function f() {
|
||||
var propNames = ["a","b","c","d","e","f","g","h","i","j","x","y"];
|
||||
var arr = [];
|
||||
for (var i=0; i<64; i++)
|
||||
arr.push({x:1, y:2});
|
||||
for (var i=0; i<64; i++) {
|
||||
// Make sure there are expandos with dynamic slots for each object.
|
||||
for (var j = 0; j < propNames.length; j++)
|
||||
arr[i][propNames[j]] = j;
|
||||
}
|
||||
var res = 0;
|
||||
for (var i=0; i<100000; i++) {
|
||||
var o = arr[i % 64];
|
||||
var p = propNames[i % propNames.length];
|
||||
res += o[p];
|
||||
}
|
||||
assertEq(res, 549984);
|
||||
}
|
||||
f();
|
|
@ -1,31 +0,0 @@
|
|||
|
||||
// Use the correct receiver when non-native objects are prototypes of other objects.
|
||||
|
||||
function Thing(a, b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
function foo() {
|
||||
var array = [];
|
||||
for (var i = 0; i < 10000; i++)
|
||||
array.push(new Thing(i, i + 1));
|
||||
|
||||
var proto = new Thing(1, 2);
|
||||
var obj = Object.create(proto);
|
||||
|
||||
Object.defineProperty(Thing.prototype, "c", {set:function() { this.d = 0; }});
|
||||
obj.c = 3;
|
||||
assertEq(obj.c, undefined);
|
||||
assertEq(obj.d, 0);
|
||||
assertEq(obj.hasOwnProperty("d"), true);
|
||||
assertEq(proto.d, undefined);
|
||||
assertEq(proto.hasOwnProperty("d"), false);
|
||||
|
||||
obj.a = 3;
|
||||
assertEq(obj.a, 3);
|
||||
assertEq(proto.a, 1);
|
||||
assertEq(obj.hasOwnProperty("a"), true);
|
||||
}
|
||||
|
||||
foo();
|
|
@ -1,52 +0,0 @@
|
|||
load(libdir + "asserts.js");
|
||||
|
||||
function O() {
|
||||
this.x = 1;
|
||||
this.y = 2;
|
||||
}
|
||||
|
||||
var arr = [];
|
||||
for (var i = 0; i < 30; i++)
|
||||
arr.push(new O);
|
||||
|
||||
function testExpandos() {
|
||||
var o = arr[arr.length-1];
|
||||
if (unboxedObjectsEnabled())
|
||||
assertEq(isUnboxedObject(o), true);
|
||||
o[0] = 0;
|
||||
o[2] = 2;
|
||||
var sym = Symbol();
|
||||
o[sym] = 1;
|
||||
o.z = 3;
|
||||
Object.defineProperty(o, '3', {value:1,enumerable:false,configurable:false,writable:false});
|
||||
o[4] = 4;
|
||||
|
||||
var props = Reflect.ownKeys(o);
|
||||
assertEq(props[props.length-1], sym);
|
||||
|
||||
assertEq(Object.getOwnPropertyNames(o).join(""), "0234xyz");
|
||||
if (unboxedObjectsEnabled())
|
||||
assertEq(isUnboxedObject(o), true, "Object should still be unboxed");
|
||||
}
|
||||
testExpandos();
|
||||
|
||||
function testBasic() {
|
||||
var o = arr[arr.length - 2];
|
||||
if (unboxedObjectsEnabled())
|
||||
assertEq(isUnboxedObject(o), true);
|
||||
|
||||
var keys = Object.keys(o);
|
||||
assertDeepEq(keys, ["x", "y"]);
|
||||
|
||||
var names = Object.getOwnPropertyNames(o);
|
||||
assertDeepEq(names, ["x", "y"]);
|
||||
|
||||
var values = Object.values(o);
|
||||
assertDeepEq(values, [1, 2]);
|
||||
|
||||
var entries = Object.entries(o);
|
||||
assertDeepEq(entries, [["x", 1], ["y", 2]]);
|
||||
if (unboxedObjectsEnabled())
|
||||
assertEq(isUnboxedObject(o), true, "Object should still be unboxed");
|
||||
}
|
||||
testBasic();
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -6557,21 +6557,6 @@ static bool IsLatin1(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool UnboxedObjectsEnabled(JSContext* cx, unsigned argc, Value* vp) {
|
||||
// Note: this also returns |false| if we're using --ion-eager or if the
|
||||
// JITs are disabled, since that affects how unboxed objects are used.
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
args.rval().setBoolean(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsUnboxedObject(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
args.rval().setBoolean(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HasCopyOnWriteElements(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
args.rval().setBoolean(
|
||||
|
@ -8862,14 +8847,6 @@ JS_FN_HELP("parseBin", BinParse, 1, 0,
|
|||
"isLatin1(s)",
|
||||
" Return true iff the string's characters are stored as Latin1."),
|
||||
|
||||
JS_FN_HELP("unboxedObjectsEnabled", UnboxedObjectsEnabled, 0, 0,
|
||||
"unboxedObjectsEnabled()",
|
||||
" Return true if unboxed objects are enabled."),
|
||||
|
||||
JS_FN_HELP("isUnboxedObject", IsUnboxedObject, 1, 0,
|
||||
"isUnboxedObject(o)",
|
||||
" Return true iff the object is an unboxed object."),
|
||||
|
||||
JS_FN_HELP("hasCopyOnWriteElements", HasCopyOnWriteElements, 1, 0,
|
||||
"hasCopyOnWriteElements(o)",
|
||||
" Return true iff the object has copy-on-write dense elements."),
|
||||
|
|
Загрузка…
Ссылка в новой задаче