Bug 1069416 - Part 1: Remove JS_HAS_SYMBOLS. r=evilpie
authorTooru Fujisawa <arai_a@mac.com>
Wed, 28 Jan 2015 13:06:37 +0900
changeset 239550 cad25450eff5dec73395b194b05d21ca27dc7344
parent 239549 56011c2c814c515023ac071d83a5ab6d93340c67
child 239551 32e5ed282edbbc44131c6e1077dad64402219ae4
push id500
push userjoshua.m.grant@gmail.com
push dateThu, 29 Jan 2015 01:48:36 +0000
reviewersevilpie
bugs1069416
milestone38.0a1
Bug 1069416 - Part 1: Remove JS_HAS_SYMBOLS. r=evilpie
js/src/builtin/MapObject.cpp
js/src/frontend/BytecodeEmitter.cpp
js/src/jsapi-tests/testForOfIterator.cpp
js/src/jsapi-tests/testSymbol.cpp
js/src/jsapi.h
js/src/jsprototypes.h
js/src/jsversion.h
js/src/vm/CommonPropertyNames.h
js/src/vm/ForOfIterator.cpp
js/src/vm/GlobalObject.cpp
js/src/vm/PIC.cpp
js/src/vm/TypedArrayObject.cpp
js/src/vm/Xdr.h
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -1072,24 +1072,19 @@ MapObject::initClass(JSContext *cx, JSOb
     if (proto) {
         // Define the "entries" method.
         JSFunction *fun = JS_DefineFunction(cx, proto, "entries", entries, 0, 0);
         if (!fun)
             return nullptr;
 
         // Define its alias.
         RootedValue funval(cx, ObjectValue(*fun));
-#if JS_HAS_SYMBOLS
         RootedId iteratorId(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator));
         if (!JS_DefinePropertyById(cx, proto, iteratorId, funval, 0))
             return nullptr;
-#else
-        if (!JS_DefineProperty(cx, proto, js_std_iterator_str, funval, 0))
-            return nullptr;
-#endif
     }
     return proto;
 }
 
 template <class Range>
 static void
 MarkKey(Range &r, const HashableValue &key, JSTracer *trc)
 {
@@ -1725,24 +1720,19 @@ SetObject::initClass(JSContext *cx, JSOb
         if (!fun)
             return nullptr;
 
         // Define its aliases.
         RootedValue funval(cx, ObjectValue(*fun));
         if (!JS_DefineProperty(cx, proto, "keys", funval, 0))
             return nullptr;
 
-#if JS_HAS_SYMBOLS
         RootedId iteratorId(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator));
         if (!JS_DefinePropertyById(cx, proto, iteratorId, funval, 0))
             return nullptr;
-#else
-        if (!JS_DefineProperty(cx, proto, js_std_iterator_str, funval, 0))
-            return nullptr;
-#endif
     }
     return proto;
 }
 
 
 bool
 SetObject::keys(JSContext *cx, HandleObject obj, JS::AutoValueVector *keys)
 {
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -4879,25 +4879,20 @@ EmitWith(ExclusiveContext *cx, BytecodeE
  * It will replace that stack value with the corresponding iterator
  */
 static bool
 EmitIterator(ExclusiveContext *cx, BytecodeEmitter *bce)
 {
     // Convert iterable to iterator.
     if (Emit1(cx, bce, JSOP_DUP) < 0)                          // OBJ OBJ
         return false;
-#ifdef JS_HAS_SYMBOLS
     if (Emit2(cx, bce, JSOP_SYMBOL, jsbytecode(JS::SymbolCode::iterator)) < 0) // OBJ OBJ @@ITERATOR
         return false;
     if (!EmitElemOpBase(cx, bce, JSOP_CALLELEM))               // OBJ ITERFN
         return false;
-#else
-    if (!EmitAtomOp(cx, cx->names().std_iterator, JSOP_CALLPROP, bce))  // OBJ ITERFN
-        return false;
-#endif
     if (Emit1(cx, bce, JSOP_SWAP) < 0)                         // ITERFN OBJ
         return false;
     if (EmitCall(cx, bce, JSOP_CALL, 0) < 0)                   // ITER
         return false;
     CheckTypeSet(cx, bce, JSOP_CALL);
     return true;
 }
 
--- a/js/src/jsapi-tests/testForOfIterator.cpp
+++ b/js/src/jsapi-tests/testForOfIterator.cpp
@@ -2,43 +2,37 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsapi-tests/tests.h"
 
-#ifdef JS_HAS_SYMBOLS
-#define STD_ITERATOR "Symbol.iterator"
-#else
-#define STD_ITERATOR "'@@iterator'"
-#endif
-
 BEGIN_TEST(testForOfIterator_basicNonIterable)
 {
     JS::RootedValue v(cx);
     // Hack to make it simple to produce an object that has a property
     // named Symbol.iterator.
-    EVAL("({[" STD_ITERATOR "]: 5})", &v);
+    EVAL("({[Symbol.iterator]: 5})", &v);
     JS::ForOfIterator iter(cx);
     bool ok = iter.init(v);
     CHECK(!ok);
     JS_ClearPendingException(cx);
     return true;
 }
 END_TEST(testForOfIterator_basicNonIterable)
 
 BEGIN_TEST(testForOfIterator_bug515273_part1)
 {
     JS::RootedValue v(cx);
 
     // Hack to make it simple to produce an object that has a property
     // named Symbol.iterator.
-    EVAL("({[" STD_ITERATOR "]: 5})", &v);
+    EVAL("({[Symbol.iterator]: 5})", &v);
 
     JS::ForOfIterator iter(cx);
     bool ok = iter.init(v, JS::ForOfIterator::AllowNonIterable);
     CHECK(!ok);
     JS_ClearPendingException(cx);
     return true;
 }
 END_TEST(testForOfIterator_bug515273_part1)
--- a/js/src/jsapi-tests/testSymbol.cpp
+++ b/js/src/jsapi-tests/testSymbol.cpp
@@ -1,16 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsapi-tests/tests.h"
 
-#ifdef JS_HAS_SYMBOLS
-
 BEGIN_TEST(testSymbol_New)
 {
     using namespace JS;
 
     RootedString desc(cx, nullptr);
     RootedSymbol sym1(cx);
     CHECK(sym1 = NewSymbol(cx, desc));
     CHECK_NULL(GetSymbolDescription(sym1));
@@ -76,10 +74,8 @@ BEGIN_TEST(testSymbol_GetWellKnownSymbol
     // GetSymbolFor never returns a well-known symbol.
     Rooted<Symbol*> sym2(cx);
     CHECK(sym2 = GetSymbolFor(cx, desc));
     CHECK(sym2 != sym1);
 
     return true;
 }
 END_TEST(testSymbol_GetWellKnownSymbol)
-
-#endif
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2283,42 +2283,34 @@ struct JSFunctionSpec {
  * Initializer macros for a JSFunctionSpec array element. JS_FN (whose name pays
  * homage to the old JSNative/JSFastNative split) simply adds the flag
  * JSFUN_STUB_GSOPS. JS_FNINFO allows the simple adding of
  * JSJitInfos. JS_SELF_HOSTED_FN declares a self-hosted function. Finally
  * JS_FNSPEC has slots for all the fields.
  *
  * The _SYM variants allow defining a function with a symbol key rather than a
  * string key. For example, use JS_SYM_FN(iterator, ...) to define an
- * @@iterator method. (In builds without ES6 symbols, it defines a method with
- * the string id "@@iterator".)
+ * @@iterator method.
  */
 #define JS_FS(name,call,nargs,flags)                                          \
     JS_FNSPEC(name, call, nullptr, nargs, flags, nullptr)
 #define JS_FN(name,call,nargs,flags)                                          \
     JS_FNSPEC(name, call, nullptr, nargs, (flags) | JSFUN_STUB_GSOPS, nullptr)
 #define JS_SYM_FN(name,call,nargs,flags)                                      \
     JS_SYM_FNSPEC(symbol, call, nullptr, nargs, (flags) | JSFUN_STUB_GSOPS, nullptr)
 #define JS_FNINFO(name,call,info,nargs,flags)                                 \
     JS_FNSPEC(name, call, info, nargs, flags, nullptr)
 #define JS_SELF_HOSTED_FN(name,selfHostedName,nargs,flags)                    \
     JS_FNSPEC(name, nullptr, nullptr, nargs, flags, selfHostedName)
 #define JS_SELF_HOSTED_SYM_FN(symbol, selfHostedName, nargs, flags)           \
     JS_SYM_FNSPEC(symbol, nullptr, nullptr, nargs, flags, selfHostedName)
-
-#ifdef JS_HAS_SYMBOLS
 #define JS_SYM_FNSPEC(symbol, call, info, nargs, flags, selfHostedName)       \
     JS_FNSPEC(reinterpret_cast<const char *>(                                 \
                   uint32_t(::JS::SymbolCode::symbol) + 1),                    \
               call, info, nargs, flags, selfHostedName)
-#else
-#define JS_SYM_FNSPEC(symbol, call, info, nargs, flags, selfHostedName)       \
-    JS_FNSPEC("@@" #symbol, call, info, nargs, flags, selfHostedName)
-#endif
-
 #define JS_FNSPEC(name,call,info,nargs,flags,selfHostedName)                  \
     {name, {call, info}, nargs, flags, selfHostedName}
 
 extern JS_PUBLIC_API(JSObject *)
 JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto,
              const JSClass *clasp, JSNative constructor, unsigned nargs,
              const JSPropertySpec *ps, const JSFunctionSpec *fs,
              const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs);
--- a/js/src/jsprototypes.h
+++ b/js/src/jsprototypes.h
@@ -51,22 +51,16 @@
 #endif
 
 #ifdef ENABLE_SHARED_ARRAY_BUFFER
 #define IF_SAB(real,imaginary) real
 #else
 #define IF_SAB(real,imaginary) imaginary
 #endif
 
-#ifdef JS_HAS_SYMBOLS
-#define IF_SYMBOLS(real,imaginary) real
-#else
-#define IF_SYMBOLS(real,imaginary) imaginary
-#endif
-
 #define JS_FOR_PROTOTYPES(real,imaginary) \
     imaginary(Null,              0,     js_InitNullClass,          dummy) \
     real(Object,                 1,     js_InitViaClassSpec,       OCLASP(Plain)) \
     real(Function,               2,     js_InitViaClassSpec,       &JSFunction::class_) \
     real(Array,                  3,     js_InitViaClassSpec,       OCLASP(Array)) \
     real(Boolean,                4,     js_InitBooleanClass,       OCLASP(Boolean)) \
     real(JSON,                   5,     js_InitJSONClass,          CLASP(JSON)) \
     real(Date,                   6,     js_InitViaClassSpec,       OCLASP(Date)) \
@@ -94,17 +88,17 @@
     real(Float32Array,          28,     js_InitViaClassSpec,       TYPED_ARRAY_CLASP(Float32)) \
     real(Float64Array,          29,     js_InitViaClassSpec,       TYPED_ARRAY_CLASP(Float64)) \
     real(Uint8ClampedArray,     30,     js_InitViaClassSpec,       TYPED_ARRAY_CLASP(Uint8Clamped)) \
     real(Proxy,                 31,     js_InitProxyClass,         OCLASP(Proxy)) \
     real(WeakMap,               32,     js_InitWeakMapClass,       OCLASP(WeakMap)) \
     real(Map,                   33,     js_InitMapClass,           OCLASP(Map)) \
     real(Set,                   34,     js_InitSetClass,           OCLASP(Set)) \
     real(DataView,              35,     js_InitDataViewClass,      OCLASP(DataView)) \
-IF_SYMBOLS(real,imaginary)(Symbol,              36,     js_InitSymbolClass,        &js::SymbolObject::class_) \
+    real(Symbol,                36,     js_InitSymbolClass,        OCLASP(Symbol)) \
 IF_SAB(real,imaginary)(SharedArrayBuffer,       37,     js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \
 IF_INTL(real,imaginary) (Intl,                  38,     js_InitIntlClass,          CLASP(Intl)) \
 IF_BDATA(real,imaginary)(TypedObject,           39,     js_InitTypedObjectModuleObject,   OCLASP(TypedObjectModule)) \
     imaginary(GeneratorFunction,     40,     js_InitIteratorClasses, dummy) \
 IF_BDATA(real,imaginary)(SIMD,                  41,     js_InitSIMDClass, OCLASP(SIMD)) \
     real(WeakSet,               42,     js_InitWeakSetClass,       OCLASP(WeakSet)) \
 IF_SAB(real,imaginary)(SharedInt8Array,         43,     js_InitViaClassSpec,       SHARED_TYPED_ARRAY_CLASP(Int8)) \
 IF_SAB(real,imaginary)(SharedUint8Array,        44,     js_InitViaClassSpec,       SHARED_TYPED_ARRAY_CLASP(Uint8)) \
--- a/js/src/jsversion.h
+++ b/js/src/jsversion.h
@@ -36,12 +36,9 @@
 #define JS_HAS_DESTRUCTURING_SHORTHAND  (JS_HAS_DESTRUCTURING == 2)
 
 /*
  * Feature for Object.prototype.__{define,lookup}{G,S}etter__ legacy support;
  * support likely to be made opt-in at some future time.
  */
 #define JS_OLD_GETTER_SETTER_METHODS    1
 
-/* Support for ES6 Symbols. */
-#define JS_HAS_SYMBOLS 1
-
 #endif /* jsversion_h */
--- a/js/src/vm/CommonPropertyNames.h
+++ b/js/src/vm/CommonPropertyNames.h
@@ -42,17 +42,16 @@
     macro(compare, compare, "compare") \
     macro(configurable, configurable, "configurable") \
     macro(construct, construct, "construct") \
     macro(constructor, constructor, "constructor") \
     macro(ConvertAndCopyTo, ConvertAndCopyTo, "ConvertAndCopyTo") \
     macro(count, count, "count") \
     macro(currency, currency, "currency") \
     macro(currencyDisplay, currencyDisplay, "currencyDisplay") \
-    macro(std_iterator, std_iterator, "@@iterator") \
     macro(DateTimeFormat, DateTimeFormat, "DateTimeFormat") \
     macro(DateTimeFormatFormatGet, DateTimeFormatFormatGet, "Intl_DateTimeFormat_format_get") \
     macro(decodeURI, decodeURI, "decodeURI") \
     macro(decodeURIComponent, decodeURIComponent, "decodeURIComponent") \
     macro(default_, default_, "default") \
     macro(defineProperty, defineProperty, "defineProperty") \
     macro(defineGetter, defineGetter, "__defineGetter__") \
     macro(defineSetter, defineSetter, "__defineSetter__") \
--- a/js/src/vm/ForOfIterator.cpp
+++ b/js/src/vm/ForOfIterator.cpp
@@ -49,24 +49,19 @@ ForOfIterator::init(HandleValue iterable
 
     // The iterator is the result of calling obj[@@iterator]().
     InvokeArgs args(cx);
     if (!args.init(0))
         return false;
     args.setThis(ObjectValue(*iterableObj));
 
     RootedValue callee(cx);
-#ifdef JS_HAS_SYMBOLS
     RootedId iteratorId(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator));
     if (!GetProperty(cx, iterableObj, iterableObj, iteratorId, &callee))
         return false;
-#else
-    if (!GetProperty(cx, iterableObj, iterableObj, cx->names().std_iterator, &callee))
-        return false;
-#endif
 
     // If obj[@@iterator] is undefined and we were asked to allow non-iterables,
     // bail out now without setting iterator.  This will make valueIsIterable(),
     // which our caller should check, return false.
     if (nonIterableBehavior == AllowNonIterable && callee.isUndefined())
         return true;
 
     // Throw if obj[@@iterator] isn't callable.
--- a/js/src/vm/GlobalObject.cpp
+++ b/js/src/vm/GlobalObject.cpp
@@ -371,21 +371,17 @@ GlobalObject::initSelfHostingBuiltins(JS
                         nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY))
     {
         return false;
     }
 
     // Define a top-level property 'std_iterator' with the name of the method
     // used by for-of loops to create an iterator.
     RootedValue std_iterator(cx);
-#ifdef JS_HAS_SYMBOLS
     std_iterator.setSymbol(cx->wellKnownSymbols().get(JS::SymbolCode::iterator));
-#else
-    std_iterator.setString(cx->names().std_iterator);
-#endif
     if (!JS_DefineProperty(cx, global, "std_iterator", std_iterator,
                            JSPROP_PERMANENT | JSPROP_READONLY))
     {
         return false;
     }
 
     return InitBareBuiltinCtor(cx, global, JSProto_Array) &&
            InitBareBuiltinCtor(cx, global, JSProto_TypedArray) &&
--- a/js/src/vm/PIC.cpp
+++ b/js/src/vm/PIC.cpp
@@ -14,22 +14,16 @@
 #include "vm/SelfHosting.h"
 
 #include "jsobjinlines.h"
 #include "vm/NativeObject-inl.h"
 
 using namespace js;
 using namespace js::gc;
 
-#ifdef JS_HAS_SYMBOLS
-#define STD_ITERATOR_ID  SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator)
-#else
-#define STD_ITERATOR_ID  ::js::NameToId(cx->names().std_iterator)
-#endif
-
 bool
 js::ForOfPIC::Chain::initialize(JSContext *cx)
 {
     MOZ_ASSERT(!initialized_);
 
     // Get the canonical Array.prototype
     RootedNativeObject arrayProto(cx, GlobalObject::getOrCreateArrayPrototype(cx, cx->global()));
     if (!arrayProto)
@@ -47,17 +41,17 @@ js::ForOfPIC::Chain::initialize(JSContex
     arrayProto_ = arrayProto;
     arrayIteratorProto_ = arrayIteratorProto;
 
     // Shortcut returns below means Array for-of will never be optimizable,
     // do set disabled_ now, and clear it later when we succeed.
     disabled_ = true;
 
     // Look up Array.prototype[@@iterator], ensure it's a slotful shape.
-    Shape *iterShape = arrayProto->lookup(cx, STD_ITERATOR_ID);
+    Shape *iterShape = arrayProto->lookup(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator));
     if (!iterShape || !iterShape->hasSlot() || !iterShape->hasDefaultGetter())
         return true;
 
     // Get the referred value, and ensure it holds the canonical ArrayValues function.
     Value iterator = arrayProto->getSlot(iterShape->slot());
     JSFunction *iterFun;
     if (!IsFunctionObject(iterator, &iterFun))
         return true;
@@ -146,17 +140,17 @@ js::ForOfPIC::Chain::tryOptimizeArray(JS
     if (numStubs() >= MAX_STUBS)
         eraseChain();
 
     // Ensure array's prototype is the actual Array.prototype
     if (!isOptimizableArray(array))
         return true;
 
     // Ensure array doesn't define @@iterator directly.
-    if (array->lookup(cx, STD_ITERATOR_ID))
+    if (array->lookup(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator)))
         return true;
 
     // Good to optimize now, create stub to add.
     RootedShape shape(cx, array->lastProperty());
     stub = cx->new_<Stub>(shape);
     if (!stub)
         return false;
 
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -702,24 +702,19 @@ FinishTypedArrayInit(JSContext *cx, Hand
     RootedFunction fun(cx, GetSelfHostedFunction(cx, "TypedArrayValues", name, 0));
     if (!fun)
         return false;
 
     RootedValue funValue(cx, ObjectValue(*fun));
     if (!DefineProperty(cx, proto, cx->names().values, funValue, nullptr, nullptr, 0))
         return false;
 
-#ifdef JS_HAS_SYMBOLS
     RootedId iteratorId(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator));
     if (!DefineProperty(cx, proto, iteratorId, funValue, nullptr, nullptr, 0))
         return false;
-#else
-    if (!DefineProperty(cx, proto, cx->names().std_iterator, funValue, nullptr, nullptr, 0))
-        return false;
-#endif
 
     return true;
 }
 
 /*
  * These next 3 functions are brought to you by the buggy GCC we use to build
  * B2G ICS. Older GCC versions have a bug in which they fail to compile
  * reinterpret_casts of templated functions with the message: "insufficient
--- a/js/src/vm/Xdr.h
+++ b/js/src/vm/Xdr.h
@@ -23,31 +23,20 @@ namespace js {
  * deserialization if there is a mismatch between the current and saved
  * versions.  If deserialization fails, the data should be invalidated if
  * possible.
  *
  * When you change this, run make_opcode_doc.py and copy the new output into
  * this wiki page:
  *
  *  https://developer.mozilla.org/en-US/docs/SpiderMonkey/Internals/Bytecode
- *
- * === GREETINGS, FELLOW SUBTRAHEND INCREMENTER! ===
- * For the time being, please increment the subtrahend by 2 each time it
- * changes, because we have two flavors of bytecode: with JSOP_SYMBOL (in
- * Nightly) and without (all others).  FIXME: Bug 1066322 - Enable ES6 symbols
- * in all builds.
  */
-static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 230;
-static_assert(XDR_BYTECODE_VERSION_SUBTRAHEND % 2 == 0, "see the comment above");
+static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 232;
 static const uint32_t XDR_BYTECODE_VERSION =
-    uint32_t(0xb973c0de - (XDR_BYTECODE_VERSION_SUBTRAHEND
-#ifdef JS_HAS_SYMBOLS
-                                                           + 1
-#endif
-                                                              ));
+    uint32_t(0xb973c0de - XDR_BYTECODE_VERSION_SUBTRAHEND);
 
 static_assert(JSErr_Limit == 367,
               "GREETINGS, POTENTIAL SUBTRAHEND INCREMENTER! If you added or "
               "removed MSG_DEFs from js.msg, you should increment "
               "XDR_BYTECODE_VERSION_SUBTRAHEND and update this assertion's "
               "expected JSErr_Limit value.");
 
 class XDRBuffer {