Bug 1472170- Added description as a property for Symbol and updated tests262. r=anba
authoromersid
Mon, 27 Aug 2018 23:14:54 -0400
changeset 433628 709590a1a24fc8d55f891204dd1e105eaf787177
parent 433627 b6d7a77d510952174e4668364fca3f0c441e328e
child 433629 873cd2e119b3296e3407969f1f7459726f5d2a17
push id34518
push useraciure@mozilla.com
push dateTue, 28 Aug 2018 21:58:56 +0000
treeherdermozilla-central@3205543f957c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanba
bugs1472170
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1472170- Added description as a property for Symbol and updated tests262. r=anba
js/src/builtin/Symbol.cpp
js/src/builtin/Symbol.h
js/src/tests/test262-update.py
js/src/tests/test262/built-ins/Symbol/prototype/description/description-symboldescriptivestring.js
js/src/tests/test262/built-ins/Symbol/prototype/description/descriptor.js
js/src/tests/test262/built-ins/Symbol/prototype/description/get.js
js/src/tests/test262/built-ins/Symbol/prototype/description/is-not-own-property.js
js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-non-symbol.js
js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-symbol.js
js/src/tests/test262/built-ins/Symbol/prototype/description/wrapper.js
--- a/js/src/builtin/Symbol.cpp
+++ b/js/src/builtin/Symbol.cpp
@@ -26,16 +26,17 @@ SymbolObject::create(JSContext* cx, JS::
     SymbolObject* obj = NewBuiltinClassInstance<SymbolObject>(cx);
     if (!obj)
         return nullptr;
     obj->setPrimitiveValue(symbol);
     return obj;
 }
 
 const JSPropertySpec SymbolObject::properties[] = {
+    JS_PSG("description", descriptionGetter, 0),
     JS_PS_END
 };
 
 const JSFunctionSpec SymbolObject::methods[] = {
     JS_FN(js_toString_str, toString, 0, 0),
     JS_FN(js_valueOf_str, valueOf, 0, 0),
     JS_SYM_FN(toPrimitive, toPrimitive, 1, JSPROP_READONLY),
     JS_FS_END
@@ -226,16 +227,41 @@ SymbolObject::toPrimitive(JSContext* cx,
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     // The specification gives exactly the same algorithm for @@toPrimitive as
     // for valueOf, so reuse the valueOf implementation.
     return CallNonGenericMethod<IsSymbol, valueOf_impl>(cx, args);
 }
 
+bool
+SymbolObject::descriptionGetter_impl(JSContext* cx, const CallArgs& args)
+{
+    // Get symbol object pointer.
+    HandleValue thisv = args.thisv();
+    MOZ_ASSERT(IsSymbol(thisv));
+    Rooted<Symbol*> sym(cx, thisv.isSymbol()
+                            ? thisv.toSymbol()
+                            : thisv.toObject().as<SymbolObject>().unbox());
+
+    // Return the symbol's description if present, otherwise return undefined.
+    if (JSString* str = sym->description())
+        args.rval().setString(str);
+    else
+        args.rval().setUndefined();
+    return true;
+}
+
+bool
+SymbolObject::descriptionGetter(JSContext* cx, unsigned argc, Value* vp)
+{
+    CallArgs args = CallArgsFromVp(argc, vp);
+    return CallNonGenericMethod<IsSymbol, descriptionGetter_impl>(cx, args);
+}
+
 JSObject*
 js::InitSymbolClass(JSContext* cx, Handle<GlobalObject*> global)
 {
     return SymbolObject::initClass(cx, global, true);
 }
 
 JSObject*
 js::InitBareSymbolCtor(JSContext* cx, Handle<GlobalObject*> global)
--- a/js/src/builtin/Symbol.h
+++ b/js/src/builtin/Symbol.h
@@ -49,16 +49,20 @@ class SymbolObject : public NativeObject
 
     // Methods defined on Symbol.prototype.
     static MOZ_MUST_USE bool toString_impl(JSContext* cx, const CallArgs& args);
     static MOZ_MUST_USE bool toString(JSContext* cx, unsigned argc, Value* vp);
     static MOZ_MUST_USE bool valueOf_impl(JSContext* cx, const CallArgs& args);
     static MOZ_MUST_USE bool valueOf(JSContext* cx, unsigned argc, Value* vp);
     static MOZ_MUST_USE bool toPrimitive(JSContext* cx, unsigned argc, Value* vp);
 
+    // Properties defined on Symbol.prototype.
+    static MOZ_MUST_USE bool descriptionGetter_impl(JSContext* cx, const CallArgs& args);
+    static MOZ_MUST_USE bool descriptionGetter(JSContext* cx, unsigned argc, Value *vp);
+
     static const JSPropertySpec properties[];
     static const JSFunctionSpec methods[];
     static const JSFunctionSpec staticMethods[];
 };
 
 extern JSObject*
 InitSymbolClass(JSContext* cx, Handle<GlobalObject*> global);
 
--- a/js/src/tests/test262-update.py
+++ b/js/src/tests/test262-update.py
@@ -25,17 +25,16 @@ UNSUPPORTED_FEATURES = set([
     "regexp-dotall",
     "regexp-lookbehind",
     "regexp-named-groups",
     "regexp-unicode-property-escapes",
     "numeric-separator-literal",
     "Intl.Locale",
     "String.prototype.matchAll",
     "Symbol.matchAll",
-    "Symbol.prototype.description",
     "global",
     "export-star-as-namespace-from-module",
 ])
 FEATURE_CHECK_NEEDED = {
     "Atomics": "!this.hasOwnProperty('Atomics')",
     "BigInt": "!this.hasOwnProperty('BigInt')",
     "SharedArrayBuffer": "!this.hasOwnProperty('SharedArrayBuffer')",
 }
--- a/js/src/tests/test262/built-ins/Symbol/prototype/description/description-symboldescriptivestring.js
+++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/description-symboldescriptivestring.js
@@ -1,9 +1,8 @@
-// |reftest| skip -- Symbol.prototype.description is not supported
 // Copyright (C) 2018 Rick Waldron. All rights reserved.
 // Copyright (C) 2018 the V8 project authors. All rights reserved.
 // This code is governed by the BSD license found in the LICENSE file.
 /*---
 esid: sec-symbol.prototype.description
 description: >
   SymbolDescriptiveString(sym) via Symbol.prototype.toString()
 info: |
--- a/js/src/tests/test262/built-ins/Symbol/prototype/description/descriptor.js
+++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/descriptor.js
@@ -1,9 +1,8 @@
-// |reftest| skip -- Symbol.prototype.description is not supported
 // Copyright 2018 Igalia, S.L. All rights reserved.
 // This code is governed by the BSD license found in the LICENSE file.
 
 /*---
 esid: sec-symbol.prototype.description
 description: >
     Test the descriptor of Symbol.prototype.description.
 info: |
--- a/js/src/tests/test262/built-ins/Symbol/prototype/description/get.js
+++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/get.js
@@ -1,9 +1,8 @@
-// |reftest| skip -- Symbol.prototype.description is not supported
 // Copyright 2018 Igalia, S.L. All rights reserved.
 // This code is governed by the BSD license found in the LICENSE file.
 
 /*---
 esid: sec-symbol.prototype.description
 description: >
     Test the get accessor function of Symbol.prototype.description.
 info: |
--- a/js/src/tests/test262/built-ins/Symbol/prototype/description/is-not-own-property.js
+++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/is-not-own-property.js
@@ -1,9 +1,8 @@
-// |reftest| skip -- Symbol.prototype.description is not supported
 // Copyright 2018 Igalia, S.L. All rights reserved.
 // This code is governed by the BSD license found in the LICENSE file.
 
 /*---
 esid: sec-symbol.prototype.description
 description: Ensure that 'description' is not an own property of Symbols
 features: [Symbol.prototype.description]
 ---*/
--- a/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-non-symbol.js
+++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-non-symbol.js
@@ -1,9 +1,8 @@
-// |reftest| skip -- Symbol.prototype.description is not supported
 // Copyright 2018 Igalia, S.L. All rights reserved.
 // This code is governed by the BSD license found in the LICENSE file.
 
 /*---
 esid: sec-symbol.prototype.description
 description: >
     Behavior when "this" value is an object without a [[SymbolData]] internal
     slot.
--- a/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-symbol.js
+++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-symbol.js
@@ -1,9 +1,8 @@
-// |reftest| skip -- Symbol.prototype.description is not supported
 // Copyright 2018 Igalia, S.L. All rights reserved.
 // This code is governed by the BSD license found in the LICENSE file.
 
 /*---
 esid: sec-symbol.prototype.description
 description: >
     Test that calling the getter on a Symbol or a Symbol wrapper object works.
 info: |
--- a/js/src/tests/test262/built-ins/Symbol/prototype/description/wrapper.js
+++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/wrapper.js
@@ -1,9 +1,8 @@
-// |reftest| skip -- Symbol.prototype.description is not supported
 // Copyright 2018 Igalia, S.L. All rights reserved.
 // This code is governed by the BSD license found in the LICENSE file.
 
 /*---
 esid: sec-symbol.prototype.description
 description: >
     Test Symbol.prototype.description called on wrapper objects.
 info: |