mirror of https://github.com/tc39/test262.git
[v8-test262-automation] Changes from https://github.com/v8/v8.git at sha 06354392 on Fri Sep 21 2018 18:29:36 GMT+0000 (Coordinated Universal Time)
This commit is contained in:
parent
89ec038cf2
commit
eeae2a723a
|
@ -1,54 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --allow-natives-syntax
|
||||
|
||||
assertEquals(1, %ToPrimitive(1));
|
||||
assertEquals(1, %ToPrimitive_Number(1));
|
||||
|
||||
assertEquals(.5, %ToPrimitive(.5));
|
||||
assertEquals(.5, %ToPrimitive_Number(.5));
|
||||
|
||||
assertEquals(null, %ToPrimitive(null));
|
||||
assertEquals(null, %ToPrimitive_Number(null));
|
||||
|
||||
assertEquals(true, %ToPrimitive(true));
|
||||
assertEquals(true, %ToPrimitive_Number(true));
|
||||
|
||||
assertEquals(false, %ToPrimitive(false));
|
||||
assertEquals(false, %ToPrimitive_Number(false));
|
||||
|
||||
assertEquals(undefined, %ToPrimitive(undefined));
|
||||
assertEquals(undefined, %ToPrimitive_Number(undefined));
|
||||
|
||||
assertEquals("random text", %ToPrimitive("random text"));
|
||||
assertEquals("random text", %ToPrimitive_Number("random text"));
|
||||
|
||||
assertEquals(Symbol.toPrimitive, %ToPrimitive(Symbol.toPrimitive));
|
||||
assertEquals(Symbol.toPrimitive, %ToPrimitive_Number(Symbol.toPrimitive));
|
||||
|
||||
var a = { toString: function() { return "xyz" }};
|
||||
assertEquals("xyz", %ToPrimitive(a));
|
||||
assertEquals("xyz", %ToPrimitive_Number(a));
|
||||
|
||||
var b = { valueOf: function() { return 42 }};
|
||||
assertEquals(42, %ToPrimitive(b));
|
||||
assertEquals(42, %ToPrimitive_Number(b));
|
||||
|
||||
var c = {
|
||||
toString: function() { return "x"},
|
||||
valueOf: function() { return 123 }
|
||||
};
|
||||
assertEquals(123, %ToPrimitive(c));
|
||||
assertEquals(123, %ToPrimitive_Number(c));
|
||||
|
||||
var d = {
|
||||
[Symbol.toPrimitive]: function(hint) { return hint }
|
||||
};
|
||||
assertEquals("default", %ToPrimitive(d));
|
||||
assertEquals("number", %ToPrimitive_Number(d));
|
||||
|
||||
var e = new Date(0);
|
||||
assertEquals(e.toString(), %ToPrimitive(e));
|
||||
assertEquals(0, %ToPrimitive_Number(e));
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
// Throw rather than overflow internal field index
|
||||
assertThrows(function() {
|
||||
Worker.prototype.terminate();
|
||||
});
|
||||
|
||||
assertThrows(function() {
|
||||
Worker.prototype.getMessage();
|
||||
});
|
||||
|
||||
assertThrows(function() {
|
||||
Worker.prototype.postMessage({});
|
||||
});
|
||||
|
||||
// Don't throw for real worker
|
||||
var worker = new Worker('');
|
||||
worker.getMessage();
|
||||
worker.postMessage({});
|
||||
worker.terminate();
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker && this.quit) {
|
||||
try {
|
||||
new Function(new Worker("55"));
|
||||
} catch(err) {}
|
||||
|
||||
quit();
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
const worker = new Worker("onmessage = function(){}");
|
||||
const buffer = new ArrayBuffer();
|
||||
worker.postMessage(buffer, [buffer]);
|
||||
try {
|
||||
worker.postMessage(buffer, [buffer]);
|
||||
} catch (e) {
|
||||
if (e != "ArrayBuffer could not be transferred") {
|
||||
throw e;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
function __f_0(byteLength) {
|
||||
var __v_1 = new ArrayBuffer(byteLength);
|
||||
var __v_5 = new Uint32Array(__v_1);
|
||||
return __v_5;
|
||||
}
|
||||
var __v_6 = new Worker('onmessage = function() {}');
|
||||
var __v_3 = __f_0(16);
|
||||
__v_6.postMessage(__v_3);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --invoke-weak-callbacks
|
||||
|
||||
if (this.Worker) {
|
||||
var __v_6 = new Worker('');
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
function __f_0() { this.s = new Object(); }
|
||||
function __f_1() {
|
||||
this.l = [new __f_0, new __f_0];
|
||||
}
|
||||
__v_6 = new __f_1;
|
||||
var __v_9 = new Worker('');
|
||||
__v_9.postMessage(__v_6);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
__v_3 = "";
|
||||
var __v_6 = new Worker('');
|
||||
__v_6.postMessage(__v_3);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
var __v_10 = new Worker('');
|
||||
__v_10.terminate();
|
||||
__v_10.getMessage();
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --no-test
|
||||
|
||||
if (this.Worker) {
|
||||
var __v_2 = new Worker('');
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
Function.prototype.toString = "foo";
|
||||
function __f_7() {}
|
||||
assertThrows(function() { var __v_5 = new Worker(__f_7.toString()); });
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
var __v_7 = new Worker('onmessage = function() {}');
|
||||
__v_7.postMessage("");
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
var __v_5 = {};
|
||||
__v_5.__defineGetter__('byteLength', function() {foo();});
|
||||
var __v_8 = new Worker('onmessage = function() {};');
|
||||
assertThrows(function() { __v_8.postMessage(__v_5); });
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
var __v_8 =
|
||||
`var __v_9 = new Worker('postMessage(42)');
|
||||
onmessage = function(parentMsg) {
|
||||
__v_9.postMessage(parentMsg);
|
||||
};`;
|
||||
var __v_9 = new Worker(__v_8);
|
||||
__v_9.postMessage(9);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
var __v_7 = new Worker('onmessage = function() {};');
|
||||
var e;
|
||||
var ab = new ArrayBuffer(2 * 1000 * 1000);
|
||||
try {
|
||||
__v_7.postMessage(ab);
|
||||
threw = false;
|
||||
} catch (e) {
|
||||
// postMessage failed, should be a DataCloneError message.
|
||||
assertContains('cloned', e.message);
|
||||
threw = true;
|
||||
}
|
||||
assertTrue(threw, 'Should throw when trying to serialize large message.');
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
Worker.prototype = 12;
|
||||
var __v_6 = new Worker('');
|
||||
__v_6.postMessage([]);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
if (this.Worker) {
|
||||
var worker = new Worker("onmessage = function(){}");
|
||||
var buf = new ArrayBuffer();
|
||||
worker.postMessage(buf, [buf]);
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
let sab = new SharedArrayBuffer(10 * 4);
|
||||
let memory = new Int32Array(sab);
|
||||
let workers = [];
|
||||
let runningWorkers = 0;
|
||||
|
||||
function startWorker(script) {
|
||||
let worker = new Worker(script);
|
||||
worker.done = false;
|
||||
worker.idx = workers.length;
|
||||
workers.push(worker);
|
||||
worker.postMessage(memory);
|
||||
++runningWorkers;
|
||||
};
|
||||
|
||||
let shared = `
|
||||
function wait(memory, index, waitCondition, wakeCondition) {
|
||||
while (memory[index] == waitCondition) {
|
||||
var result = Atomics.wait(memory, index, waitCondition);
|
||||
switch (result) {
|
||||
case 'not-equal':
|
||||
case 'ok':
|
||||
break;
|
||||
default:
|
||||
postMessage('Error: bad result from wait: ' + result);
|
||||
break;
|
||||
}
|
||||
var value = memory[index];
|
||||
if (value != wakeCondition) {
|
||||
postMessage(
|
||||
'Error: wait returned not-equal but the memory has a bad value: ' +
|
||||
value);
|
||||
}
|
||||
}
|
||||
var value = memory[index];
|
||||
if (value != wakeCondition) {
|
||||
postMessage(
|
||||
'Error: done waiting but the memory has a bad value: ' + value);
|
||||
}
|
||||
}
|
||||
|
||||
function wake(memory, index) {
|
||||
var result = Atomics.wake(memory, index, 1);
|
||||
if (result != 0 && result != 1) {
|
||||
postMessage('Error: bad result from wake: ' + result);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
let worker1 = startWorker(shared + `
|
||||
onmessage = function(msg) {
|
||||
let memory = msg;
|
||||
const didStartIdx = 0;
|
||||
const shouldGoIdx = 1;
|
||||
const didEndIdx = 2;
|
||||
|
||||
postMessage("started");
|
||||
postMessage("memory: " + memory);
|
||||
wait(memory, didStartIdx, 0, 1);
|
||||
memory[shouldGoIdx] = 1;
|
||||
wake(memory, shouldGoIdx);
|
||||
wait(memory, didEndIdx, 0, 1);
|
||||
postMessage("memory: " + memory);
|
||||
postMessage("done");
|
||||
};
|
||||
`);
|
||||
|
||||
let worker2 = startWorker(shared + `
|
||||
onmessage = function(msg) {
|
||||
let memory = msg;
|
||||
const didStartIdx = 0;
|
||||
const shouldGoIdx = 1;
|
||||
const didEndIdx = 2;
|
||||
|
||||
postMessage("started");
|
||||
postMessage("memory: " + memory);
|
||||
Atomics.store(memory, didStartIdx, 1);
|
||||
wake(memory, didStartIdx);
|
||||
wait(memory, shouldGoIdx, 0, 1);
|
||||
Atomics.store(memory, didEndIdx, 1);
|
||||
wake(memory, didEndIdx, 1);
|
||||
postMessage("memory: " + memory);
|
||||
postMessage("done");
|
||||
};
|
||||
`);
|
||||
|
||||
let running = true;
|
||||
while (running) {
|
||||
for (let worker of workers) {
|
||||
if (worker.done) continue;
|
||||
|
||||
let msg = worker.getMessage();
|
||||
if (msg) {
|
||||
switch (msg) {
|
||||
case "done":
|
||||
if (worker.done === false) {
|
||||
print("worker #" + worker.idx + " done.");
|
||||
worker.done = true;
|
||||
if (--runningWorkers === 0) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
print("msg from worker #" + worker.idx + ": " + msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
load('test/mjsunit/wasm/wasm-constants.js');
|
||||
load('test/mjsunit/wasm/wasm-module-builder.js');
|
||||
|
||||
var builder = new WasmModuleBuilder();
|
||||
let module = new WebAssembly.Module(builder.toBuffer());
|
||||
var worker = new Worker('onmessage = function() {};');
|
||||
worker.postMessage(module)
|
|
@ -1,13 +0,0 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --wasm-lazy-compilation
|
||||
|
||||
load('test/mjsunit/wasm/wasm-constants.js');
|
||||
load('test/mjsunit/wasm/wasm-module-builder.js');
|
||||
|
||||
var builder = new WasmModuleBuilder();
|
||||
let module = new WebAssembly.Module(builder.toBuffer());
|
||||
var worker = new Worker('onmessage = function() {};');
|
||||
worker.postMessage(module)
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --no-wasm-disable-structured-cloning
|
||||
|
||||
load("test/mjsunit/wasm/wasm-constants.js");
|
||||
load("test/mjsunit/wasm/wasm-module-builder.js");
|
||||
|
||||
(function TestPostModule() {
|
||||
let builder = new WasmModuleBuilder();
|
||||
builder.addFunction("add", kSig_i_ii)
|
||||
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add])
|
||||
.exportFunc();
|
||||
|
||||
let module = builder.toModule();
|
||||
|
||||
let workerScript = `
|
||||
onmessage = function(module) {
|
||||
try {
|
||||
let instance = new WebAssembly.Instance(module);
|
||||
let result = instance.exports.add(40, 2);
|
||||
postMessage(result);
|
||||
} catch(e) {
|
||||
postMessage('ERROR: ' + e);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
let realm = Realm.create();
|
||||
Realm.shared = { m:module, s:workerScript };
|
||||
|
||||
let realmScript = `
|
||||
let worker = new Worker(Realm.shared.s);
|
||||
worker.postMessage(Realm.shared.m);
|
||||
let message = worker.getMessage();
|
||||
worker.terminate();
|
||||
message;
|
||||
`;
|
||||
let message = Realm.eval(realm, realmScript);
|
||||
assertEquals(42, message);
|
||||
})();
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --wasm-lazy-compilation
|
||||
|
||||
load('test/mjsunit/wasm/wasm-constants.js');
|
||||
load('test/mjsunit/wasm/wasm-module-builder.js');
|
||||
|
||||
const builder = new WasmModuleBuilder();
|
||||
builder.addFunction('test', kSig_i_i).addBody([kExprUnreachable]);
|
||||
let module = new WebAssembly.Module(builder.toBuffer());
|
||||
var worker = new Worker('onmessage = function() {};');
|
||||
worker.postMessage(module);
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --allow-natives-syntax
|
||||
|
||||
load('test/mjsunit/wasm/wasm-constants.js');
|
||||
load('test/mjsunit/wasm/wasm-module-builder.js');
|
||||
|
||||
// The number of locals must be greater than the constant defined here:
|
||||
// https://cs.chromium.org/chromium/src/v8/src/compiler/x64/code-generator-x64.cc?l=3146
|
||||
const kNumLocals = 128;
|
||||
|
||||
function varuint32(val) {
|
||||
let bytes = [];
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
bytes.push(0x80 | ((val >> (7 * i)) & 0x7f));
|
||||
}
|
||||
bytes.push((val >> (7 * 4)) & 0x7f);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Generate a function that calls the "get" import `kNumLocals` times, and
|
||||
// stores each result in a local, then calls the "call" import `kNumLocals`
|
||||
// times with the stored local values.
|
||||
//
|
||||
// The intention is to create a function that has a large stack frame.
|
||||
let body = [];
|
||||
|
||||
for (let i = 0; i < kNumLocals; ++i) {
|
||||
body.push(kExprCallFunction, 0, kExprSetLocal, ...varuint32(i));
|
||||
}
|
||||
|
||||
for (let i = 0; i < kNumLocals; ++i) {
|
||||
body.push(kExprGetLocal, ...varuint32(i), kExprCallFunction, 1);
|
||||
}
|
||||
|
||||
let builder = new WasmModuleBuilder();
|
||||
builder.addImport('mod', 'get', kSig_i_v);
|
||||
builder.addImport('mod', 'call', kSig_v_i);
|
||||
builder.
|
||||
addFunction('main', kSig_v_v).
|
||||
addLocals({i32_count: kNumLocals}).
|
||||
addBody(body).
|
||||
exportAs('main');
|
||||
let m1_bytes = builder.toBuffer();
|
||||
let m1 = new WebAssembly.Module(m1_bytes);
|
||||
|
||||
// Serialize the module and postMessage it to another thread.
|
||||
let serialized_m1 = %SerializeWasmModule(m1);
|
||||
|
||||
let worker_onmessage = function(msg) {
|
||||
let {serialized_m1, m1_bytes} = msg;
|
||||
|
||||
let m1_clone = %DeserializeWasmModule(serialized_m1, m1_bytes);
|
||||
let imports = {mod: {get: () => 3, call: () => {}}};
|
||||
let i2 = new WebAssembly.Instance(m1_clone, imports);
|
||||
i2.exports.main();
|
||||
postMessage('done');
|
||||
}
|
||||
let workerScript = "onmessage = " + worker_onmessage.toString();
|
||||
|
||||
let worker = new Worker(workerScript);
|
||||
worker.postMessage({serialized_m1, m1_bytes});
|
||||
|
||||
// Wait for worker to finish.
|
||||
print(worker.getMessage());
|
|
@ -1,120 +0,0 @@
|
|||
// Copyright 2010 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Flags: --expose-natives-as natives --allow-natives-syntax
|
||||
// Test the SameValue and SameValueZero internal methods.
|
||||
|
||||
var obj1 = {x: 10, y: 11, z: "test"};
|
||||
var obj2 = {x: 10, y: 11, z: "test"};
|
||||
|
||||
var sameValue = Object.is;
|
||||
var sameValueZero = function(x, y) { return %SameValueZero(x, y); }
|
||||
|
||||
// Calls SameValue and SameValueZero and checks that their results match.
|
||||
function sameValueBoth(a, b) {
|
||||
var result = sameValue(a, b);
|
||||
assertTrue(result === sameValueZero(a, b));
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calls SameValue and SameValueZero and checks that their results don't match.
|
||||
function sameValueZeroOnly(a, b) {
|
||||
var result = sameValueZero(a, b);
|
||||
assertTrue(result && !sameValue(a, b));
|
||||
return result;
|
||||
}
|
||||
|
||||
assertTrue(sameValueBoth(0, 0));
|
||||
assertTrue(sameValueBoth(+0, +0));
|
||||
assertTrue(sameValueBoth(-0, -0));
|
||||
assertTrue(sameValueBoth(1, 1));
|
||||
assertTrue(sameValueBoth(2, 2));
|
||||
assertTrue(sameValueBoth(-1, -1));
|
||||
assertTrue(sameValueBoth(0.5, 0.5));
|
||||
assertTrue(sameValueBoth(true, true));
|
||||
assertTrue(sameValueBoth(false, false));
|
||||
assertTrue(sameValueBoth(NaN, NaN));
|
||||
assertTrue(sameValueBoth(null, null));
|
||||
assertTrue(sameValueBoth("foo", "foo"));
|
||||
assertTrue(sameValueBoth(obj1, obj1));
|
||||
// Undefined values.
|
||||
assertTrue(sameValueBoth());
|
||||
assertTrue(sameValueBoth(undefined, undefined));
|
||||
|
||||
assertFalse(sameValueBoth(0,1));
|
||||
assertFalse(sameValueBoth("foo", "bar"));
|
||||
assertFalse(sameValueBoth(obj1, obj2));
|
||||
assertFalse(sameValueBoth(true, false));
|
||||
|
||||
assertFalse(sameValueBoth(obj1, true));
|
||||
assertFalse(sameValueBoth(obj1, "foo"));
|
||||
assertFalse(sameValueBoth(obj1, 1));
|
||||
assertFalse(sameValueBoth(obj1, undefined));
|
||||
assertFalse(sameValueBoth(obj1, NaN));
|
||||
|
||||
assertFalse(sameValueBoth(undefined, true));
|
||||
assertFalse(sameValueBoth(undefined, "foo"));
|
||||
assertFalse(sameValueBoth(undefined, 1));
|
||||
assertFalse(sameValueBoth(undefined, obj1));
|
||||
assertFalse(sameValueBoth(undefined, NaN));
|
||||
|
||||
assertFalse(sameValueBoth(NaN, true));
|
||||
assertFalse(sameValueBoth(NaN, "foo"));
|
||||
assertFalse(sameValueBoth(NaN, 1));
|
||||
assertFalse(sameValueBoth(NaN, obj1));
|
||||
assertFalse(sameValueBoth(NaN, undefined));
|
||||
|
||||
assertFalse(sameValueBoth("foo", true));
|
||||
assertFalse(sameValueBoth("foo", 1));
|
||||
assertFalse(sameValueBoth("foo", obj1));
|
||||
assertFalse(sameValueBoth("foo", undefined));
|
||||
assertFalse(sameValueBoth("foo", NaN));
|
||||
|
||||
assertFalse(sameValueBoth(true, 1));
|
||||
assertFalse(sameValueBoth(true, obj1));
|
||||
assertFalse(sameValueBoth(true, undefined));
|
||||
assertFalse(sameValueBoth(true, NaN));
|
||||
assertFalse(sameValueBoth(true, "foo"));
|
||||
|
||||
assertFalse(sameValueBoth(1, true));
|
||||
assertFalse(sameValueBoth(1, obj1));
|
||||
assertFalse(sameValueBoth(1, undefined));
|
||||
assertFalse(sameValueBoth(1, NaN));
|
||||
assertFalse(sameValueBoth(1, "foo"));
|
||||
|
||||
// Special string cases.
|
||||
assertFalse(sameValueBoth("1", 1));
|
||||
assertFalse(sameValueBoth("true", true));
|
||||
assertFalse(sameValueBoth("false", false));
|
||||
assertFalse(sameValueBoth("undefined", undefined));
|
||||
assertFalse(sameValueBoth("NaN", NaN));
|
||||
|
||||
// SameValue considers -0 and +0 to be different; SameValueZero considers
|
||||
// -0 and +0 to be the same.
|
||||
assertTrue(sameValueZeroOnly(+0, -0));
|
||||
assertTrue(sameValueZeroOnly(-0, +0));
|
|
@ -1,117 +0,0 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --allow-natives-syntax
|
||||
|
||||
// Used for async tests. See definition below for more documentation.
|
||||
var testAsync;
|
||||
|
||||
(function () { // Scope for utility functions.
|
||||
/**
|
||||
* This is to be used through the testAsync helper function defined
|
||||
* below.
|
||||
*
|
||||
* This requires the --allow-natives-syntax flag to allow calling
|
||||
* runtime functions.
|
||||
*
|
||||
* There must be at least one assertion in an async test. A test
|
||||
* with no assertions will fail.
|
||||
*
|
||||
* @example
|
||||
* testAsync(assert => {
|
||||
* assert.plan(1) // There should be one assertion in this test.
|
||||
* Promise.resolve(1)
|
||||
* .then(val => assert.equals(1, val),
|
||||
* assert.unreachable);
|
||||
* })
|
||||
*/
|
||||
class AsyncAssertion {
|
||||
constructor(test, name) {
|
||||
this.expectedAsserts_ = -1;
|
||||
this.actualAsserts_ = 0;
|
||||
this.test_ = test;
|
||||
this.name_ = name || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of expected asserts in the test. The test fails
|
||||
* if the number of asserts computed after running the test is not
|
||||
* equal to this specified value.
|
||||
* @param {number} expectedAsserts
|
||||
*/
|
||||
plan(expectedAsserts) {
|
||||
this.expectedAsserts_ = expectedAsserts;
|
||||
}
|
||||
|
||||
fail(expectedText, found) {
|
||||
let message = formatFailureText(expectedText, found);
|
||||
message += "\nin test:" + this.name_
|
||||
message += "\n" + Function.prototype.toString.apply(this.test_);
|
||||
%AbortJS(message);
|
||||
}
|
||||
|
||||
equals(expected, found, name_opt) {
|
||||
this.actualAsserts_++;
|
||||
if (expected !== found) {
|
||||
this.fail(prettyPrinted(expected), found, name_opt);
|
||||
}
|
||||
}
|
||||
|
||||
unreachable() {
|
||||
let message = "Failure: unreachable in test: " + this.name_;
|
||||
message += "\n" + Function.prototype.toString.apply(this.test_);
|
||||
%AbortJS(message);
|
||||
}
|
||||
|
||||
unexpectedRejection(details) {
|
||||
return (error) => {
|
||||
let message =
|
||||
"Failure: unexpected Promise rejection in test: " + this.name_;
|
||||
if (details) message += "\n @" + details;
|
||||
if (error instanceof Error) {
|
||||
message += "\n" + String(error.stack);
|
||||
} else {
|
||||
message += "\n" + String(error);
|
||||
}
|
||||
message += "\n\n" + Function.prototype.toString.apply(this.test_);
|
||||
%AbortJS(message);
|
||||
};
|
||||
}
|
||||
|
||||
drainMicrotasks() {
|
||||
%RunMicrotasks();
|
||||
}
|
||||
|
||||
done_() {
|
||||
if (this.expectedAsserts_ === -1) {
|
||||
let message = "Please call t.plan(count) to initialize test harness " +
|
||||
"with correct assert count (Note: count > 0)";
|
||||
%AbortJS(message);
|
||||
}
|
||||
|
||||
if (this.expectedAsserts_ !== this.actualAsserts_) {
|
||||
let message = "Expected asserts: " + this.expectedAsserts_;
|
||||
message += ", Actual asserts: " + this.actualAsserts_;
|
||||
message += "\nin test: " + this.name_;
|
||||
message += "\n" + Function.prototype.toString.apply(this.test_);
|
||||
%AbortJS(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This is used to test async functions and promises.
|
||||
* @param {testCallback} test - test function
|
||||
* @param {string} [name] - optional name of the test
|
||||
*
|
||||
*
|
||||
* @callback testCallback
|
||||
* @param {AsyncAssertion} assert
|
||||
*/
|
||||
testAsync = function(test, name) {
|
||||
let assert = new AsyncAssertion(test, name);
|
||||
test(assert);
|
||||
%RunMicrotasks();
|
||||
assert.done_();
|
||||
}
|
||||
})();
|
|
@ -1,118 +0,0 @@
|
|||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
$262.agent = (function () {
|
||||
|
||||
var workers = [];
|
||||
var i32a = null;
|
||||
var pendingReports = [];
|
||||
|
||||
// Agents call Atomics.wait on this location to sleep.
|
||||
var SLEEP_LOC = 0;
|
||||
// 1 if the started worker is ready, 0 otherwise.
|
||||
var START_LOC = 1;
|
||||
// The number of workers that have received the broadcast.
|
||||
var BROADCAST_LOC = 2;
|
||||
// Each worker has a count of outstanding reports; worker N uses memory
|
||||
// location [WORKER_REPORT_LOC + N].
|
||||
var WORKER_REPORT_LOC = 3;
|
||||
|
||||
function workerScript(script) {
|
||||
return `
|
||||
var index;
|
||||
var i32a = null;
|
||||
var broadcasts = [];
|
||||
var pendingReceiver = null;
|
||||
|
||||
function handleBroadcast() {
|
||||
if (pendingReceiver && broadcasts.length > 0) {
|
||||
pendingReceiver.apply(null, broadcasts.shift());
|
||||
pendingReceiver = null;
|
||||
}
|
||||
};
|
||||
|
||||
var onmessage = function(msg) {
|
||||
switch (msg.kind) {
|
||||
case 'start':
|
||||
i32a = msg.i32a;
|
||||
index = msg.index;
|
||||
(0, eval)(\`${script}\`);
|
||||
break;
|
||||
|
||||
case 'broadcast':
|
||||
Atomics.add(i32a, ${BROADCAST_LOC}, 1);
|
||||
broadcasts.push([msg.sab, msg.id]);
|
||||
handleBroadcast();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
var $262 = {
|
||||
agent: {
|
||||
receiveBroadcast(receiver) {
|
||||
pendingReceiver = receiver;
|
||||
handleBroadcast();
|
||||
},
|
||||
|
||||
report(msg) {
|
||||
postMessage(String(msg));
|
||||
Atomics.add(i32a, ${WORKER_REPORT_LOC} + index, 1);
|
||||
},
|
||||
|
||||
sleep(s) { Atomics.wait(i32a, ${SLEEP_LOC}, 0, s); },
|
||||
|
||||
leaving() {},
|
||||
|
||||
monotonicNow() {
|
||||
return performance.now();
|
||||
}
|
||||
}
|
||||
};`;
|
||||
}
|
||||
|
||||
var agent = {
|
||||
start(script) {
|
||||
if (i32a === null) {
|
||||
i32a = new Int32Array(new SharedArrayBuffer(256));
|
||||
}
|
||||
var w = new Worker(workerScript(script));
|
||||
w.index = workers.length;
|
||||
w.postMessage({kind: 'start', i32a: i32a, index: w.index});
|
||||
workers.push(w);
|
||||
},
|
||||
|
||||
broadcast(sab, id) {
|
||||
if (!(sab instanceof SharedArrayBuffer)) {
|
||||
throw new TypeError('sab must be a SharedArrayBuffer.');
|
||||
}
|
||||
|
||||
Atomics.store(i32a, BROADCAST_LOC, 0);
|
||||
|
||||
for (var w of workers) {
|
||||
w.postMessage({kind: 'broadcast', sab: sab, id: id|0});
|
||||
}
|
||||
|
||||
while (Atomics.load(i32a, BROADCAST_LOC) != workers.length) {}
|
||||
},
|
||||
|
||||
getReport() {
|
||||
for (var w of workers) {
|
||||
while (Atomics.load(i32a, WORKER_REPORT_LOC + w.index) > 0) {
|
||||
pendingReports.push(w.getMessage());
|
||||
Atomics.sub(i32a, WORKER_REPORT_LOC + w.index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return pendingReports.shift() || null;
|
||||
},
|
||||
|
||||
sleep(s) { Atomics.wait(i32a, SLEEP_LOC, 0, s); },
|
||||
|
||||
monotonicNow() {
|
||||
return performance.now();
|
||||
}
|
||||
};
|
||||
return agent;
|
||||
|
||||
})();
|
Loading…
Reference in New Issue