diff --git a/js/xpconnect/wrappers/AccessCheck.cpp b/js/xpconnect/wrappers/AccessCheck.cpp index 92fa09c2939..42f3ea941a3 100644 --- a/js/xpconnect/wrappers/AccessCheck.cpp +++ b/js/xpconnect/wrappers/AccessCheck.cpp @@ -304,6 +304,13 @@ IsInSandbox(JSContext *cx, JSObject *obj) return !strcmp(js::GetObjectJSClass(global)->name, "Sandbox"); } +static void +EnterAndThrow(JSContext *cx, JSObject *wrapper, const char *msg) +{ + JSAutoCompartment ac(cx, wrapper); + JS_ReportError(cx, msg); +} + bool ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper::Action act) { @@ -369,7 +376,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper: return false; if (!exposedProps.isObject()) { - JS_ReportError(cx, "__exposedProps__ must be undefined, null, or an Object"); + EnterAndThrow(cx, wrapper, "__exposedProps__ must be undefined, null, or an Object"); return false; } @@ -385,7 +392,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper: return false; if (!JSVAL_IS_STRING(desc.value)) { - JS_ReportError(cx, "property must be a string"); + EnterAndThrow(cx, wrapper, "property must be a string"); return false; } @@ -399,7 +406,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper: switch (chars[i]) { case 'r': if (access & READ) { - JS_ReportError(cx, "duplicate 'readable' property flag"); + EnterAndThrow(cx, wrapper, "duplicate 'readable' property flag"); return false; } access = Access(access | READ); @@ -407,20 +414,20 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper: case 'w': if (access & WRITE) { - JS_ReportError(cx, "duplicate 'writable' property flag"); + EnterAndThrow(cx, wrapper, "duplicate 'writable' property flag"); return false; } access = Access(access | WRITE); break; default: - JS_ReportError(cx, "properties can only be readable or read and writable"); + EnterAndThrow(cx, wrapper, "properties can only be readable or read and writable"); return false; } } if (access == NO_ACCESS) { - JS_ReportError(cx, "specified properties must have a permission bit set"); + EnterAndThrow(cx, wrapper, "specified properties must have a permission bit set"); return false; }