summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/arguments/bug1762575-3.js
blob: 371eab009f3b7165c6b3e001f2529e7d88a73063 (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
87
88
89
// Test implementation details when arguments object keep strong references
// to their elements.

function checkWeakRef(f, isCleared = true) {
  let [wr, args] = f({});

  assertEq(wr.deref() !== undefined, true);

  clearKeptObjects();
  gc();

  // In an ideal world, the reference is always cleared. But in specific
  // circumstances we're currently keeping the reference alive. Should this
  // ever change, feel free to update this test case accordingly. IOW having
  // |isCleared == false| is okay for spec correctness, but it isn't optimal.
  assertEq(wr.deref() === undefined, isCleared);
}

checkWeakRef(function() {
  // Create a weak-ref for the first argument.
  let wr = new WeakRef(arguments[0]);

  // Clear the reference from the arguments object.
  arguments[0] = null;

  // Let the arguments object escape.
  return [wr, arguments];
});

checkWeakRef(function() {
  // Create a weak-ref for the first argument.
  let wr = new WeakRef(arguments[0]);

  // Clear the reference from the arguments object.
  Object.defineProperty(arguments, 0, {value: null});

  // Let the arguments object escape.
  return [wr, arguments];
});

checkWeakRef(function self() {
  // Create a weak-ref for the first argument.
  let wr = new WeakRef(arguments[0]);

  // Delete operation doesn't clear the reference!
  delete arguments[0];

  // Let the arguments object escape.
  return [wr, arguments];
}, /*isCleared=*/ false);

checkWeakRef(function() {
  "use strict";

  // Create a weak-ref for the first argument.
  let wr = new WeakRef(arguments[0]);

  // Clear the reference from the arguments object.
  arguments[0] = null;

  // Let the arguments object escape.
  return [wr, arguments];
});

checkWeakRef(function() {
  "use strict";

  // Create a weak-ref for the first argument.
  let wr = new WeakRef(arguments[0]);

  // This define operation doesn't clear the reference!
  Object.defineProperty(arguments, 0, {value: null});

  // Let the arguments object escape.
  return [wr, arguments];
}, /*isCleared=*/ false);

checkWeakRef(function() {
  "use strict";

  // Create a weak-ref for the first argument.
  let wr = new WeakRef(arguments[0]);

  // Delete operation doesn't clear the reference!
  delete arguments[0];

  // Let the arguments object escape.
  return [wr, arguments];
}, /*isCleared=*/ false);