Bug 790349 - Allow atoms to be referred to by |cx->names().foo| where |foo| is the text of the atom (except in cases where the text of the atom isn't a C++ identifier). r=jorendorff

--HG--
extra : rebase_source : dcd3f2af4b9e9f9ea0fc98cd4f5ad3559cde4358
This commit is contained in:
Jeff Walden 2012-09-10 13:27:19 -07:00
Родитель 3c58f7a44a
Коммит 1be4a4bcc6
9 изменённых файлов: 161 добавлений и 157 удалений

Просмотреть файл

@ -4040,9 +4040,9 @@ Parser::statement()
if (!pn)
return NULL;
if (!tokenStream.matchToken(TOK_NAME) ||
tokenStream.currentToken().name() != context->runtime->atomState.xmlAtom ||
tokenStream.currentToken().name() != context->names().xml ||
!tokenStream.matchToken(TOK_NAME) ||
tokenStream.currentToken().name() != context->runtime->atomState.namespaceAtom ||
tokenStream.currentToken().name() != context->names().namespace_ ||
!tokenStream.matchToken(TOK_ASSIGN))
{
reportError(NULL, JSMSG_BAD_DEFAULT_XML_NAMESPACE);

Просмотреть файл

@ -61,7 +61,7 @@ const char * js::TypeStrings[] = {
JS_FOR_EACH_PROTOTYPE(DEFINE_PROTO_STRING)
#undef DEFINE_PROTO_STRING
#define CONST_CHAR_STR(id, text) const char js_##id##_str[] = text;
#define CONST_CHAR_STR(idpart, id, text) const char js_##idpart##_str[] = text;
FOR_EACH_COMMON_PROPERTYNAME(CONST_CHAR_STR)
#undef CONST_CHAR_STR
@ -151,7 +151,7 @@ bool
js::InitCommonNames(JSContext *cx)
{
static const CommonNameInfo cachedNames[] = {
#define COMMON_NAME_INFO(id, text) { js_##id##_str, sizeof(text) - 1 },
#define COMMON_NAME_INFO(idpart, id, text) { js_##idpart##_str, sizeof(text) - 1 },
FOR_EACH_COMMON_PROPERTYNAME(COMMON_NAME_INFO)
#undef COMMON_NAME_INFO
#define COMMON_NAME_INFO(name, code, init) { js_##name##_str, sizeof(#name) - 1 },

Просмотреть файл

@ -154,7 +154,7 @@ AtomIsInterned(JSContext *cx, JSAtom *atom);
JS_FOR_EACH_PROTOTYPE(DECLARE_PROTO_STR)
#undef DECLARE_PROTO_STR
#define DECLARE_CONST_CHAR_STR(id, text) extern const char js_##id##_str[];
#define DECLARE_CONST_CHAR_STR(idpart, id, text) extern const char js_##idpart##_str[];
FOR_EACH_COMMON_PROPERTYNAME(DECLARE_CONST_CHAR_STR)
#undef DECLARE_CONST_CHAR_STR

Просмотреть файл

@ -188,7 +188,7 @@ js_InitBooleanClass(JSContext *cx, JSObject *obj)
JSString *
js_BooleanToString(JSContext *cx, JSBool b)
{
return b ? cx->runtime->atomState.trueAtom : cx->runtime->atomState.falseAtom;
return b ? cx->runtime->atomState.true_ : cx->runtime->atomState.false_;
}
namespace js {

Просмотреть файл

@ -382,15 +382,17 @@ struct RuntimeSizes;
/* Various built-in or commonly-used names pinned on first context. */
struct JSAtomState
{
#define PROPERTYNAME_FIELD(id, text) js::PropertyName *id##Atom;
#define PROPERTYNAME_FIELD(idpart, id, text) \
union { js::PropertyName *idpart##Atom; js::PropertyName *id; };
FOR_EACH_COMMON_PROPERTYNAME(PROPERTYNAME_FIELD)
#undef PROPERTYNAME_FIELD
#define PROPERTYNAME_FIELD(name, code, init) js::PropertyName *name##Atom;
#define PROPERTYNAME_FIELD(name, code, init) \
union { js::PropertyName *name##Atom; js::PropertyName *name; };
JS_FOR_EACH_PROTOTYPE(PROPERTYNAME_FIELD)
#undef PROPERTYNAME_FIELD
};
#define ATOM(name) js::HandlePropertyName::fromMarkedLocation(&cx->runtime->atomState.name##Atom)
#define ATOM(name) js::HandlePropertyName::fromMarkedLocation(&cx->names().name)
#define NAME_OFFSET(name) offsetof(JSAtomState, name##Atom)
#define OFFSET_TO_NAME(rt,off) (*(js::PropertyName **)((char*)&(rt)->atomState + (off)))
@ -1567,6 +1569,8 @@ struct JSContext : js::ContextFriendFields
exception.setUndefined();
}
JSAtomState & names() { return runtime->atomState; }
#ifdef DEBUG
/*
* Controls whether a quadratic-complexity assertion is performed during

Просмотреть файл

@ -268,7 +268,7 @@ InitExnPrivate(JSContext *cx, HandleObject exnObject, HandleString message,
/* Ask the crystal CAPS ball whether we can see across compartments. */
if (checkAccess && i.isNonEvalFunctionFrame()) {
RootedValue v(cx);
RootedId callerid(cx, NameToId(cx->runtime->atomState.callerAtom));
RootedId callerid(cx, NameToId(cx->names().caller));
RootedObject obj(cx, i.callee());
if (!checkAccess(cx, obj, callerid, JSACC_READ, &v))
break;
@ -410,7 +410,7 @@ exn_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
if (priv && JSID_IS_ATOM(id)) {
str = JSID_TO_STRING(id);
atom = cx->runtime->atomState.messageAtom;
atom = cx->names().message;
if (str == atom) {
prop = js_message_str;
@ -427,7 +427,7 @@ exn_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
goto define;
}
atom = cx->runtime->atomState.fileNameAtom;
atom = cx->names().fileName;
if (str == atom) {
prop = js_fileName_str;
v = STRING_TO_JSVAL(priv->filename);
@ -435,7 +435,7 @@ exn_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
goto define;
}
atom = cx->runtime->atomState.lineNumberAtom;
atom = cx->names().lineNumber;
if (str == atom) {
prop = js_lineNumber_str;
v = UINT_TO_JSVAL(priv->lineno);
@ -443,7 +443,7 @@ exn_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
goto define;
}
atom = cx->runtime->atomState.columnNumberAtom;
atom = cx->names().columnNumber;
if (str == atom) {
prop = js_columnNumber_str;
v = UINT_TO_JSVAL(priv->column);
@ -451,7 +451,7 @@ exn_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
goto define;
}
atom = cx->runtime->atomState.stackAtom;
atom = cx->names().stack;
if (str == atom) {
stack = StackTraceToString(cx, priv);
if (!stack)
@ -546,7 +546,7 @@ Exception(JSContext *cx, unsigned argc, Value *vp)
*/
RootedObject callee(cx, &args.callee());
RootedValue protov(cx);
if (!JSObject::getProperty(cx, callee, callee, cx->runtime->atomState.classPrototypeAtom, &protov))
if (!JSObject::getProperty(cx, callee, callee, cx->names().classPrototype, &protov))
return false;
if (!protov.isObject()) {
@ -629,13 +629,13 @@ exn_toString(JSContext *cx, unsigned argc, Value *vp)
/* Step 3. */
RootedValue nameVal(cx);
if (!JSObject::getProperty(cx, obj, obj, cx->runtime->atomState.nameAtom, &nameVal))
if (!JSObject::getProperty(cx, obj, obj, cx->names().name, &nameVal))
return false;
/* Step 4. */
RootedString name(cx);
if (nameVal.isUndefined()) {
name = cx->runtime->atomState.ErrorAtom;
name = cx->names().Error;
} else {
name = ToString(cx, nameVal);
if (!name)
@ -644,7 +644,7 @@ exn_toString(JSContext *cx, unsigned argc, Value *vp)
/* Step 5. */
RootedValue msgVal(cx);
if (!JSObject::getProperty(cx, obj, obj, cx->runtime->atomState.messageAtom, &msgVal))
if (!JSObject::getProperty(cx, obj, obj, cx->names().message, &msgVal))
return false;
/* Step 6. */
@ -659,7 +659,7 @@ exn_toString(JSContext *cx, unsigned argc, Value *vp)
/* Step 7. */
if (name->empty() && message->empty()) {
args.rval().setString(cx->runtime->atomState.ErrorAtom);
args.rval().setString(cx->names().Error);
return true;
}
@ -703,7 +703,7 @@ exn_toSource(JSContext *cx, unsigned argc, Value *vp)
RootedValue nameVal(cx);
RootedString name(cx);
if (!JSObject::getProperty(cx, obj, obj, cx->runtime->atomState.nameAtom, &nameVal) ||
if (!JSObject::getProperty(cx, obj, obj, cx->names().name, &nameVal) ||
!(name = ToString(cx, nameVal)))
{
return false;
@ -711,7 +711,7 @@ exn_toSource(JSContext *cx, unsigned argc, Value *vp)
RootedValue messageVal(cx);
RootedString message(cx);
if (!JSObject::getProperty(cx, obj, obj, cx->runtime->atomState.messageAtom, &messageVal) ||
if (!JSObject::getProperty(cx, obj, obj, cx->names().message, &messageVal) ||
!(message = js_ValueToSource(cx, messageVal)))
{
return false;
@ -719,7 +719,7 @@ exn_toSource(JSContext *cx, unsigned argc, Value *vp)
RootedValue filenameVal(cx);
RootedString filename(cx);
if (!JSObject::getProperty(cx, obj, obj, cx->runtime->atomState.fileNameAtom, &filenameVal) ||
if (!JSObject::getProperty(cx, obj, obj, cx->names().fileName, &filenameVal) ||
!(filename = js_ValueToSource(cx, filenameVal)))
{
return false;
@ -727,7 +727,7 @@ exn_toSource(JSContext *cx, unsigned argc, Value *vp)
RootedValue linenoVal(cx);
uint32_t lineno;
if (!JSObject::getProperty(cx, obj, obj, cx->runtime->atomState.lineNumberAtom, &linenoVal) ||
if (!JSObject::getProperty(cx, obj, obj, cx->names().lineNumber, &linenoVal) ||
!ToUint32(cx, linenoVal, &lineno))
{
return false;
@ -797,11 +797,11 @@ InitErrorClass(JSContext *cx, Handle<GlobalObject*> global, int type, HandleObje
RootedValue nameValue(cx, StringValue(name));
RootedValue zeroValue(cx, Int32Value(0));
RootedValue empty(cx, StringValue(cx->runtime->emptyString));
RootedId nameId(cx, NameToId(cx->runtime->atomState.nameAtom));
RootedId messageId(cx, NameToId(cx->runtime->atomState.messageAtom));
RootedId fileNameId(cx, NameToId(cx->runtime->atomState.fileNameAtom));
RootedId lineNumberId(cx, NameToId(cx->runtime->atomState.lineNumberAtom));
RootedId columnNumberId(cx, NameToId(cx->runtime->atomState.columnNumberAtom));
RootedId nameId(cx, NameToId(cx->names().name));
RootedId messageId(cx, NameToId(cx->names().message));
RootedId fileNameId(cx, NameToId(cx->names().fileName));
RootedId lineNumberId(cx, NameToId(cx->names().lineNumber));
RootedId columnNumberId(cx, NameToId(cx->names().columnNumber));
if (!DefineNativeProperty(cx, errorProto, nameId, nameValue,
JS_PropertyStub, JS_StrictPropertyStub, 0, 0, 0) ||
!DefineNativeProperty(cx, errorProto, messageId, empty,

Просмотреть файл

@ -867,7 +867,7 @@ ScriptedIndirectProxyHandler::delete_(JSContext *cx, JSObject *proxy, jsid id_,
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy));
RootedId id(cx, id_);
RootedValue fval(cx), value(cx);
return GetFundamentalTrap(cx, handler, ATOM(delete), &fval) &&
return GetFundamentalTrap(cx, handler, ATOM(delete_), &fval) &&
Trap1(cx, handler, fval, id, value.address()) &&
ValueToBool(cx, value, bp);
}

Просмотреть файл

@ -15,135 +15,135 @@
#if JS_HAS_XML_SUPPORT
#define FOR_EACH_XML_ONLY_NAME(macro) \
macro(etago, "</") \
macro(functionNamespaceURI, "@mozilla.org/js/function") \
macro(namespace, "namespace") \
macro(ptagc, "/>") \
macro(qualifier, "::") \
macro(space, " ") \
macro(stago, "<") \
macro(star, "*") \
macro(starQualifier, "*::") \
macro(tagc, ">") \
macro(XMLList, "XMLList")
macro(etago, etago, "</") \
macro(functionNamespaceURI, functionNamespaceURI, "@mozilla.org/js/function") \
macro(namespace, namespace_, "namespace") \
macro(ptagc, ptagc, "/>") \
macro(qualifier, qualifier, "::") \
macro(space, space, " ") \
macro(stago, stago, "<") \
macro(star, star, "*") \
macro(starQualifier, starQualifier, "*::") \
macro(tagc, tagc, ">") \
macro(XMLList, XMLList, "XMLList")
#else
#define FOR_EACH_XML_ONLY_NAME(macro) /* nothing */
#endif /* JS_HAS_XML_SUPPORT */
#define FOR_EACH_COMMON_PROPERTYNAME(macro) \
macro(anonymous, "anonymous") \
macro(apply, "apply") \
macro(arguments, "arguments") \
macro(buffer, "buffer") \
macro(builder, "builder") \
macro(byteLength, "byteLength") \
macro(byteOffset, "byteOffset") \
macro(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \
macro(call, "call") \
macro(callee, "callee") \
macro(caller, "caller") \
macro(_CallFunction, "_CallFunction") \
macro(classPrototype, "prototype") \
macro(columnNumber, "columnNumber") \
macro(configurable, "configurable") \
macro(construct, "construct") \
macro(constructor, "constructor") \
macro(decodeURI, "decodeURI") \
macro(decodeURIComponent, "decodeURIComponent") \
macro(defineProperty, "defineProperty") \
macro(defineGetter, "__defineGetter__") \
macro(defineSetter, "__defineSetter__") \
macro(delete, "delete") \
macro(deleteProperty, "deleteProperty") \
macro(each, "each") \
macro(empty, "") \
macro(encodeURI, "encodeURI") \
macro(encodeURIComponent, "encodeURIComponent") \
macro(enumerable, "enumerable") \
macro(enumerate, "enumerate") \
macro(escape, "escape") \
macro(eval, "eval") \
macro(false, "false") \
macro(fileName, "fileName") \
macro(fix, "fix") \
macro(get, "get") \
macro(getOwnPropertyDescriptor, "getOwnPropertyDescriptor") \
macro(getOwnPropertyNames, "getOwnPropertyNames") \
macro(getPropertyDescriptor, "getPropertyDescriptor") \
macro(global, "global") \
macro(has, "has") \
macro(hasOwn, "hasOwn") \
macro(hasOwnProperty, "hasOwnProperty") \
macro(ignoreCase, "ignoreCase") \
macro(index, "index") \
macro(innermost, "innermost") \
macro(input, "input") \
macro(isFinite, "isFinite") \
macro(isNaN, "isNaN") \
macro(isPrototypeOf, "isPrototypeOf") \
macro(isXMLName, "isXMLName") \
macro(iterate, "iterate") \
macro(Infinity, "Infinity") \
macro(iterator, "iterator") \
macro(iteratorIntrinsic, "__iterator__") \
macro(join, "join") \
macro(keys, "keys") \
macro(lastIndex, "lastIndex") \
macro(length, "length") \
macro(line, "line") \
macro(lineNumber, "lineNumber") \
macro(loc, "loc") \
macro(lookupGetter, "__lookupGetter__") \
macro(lookupSetter, "__lookupSetter__") \
macro(message, "message") \
macro(multiline, "multiline") \
macro(name, "name") \
macro(NaN, "NaN") \
macro(next, "next") \
macro(noSuchMethod, "__noSuchMethod__") \
macro(objectNull, "[object Null]") \
macro(objectUndefined, "[object Undefined]") \
macro(of, "of") \
macro(parseFloat, "parseFloat") \
macro(parseInt, "parseInt") \
macro(propertyIsEnumerable, "propertyIsEnumerable") \
macro(proto, "__proto__") \
macro(return, "return") \
macro(set, "set") \
macro(shape, "shape") \
macro(source, "source") \
macro(stack, "stack") \
macro(sticky, "sticky") \
macro(test, "test") \
macro(throw, "throw") \
macro(toGMTString, "toGMTString") \
macro(toISOString, "toISOString") \
macro(toJSON, "toJSON") \
macro(toLocaleString, "toLocaleString") \
macro(toSource, "toSource") \
macro(toString, "toString") \
macro(toUTCString, "toUTCString") \
macro(true, "true") \
macro(unescape, "unescape") \
macro(uneval, "uneval") \
macro(unwatch, "unwatch") \
macro(url, "url") \
macro(useStrict, "use strict") \
macro(value, "value") \
macro(valueOf, "valueOf") \
macro(var, "var") \
macro(void0, "(void 0)") \
macro(watch, "watch") \
macro(writable, "writable") \
macro(anonymous, anonymous, "anonymous") \
macro(apply, apply, "apply") \
macro(arguments, arguments, "arguments") \
macro(buffer, buffer, "buffer") \
macro(builder, builder, "builder") \
macro(byteLength, byteLength, "byteLength") \
macro(byteOffset, byteOffset, "byteOffset") \
macro(BYTES_PER_ELEMENT, BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \
macro(call, call, "call") \
macro(callee, callee, "callee") \
macro(caller, caller, "caller") \
macro(_CallFunction, _CallFunction, "_CallFunction") \
macro(classPrototype, classPrototype, "prototype") \
macro(columnNumber, columnNumber, "columnNumber") \
macro(configurable, configurable, "configurable") \
macro(construct, construct, "construct") \
macro(constructor, constructor, "constructor") \
macro(decodeURI, decodeURI, "decodeURI") \
macro(decodeURIComponent, decodeURIComponent, "decodeURIComponent") \
macro(defineProperty, defineProperty, "defineProperty") \
macro(defineGetter, defineGetter, "__defineGetter__") \
macro(defineSetter, defineSetter, "__defineSetter__") \
macro(delete, delete_, "delete") \
macro(deleteProperty, deleteProperty, "deleteProperty") \
macro(each, each, "each") \
macro(empty, empty, "") \
macro(encodeURI, encodeURI, "encodeURI") \
macro(encodeURIComponent, encodeURIComponent, "encodeURIComponent") \
macro(enumerable, enumerable, "enumerable") \
macro(enumerate, enumerate, "enumerate") \
macro(escape, escape, "escape") \
macro(eval, eval, "eval") \
macro(false, false_, "false") \
macro(fileName, fileName, "fileName") \
macro(fix, fix, "fix") \
macro(get, get, "get") \
macro(getOwnPropertyDescriptor, getOwnPropertyDescriptor, "getOwnPropertyDescriptor") \
macro(getOwnPropertyNames, getOwnPropertyNames, "getOwnPropertyNames") \
macro(getPropertyDescriptor, getPropertyDescriptor, "getPropertyDescriptor") \
macro(global, global, "global") \
macro(has, has, "has") \
macro(hasOwn, hasOwn, "hasOwn") \
macro(hasOwnProperty, hasOwnProperty, "hasOwnProperty") \
macro(ignoreCase, ignoreCase, "ignoreCase") \
macro(index, index, "index") \
macro(innermost, innermost, "innermost") \
macro(input, input, "input") \
macro(isFinite, isFinite, "isFinite") \
macro(isNaN, isNaN, "isNaN") \
macro(isPrototypeOf, isPrototypeOf, "isPrototypeOf") \
macro(isXMLName, isXMLName, "isXMLName") \
macro(iterate, iterate, "iterate") \
macro(Infinity, Infinity, "Infinity") \
macro(iterator, iterator, "iterator") \
macro(iteratorIntrinsic, iteratorIntrinsic, "__iterator__") \
macro(join, join, "join") \
macro(keys, keys, "keys") \
macro(lastIndex, lastIndex, "lastIndex") \
macro(length, length, "length") \
macro(line, line, "line") \
macro(lineNumber, lineNumber, "lineNumber") \
macro(loc, loc, "loc") \
macro(lookupGetter, lookupGetter, "__lookupGetter__") \
macro(lookupSetter, lookupSetter, "__lookupSetter__") \
macro(message, message, "message") \
macro(multiline, multiline, "multiline") \
macro(name, name, "name") \
macro(NaN, NaN, "NaN") \
macro(next, next, "next") \
macro(noSuchMethod, noSuchMethod, "__noSuchMethod__") \
macro(objectNull, objectNull, "[object Null]") \
macro(objectUndefined, objectUndefined, "[object Undefined]") \
macro(of, of, "of") \
macro(parseFloat, parseFloat, "parseFloat") \
macro(parseInt, parseInt, "parseInt") \
macro(propertyIsEnumerable, propertyIsEnumerable, "propertyIsEnumerable") \
macro(proto, proto, "__proto__") \
macro(return, return_, "return") \
macro(set, set, "set") \
macro(shape, shape, "shape") \
macro(source, source, "source") \
macro(stack, stack, "stack") \
macro(sticky, sticky, "sticky") \
macro(test, test, "test") \
macro(throw, throw_, "throw") \
macro(toGMTString, toGMTString, "toGMTString") \
macro(toISOString, toISOString, "toISOString") \
macro(toJSON, toJSON, "toJSON") \
macro(toLocaleString, toLocaleString, "toLocaleString") \
macro(toSource, toSource, "toSource") \
macro(toString, toString, "toString") \
macro(toUTCString, toUTCString, "toUTCString") \
macro(true, true_, "true") \
macro(unescape, unescape, "unescape") \
macro(uneval, uneval, "uneval") \
macro(unwatch, unwatch, "unwatch") \
macro(url, url, "url") \
macro(useStrict, useStrict, "use strict") \
macro(value, value, "value") \
macro(valueOf, valueOf, "valueOf") \
macro(var, var, "var") \
macro(void0, void0, "(void 0)") \
macro(watch, watch, "watch") \
macro(writable, writable, "writable") \
/* Type names must be contiguous and ordered; see js::TypeName. */ \
macro(undefined, "undefined") \
macro(object, "object") \
macro(function, "function") \
macro(string, "string") \
macro(number, "number") \
macro(boolean, "boolean") \
macro(null, "null") \
macro(xml, "xml") \
macro(undefined, undefined, "undefined") \
macro(object, object, "object") \
macro(function, function, "function") \
macro(string, string, "string") \
macro(number, number, "number") \
macro(boolean, boolean, "boolean") \
macro(null, null, "null") \
macro(xml, xml, "xml") \
FOR_EACH_XML_ONLY_NAME(macro)
#endif /* CommonPropertyNames_h__ */

Просмотреть файл

@ -778,11 +778,11 @@ Debugger::newCompletionValue(JSContext *cx, JSTrapStatus status, Value value_, V
switch (status) {
case JSTRAP_RETURN:
key = NameToId(cx->runtime->atomState.returnAtom);
key = NameToId(cx->names().return_);
break;
case JSTRAP_THROW:
key = NameToId(cx->runtime->atomState.throwAtom);
key = NameToId(cx->names().throw_);
break;
case JSTRAP_ERROR:
@ -839,8 +839,8 @@ Debugger::parseResumptionValue(Maybe<AutoCompartment> &ac, bool ok, const Value
JSContext *cx = ac.ref().context();
Rooted<JSObject*> obj(cx);
Shape *shape;
jsid returnId = NameToId(cx->runtime->atomState.returnAtom);
jsid throwId = NameToId(cx->runtime->atomState.throwAtom);
jsid returnId = NameToId(cx->names().return_);
jsid throwId = NameToId(cx->names().throw_);
bool okResumption = rv.isObject();
if (okResumption) {
obj = &rv.toObject();