summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/name.js
blob: c3ca6be91cccfeaa8e15acdbee9c933aec314ecc (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-wrappedfunctioncreate
description: >
  The value of WrappedFunction.name is copied from the target function
info: |
  WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, )

  ...
  7. Let result be CopyNameAndLength(wrapped, Target).
  ...

  CopyNameAndLength ( F: a function object, Target: a function object, prefix: a String, optional argCount: a Number, )

  ...
  6. Let targetName be ? Get(Target, "name").
  7. If Type(targetName) is not String, set targetName to the empty String.
  8. Perform ! SetFunctionName(F, targetName, prefix).

  SetFunctionName ( F, name [ , prefix ] )

  ...
  6. Return ! DefinePropertyOrThrow(F, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }).

includes: [propertyHelper.js]
features: [ShadowRealm]
---*/

assert.sameValue(
  typeof ShadowRealm.prototype.evaluate,
  'function',
  'This test must fail if ShadowRealm.prototype.evaluate is not a function'
);

const r = new ShadowRealm();

let wrapped = r.evaluate(`
function fn() {}
fn;
`);
verifyProperty(wrapped, "name", {
  value: "fn",
  enumerable: false,
  writable: false,
  configurable: true,
});

// The name property is an accessor.
wrapped = r.evaluate(`
function fn() {}
Object.defineProperty(fn, 'name', {
  get: () => "bar",
  enumerable: false,
  configurable: true,
});
fn;
`);
verifyProperty(wrapped, "name", {
  value: "bar",
  enumerable: false,
  writable: false,
  configurable: true,
});

// The value of fn.name is not a string.
for (const name of [null, undefined, 0, '1n', false, NaN, Infinity, 'Symbol()', '[]', '{}']) {
  wrapped = r.evaluate(`
function fn() {}
Object.defineProperty(fn, 'name', {
  value: ${String(name)},
  enumerable: false,
  configurable: true,
});
fn;
`);
  verifyProperty(wrapped, "name", {
    value: "",
    enumerable: false,
    writable: false,
    configurable: true,
  });
}

reportCompare(0, 0);