mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 645416, part 29 - Implement Symbol.keyFor(). r=efaust.
--HG-- extra : rebase_source : 2494792929754ba1915f380c0384471c3d5cb8e0
This commit is contained in:
parent
a0cbf316e5
commit
7f9e00a477
@ -50,6 +50,7 @@ const JSFunctionSpec SymbolObject::methods[] = {
|
||||
|
||||
const JSFunctionSpec SymbolObject::staticMethods[] = {
|
||||
JS_FN("for", for_, 1, 0),
|
||||
JS_FN("keyFor", keyFor, 1, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
@ -148,6 +149,36 @@ SymbolObject::for_(JSContext *cx, unsigned argc, Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
// ES6 rev 25 (2014 May 22) 19.4.2.7
|
||||
bool
|
||||
SymbolObject::keyFor(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
// step 1
|
||||
HandleValue arg = args.get(0);
|
||||
if (!arg.isSymbol()) {
|
||||
js_ReportValueErrorFlags(cx, JSREPORT_ERROR, JSMSG_UNEXPECTED_TYPE, JSDVG_SEARCH_STACK,
|
||||
arg, js::NullPtr(), "not a symbol", nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
// step 2
|
||||
if (arg.toSymbol()->code() == JS::SymbolCode::InSymbolRegistry) {
|
||||
#ifdef DEBUG
|
||||
RootedString desc(cx, arg.toSymbol()->description());
|
||||
MOZ_ASSERT(Symbol::for_(cx, desc) == arg.toSymbol());
|
||||
#endif
|
||||
args.rval().setString(arg.toSymbol()->description());
|
||||
return true;
|
||||
}
|
||||
|
||||
// step 3: omitted
|
||||
// step 4
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
IsSymbol(HandleValue v)
|
||||
{
|
||||
|
@ -46,6 +46,7 @@ class SymbolObject : public JSObject
|
||||
|
||||
// Static methods.
|
||||
static bool for_(JSContext *cx, unsigned argc, Value *vp);
|
||||
static bool keyFor(JSContext *cx, unsigned argc, Value *vp);
|
||||
|
||||
// Methods defined on Symbol.prototype.
|
||||
static bool toString_impl(JSContext *cx, CallArgs args);
|
||||
|
15
js/src/tests/ecma_6/Symbol/keyFor.js
Normal file
15
js/src/tests/ecma_6/Symbol/keyFor.js
Normal file
@ -0,0 +1,15 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
|
||||
assertEq(Symbol.keyFor(Symbol.for("moon")), "moon");
|
||||
assertEq(Symbol.keyFor(Symbol.for("")), "");
|
||||
assertEq(Symbol.keyFor(Symbol("moon")), undefined);
|
||||
assertEq(Symbol.keyFor(Symbol.iterator), undefined);
|
||||
|
||||
assertThrowsInstanceOf(() => Symbol.keyFor(), TypeError);
|
||||
assertThrowsInstanceOf(() => Symbol.keyFor(Object(Symbol("moon"))), TypeError);
|
||||
|
||||
assertEq(Symbol.keyFor.length, 1);
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(0, 0);
|
Loading…
Reference in New Issue
Block a user