Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,5 @@
// 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.
async(o = (function(await) {})) => 0

View File

@ -0,0 +1,42 @@
// Copyright 2016 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
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
assertEqualsAsync("[1,2,3]", () => (function() {
return (async () => JSON.stringify([...arguments]))();
})(1, 2, 3));
assertEqualsAsync("[4,5,6]",
() => (function() {
return (async () => {
return JSON.stringify([...await arguments]) })();
})(4, 5, 6));

View File

@ -0,0 +1,43 @@
// Copyright 2016 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
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
class BaseClass {
constructor() {
return async () => new.target;
}
}
class ChildClass extends BaseClass {}
assertEqualsAsync(BaseClass, () => new BaseClass()());
assertEqualsAsync(ChildClass, () => new ChildClass()());

View File

@ -0,0 +1,58 @@
// Copyright 2016 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
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
class BaseClass {
constructor(x) {
this.name_ = x;
}
get name() { return this.name_; }
};
class DeferredSuperCall extends BaseClass {
constructor(x) {
return async() => super(x);
}
};
assertEqualsAsync(
"LexicalSuperCall",
() => new DeferredSuperCall("LexicalSuperCall")().then(x => x.name));
class DeferredSuperProperty extends BaseClass {
deferredName() { return async() => super.name; }
};
assertEqualsAsync(
"LexicalSuperProperty",
() => new DeferredSuperProperty("LexicalSuperProperty").deferredName()());

View File

@ -0,0 +1,48 @@
// Copyright 2016 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
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
var O = {
[Symbol.toStringTag]: "LexicalThis",
run(n) {
return async passFail => `${n}. ${passFail}: ${this}`;
},
};
assertEqualsAsync("1. PASS: [object LexicalThis]", () => O.run(1)("PASS"));
var O2 = {
[Symbol.toStringTag]: "LexicalThis",
run: O.run(2)
};
assertEqualsAsync("2. PASS: [object LexicalThis]", () => O2.run("PASS"));

View File

@ -0,0 +1,603 @@
// Copyright 2016 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
// Do not install `AsyncFunction` constructor on global object
function assertThrowsAsync(run, errorType, message) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (!hadError) {
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw " + errorType.name +
", but did not throw.");
}
if (!(actual instanceof errorType))
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw " + errorType.name +
", but threw '" + actual + "'");
if (message !== void 0 && actual.message !== message)
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw '" + message + "', but threw '" +
actual.message + "'");
};
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
assertEquals(undefined, this.AsyncFunction);
let AsyncFunction = (async function() {}).constructor;
// The AsyncFunction Constructor is the %AsyncFunction% intrinsic object and
// is a subclass of Function.
// (https://tc39.github.io/ecmascript-asyncawait/#async-function-constructor)
assertEquals(Object.getPrototypeOf(AsyncFunction), Function);
assertEquals(Object.getPrototypeOf(AsyncFunction.prototype),
Function.prototype);
assertTrue(async function() {} instanceof Function);
// Let functionPrototype be the intrinsic object %AsyncFunctionPrototype%.
async function asyncFunctionForProto() {}
assertEquals(AsyncFunction.prototype,
Object.getPrototypeOf(asyncFunctionForProto));
assertEquals(AsyncFunction.prototype,
Object.getPrototypeOf(async function() {}));
assertEquals(AsyncFunction.prototype, Object.getPrototypeOf(async () => {}));
assertEquals(AsyncFunction.prototype,
Object.getPrototypeOf({ async method() {} }.method));
assertEquals(AsyncFunction.prototype, Object.getPrototypeOf(AsyncFunction()));
assertEquals(AsyncFunction.prototype,
Object.getPrototypeOf(new AsyncFunction()));
// AsyncFunctionCreate does not produce an object with a Prototype
assertEquals(undefined, asyncFunctionForProto.prototype);
assertEquals(false, asyncFunctionForProto.hasOwnProperty("prototype"));
assertEquals(undefined, (async function() {}).prototype);
assertEquals(false, (async function() {}).hasOwnProperty("prototype"));
assertEquals(undefined, (async() => {}).prototype);
assertEquals(false, (async() => {}).hasOwnProperty("prototype"));
assertEquals(undefined, ({ async method() {} }).method.prototype);
assertEquals(false, ({ async method() {} }).method.hasOwnProperty("prototype"));
assertEquals(undefined, AsyncFunction().prototype);
assertEquals(false, AsyncFunction().hasOwnProperty("prototype"));
assertEquals(undefined, (new AsyncFunction()).prototype);
assertEquals(false, (new AsyncFunction()).hasOwnProperty("prototype"));
assertEquals(1, async function(a) { await 1; }.length);
assertEquals(2, async function(a, b) { await 1; }.length);
assertEquals(1, async function(a, b = 2) { await 1; }.length);
assertEquals(2, async function(a, b, ...c) { await 1; }.length);
assertEquals(1, (async(a) => await 1).length);
assertEquals(2, (async(a, b) => await 1).length);
assertEquals(1, (async(a, b = 2) => await 1).length);
assertEquals(2, (async(a, b, ...c) => await 1).length);
assertEquals(1, ({ async f(a) { await 1; } }).f.length);
assertEquals(2, ({ async f(a, b) { await 1; } }).f.length);
assertEquals(1, ({ async f(a, b = 2) { await 1; } }).f.length);
assertEquals(2, ({ async f(a, b, ...c) { await 1; } }).f.length);
assertEquals(1, AsyncFunction("a", "await 1").length);
assertEquals(2, AsyncFunction("a", "b", "await 1").length);
assertEquals(1, AsyncFunction("a", "b = 2", "await 1").length);
assertEquals(2, AsyncFunction("a", "b", "...c", "await 1").length);
assertEquals(1, (new AsyncFunction("a", "await 1")).length);
assertEquals(2, (new AsyncFunction("a", "b", "await 1")).length);
assertEquals(1, (new AsyncFunction("a", "b = 2", "await 1")).length);
assertEquals(2, (new AsyncFunction("a", "b", "...c", "await 1")).length);
// AsyncFunction.prototype[ @@toStringTag ]
var descriptor =
Object.getOwnPropertyDescriptor(AsyncFunction.prototype,
Symbol.toStringTag);
assertEquals("AsyncFunction", descriptor.value);
assertEquals(false, descriptor.enumerable);
assertEquals(false, descriptor.writable);
assertEquals(true, descriptor.configurable);
assertEquals(1, AsyncFunction.length);
// Let F be ! FunctionAllocate(functionPrototype, Strict, "non-constructor")
async function asyncNonConstructorDecl() {}
assertThrows(() => new asyncNonConstructorDecl(), TypeError);
assertThrows(() => asyncNonConstructorDecl.caller, TypeError);
assertThrows(() => asyncNonConstructorDecl.arguments, TypeError);
assertThrows(() => new (async function() {}), TypeError);
assertThrows(() => (async function() {}).caller, TypeError);
assertThrows(() => (async function() {}).arguments, TypeError);
assertThrows(
() => new ({ async nonConstructor() {} }).nonConstructor(), TypeError);
assertThrows(
() => ({ async nonConstructor() {} }).nonConstructor.caller, TypeError);
assertThrows(
() => ({ async nonConstructor() {} }).nonConstructor.arguments, TypeError);
assertThrows(() => new (() => "not a constructor!"), TypeError);
assertThrows(() => (() => 1).caller, TypeError);
assertThrows(() => (() => 1).arguments, TypeError);
assertThrows(() => new (AsyncFunction()), TypeError);
assertThrows(() => AsyncFunction().caller, TypeError);
assertThrows(() => AsyncFunction().arguments, TypeError);
assertThrows(() => new (new AsyncFunction()), TypeError);
assertThrows(() => (new AsyncFunction()).caller, TypeError);
assertThrows(() => (new AsyncFunction()).arguments, TypeError);
// Normal completion
async function asyncDecl() { return "test"; }
assertEqualsAsync("test", asyncDecl);
assertEqualsAsync("test2", async function() { return "test2"; });
assertEqualsAsync("test3", async () => "test3");
assertEqualsAsync("test4", () => ({ async f() { return "test4"; } }).f());
assertEqualsAsync("test5", () => AsyncFunction("no", "return 'test' + no;")(5));
assertEqualsAsync("test6",
() => (new AsyncFunction("no", "return 'test' + no;"))(6));
class MyError extends Error {};
// Throw completion
async function asyncDeclThrower(e) { throw new MyError(e); }
assertThrowsAsync(() => asyncDeclThrower("boom!"), MyError, "boom!");
assertThrowsAsync(
() => (async function(e) { throw new MyError(e); })("boom!!!"),
MyError, "boom!!!");
assertThrowsAsync(
() => (async e => { throw new MyError(e) })("boom!!"), MyError, "boom!!");
assertThrowsAsync(
() => ({ async thrower(e) { throw new MyError(e); } }).thrower("boom!1!"),
MyError, "boom!1!");
assertThrowsAsync(
() => AsyncFunction("msg", "throw new MyError(msg)")("boom!2!!"),
MyError, "boom!2!!");
assertThrowsAsync(
() => (new AsyncFunction("msg", "throw new MyError(msg)"))("boom!2!!!"),
MyError, "boom!2!!!");
function resolveLater(value) { return Promise.resolve(value); }
function rejectLater(error) { return Promise.reject(error); }
// Resume after Normal completion
var log = [];
async function resumeAfterNormal(value) {
log.push("start:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
return value + 1;
}
assertEqualsAsync(4, () => resumeAfterNormal(1));
assertEquals("start:1 resume:2 resume:3", log.join(" "));
var O = {
async resumeAfterNormal(value) {
log.push("start:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
return value + 1;
}
};
log = [];
assertEqualsAsync(5, () => O.resumeAfterNormal(2));
assertEquals("start:2 resume:3 resume:4", log.join(" "));
var resumeAfterNormalArrow = async (value) => {
log.push("start:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
return value + 1;
};
log = [];
assertEqualsAsync(6, () => resumeAfterNormalArrow(3));
assertEquals("start:3 resume:4 resume:5", log.join(" "));
var resumeAfterNormalEval = AsyncFunction("value", `
log.push("start:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
return value + 1;`);
log = [];
assertEqualsAsync(7, () => resumeAfterNormalEval(4));
assertEquals("start:4 resume:5 resume:6", log.join(" "));
var resumeAfterNormalNewEval = new AsyncFunction("value", `
log.push("start:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
value = await resolveLater(value + 1);
log.push("resume:" + value);
return value + 1;`);
log = [];
assertEqualsAsync(8, () => resumeAfterNormalNewEval(5));
assertEquals("start:5 resume:6 resume:7", log.join(" "));
// Resume after Throw completion
async function resumeAfterThrow(value) {
log.push("start:" + value);
try {
value = await rejectLater("throw1");
} catch (e) {
log.push("resume:" + e);
}
try {
value = await rejectLater("throw2");
} catch (e) {
log.push("resume:" + e);
}
return value + 1;
}
log = [];
assertEqualsAsync(2, () => resumeAfterThrow(1));
assertEquals("start:1 resume:throw1 resume:throw2", log.join(" "));
var O = {
async resumeAfterThrow(value) {
log.push("start:" + value);
try {
value = await rejectLater("throw1");
} catch (e) {
log.push("resume:" + e);
}
try {
value = await rejectLater("throw2");
} catch (e) {
log.push("resume:" + e);
}
return value + 1;
}
}
log = [];
assertEqualsAsync(3, () => O.resumeAfterThrow(2));
assertEquals("start:2 resume:throw1 resume:throw2", log.join(" "));
var resumeAfterThrowArrow = async (value) => {
log.push("start:" + value);
try {
value = await rejectLater("throw1");
} catch (e) {
log.push("resume:" + e);
}
try {
value = await rejectLater("throw2");
} catch (e) {
log.push("resume:" + e);
}
return value + 1;
};
log = [];
assertEqualsAsync(4, () => resumeAfterThrowArrow(3));
assertEquals("start:3 resume:throw1 resume:throw2", log.join(" "));
var resumeAfterThrowEval = AsyncFunction("value", `
log.push("start:" + value);
try {
value = await rejectLater("throw1");
} catch (e) {
log.push("resume:" + e);
}
try {
value = await rejectLater("throw2");
} catch (e) {
log.push("resume:" + e);
}
return value + 1;`);
log = [];
assertEqualsAsync(5, () => resumeAfterThrowEval(4));
assertEquals("start:4 resume:throw1 resume:throw2", log.join(" "));
var resumeAfterThrowNewEval = new AsyncFunction("value", `
log.push("start:" + value);
try {
value = await rejectLater("throw1");
} catch (e) {
log.push("resume:" + e);
}
try {
value = await rejectLater("throw2");
} catch (e) {
log.push("resume:" + e);
}
return value + 1;`);
log = [];
assertEqualsAsync(6, () => resumeAfterThrowNewEval(5));
assertEquals("start:5 resume:throw1 resume:throw2", log.join(" "));
async function foo() {}
assertEquals("async function foo() {}", foo.toString());
assertEquals("async function () {}", async function () {}.toString());
assertEquals("async x => x", (async x => x).toString());
assertEquals("async x => { return x }", (async x => { return x }).toString());
class AsyncMethod { async foo() { } }
assertEquals("async foo() { }",
Function.prototype.toString.call(AsyncMethod.prototype.foo));
assertEquals("async foo() { }",
Function.prototype.toString.call({async foo() { }}.foo));
// Async functions are not constructible
assertThrows(() => class extends (async function() {}) {}, TypeError);
// Regress v8:5148
assertEqualsAsync("1", () => (async({ a = NaN }) => a)({ a: "1" }));
assertEqualsAsync(
"10", () => (async(foo, { a = NaN }) => foo + a)("1", { a: "0" }));
assertEqualsAsync("2", () => (async({ a = "2" }) => a)({ a: undefined }));
assertEqualsAsync(
"20", () => (async(foo, { a = "0" }) => foo + a)("2", { a: undefined }));
assertThrows(() => eval("async({ foo = 1 })"), SyntaxError);
assertThrows(() => eval("async(a, { foo = 1 })"), SyntaxError);
// https://bugs.chromium.org/p/chromium/issues/detail?id=638019
async function gaga() {
let i = 1;
while (i-- > 0) { await 42 }
}
assertDoesNotThrow(gaga);
{
let log = [];
async function foo() {
try {
Promise.resolve().then(() => log.push("a"))
} finally {
log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "a", "c"], log);
}
{
let log = [];
async function foo() {
try {
return Promise.resolve().then(() => log.push("a"))
} finally {
log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "a", "c"], log);
}
{
let log = [];
async function foo() {
try {
return await Promise.resolve().then(() => log.push("a"))
} finally {
log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["a", "b", "c"], log);
}
{
let log = [];
async function foo() {
try {
Promise.resolve().then().then(() => log.push("a"))
} finally {
log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "c", "a"], log);
}
{
let log = [];
async function foo() {
try {
return Promise.resolve().then().then(() => log.push("a"))
} finally {
log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "a", "c"], log);
}
{
let log = [];
async function foo() {
try {
return await Promise.resolve().then().then(() => log.push("a"))
} finally {
log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["a", "b", "c"], log);
}
{
let log = [];
async function foo() {
try {
Promise.resolve().then(() => log.push("a"))
} finally {
return log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "a", "c"], log);
}
{
let log = [];
async function foo() {
try {
return Promise.resolve().then(() => log.push("a"))
} finally {
return log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "a", "c"], log);
}
{
let log = [];
async function foo() {
try {
return await Promise.resolve().then(() => log.push("a"))
} finally {
return log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["a", "b", "c"], log);
}
{
let log = [];
async function foo() {
try {
Promise.resolve().then().then(() => log.push("a"))
} finally {
return log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "c", "a"], log);
}
{
let log = [];
async function foo() {
try {
return Promise.resolve().then().then(() => log.push("a"))
} finally {
return log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["b", "c", "a"], log);
}
{
let log = [];
async function foo() {
try {
return await Promise.resolve().then().then(() => log.push("a"))
} finally {
return log.push("b");
}
}
foo().then(() => log.push("c"));
%PerformMicrotaskCheckpoint();
assertEquals(["a", "b", "c"], log);
}
{
function f1() {
var x;
with ({get await() { return [42] }}) {
x = await
[0];
};
return x;
}
assertEquals(42, f1());
async function f2() {
var x;
with ({get await() { return [42] }}) {
x = await
[0];
};
return x;
}
var ans;
f2().then(x => ans = x).catch(e => ans = e);
%PerformMicrotaskCheckpoint();
assertEquals([0], ans);
}
{
function f1() {
var x, y;
with ({get await() { return [42] }}) {
x = await
y = 1
};
return y;
}
assertEquals(1, f1());
}

View File

@ -0,0 +1,63 @@
// Copyright 2018 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: --ignore-unhandled-promises
// Check for correct interleaving of Promises and async/await
(function () {
const iterations = 10;
let promiseCounter = iterations;
let awaitCounter = 0;
async function check(v) {
awaitCounter = v;
// The following checks ensure that "await" takes 3 ticks on the
// microtask queue. Note: this will change in the future
if (awaitCounter === 0) {
assertEquals(iterations, promiseCounter);
} else if (awaitCounter <= Math.floor(iterations / 3)) {
assertEquals(iterations - awaitCounter * 3, promiseCounter);
} else {
assertEquals(0, promiseCounter);
}
}
async function f() {
for (let i = 0; i < iterations; i++) {
await check(i);
}
return 0;
}
function countdown(v) {
promiseCounter = v;
if (v > 0) Promise.resolve(v - 1).then(countdown);
}
countdown(iterations);
f();
})();

View File

@ -0,0 +1,27 @@
// Copyright 2016 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 --ignore-unhandled-promises
'use strict';
var resolved = Promise.resolve();
var count = 0;
Object.defineProperty(Promise.prototype, 'constructor',
{ get() { count++; return Promise; } })
async function foo() {
await resolved;
return resolved;
}
async function bar() {
throw 1;
}
foo();
bar();
%PerformMicrotaskCheckpoint();
assertEquals(2, count);

View File

@ -0,0 +1,7 @@
// Copyright 2016 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.
var resolved = Promise.resolve();
assertTrue((async() => resolved)() !== resolved);

View File

@ -0,0 +1,102 @@
// Copyright 2016 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
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
// Rename a function so that it can help omit things from stack trace.
function test(fn) {
return Object.defineProperty(fn, "name", {
enumerable: false,
configurable: true,
value: "@" + fn.name,
writable: false
});
}
function getStack(error) {
var stack = error.stack.split('\n').
filter(function(line) {
return /^\s*at @?[a-zA-Z0-9_]/.test(line);
}).
map(line =>
line.replace(/^\s*at (@?(?:new )?[a-zA-Z0-9_\.\[\]]+)(.*)/, "$1"));
// remove `Promise.then()` invocation by assertEqualsAsync()
if (stack[2] === "assertEqualsAsync") return [];
return stack.reverse();
}
var log = [];
class FakePromise extends Promise {
constructor(executor) {
var stack = getStack(new Error("Getting Callstack"));
if (stack.length) {
var first = -1;
for (var i = 0; i < stack.length; ++i) {
if (stack[i][0] === '@') {
first = i;
break;
}
}
while (first > 0) stack.shift(), --first;
if (stack.length) {
log.push("@@Species: [" + stack.join(" > ") + "]");
}
}
return new Promise(executor);
}
};
Object.defineProperty(Promise, Symbol.species, {
value: FakePromise,
configurable: true,
enumerable: false,
writable: false
});
// Internal `AsyncFunctionAwait` only --- no @@species invocations.
async function asyncFn() { return await "foo"; }
assertEqualsAsync("foo", test(function testInternalOnly() { return asyncFn(); },
"should not call Promise[@@Species]"));
assertEquals([], log);
log.length = 0;
assertEqualsAsync(
"foo",
test(function testThenOnReturnedPromise() {
return asyncFn().then(x => (log.push("Then: " + x), x));
}),
"should call Promise[@@Species] after non-internal Then");
assertEquals([
"@@Species: [@testThenOnReturnedPromise > Promise.then > new FakePromise]",
"Then: foo"
], log);

View File

@ -0,0 +1,516 @@
// Copyright 2016 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
function assertThrowsAsync(run, errorType, message) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (!hadError) {
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw " + errorType.name +
", but did not throw.");
}
if (!(actual instanceof errorType))
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw " + errorType.name +
", but threw '" + actual + "'");
if (message !== void 0 && actual.message !== message)
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw '" + message + "', but threw '" +
actual.message + "'");
};
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
(function TestDefaultEvaluationOrder() {
var y = 0;
var z = 0;
var w = 0;
async function f1(x = (y = 1)) { z = 1; await undefined; w = 1; };
assertEquals(0, y);
assertEquals(0, z);
assertEquals(0, w);
f1();
assertEquals(1, y);
assertEquals(1, z);
assertEquals(0, w);
%PerformMicrotaskCheckpoint();
assertEquals(1, y);
assertEquals(1, z);
assertEquals(1, w);
})();
(function TestShadowingOfParameters() {
async function f1({x}) { var x = 2; return x }
assertEqualsAsync(2, () => f1({x: 1}));
async function f2({x}) { { var x = 2; } return x; }
assertEqualsAsync(2, () => f2({x: 1}));
async function f3({x}) { var y = x; var x = 2; return y; }
assertEqualsAsync(1, () => f3({x: 1}));
async function f4({x}) { { var y = x; var x = 2; } return y; }
assertEqualsAsync(1, () => f4({x: 1}));
async function f5({x}, g = () => x) { var x = 2; return g(); }
assertEqualsAsync(1, () => f5({x: 1}));
async function f6({x}, g = () => x) { { var x = 2; } return g(); }
assertEqualsAsync(1, () => f6({x: 1}));
async function f7({x}) { var g = () => x; var x = 2; return g(); }
assertEqualsAsync(2, () => f7({x: 1}));
async function f8({x}) { { var g = () => x; var x = 2; } return g(); }
assertEqualsAsync(2, () => f8({x: 1}));
async function f9({x}, g = () => eval("x")) { var x = 2; return g(); }
assertEqualsAsync(1, () => f9({x: 1}));
async function f10({x}, y) { var y; return y }
assertEqualsAsync(2, () => f10({x: 6}, 2));
async function f11({x}, y) { var z = y; var y = 2; return z; }
assertEqualsAsync(1, () => f11({x: 6}, 1));
async function f12(y, g = () => y) { var y = 2; return g(); }
assertEqualsAsync(1, () => f12(1));
async function f13({x}, y, [z], v) { var x, y, z; return x*y*z*v }
assertEqualsAsync(210, () => f13({x: 2}, 3, [5], 7));
async function f20({x}) { function x() { return 2 }; return x(); }
assertEqualsAsync(2, () => f20({x: 1}));
// Annex B 3.3 function hoisting is blocked by the conflicting x declaration
async function f21({x}) { { function x() { return 2 } } return x; }
assertEqualsAsync(1, () => f21({x: 1}));
var g1 = async ({x}) => { var x = 2; return x };
assertEqualsAsync(2, () => g1({x: 1}));
var g2 = async ({x}) => { { var x = 2; } return x; };
assertEqualsAsync(2, () => g2({x: 1}));
var g3 = async ({x}) => { var y = x; var x = 2; return y; };
assertEqualsAsync(1, () => g3({x: 1}));
var g4 = async ({x}) => { { var y = x; var x = 2; } return y; };
assertEqualsAsync(1, () => g4({x: 1}));
var g5 = async ({x}, g = () => x) => { var x = 2; return g(); };
assertEqualsAsync(1, () => g5({x: 1}));
var g6 = async ({x}, g = () => x) => { { var x = 2; } return g(); };
assertEqualsAsync(1, () => g6({x: 1}));
var g7 = async ({x}) => { var g = () => x; var x = 2; return g(); };
assertEqualsAsync(2, () => g7({x: 1}));
var g8 = async ({x}) => { { var g = () => x; var x = 2; } return g(); };
assertEqualsAsync(2, () => g8({x: 1}));
var g9 = async ({x}, g = () => eval("x")) => { var x = 2; return g(); };
assertEqualsAsync(1, () => g9({x: 1}));
var g10 = async ({x}, y) => { var y; return y };
assertEqualsAsync(2, () => g10({x: 6}, 2));
var g11 = async ({x}, y) => { var z = y; var y = 2; return z; };
assertEqualsAsync(1, () => g11({x: 6}, 1));
var g12 = async (y, g = () => y) => { var y = 2; return g(); };
assertEqualsAsync(1, () => g12(1));
var g13 = async ({x}, y, [z], v) => { var x, y, z; return x*y*z*v };
assertEqualsAsync(210, () => g13({x: 2}, 3, [5], 7));
var g20 = async ({x}) => { function x() { return 2 }; return x(); }
assertEqualsAsync(2, () => g20({x: 1}));
var g21 = async ({x}) => { { function x() { return 2 } } return x(); }
assertThrowsAsync(() => g21({x: 1}), TypeError);
// These errors are not recognized in lazy parsing; see mjsunit/bugs/bug-2728.js
assertThrows("'use strict'; (async function f(x) { let x = 0; })()", SyntaxError);
assertThrows("'use strict'; (async function f({x}) { let x = 0; })()", SyntaxError);
assertThrows("'use strict'; (async function f(x) { const x = 0; })()", SyntaxError);
assertThrows("'use strict'; (async function f({x}) { const x = 0; })()", SyntaxError);
assertThrows("'use strict'; let g = async (x) => { let x = 0; }", SyntaxError);
assertThrows("'use strict'; let g = async ({x}) => { let x = 0; }", SyntaxError);
assertThrows("'use strict'; let g = async (x) => { const x = 0; }", SyntaxError);
assertThrows("'use strict'; let g = async ({x}) => { const x = 0; }", SyntaxError);
}());
(function TestDefaults() {
async function f1(x = 1) { return x }
assertEqualsAsync(1, () => f1());
assertEqualsAsync(1, () => f1(undefined));
assertEqualsAsync(2, () => f1(2));
assertEqualsAsync(null, () => f1(null));
async function f2(x, y = x) { return x + y; }
assertEqualsAsync(8, () => f2(4));
assertEqualsAsync(8, () => f2(4, undefined));
assertEqualsAsync(6, () => f2(4, 2));
async function f3(x = 1, y) { return x + y; }
assertEqualsAsync(8, () => f3(5, 3));
assertEqualsAsync(3, () => f3(undefined, 2));
assertEqualsAsync(6, () => f3(4, 2));
async function f4(x = () => 1) { return x() }
assertEqualsAsync(1, () => f4());
assertEqualsAsync(1, () => f4(undefined));
assertEqualsAsync(2, () => f4(() => 2));
assertThrowsAsync(() => f4(null), TypeError);
async function f5(x, y = () => x) { return x + y(); }
assertEqualsAsync(8, () => f5(4));
assertEqualsAsync(8, () => f5(4, undefined));
assertEqualsAsync(6, () => f5(4, () => 2));
async function f6(x = {a: 1, m() { return 2 }}) { return x.a + x.m(); }
assertEqualsAsync(3, () => f6());
assertEqualsAsync(3, () => f6(undefined));
assertEqualsAsync(5, () => f6({a: 2, m() { return 3 }}));
var g1 = async (x = 1) => { return x };
assertEqualsAsync(1, () => g1());
assertEqualsAsync(1, () => g1(undefined));
assertEqualsAsync(2, () => g1(2));
assertEqualsAsync(null, () => g1(null));
var g2 = async (x, y = x) => { return x + y; };
assertEqualsAsync(8, () => g2(4));
assertEqualsAsync(8, () => g2(4, undefined));
assertEqualsAsync(6, () => g2(4, 2));
var g3 = async (x = 1, y) => { return x + y; };
assertEqualsAsync(8, () => g3(5, 3));
assertEqualsAsync(3, () => g3(undefined, 2));
assertEqualsAsync(6, () => g3(4, 2));
var g4 = async (x = () => 1) => { return x() };
assertEqualsAsync(1, () => g4());
assertEqualsAsync(1, () => g4(undefined));
assertEqualsAsync(2, () => g4(() => 2));
assertThrowsAsync(() => g4(null), TypeError);
var g5 = async (x, y = () => x) => { return x + y(); };
assertEqualsAsync(8, () => g5(4));
assertEqualsAsync(8, () => g5(4, undefined));
assertEqualsAsync(6, () => g5(4, () => 2));
var g6 = async (x = {a: 1, m() { return 2 }}) => { return x.a + x.m(); };
assertEqualsAsync(3, () => g6());
assertEqualsAsync(3, () => g6(undefined));
assertEqualsAsync(5, () => g6({a: 2, m() { return 3 }}));
}());
(function TestEvalInParameters() {
async function f1(x = eval(0)) { return x }
assertEqualsAsync(0, f1);
async function f2(x = () => eval(1)) { return x() }
assertEqualsAsync(1, f2);
})();
(function TestParameterScopingSloppy() {
var x = 1;
async function f1(a = x) { var x = 2; return a; }
assertEqualsAsync(1, f1);
async function f2(a = x) { function x() {}; return a; }
assertEqualsAsync(1, () => f2());
async function f3(a = eval("x")) { var x; return a; }
assertEqualsAsync(1, () => f3());
async function f31(a = eval("'use strict'; x")) { var x; return a; }
assertEqualsAsync(1, () => f31());
async function f4(a = function() { return x }) { var x; return a(); }
assertEqualsAsync(1, () => f4());
async function f5(a = () => x) { var x; return a(); }
assertEqualsAsync(1, () => f5());
async function f6(a = () => eval("x")) { var x; return a(); }
assertEqualsAsync(1, () => f6());
async function f61(a = () => { 'use strict'; return eval("x") }) { var x; return a(); }
assertEqualsAsync(1, () => f61());
async function f62(a = () => eval("'use strict'; x")) { var x; return a(); }
assertEqualsAsync(1, () => f62());
var g1 = async (a = x) => { var x = 2; return a; };
assertEqualsAsync(1, () => g1());
var g2 = async (a = x) => { function x() {}; return a; };
assertEqualsAsync(1, () => g2());
var g3 = async (a = eval("x")) => { var x; return a; };
assertEqualsAsync(1, g3);
var g31 = async (a = eval("'use strict'; x")) => { var x; return a; };
assertEqualsAsync(1, () => g31());
var g4 = async (a = function() { return x }) => { var x; return a(); };
assertEqualsAsync(1, () => g4());
var g5 = async (a = () => x) => { var x; return a(); };
assertEqualsAsync(1, () => g5());
var g6 = async (a = () => eval("x")) => { var x; return a(); };
assertEqualsAsync(1, () => g6());
var g61 = async (a = () => { 'use strict'; return eval("x") }) => { var x; return a(); };
assertEqualsAsync(1, () => g61());
var g62 = async (a = () => eval("'use strict'; x")) => { var x; return a(); };
assertEqualsAsync(1, () => g62());
var f11 = async function f(x = f) { var f; return x; }
assertEqualsAsync(f11, f11);
var f12 = async function f(x = f) { function f() {}; return x; }
assertEqualsAsync(f12, f12);
var f13 = async function f(f = 7, x = f) { return x; }
assertEqualsAsync(7, f13);
var o1 = {f: async function(x = this) { return x; }};
assertEqualsAsync(o1, () => o1.f());
assertEqualsAsync(1, () => o1.f(1));
})();
(function TestParameterScopingStrict() {
"use strict";
var x = 1;
async function f1(a = x) { let x = 2; return a; }
assertEqualsAsync(1, () => f1());
async function f2(a = x) { const x = 2; return a; }
assertEqualsAsync(1, () => f2());
async function f3(a = x) { function x() {}; return a; }
assertEqualsAsync(1, () => f3());
async function f4(a = eval("x")) { var x; return a; }
assertEqualsAsync(1, () => f4());
async function f5(a = () => eval("x")) { var x; return a(); }
assertEqualsAsync(1, () => f5());
var g1 = async (a = x) => { let x = 2; return a; };
assertEqualsAsync(1, () => g1());
var g2 = async (a = x) => { const x = 2; return a; };
assertEqualsAsync(1, () => g2());
var g3 = async (a = x) => { function x() {}; return a; };
assertEqualsAsync(1, () => g3());
var g4 = async (a = eval("x")) => { var x; return a; };
assertEqualsAsync(1, () => g4());
var g5 = async (a = () => eval("x")) => { var x; return a(); };
assertEqualsAsync(1, () => g5());
var f11 = async function f(x = f) { let f; return x; }
assertEqualsAsync(f11, f11);
var f12 = async function f(x = f) { const f = 0; return x; }
assertEqualsAsync(f12, f12);
var f13 = async function f(x = f) { function f() {}; return x; }
assertEqualsAsync(f13, f13);
})();
(function TestSloppyEvalScoping() {
var x = 1;
async function f1(y = eval("var x = 2")) { with ({}) { return x; } }
assertEqualsAsync(2, () => f1());
async function f2(y = eval("var x = 2"), z = x) { return z; }
assertEqualsAsync(2, () => f2());
assertEqualsAsync(1, () => f2(0));
async function f3(y = eval("var x = 2"), z = eval("x")) { return z; }
assertEqualsAsync(2, () => f3());
assertEqualsAsync(1, () => f3(0));
async function f8(y = (eval("var x = 2"), x)) { return y; }
assertEqualsAsync(2, () => f8());
assertEqualsAsync(0, () => f8(0));
async function f11(z = eval("var y = 2")) { return y; }
assertEqualsAsync(2, () => f11());
async function f12(z = eval("var y = 2"), b = y) { return b; }
assertEqualsAsync(2, () => f12());
async function f13(z = eval("var y = 2"), b = eval("y")) { return b; }
assertEqualsAsync(2, () => f13());
async function f21(f = () => x) { eval("var x = 2"); return f() }
assertEqualsAsync(1, () => f21());
assertEqualsAsync(3, () => f21(() => 3));
async function f22(f = () => eval("x")) { eval("var x = 2"); return f() }
assertEqualsAsync(1, () => f22());
assertEqualsAsync(3, () => f22(() => 3));
var g1 = async (y = eval("var x = 2")) => { with ({}) { return x; } };
assertEqualsAsync(2, () => g1());
var g2 = async (y = eval("var x = 2"), z = x) => { return z; };
assertEqualsAsync(2, () => g2());
assertEqualsAsync(1, () => g2(0));
var g3 = async (y = eval("var x = 2"), z = eval("x")) => { return z; };
assertEqualsAsync(2, () => g3());
assertEqualsAsync(1, () => g3(0));
var g8 = async (y = (eval("var x = 2"), x)) => { return y; };
assertEqualsAsync(2, () => g8());
assertEqualsAsync(0, () => g8(0));
var g11 = async (z = eval("var y = 2")) => { return y; };
assertEqualsAsync(2, () => g11());
var g12 = async (z = eval("var y = 2"), b = y) => { return b; };
assertEqualsAsync(2, () => g12());
var g13 = async (z = eval("var y = 2"), b = eval("y")) => { return b; };
assertEqualsAsync(2, () => g13());
var g21 = async (f = () => x) => { eval("var x = 2"); return f() };
assertEqualsAsync(1, () => g21());
assertEqualsAsync(3, () => g21(() => 3));
var g22 = async (f = () => eval("x")) => { eval("var x = 2"); return f() };
assertEqualsAsync(1, () => g22());
assertEqualsAsync(3, () => g22(() => 3));
})();
(function TestStrictEvalScoping() {
'use strict';
var x = 1;
async function f1(y = eval("var x = 2")) { return x; }
assertEqualsAsync(1, () => f1());
async function f2(y = eval("var x = 2"), z = x) { return z; }
assertEqualsAsync(1, () => f2());
assertEqualsAsync(1, () => f2(0));
async function f3(y = eval("var x = 2"), z = eval("x")) { return z; }
assertEqualsAsync(1, () => f3());
assertEqualsAsync(1, () => f3(0));
async function f8(y = (eval("var x = 2"), x)) { return y; }
assertEqualsAsync(1, () => f8());
assertEqualsAsync(0, () => f8(0));
async function f11(z = eval("var y = 2")) { return y; }
assertThrowsAsync(f11, ReferenceError);
async function f12(z = eval("var y = 2"), b = y) {}
assertThrowsAsync(f12, ReferenceError);
async function f13(z = eval("var y = 2"), b = eval("y")) {}
assertThrowsAsync(f13, ReferenceError);
async function f21(f = () => x) { eval("var x = 2"); return f() }
assertEqualsAsync(1, () => f21());
assertEqualsAsync(3, () => f21(() => 3));
async function f22(f = () => eval("x")) { eval("var x = 2"); return f() }
assertEqualsAsync(1, () => f22());
assertEqualsAsync(3, () => f22(() => 3));
})();
(function TestParameterTDZSloppy() {
async function f1(a = x, x) { return a }
assertThrowsAsync(() => f1(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f1(4, 5));
async function f2(a = eval("x"), x) { return a }
assertThrowsAsync(() => f2(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f2(4, 5));
async function f3(a = eval("'use strict'; x"), x) { return a }
assertThrowsAsync(() => f3(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f3(4, 5));
async function f4(a = () => x, x) { return a() }
assertEqualsAsync(4, () => f4(() => 4, 5));
async function f5(a = () => eval("x"), x) { return a() }
assertEqualsAsync(4, () => f5(() => 4, 5));
async function f6(a = () => eval("'use strict'; x"), x) { return a() }
assertEqualsAsync(4, () => f6(() => 4, 5));
async function f11(a = x, x = 2) { return a }
assertThrowsAsync(() => f11(), ReferenceError);
assertThrowsAsync(() => f11(undefined), ReferenceError);
assertThrowsAsync(() => f11(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f1(4, 5));
async function f12(a = eval("x"), x = 2) { return a }
assertThrowsAsync(() => f12(), ReferenceError);
assertThrowsAsync(() => f12(undefined), ReferenceError);
assertThrowsAsync(() => f12(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f12(4, 5));
async function f13(a = eval("'use strict'; x"), x = 2) { return a }
assertThrowsAsync(() => f13(), ReferenceError);
assertThrowsAsync(() => f13(undefined), ReferenceError);
assertThrowsAsync(() => f13(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f13(4, 5));
async function f21(x = function() { return a }, ...a) { return x()[0] }
assertEqualsAsync(4, () => f21(undefined, 4));
async function f22(x = () => a, ...a) { return x()[0] }
assertEqualsAsync(4, () => f22(undefined, 4));
async function f23(x = () => eval("a"), ...a) { return x()[0] }
assertEqualsAsync(4, () => f23(undefined, 4));
async function f24(x = () => {'use strict'; return eval("a") }, ...a) {
return x()[0]
}
assertEqualsAsync(4, () => f24(undefined, 4));
async function f25(x = () => eval("'use strict'; a"), ...a) { return x()[0] }
assertEqualsAsync(4, () => f25(undefined, 4));
var g1 = async (x = function() { return a }, ...a) => { return x()[0] };
assertEqualsAsync(4, () => g1(undefined, 4));
var g2 = async (x = () => a, ...a) => { return x()[0] };
assertEqualsAsync(4, () => g2(undefined, 4));
})();
(function TestParameterTDZStrict() {
"use strict";
async function f1(a = eval("x"), x) { return a }
assertThrowsAsync(() => f1(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f1(4, 5));
async function f2(a = () => eval("x"), x) { return a() }
assertEqualsAsync(4, () => f2(() => 4, 5));
async function f11(a = eval("x"), x = 2) { return a }
assertThrowsAsync(() => f11(), ReferenceError);
assertThrowsAsync(() => f11(undefined), ReferenceError);
assertThrowsAsync(() => f11(undefined, 4), ReferenceError);
assertEqualsAsync(4, () => f11(4, 5));
async function f21(x = () => eval("a"), ...a) { return x()[0] }
assertEqualsAsync(4, () => f21(undefined, 4));
})();
(function TestArgumentsForNonSimpleParameters() {
async function f1(x = 900) { arguments[0] = 1; return x }
assertEqualsAsync(9, () => f1(9));
assertEqualsAsync(900, () => f1());
async function f2(x = 1001) { x = 2; return arguments[0] }
assertEqualsAsync(10, () => f2(10));
assertEqualsAsync(undefined, () => f2());
}());
(function TestFunctionLength() {
assertEquals(0, (async function(x = 1) {}).length);
assertEquals(0, (async function(x = 1, ...a) {}).length);
assertEquals(1, (async function(x, y = 1) {}).length);
assertEquals(1, (async function(x, y = 1, ...a) {}).length);
assertEquals(2, (async function(x, y, z = 1) {}).length);
assertEquals(2, (async function(x, y, z = 1, ...a) {}).length);
assertEquals(1, (async function(x, y = 1, z) {}).length);
assertEquals(1, (async function(x, y = 1, z, ...a) {}).length);
assertEquals(1, (async function(x, y = 1, z, v = 2) {}).length);
assertEquals(1, (async function(x, y = 1, z, v = 2, ...a) {}).length);
})();
(function TestDirectiveThrows() {
"use strict";
assertThrows("(async function(x=1){'use strict';})", SyntaxError);
assertThrows("(async function(a, x=1){'use strict';})", SyntaxError);
assertThrows("(async function({x}){'use strict';})", SyntaxError);
})();

View File

@ -0,0 +1,176 @@
// Copyright 2016 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: --noasync-stack-traces
async function test(func, funcs) {
try {
await func();
throw new Error("Expected " + func.toString() + " to throw");
} catch (e) {
var stack = e.stack.split('\n').
slice(1).
map(line => line.trim()).
map(line => line.match(/at (?:(.*) )?.*$/)[1]).
filter(x => typeof x === 'string' && x.length);
assertEquals(funcs, stack, `Unexpected stack trace ${e.stack}`);
}
}
function thrower() { throw new Error("NOPE"); }
function reject() { return Promise.reject(new Error("NOPE")); }
async function runTests() {
await test(async function a() {
throw new Error("FAIL");
},
["a", "test", "runTests"]);
await test(async function a2() {
await 1;
throw new Error("FAIL");
}, ["a2"]);
await test(async function a3() {
await 1;
try { await thrower(); } catch (e) { throw new Error("FAIL"); }
}, ["a3"]);
await test(async function a4() {
await 1;
try { await reject(); } catch (e) { throw new Error("FAIL"); }
}, ["a4"]);
await test({ async b() {
throw new Error("FAIL");
}}.b,
["b", "test", "runTests"]);
await test({ async b2() {
await 1;
throw new Error("FAIL");
}}.b2, ["b2"]);
await test({ async b3() {
await 1;
try { await thrower(); } catch (e) { throw new Error("FAIL"); }
} }.b3, ["b3"]);
await test({ async b4() {
await 1;
try { await reject(); } catch (e) { throw new Error("FAIL"); }
} }.b4, ["b4"]);
await test((new class { async c() {
throw new Error("FAIL");
} }).c,
["c", "test", "runTests"]);
await test((new class { async c2() {
await 1;
throw new Error("FAIL");
} }).c2, ["c2"]);
await test((new class { async c3() {
await 1;
try { await thrower(); } catch (e) { throw new Error("FAIL"); }
} }).c3, ["c3"]);
await test((new class { async c4() {
await 1;
try { await reject(); } catch (e) { throw new Error("FAIL"); }
} }).c4, ["c4"]);
await test(async x => { throw new Error("FAIL") },
["test", "runTests"]);
await test(async() => { throw new Error("FAIL") },
["test", "runTests"]);
await test(async(a) => { throw new Error("FAIL") },
["test", "runTests"]);
await test(async(a, b) => { throw new Error("FAIL") },
["test", "runTests"]);
await test(async x => { await 1; throw new Error("FAIL") }, []);
await test(async() => { await 1; throw new Error("FAIL") }, []);
await test(async(a) => { await 1; throw new Error("FAIL") }, []);
await test(async(a, b) => { await 1; throw new Error("FAIL") }, []);
await test(async x => {
await 1;
try {
await thrower();
} catch (e) {
throw new Error("FAIL");
}
}, []);
await test(async() => {
await 1;
try {
await thrower();
} catch (e) {
throw new Error("FAIL");
}
}, []);
await test(async(a) => {
await 1;
try {
await thrower();
} catch (e) {
throw new Error("FAIL");
}
}, []);
await test(async(a, b) => {
await 1;
try {
await thrower();
} catch (e) {
throw new Error("FAIL");
}
}, []);
await test(async x => {
await 1;
try {
await reject();
} catch (e) {
throw new Error("FAIL");
}
}, []);
await test(async() => {
await 1;
try {
await reject();
} catch (e) {
throw new Error("FAIL");
}
}, []);
await test(async(a) => {
await 1;
try {
await reject();
} catch (e) {
throw new Error("FAIL");
}
}, []);
await test(async(a, b) => {
await 1;
try {
await reject();
} catch (e) {
throw new Error("FAIL");
}
}, []);
}
runTests().catch(e => {
print(e);
quit(1);
});

View File

@ -0,0 +1,201 @@
// 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.
// Flags: --allow-natives-syntax
function assertThrowsAsync(run, errorType, message) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (!hadError) {
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw " + errorType.name +
", but did not throw.");
}
if (!(actual instanceof errorType))
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw " + errorType.name +
", but threw '" + actual + "'");
if (message !== void 0 && actual.message !== message)
throw new MjsUnitAssertionError(
"Expected " + run + "() to throw '" + message + "', but threw '" +
actual.message + "'");
};
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + PrettyPrint(promise));
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
};
function resolveLater(value) {
return new Promise(function(resolve) {
resolve(value);
});
}
function rejectLater(reason) {
return new Promise(function(resolve, reject) {
reject(reason);
});
}
class MyError extends Error {};
var AsyncFunction = async function() {}.constructor;
assertEqualsAsync("finally-return (func-expr)", async function() {
try {
return "early-return (func-expr)";
} finally {
return "finally-return (func-expr)";
}
});
assertEqualsAsync("finally-return (arrow)", async() => {
try {
return "early-return (arrow)";
} finally {
return "finally-return (arrow)";
}
});
assertEqualsAsync("finally-return (eval)", AsyncFunction(`
try {
return "early-return (eval)";
} finally {
return "finally-return (eval)";
}
`));
assertEqualsAsync("promise-finally-return (func-expr)", async function() {
try {
return new Promise(function() {});
} finally {
return "promise-finally-return (func-expr)";
}
});
assertEqualsAsync("promise-finally-return (arrow)", async() => {
try {
return new Promise(function() {});
} finally {
return "promise-finally-return (arrow)";
}
});
assertEqualsAsync("promise-finally-return (eval)", AsyncFunction(`
try {
return new Promise(function() {});
} finally {
return "promise-finally-return (eval)";
}
`));
assertEqualsAsync("await-finally-return (func-expr)", async function() {
try {
return "early-return (func-expr)";
} finally {
return await resolveLater("await-finally-return (func-expr)");
}
});
assertEqualsAsync("await-finally-return (arrow)", async() => {
try {
return "early-return (arrow)";
} finally {
return await resolveLater("await-finally-return (arrow)");
}
});
assertEqualsAsync("await-finally-return (eval)", AsyncFunction(`
try {
return "early-return (eval)";
} finally {
return await resolveLater("await-finally-return (eval)");
}
`));
assertThrowsAsync(async function() {
try {
return "early-return (func-expr)";
} finally {
throw new MyError("finally-throw (func-expr)");
}
}, MyError, "finally-throw (func-expr)");
assertThrowsAsync(async() => {
try {
return "early-return (arrow)";
} finally {
throw new MyError("finally-throw (arrow)");
}
}, MyError, "finally-throw (arrow)");
assertThrowsAsync(AsyncFunction(`
try {
return "early-return (eval)";
} finally {
throw new MyError("finally-throw (eval)");
}
`), MyError, "finally-throw (eval)");
assertThrowsAsync(async function() {
try {
return "early-return (func-expr)";
} finally {
await rejectLater(new MyError("await-finally-throw (func-expr)"));
}
}, MyError, "await-finally-throw (func-expr)");
assertThrowsAsync(async() => {
try {
return "early-return (arrow)";
} finally {
await rejectLater(new MyError("await-finally-throw (arrow)"));
}
}, MyError, "await-finally-throw (arrow)");
assertThrowsAsync(AsyncFunction(`
try {
return "early-return (eval)";
} finally {
await rejectLater(new MyError("await-finally-throw (eval)"));
}
`), MyError, "await-finally-throw (eval)");

View File

@ -0,0 +1,411 @@
// Copyright 2016 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
function TestMeta() {
assertEquals(1, Object.entries.length);
assertEquals(Function.prototype, Object.getPrototypeOf(Object.entries));
assertEquals("entries", Object.entries.name);
var descriptor = Object.getOwnPropertyDescriptor(Object, "entries");
assertTrue(descriptor.writable);
assertFalse(descriptor.enumerable);
assertTrue(descriptor.configurable);
assertThrows(() => new Object.entries({}), TypeError);
}
TestMeta();
function TestBasic(withWarmup) {
var x = 16;
var O = {
d: 1,
c: 3,
[Symbol.iterator]: void 0,
0: 123,
1000: 456,
[x * x]: "ducks",
[`0x${(x * x).toString(16)}`]: "quack"
};
O.a = 2;
O.b = 4;
Object.defineProperty(O, "HIDDEN", { enumerable: false, value: NaN });
if (withWarmup) {
for (const key in O) {}
}
O.c = 6;
const resultEntries = [
["0", 123],
["256", "ducks"],
["1000", 456],
["d", 1],
["c", 6],
["0x100", "quack"],
["a", 2],
["b", 4]
];
assertEquals(resultEntries, Object.entries(O));
assertEquals(resultEntries, Object.entries(O));
assertEquals(Object.entries(O), Object.keys(O).map(key => [key, O[key]]));
assertTrue(Array.isArray(Object.entries({})));
assertEquals(0, Object.entries({}).length);
}
TestBasic();
TestBasic(true);
function TestToObject() {
assertThrows(function() { Object.entries(); }, TypeError);
assertThrows(function() { Object.entries(null); }, TypeError);
assertThrows(function() { Object.entries(void 0); }, TypeError);
}
TestToObject();
function TestOrder(withWarmup) {
var O = {
a: 1,
[Symbol.iterator]: null
};
O[456] = 123;
Object.defineProperty(O, "HIDDEN", { enumerable: false, value: NaN });
var priv = %CreatePrivateSymbol("Secret");
O[priv] = 56;
var log = [];
var P = new Proxy(O, {
ownKeys(target) {
log.push("[[OwnPropertyKeys]]");
return Reflect.ownKeys(target);
},
get(target, name) {
log.push(`[[Get]](${JSON.stringify(name)})`);
return Reflect.get(target, name);
},
getOwnPropertyDescriptor(target, name) {
log.push(`[[GetOwnProperty]](${JSON.stringify(name)})`);
return Reflect.getOwnPropertyDescriptor(target, name);
},
set(target, name, value) {
assertUnreachable();
}
});
if (withWarmup) {
for (const key in P) {}
}
log = [];
assertEquals([["456", 123], ["a", 1]], Object.entries(P));
assertEquals([
"[[OwnPropertyKeys]]",
"[[GetOwnProperty]](\"456\")",
"[[Get]](\"456\")",
"[[GetOwnProperty]](\"a\")",
"[[Get]](\"a\")",
"[[GetOwnProperty]](\"HIDDEN\")"
], log);
}
TestOrder();
TestOrder(true);
function TestOrderWithDuplicates(withWarmup) {
var O = {
a: 1,
[Symbol.iterator]: null
};
O[456] = 123;
Object.defineProperty(O, "HIDDEN", { enumerable: false, value: NaN });
var priv = %CreatePrivateSymbol("Secret");
O[priv] = 56;
var log = [];
var P = new Proxy(O, {
ownKeys(target) {
log.push("[[OwnPropertyKeys]]");
return ["a", Symbol.iterator, "a", "456", "HIDDEN", "HIDDEN", "456"];
},
get(target, name) {
log.push(`[[Get]](${JSON.stringify(name)})`);
return Reflect.get(target, name);
},
getOwnPropertyDescriptor(target, name) {
log.push(`[[GetOwnProperty]](${JSON.stringify(name)})`);
return Reflect.getOwnPropertyDescriptor(target, name);
},
set(target, name, value) {
assertUnreachable();
}
});
if (withWarmup) {
for (const key in O) {};
try { for (const key in P) {} } catch {};
}
assertThrows(() => Object.entries(P), TypeError);
}
TestOrderWithDuplicates();
TestOrderWithDuplicates(true);
function TestDescriptorProperty() {
function f() {};
const o = {};
o.a = f;
for (const key in o) {};
const entries = Object.entries(o);
assertEquals([['a', f]], entries);
}
TestDescriptorProperty();
function TestPropertyFilter(withWarmup) {
var object = { prop3: 30 };
object[2] = 40;
object["prop4"] = 50;
Object.defineProperty(object, "prop5", { value: 60, enumerable: true });
Object.defineProperty(object, "prop6", { value: 70, enumerable: false });
Object.defineProperty(object, "prop7", {
enumerable: true, get() { return 80; }});
var sym = Symbol("prop8");
object[sym] = 90;
if (withWarmup) {
for (const key in object) {}
}
values = Object.entries(object);
assertEquals(5, values.length);
assertEquals([
[ "2", 40 ],
[ "prop3", 30 ],
[ "prop4", 50 ],
[ "prop5", 60 ],
[ "prop7", 80 ]
], values);
}
TestPropertyFilter();
TestPropertyFilter(true);
function TestPropertyFilter2(withWarmup) {
var object = { };
Object.defineProperty(object, "prop1", { value: 10 });
Object.defineProperty(object, "prop2", { value: 20 });
object.prop3 = 30;
if (withWarmup) {
for (const key in object) {}
}
values = Object.entries(object);
assertEquals(1, values.length);
assertEquals([
[ "prop3", 30 ],
], values);
}
TestPropertyFilter2();
TestPropertyFilter2(true);
function TestWithProxy(withWarmup) {
var obj1 = {prop1:10};
var proxy1 = new Proxy(obj1, { });
if (withWarmup) {
for (const key in proxy1) {}
}
assertEquals([ [ "prop1", 10 ] ], Object.entries(proxy1));
var obj2 = {};
Object.defineProperty(obj2, "prop2", { value: 20, enumerable: true });
Object.defineProperty(obj2, "prop3", {
get() { return 30; }, enumerable: true });
var proxy2 = new Proxy(obj2, {
getOwnPropertyDescriptor(target, name) {
return Reflect.getOwnPropertyDescriptor(target, name);
}
});
if (withWarmup) {
for (const key in proxy2) {}
}
assertEquals([ [ "prop2", 20 ], [ "prop3", 30 ] ], Object.entries(proxy2));
var obj3 = {};
var count = 0;
var proxy3 = new Proxy(obj3, {
get(target, property, receiver) {
return count++ * 5;
},
getOwnPropertyDescriptor(target, property) {
return { configurable: true, enumerable: true };
},
ownKeys(target) {
return [ "prop0", "prop1", Symbol("prop2"), Symbol("prop5") ];
}
});
if (withWarmup) {
for (const key in proxy3) {}
}
assertEquals([ [ "prop0", 0 ], [ "prop1", 5 ] ], Object.entries(proxy3));
}
TestWithProxy();
TestWithProxy(true);
function TestMutateDuringEnumeration(withWarmup) {
var aDeletesB = {
get a() {
delete this.b;
return 1;
},
b: 2
};
if (withWarmup) {
for (const key in aDeletesB) {}
}
assertEquals([ [ "a", 1 ] ], Object.entries(aDeletesB));
var aRemovesB = {
get a() {
Object.defineProperty(this, "b", { enumerable: false });
return 1;
},
b: 2
};
if (withWarmup) {
for (const key in aRemovesB) {}
}
assertEquals([ [ "a", 1 ] ], Object.entries(aRemovesB));
var aAddsB = { get a() { this.b = 2; return 1; } };
if (withWarmup) {
for (const key in aAddsB) {}
}
assertEquals([ [ "a", 1 ] ], Object.entries(aAddsB));
var aMakesBEnumerable = {};
Object.defineProperty(aMakesBEnumerable, "a", {
get() {
Object.defineProperty(this, "b", { enumerable: true });
return 1;
},
enumerable: true
});
Object.defineProperty(aMakesBEnumerable, "b", {
value: 2, configurable:true, enumerable: false });
if (withWarmup) {
for (const key in aMakesBEnumerable) {}
}
assertEquals([ [ "a", 1 ], [ "b", 2 ] ], Object.entries(aMakesBEnumerable));
}
TestMutateDuringEnumeration();
TestMutateDuringEnumeration(true);
function TestElementKinds(withWarmup) {
var O1 = { name: "1" }, O2 = { name: "2" }, O3 = { name: "3" };
var PI = 3.141592653589793;
var E = 2.718281828459045;
function fastSloppyArguments(a, b, c) {
delete arguments[0];
arguments[0] = a;
return arguments;
}
function slowSloppyArguments(a, b, c) {
delete arguments[0];
arguments[0] = a;
Object.defineProperties(arguments, {
0: {
enumerable: true,
value: a
},
9999: {
enumerable: false,
value: "Y"
}
});
arguments[10000] = "X";
return arguments;
}
var element_kinds = {
PACKED_SMI_ELEMENTS: [ [1, 2, 3], [ ["0", 1], ["1", 2], ["2", 3] ] ],
HOLEY_SMI_ELEMENTS: [ [, , 3], [ ["2", 3] ] ],
PACKED_ELEMENTS: [ [O1, O2, O3], [ ["0", O1], ["1", O2], ["2", O3] ] ],
HOLEY_ELEMENTS: [ [, , O3], [ ["2", O3] ] ],
PACKED_DOUBLE_ELEMENTS: [ [E, NaN, PI], [ ["0", E], ["1", NaN], ["2", PI] ] ],
HOLEY_DOUBLE_ELEMENTS: [ [, , NaN], [ ["2", NaN] ] ],
DICTIONARY_ELEMENTS: [ Object.defineProperties({ 10000: "world" }, {
100: { enumerable: true, value: "hello", configurable: true},
99: { enumerable: false, value: "nope", configurable: true}
}), [ ["100", "hello"], ["10000", "world" ] ] ],
FAST_SLOPPY_ARGUMENTS_ELEMENTS: [
fastSloppyArguments("a", "b", "c"),
[ ["0", "a"], ["1", "b"], ["2", "c"] ] ],
SLOW_SLOPPY_ARGUMENTS_ELEMENTS: [
slowSloppyArguments("a", "b", "c"),
[ ["0", "a"], ["1", "b"], ["2", "c"], ["10000", "X"] ] ],
FAST_STRING_WRAPPER_ELEMENTS: [ new String("str"),
[ ["0", "s"], ["1", "t"], ["2", "r"]] ],
SLOW_STRING_WRAPPER_ELEMENTS: [
Object.defineProperties(new String("str"), {
10000: { enumerable: false, value: "X", configurable: true},
9999: { enumerable: true, value: "Y", configurable: true}
}), [["0", "s"], ["1", "t"], ["2", "r"], ["9999", "Y"]] ],
};
if (withWarmup) {
for (const key in element_kinds) {}
}
for (let [kind, [object, expected]] of Object.entries(element_kinds)) {
if (withWarmup) {
for (const key in object) {}
}
let result1 = Object.entries(object);
%HeapObjectVerify(object);
%HeapObjectVerify(result1);
assertEquals(expected, result1, `fast Object.entries() with ${kind}`);
let proxy = new Proxy(object, {});
if (withWarmup) {
for (const key in proxy) {}
}
let result2 = Object.entries(proxy);
%HeapObjectVerify(result2);
assertEquals(result1, result2, `slow Object.entries() with ${kind}`);
}
function makeFastElements(array) {
// Remove all possible getters.
for (let k of Object.getOwnPropertyNames(this)) {
if (k == "length") continue;
delete this[k];
}
// Make the array large enough to trigger re-checking for compaction.
this[1000] = 1;
// Make the elements fast again.
Array.prototype.unshift.call(this, 1.1);
}
// Test that changing the elements kind is supported.
for (let [kind, [object, expected]] of Object.entries(element_kinds)) {
if (kind == "FAST_STRING_WRAPPER_ELEMENTS") break;
object.__defineGetter__(1, makeFastElements);
if (withWarmup) {
for (const key in object) {}
}
let result1 = Object.entries(object).toString();
%HeapObjectVerify(object);
%HeapObjectVerify(result1);
}
}
TestElementKinds();
TestElementKinds(true);

View File

@ -0,0 +1,220 @@
// Copyright 2016 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
function DataDescriptor(value) {
return { "enumerable": true, "configurable": true, "writable": true, value };
}
function TestMeta() {
assertEquals(1, Object.getOwnPropertyDescriptors.length);
assertEquals(Function.prototype,
Object.getPrototypeOf(Object.getOwnPropertyDescriptors));
assertEquals(
'getOwnPropertyDescriptors', Object.getOwnPropertyDescriptors.name);
var desc = Reflect.getOwnPropertyDescriptor(
Object, 'getOwnPropertyDescriptors');
assertFalse(desc.enumerable);
assertTrue(desc.writable);
assertTrue(desc.configurable);
}
TestMeta();
function TestToObject() {
assertThrows(function() {
Object.getOwnPropertyDescriptors(null);
}, TypeError);
assertThrows(function() {
Object.getOwnPropertyDescriptors(undefined);
}, TypeError);
assertThrows(function() {
Object.getOwnPropertyDescriptors();
}, TypeError);
}
TestToObject();
function TestPrototypeProperties() {
function F() {};
F.prototype.a = "A";
F.prototype.b = "B";
var F2 = new F();
Object.defineProperties(F2, {
"b": {
enumerable: false,
configurable: true,
writable: false,
value: "Shadowed 'B'"
},
"c": {
enumerable: false,
configurable: true,
writable: false,
value: "C"
}
});
assertEquals({
"b": {
enumerable: false,
configurable: true,
writable: false,
value: "Shadowed 'B'"
},
"c": {
enumerable: false,
configurable: true,
writable: false,
value: "C"
}
}, Object.getOwnPropertyDescriptors(F2));
}
TestPrototypeProperties();
function TestPrototypeProperties() {
function F() {};
F.prototype.a = "A";
F.prototype.b = "B";
var F2 = new F();
Object.defineProperties(F2, {
"b": {
enumerable: false,
configurable: true,
writable: false,
value: "Shadowed 'B'"
},
"c": {
enumerable: false,
configurable: true,
writable: false,
value: "C"
}
});
assertEquals({
"b": {
enumerable: false,
configurable: true,
writable: false,
value: "Shadowed 'B'"
},
"c": {
enumerable: false,
configurable: true,
writable: false,
value: "C"
}
}, Object.getOwnPropertyDescriptors(F2));
}
TestPrototypeProperties();
function TestTypeFilteringAndOrder() {
var log = [];
var sym = Symbol("foo");
var psym = %CreatePrivateSymbol("private");
var O = {
0: 0,
[sym]: 3,
"a": 2,
[psym]: 4,
1: 1,
};
var P = new Proxy(O, {
ownKeys(target) {
log.push("ownKeys()");
return Reflect.ownKeys(target);
},
getOwnPropertyDescriptor(target, name) {
log.push(`getOwnPropertyDescriptor(${String(name)})`);
return Reflect.getOwnPropertyDescriptor(target, name);
},
get(target, name) { assertUnreachable(); },
set(target, name, value) { assertUnreachable(); },
deleteProperty(target, name) { assertUnreachable(); },
defineProperty(target, name, desc) { assertUnreachable(); }
});
var result1 = Object.getOwnPropertyDescriptors(O);
assertEquals({
0: DataDescriptor(0),
1: DataDescriptor(1),
"a": DataDescriptor(2),
[sym]: DataDescriptor(3)
}, result1);
var result2 = Object.getOwnPropertyDescriptors(P);
assertEquals([
"ownKeys()",
"getOwnPropertyDescriptor(0)",
"getOwnPropertyDescriptor(1)",
"getOwnPropertyDescriptor(a)",
"getOwnPropertyDescriptor(Symbol(foo))"
], log);
assertEquals({
0: DataDescriptor(0),
1: DataDescriptor(1),
"a": DataDescriptor(2),
[sym]: DataDescriptor(3)
}, result2);
}
TestTypeFilteringAndOrder();
function TestDuplicateKeys() {
var i = 0;
var log = [];
var P = new Proxy({}, {
ownKeys() {
log.push(`ownKeys()`);
return ["A", "A"];
},
getOwnPropertyDescriptor(t, name) {
log.push(`getOwnPropertyDescriptor(${name})`);
if (i++) return;
return {
configurable: true,
writable: false,
value: "VALUE"
};
},
get(target, name) { assertUnreachable(); },
set(target, name, value) { assertUnreachable(); },
deleteProperty(target, name) { assertUnreachable(); },
defineProperty(target, name, desc) { assertUnreachable(); }
});
assertThrows(() => Object.getOwnPropertyDescriptors(P), TypeError);
}
TestDuplicateKeys();
function TestFakeProperty() {
var log = [];
var P = new Proxy({}, {
ownKeys() {
log.push(`ownKeys()`);
return ["fakeProperty"];
},
getOwnPropertyDescriptor(target, name) {
log.push(`getOwnPropertyDescriptor(${name})`);
return;
}
});
var result = Object.getOwnPropertyDescriptors(P);
assertEquals({}, result);
assertFalse(result.hasOwnProperty("fakeProperty"));
assertEquals([
"ownKeys()",
"getOwnPropertyDescriptor(fakeProperty)"
], log);
}
TestFakeProperty();

View File

@ -0,0 +1,284 @@
// Copyright 2016 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
function TestMeta() {
assertEquals(1, Object.values.length);
assertEquals(Function.prototype, Object.getPrototypeOf(Object.values));
assertEquals("values", Object.values.name);
var descriptor = Object.getOwnPropertyDescriptor(Object, "values");
assertTrue(descriptor.writable);
assertFalse(descriptor.enumerable);
assertTrue(descriptor.configurable);
assertThrows(() => new Object.values({}), TypeError);
}
TestMeta();
function TestBasic() {
var x = 16;
var O = {
d: 1,
c: 3,
[Symbol.iterator]: void 0,
0: 123,
1000: 456,
[x * x]: "ducks",
[`0x${(x * x).toString(16)}`]: "quack"
};
O.a = 2;
O.b = 4;
Object.defineProperty(O, "HIDDEN", { enumerable: false, value: NaN });
assertEquals([123, "ducks", 456, 1, 3, "quack", 2, 4], Object.values(O));
assertEquals(Object.values(O), Object.keys(O).map(key => O[key]));
assertTrue(Array.isArray(Object.values({})));
assertEquals(0, Object.values({}).length);
}
TestBasic();
function TestToObject() {
assertThrows(function() { Object.values(); }, TypeError);
assertThrows(function() { Object.values(null); }, TypeError);
assertThrows(function() { Object.values(void 0); }, TypeError);
}
TestToObject();
function TestOrder() {
var O = {
a: 1,
[Symbol.iterator]: null
};
O[456] = 123;
Object.defineProperty(O, "HIDDEN", { enumerable: false, value: NaN });
var priv = %CreatePrivateSymbol("Secret");
O[priv] = 56;
var log = [];
var P = new Proxy(O, {
ownKeys(target) {
log.push("[[OwnPropertyKeys]]");
return Reflect.ownKeys(target);
},
get(target, name) {
log.push(`[[Get]](${JSON.stringify(name)})`);
return Reflect.get(target, name);
},
getOwnPropertyDescriptor(target, name) {
log.push(`[[GetOwnProperty]](${JSON.stringify(name)})`);
return Reflect.getOwnPropertyDescriptor(target, name);
},
set(target, name, value) {
assertUnreachable();
}
});
assertEquals([123, 1], Object.values(P));
assertEquals([
"[[OwnPropertyKeys]]",
"[[GetOwnProperty]](\"456\")",
"[[Get]](\"456\")",
"[[GetOwnProperty]](\"a\")",
"[[Get]](\"a\")",
"[[GetOwnProperty]](\"HIDDEN\")"
], log);
}
TestOrder();
function TestOrderWithDuplicates() {
var O = {
a: 1,
[Symbol.iterator]: null
};
O[456] = 123;
Object.defineProperty(O, "HIDDEN", { enumerable: false, value: NaN });
O[priv] = 56;
var priv = %CreatePrivateSymbol("private");
var log = [];
var P = new Proxy(O, {
ownKeys(target) {
log.push("[[OwnPropertyKeys]]");
return [ "a", Symbol.iterator, "a", "456", "HIDDEN", "HIDDEN", "456" ];
},
get(target, name) {
log.push(`[[Get]](${JSON.stringify(name)})`);
return Reflect.get(target, name);
},
getOwnPropertyDescriptor(target, name) {
log.push(`[[GetOwnProperty]](${JSON.stringify(name)})`);
return Reflect.getOwnPropertyDescriptor(target, name);
},
set(target, name, value) {
assertUnreachable();
}
});
assertThrows(() => Object.values(P), TypeError);
}
TestOrderWithDuplicates();
function TestPropertyFilter() {
var object = { prop3: 30 };
object[2] = 40;
object["prop4"] = 50;
Object.defineProperty(object, "prop5", { value: 60, enumerable: true });
Object.defineProperty(object, "prop6", { value: 70, enumerable: false });
Object.defineProperty(object, "prop7", {
enumerable: true, get() { return 80; }});
var sym = Symbol("prop8");
object[sym] = 90;
values = Object.values(object);
assertEquals(5, values.length);
assertEquals([40,30,50,60,80], values);
}
TestPropertyFilter();
function TestWithProxy() {
var obj1 = {prop1:10};
var proxy1 = new Proxy(obj1, { });
assertEquals([10], Object.values(proxy1));
var obj2 = {};
Object.defineProperty(obj2, "prop2", { value: 20, enumerable: true });
Object.defineProperty(obj2, "prop3", {
get() { return 30; }, enumerable: true });
var proxy2 = new Proxy(obj2, {
getOwnPropertyDescriptor(target, name) {
return Reflect.getOwnPropertyDescriptor(target, name);
}
});
assertEquals([20, 30], Object.values(proxy2));
var obj3 = {};
var count = 0;
var proxy3 = new Proxy(obj3, {
get(target, property, receiver) {
return count++ * 5;
},
getOwnPropertyDescriptor(target, property) {
return { configurable: true, enumerable: true };
},
ownKeys(target) {
return [ "prop0", "prop1", Symbol("prop2"), Symbol("prop5") ];
}
});
assertEquals([0, 5], Object.values(proxy3));
}
TestWithProxy();
function TestMutateDuringEnumeration() {
var aDeletesB = {
get a() {
delete this.b;
return 1;
},
b: 2
};
assertEquals([1], Object.values(aDeletesB));
var aRemovesB = {
get a() {
Object.defineProperty(this, "b", { enumerable: false });
return 1;
},
b: 2
};
assertEquals([1], Object.values(aRemovesB));
var aAddsB = { get a() { this.b = 2; return 1; } };
assertEquals([1], Object.values(aAddsB));
var aMakesBEnumerable = {};
Object.defineProperty(aMakesBEnumerable, "a", {
get() {
Object.defineProperty(this, "b", { enumerable: true });
return 1;
},
enumerable: true
});
Object.defineProperty(aMakesBEnumerable, "b", {
value: 2, configurable:true, enumerable: false });
assertEquals([1, 2], Object.values(aMakesBEnumerable));
}
TestMutateDuringEnumeration();
(function TestElementKinds() {
var O1 = { name: "1" }, O2 = { name: "2" }, O3 = { name: "3" };
var PI = 3.141592653589793;
var E = 2.718281828459045;
function fastSloppyArguments(a, b, c) {
delete arguments[0];
arguments[0] = a;
return arguments;
}
function slowSloppyArguments(a, b, c) {
delete arguments[0];
arguments[0] = a;
Object.defineProperties(arguments, {
0: {
enumerable: true,
value: a
},
9999: {
enumerable: false,
value: "Y"
}
});
arguments[10000] = "X";
return arguments;
}
var element_kinds = {
PACKED_SMI_ELEMENTS: [ [1, 2, 3], [1, 2, 3] ],
HOLEY_SMI_ELEMENTS: [ [, , 3], [ 3 ] ],
PACKED_ELEMENTS: [ [O1, O2, O3], [O1, O2, O3] ],
HOLEY_ELEMENTS: [ [, , O3], [O3] ],
PACKED_DOUBLE_ELEMENTS: [ [E, NaN, PI], [E, NaN, PI] ],
HOLEY_DOUBLE_ELEMENTS: [ [, , NaN], [NaN] ],
DICTIONARY_ELEMENTS: [ Object.defineProperties({ 10000: "world" }, {
100: { enumerable: true, value: "hello" },
99: { enumerable: false, value: "nope" }
}), [ "hello", "world" ] ],
FAST_SLOPPY_ARGUMENTS_ELEMENTS: [
fastSloppyArguments("a", "b", "c"), ["a", "b", "c"] ],
SLOW_SLOPPY_ARGUMENTS_ELEMENTS: [
slowSloppyArguments("a", "b", "c"), [ "a", "b", "c", "X"]],
FAST_STRING_WRAPPER_ELEMENTS: [ new String("str"), ["s", "t", "r"] ],
SLOW_STRING_WRAPPER_ELEMENTS: [
Object.defineProperties(new String("str"), {
10000: { enumerable: false, value: "X" },
9999: { enumerable: true, value: "Y" }
}), ["s", "t", "r", "Y"] ],
};
for (let [kind, [object, expected]] of Object.entries(element_kinds)) {
let result1 = Object.values(object);
assertEquals(expected, result1, `fast Object.values() with ${kind}`);
let proxy = new Proxy(object, {});
let result2 = Object.values(proxy);
assertEquals(result1, result2, `slow Object.values() with ${kind}`);
}
})();
(function TestGlobalObject() {
let values = Object.values(globalThis);
assertTrue(values.length > 0);
})();

View File

@ -0,0 +1,12 @@
// Copyright 2016 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.
try {
} catch(e) {; }
function __f_7(expected, run) {
var __v_10 = run();
};
__f_7("[1,2,3]", () => (function() {
return (async () => {[...await arguments] })();
})());

View File

@ -0,0 +1,11 @@
// Copyright 2016 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.
(function f() {
try {
f();
} catch (e) {
(async() => await 1).length;
}
})();

View File

@ -0,0 +1,8 @@
// 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.
// Object.getOwnPropertyDescriptors loads %FunctionPrototype%.caller, an
// accessor property which inspects the current callstack. Verify that this
// callstack iteration doesn't crash when there are no JS frames on the stack.
Promise.resolve(function () {}).then(Object.getOwnPropertyDescriptors);

View File

@ -0,0 +1,28 @@
// Copyright 2016 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.
// Async functions don't get sloppy-mode block-scoped function hoisting
// No hoisting to the global scope
{
async function foo() {}
assertEquals('function', typeof foo);
}
assertEquals('undefined', typeof foo);
// No hoisting within a function scope
(function() {
{ async function bar() {} }
assertEquals('undefined', typeof bar);
})();
// Lexical shadowing allowed, no hoisting
(function() {
var y;
async function x() { y = 1; }
{ async function x() { y = 2; } }
x();
assertEquals(1, y);
})();