Reland "[mjsunit] Add test that calls functions on prototypes with no arguments"
This is a reland of 5fbc5015de
Original change's description:
> [mjsunit] Add test that calls functions on prototypes with no arguments
>
> Change-Id: I0ede9f309b89cfa878a325e3f68327b1682d4ced
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1538123
> Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
> Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#60541}
TBR=jarin@chromium.org
Change-Id: I409e3dab72057bcba6c729f3b181fc29e8c861ad
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1547654
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60547}
This commit is contained in:
parent
c9abc31189
commit
5e8eb540e5
67
test/mjsunit/prototype-arity.js
vendored
Normal file
67
test/mjsunit/prototype-arity.js
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright 2019 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
|
||||
|
||||
const types = [
|
||||
[Object, "{}"],
|
||||
[String, "\"abc\""],
|
||||
[RegExp, "/abc/"],
|
||||
[WeakMap, "(new WeakMap())"],
|
||||
[WeakSet, "(new WeakSet())"],
|
||||
[Map, "(new Map())"],
|
||||
[Set, "(new Set())"],
|
||||
[Function, "(function f() {return 1})"],
|
||||
[Array, "[1,2,3, {}]"],
|
||||
[Boolean, "(new Boolean())"],
|
||||
[Symbol, "(new Symbol())"],
|
||||
[BigInt, "(new BigInt(42))"],
|
||||
[Math, "Math"],
|
||||
[Date, "(new Date())"],
|
||||
[Promise, "(new Promise())"],
|
||||
[Reflect, "Reflect"],
|
||||
[Proxy, "(new Proxy({}, {}))"],
|
||||
];
|
||||
|
||||
if (typeof Intl == "object") {
|
||||
types.push([Intl, "Intl"]);
|
||||
types.push([Intl.Collator, "Intl.Collator"]);
|
||||
types.push([Intl.ListFormat, "Intl.ListFormat"]);
|
||||
types.push([Intl.NumberFormat, "Intl.NumberFormat"]);
|
||||
types.push([Intl.PluralRules, "Intl.PluralRules"]);
|
||||
types.push([Intl.RelativeTimeFormat, "Intl.RelativeTimeFormat"]);
|
||||
}
|
||||
|
||||
const callTemplate = () => {
|
||||
function f() {
|
||||
return constr_exp.propCall(args)
|
||||
}
|
||||
%PrepareFunctionForOptimization(f);
|
||||
try { f(); } catch (e) {}
|
||||
try { f(); } catch (e) {}
|
||||
%OptimizeFunctionOnNextCall(f);
|
||||
try { f(); } catch (e) {}
|
||||
}
|
||||
|
||||
const mkCall = (constr_exp, propCall) => {
|
||||
const arrowFunction = callTemplate.toString().replace("constr_exp", constr_exp).replace("propCall", propCall).replace("args", "");
|
||||
return `(${arrowFunction})();`;
|
||||
}
|
||||
|
||||
for ([type, constr_exp, blacklist] of types) {
|
||||
const proto = type.prototype || type;
|
||||
for (const f of Object.getOwnPropertyNames(proto)) {
|
||||
const d = Object.getOwnPropertyDescriptor(proto, f);
|
||||
if (d.get || d.set || (typeof proto[f]) != "function") continue;
|
||||
const source = mkCall(constr_exp, f);
|
||||
try {
|
||||
eval(source);
|
||||
} catch (err) {
|
||||
// Exceptions are OK.
|
||||
console.log(`EXN ${err} for ${type.toString()} ${f}`)
|
||||
console.log(source);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user