summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/prototype-arity.js
blob: bd0319f13f895894932069430c12faf6a26318e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
    }
  }
}