Commit 5e8eb540 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

Reland "[mjsunit] Add test that calls functions on prototypes with no arguments"

This is a reland of 5fbc5015

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/+/1547654Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60547}
parent c9abc311
// 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;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment