From 8b3a3efd8bd9f6b6eb1f7127f9bbca0f313d3d3f Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 2 Jun 2015 23:27:39 +0200 Subject: [PATCH] Bug 1135993 - Remove js::IsInNonStrictPropertySet. r=jorendorff --- dom/bindings/Codegen.py | 18 +++++++----------- dom/bindings/Errors.msg | 2 -- js/public/Class.h | 2 ++ js/src/js.msg | 6 ++++-- js/src/jsapi.cpp | 36 +++++++++++++++++++++++++++++++----- js/src/jsfriendapi.cpp | 8 -------- js/src/jsfriendapi.h | 9 --------- js/src/vm/Xdr.h | 4 ++-- 8 files changed, 46 insertions(+), 39 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 5077e3692e33..b51182724959 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -10457,15 +10457,13 @@ class CGDOMJSProxyHandler_defineProperty(ClassMethod): # indexed setter. That's how the object would normally behave if # you tried to set the property on it. That means we don't need to # do anything special for Xrays here. - set += fill( + set += dedent( """ if (IsArrayIndex(GetArrayIndexFromId(cx, id))) { - return js::IsInNonStrictPropertySet(cx) - ? opresult.succeed() - : ThrowErrorMessage(cx, MSG_NO_INDEXED_SETTER, "${name}"); + *defined = true; + return opresult.failNoIndexedSetter(); } - """, - name=self.descriptor.name) + """) namedSetter = self.descriptor.operations['NamedSetter'] if namedSetter: @@ -10498,13 +10496,11 @@ class CGDOMJSProxyHandler_defineProperty(ClassMethod): $*{presenceChecker} if (found) { - return js::IsInNonStrictPropertySet(cx) - ? opresult.succeed() - : ThrowErrorMessage(cx, MSG_NO_NAMED_SETTER, "${name}"); + *defined = true; + return opresult.failNoNamedSetter(); } """, - presenceChecker=CGProxyNamedPresenceChecker(self.descriptor, foundVar="found").define(), - name=self.descriptor.name) + presenceChecker=CGProxyNamedPresenceChecker(self.descriptor, foundVar="found").define()) set += ("return mozilla::dom::DOMProxyHandler::defineProperty(%s);\n" % ", ".join(a.name for a in self.args)) return set diff --git a/dom/bindings/Errors.msg b/dom/bindings/Errors.msg index 2b38a24bf14f..f368163eeb70 100644 --- a/dom/bindings/Errors.msg +++ b/dom/bindings/Errors.msg @@ -34,8 +34,6 @@ MSG_DEF(MSG_THIS_DOES_NOT_IMPLEMENT_INTERFACE, 1, JSEXN_TYPEERR, "\"this\" objec MSG_DEF(MSG_NOT_IN_UNION, 2, JSEXN_TYPEERR, "{0} could not be converted to any of: {1}.") MSG_DEF(MSG_ILLEGAL_CONSTRUCTOR, 0, JSEXN_TYPEERR, "Illegal constructor.") MSG_DEF(MSG_CONSTRUCTOR_WITHOUT_NEW, 1, JSEXN_TYPEERR, "Constructor {0} requires 'new'") -MSG_DEF(MSG_NO_INDEXED_SETTER, 1, JSEXN_TYPEERR, "{0} doesn't have an indexed property setter.") -MSG_DEF(MSG_NO_NAMED_SETTER, 1, JSEXN_TYPEERR, "{0} doesn't have a named property setter.") MSG_DEF(MSG_ENFORCE_RANGE_NON_FINITE, 1, JSEXN_TYPEERR, "Non-finite value is out of range for {0}.") MSG_DEF(MSG_ENFORCE_RANGE_OUT_OF_RANGE, 1, JSEXN_TYPEERR, "Value is out of range for {0}.") MSG_DEF(MSG_NOT_SEQUENCE, 1, JSEXN_TYPEERR, "{0} can't be converted to a sequence.") diff --git a/js/public/Class.h b/js/public/Class.h index 7570ed473912..15b5dfd3eea0 100644 --- a/js/public/Class.h +++ b/js/public/Class.h @@ -142,6 +142,8 @@ class ObjectOpResult JS_PUBLIC_API(bool) failCantDeleteWindowElement(); JS_PUBLIC_API(bool) failCantDeleteWindowNamedProperty(); JS_PUBLIC_API(bool) failCantPreventExtensions(); + JS_PUBLIC_API(bool) failNoNamedSetter(); + JS_PUBLIC_API(bool) failNoIndexedSetter(); uint32_t failureCode() const { MOZ_ASSERT(!ok()); diff --git a/js/src/js.msg b/js/src/js.msg index 4d84c8f4738c..c61ebdea51d7 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -487,11 +487,13 @@ MSG_DEF(JSMSG_ATOMICS_TOO_LONG, 0, JSEXN_RANGEERR, "timeout value too l MSG_DEF(JSMSG_ATOMICS_WAIT_NOT_ALLOWED, 0, JSEXN_ERR, "waiting is not allowed on this thread") // XPConnect wrappers and DOM bindings -MSG_DEF(JSMSG_CANT_SET_INTERPOSED, 1, JSEXN_TYPEERR, "unable to set interposed data property '{0}'") +MSG_DEF(JSMSG_CANT_SET_INTERPOSED, 1, JSEXN_TYPEERR, "unable to set interposed data property '{0}'") MSG_DEF(JSMSG_CANT_DEFINE_WINDOW_ELEMENT, 0, JSEXN_TYPEERR, "can't define elements on a Window object") MSG_DEF(JSMSG_CANT_DELETE_WINDOW_ELEMENT, 0, JSEXN_TYPEERR, "can't delete elements from a Window object") MSG_DEF(JSMSG_CANT_DELETE_WINDOW_NAMED_PROPERTY, 1, JSEXN_TYPEERR, "can't delete property {0} from window's named properties object") -MSG_DEF(JSMSG_CANT_PREVENT_EXTENSIONS, 0, JSEXN_TYPEERR, "can't prevent extensions on this proxy object") +MSG_DEF(JSMSG_CANT_PREVENT_EXTENSIONS, 0, JSEXN_TYPEERR, "can't prevent extensions on this proxy object") +MSG_DEF(JSMSG_NO_NAMED_SETTER, 2, JSEXN_TYPEERR, "{0} doesn't have a named property setter for '{1}'") +MSG_DEF(JSMSG_NO_INDEXED_SETTER, 2, JSEXN_TYPEERR, "{0} doesn't have an indexed property setter for '{1}'") // Super MSG_DEF(JSMSG_CANT_DELETE_SUPER, 0, JSEXN_REFERENCEERR, "invalid delete involving 'super'") diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 25cf496685dd..ccde14cfafae 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -130,12 +130,21 @@ JS::CallArgs::requireAtLeast(JSContext* cx, const char* fnname, unsigned require } static bool -ErrorTakesIdArgument(unsigned msg) +ErrorTakesArguments(unsigned msg) { MOZ_ASSERT(msg < JSErr_Limit); unsigned argCount = js_ErrorFormatString[msg].argCount; - MOZ_ASSERT(argCount <= 1); - return argCount == 1; + MOZ_ASSERT(argCount <= 2); + return argCount == 1 || argCount == 2; +} + +static bool +ErrorTakesObjectArgument(unsigned msg) +{ + MOZ_ASSERT(msg < JSErr_Limit); + unsigned argCount = js_ErrorFormatString[msg].argCount; + MOZ_ASSERT(argCount <= 2); + return argCount == 2; } JS_PUBLIC_API(bool) @@ -153,7 +162,7 @@ JS::ObjectOpResult::reportStrictErrorOrWarning(JSContext* cx, HandleObject obj, return ReportValueErrorFlags(cx, flags, code_, JSDVG_IGNORE_STACK, val, nullptr, nullptr, nullptr); } - if (ErrorTakesIdArgument(code_)) { + if (ErrorTakesArguments(code_)) { RootedValue idv(cx, IdToValue(id)); RootedString str(cx, ValueToSource(cx, idv)); if (!str) @@ -163,6 +172,11 @@ JS::ObjectOpResult::reportStrictErrorOrWarning(JSContext* cx, HandleObject obj, if (!propName) return false; + if (ErrorTakesObjectArgument(code_)) { + return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, code_, + obj->getClass()->name, propName.ptr()); + } + return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, code_, propName.ptr()); } @@ -174,7 +188,7 @@ JS::ObjectOpResult::reportStrictErrorOrWarning(JSContext* cx, HandleObject obj, { MOZ_ASSERT(code_ != Uninitialized); MOZ_ASSERT(!ok()); - MOZ_ASSERT(!ErrorTakesIdArgument(code_)); + MOZ_ASSERT(!ErrorTakesArguments(code_)); unsigned flags = strict ? JSREPORT_ERROR : (JSREPORT_WARNING | JSREPORT_STRICT); return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, code_); @@ -234,6 +248,18 @@ JS::ObjectOpResult::failCantPreventExtensions() return fail(JSMSG_CANT_PREVENT_EXTENSIONS); } +JS_PUBLIC_API(bool) +JS::ObjectOpResult::failNoNamedSetter() +{ + return fail(JSMSG_NO_NAMED_SETTER); +} + +JS_PUBLIC_API(bool) +JS::ObjectOpResult::failNoIndexedSetter() +{ + return fail(JSMSG_NO_INDEXED_SETTER); +} + JS_PUBLIC_API(int64_t) JS_Now() { diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 0840bf29b19c..a3092e91e5cf 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -308,14 +308,6 @@ js::IsAtomsZone(JS::Zone* zone) return zone->runtimeFromAnyThread()->isAtomsZone(zone); } -JS_FRIEND_API(bool) -js::IsInNonStrictPropertySet(JSContext* cx) -{ - jsbytecode* pc; - JSScript* script = cx->currentScript(&pc, JSContext::ALLOW_CROSS_COMPARTMENT); - return script && !IsStrictSetPC(pc) && (js_CodeSpec[*pc].format & JOF_SET); -} - JS_FRIEND_API(bool) js::IsFunctionObject(JSObject* obj) { diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 1465a1ef790d..99843edb5b47 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -481,15 +481,6 @@ IsAtomsCompartment(JSCompartment* comp); extern JS_FRIEND_API(bool) IsAtomsZone(JS::Zone* zone); -/* - * Returns whether we're in a non-strict property set (in that we're in a - * non-strict script and the bytecode we're on is a property set). The return - * value does NOT indicate any sort of exception was thrown: it's just a - * boolean. - */ -extern JS_FRIEND_API(bool) -IsInNonStrictPropertySet(JSContext* cx); - struct WeakMapTracer { JSRuntime* runtime; diff --git a/js/src/vm/Xdr.h b/js/src/vm/Xdr.h index 1121294af792..141e2d63f2d8 100644 --- a/js/src/vm/Xdr.h +++ b/js/src/vm/Xdr.h @@ -29,11 +29,11 @@ namespace js { * * https://developer.mozilla.org/en-US/docs/SpiderMonkey/Internals/Bytecode */ -static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 287; +static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 288; static const uint32_t XDR_BYTECODE_VERSION = uint32_t(0xb973c0de - XDR_BYTECODE_VERSION_SUBTRAHEND); -static_assert(JSErr_Limit == 398, +static_assert(JSErr_Limit == 400, "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 "