Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JSC] WeakMap / WeakSet constructor should accept symbols
https://bugs.webkit.org/show_bug.cgi?id=247997 rdar://102440538 Reviewed by Alexey Shvayka. This patch fixes missing handling of symbols in WeakMap / WeakSet constructors. * JSTests/stress/weak-map-constructor-symbol.js: Added. (shouldBe): (shouldThrow): * JSTests/stress/weak-set-constructor-symbol.js: Added. (shouldBe): (shouldThrow): (test.set shouldThrow): * Source/JavaScriptCore/runtime/WeakMapConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakMapPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakSetConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakSetPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): Canonical link: https://commits.webkit.org/256758@main
- Loading branch information
1 parent
e015c58
commit dd4f45d5e334782e7e809d3a28be5d1f04bd2f5a
Showing
6 changed files
with
78 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function shouldThrow(func, errorMessage) { | ||
var errorThrown = false; | ||
var error = null; | ||
try { | ||
func(); | ||
} catch (e) { | ||
errorThrown = true; | ||
error = e; | ||
} | ||
if (!errorThrown) | ||
throw new Error('not thrown'); | ||
if (String(error) !== errorMessage) | ||
throw new Error(`bad error: ${String(error)}`); | ||
} | ||
|
||
function test() { | ||
var symbol = Symbol("Hello"); | ||
var map = new WeakMap([ | ||
[ symbol, 42 ] | ||
]); | ||
shouldBe(map.get(symbol), 42); | ||
shouldThrow(() => { | ||
var registered = Symbol.for("Hello"); | ||
new WeakMap([ [ registered, 42 ] ]); | ||
}, `TypeError: WeakMap keys must be objects or non-registered symbols`); | ||
} | ||
|
||
for (var i = 0; i < 1e4; ++i) | ||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function shouldThrow(func, errorMessage) { | ||
var errorThrown = false; | ||
var error = null; | ||
try { | ||
func(); | ||
} catch (e) { | ||
errorThrown = true; | ||
error = e; | ||
} | ||
if (!errorThrown) | ||
throw new Error('not thrown'); | ||
if (String(error) !== errorMessage) | ||
throw new Error(`bad error: ${String(error)}`); | ||
} | ||
|
||
function test() { | ||
var symbol = Symbol("Hello"); | ||
var set = new WeakSet([ | ||
symbol | ||
]); | ||
shouldBe(set.has(symbol), true); | ||
shouldThrow(() => { | ||
var registered = Symbol.for("Hello"); | ||
new WeakSet([ registered ]); | ||
}, `TypeError: WeakSet values must be objects or non-registered symbols`); | ||
} | ||
|
||
for (var i = 0; i < 1e4; ++i) | ||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters