Debian Codegraph @

js/src/jit-test/tests/cacheir/add-function-prototype.js

raw
1 function checkPrototype(fun, proto, resolvesPrototype) {
2 var desc = Object.getOwnPropertyDescriptor(fun, "prototype");
3 assertEq(desc.value, proto);
4 assertEq(desc.configurable, !resolvesPrototype);
5 assertEq(desc.enumerable, !resolvesPrototype);
6 assertEq(desc.writable, true);
7 }
8 function addPrototype(fun, proto, resolvesPrototype) {
9 fun.prototype = proto;
10 checkPrototype(fun, proto, resolvesPrototype);
11 }
12 function test() {
13 for (var i=0; i<50; i++) {
14 addPrototype(function() {}, i, true);
15 addPrototype(function*() {}, i, true);
16 addPrototype(function async() {}, i, true);
17 // Builtins, arrow functions, bound functions don't have a default
18 // prototype property.
19 addPrototype(Math.abs, i, false);
20 addPrototype(Array.prototype.map, i, false);
21 addPrototype(() => 1, i, false);
22 addPrototype((function() {}).bind(null), i, false);
23 }
24
25 // Now test this with a different IC for each function type.
26 for (var i=0; i<50; i++) {
27 var f = function() {};
28 f.prototype = i;
29 checkPrototype(f, i, true);
30
31 f = function*() {};
32 f.prototype = i;
33 checkPrototype(f, i, true);
34
35 f = function async() {};
36 f.prototype = i;
37 checkPrototype(f, i, true);
38
39 Math.sin.prototype = i;
40 checkPrototype(Math.sin, i, false);
41
42 Array.prototype.filter.prototype = i;
43 checkPrototype(Array.prototype.filter, i, false);
44
45 f = () => 1;
46 f.prototype = i;
47 checkPrototype(f, i, false);
48
49 f = (function() {}).bind(null);
50 f.prototype = i;
51 checkPrototype(f, i, false);
52 }
53
54 }
55 test();