зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1277801 - Introduce Cu.isOpaqueWrapper. r=peterv
With the following changes Object.prototype.toString is not using the JSClass' name anymore. This means we now fail to detect opaque wrappers, because they just get the default string: [object Object] Differential Revision: https://phabricator.services.mozilla.com/D74016
This commit is contained in:
Родитель
3df4970bcc
Коммит
25a8ce26ec
|
@ -524,6 +524,11 @@ interface nsIXPCComponents_Utils : nsISupports
|
|||
[implicit_jscontext]
|
||||
void unblockScriptForGlobal(in jsval global);
|
||||
|
||||
/**
|
||||
* Check whether the given object is an opaque wrapper (PermissiveXrayOpaque).
|
||||
*/
|
||||
bool isOpaqueWrapper(in jsval obj);
|
||||
|
||||
/**
|
||||
* Check whether the given object is an XrayWrapper.
|
||||
*/
|
||||
|
|
|
@ -2153,6 +2153,13 @@ nsXPCComponents_Utils::UnblockScriptForGlobal(HandleValue globalArg,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::IsOpaqueWrapper(HandleValue obj, bool* aRetval) {
|
||||
*aRetval =
|
||||
obj.isObject() && xpc::WrapperFactory::IsOpaqueWrapper(&obj.toObject());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::IsXrayWrapper(HandleValue obj, bool* aRetval) {
|
||||
*aRetval =
|
||||
|
|
|
@ -78,8 +78,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
|
|||
"we end up with the appropriate constructor: " + c);
|
||||
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin[c](...args)).constructor), iwin[c],
|
||||
"constructor property is set up right: " + c);
|
||||
let expectedProto = /Opaque/.test(new iwin[c](...args)) ? iwin['Object'].prototype
|
||||
: iwin[c].prototype;
|
||||
let expectedProto = Cu.isOpaqueWrapper(new iwin[c](...args)) ?
|
||||
iwin['Object'].prototype : iwin[c].prototype;
|
||||
is(Object.getPrototypeOf(new iwin[c](...args)), expectedProto,
|
||||
"prototype is correct: " + c);
|
||||
is(global(new iwin[c](...args)), iwin, "Got the right global: " + c);
|
||||
|
@ -148,8 +148,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
|
|||
"we end up with the appropriate AggregateError constructor");
|
||||
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin.AggregateError(...args)).constructor), iwin.AggregateError,
|
||||
"AggregateError constructor property is set up right");
|
||||
let expectedProto = /Opaque/.test(new iwin.AggregateError(...args)) ? iwin['Object'].prototype
|
||||
: iwin.AggregateError.prototype;
|
||||
let expectedProto = Cu.isOpaqueWrapper(new iwin.AggregateError(...args)) ?
|
||||
iwin['Object'].prototype : iwin.AggregateError.prototype;
|
||||
is(Object.getPrototypeOf(new iwin.AggregateError(...args)), expectedProto,
|
||||
"AggregateError prototype is correct");
|
||||
is(global(new iwin.AggregateError(...args)), iwin, "Got the right global for AggregateError");
|
||||
|
@ -383,11 +383,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
|
|||
is(method.call(xray) + "", local.call(xray) + "",
|
||||
"Xray and local method results stringify identically");
|
||||
|
||||
// If invoking this method returns something non-Xrayable, the
|
||||
// stringification is going to return [object Opaque].
|
||||
// If invoking this method returns something non-Xrayable (opaque), the
|
||||
// stringification is going to return [object Object].
|
||||
// This happens for set[@@iterator] and other Iterator objects.
|
||||
let callable = lookupCallable(xray.wrappedJSObject);
|
||||
if (!/Opaque/.test(method.call(xray)) && callable) {
|
||||
if (!Cu.isOpaqueWrapper(method.call(xray)) && callable) {
|
||||
is(method.call(xray) + "",
|
||||
callable.call(xray.wrappedJSObject) + "",
|
||||
"Xray and waived method results stringify identically");
|
||||
|
|
|
@ -44,6 +44,11 @@ const Wrapper XrayWaiver(WrapperFactory::WAIVE_XRAY_WRAPPER_FLAG);
|
|||
// off it.
|
||||
const WaiveXrayWrapper WaiveXrayWrapper::singleton(0);
|
||||
|
||||
bool WrapperFactory::IsOpaqueWrapper(JSObject* obj) {
|
||||
return IsWrapper(obj) &&
|
||||
Wrapper::wrapperHandler(obj) == &PermissiveXrayOpaque::singleton;
|
||||
}
|
||||
|
||||
bool WrapperFactory::IsCOW(JSObject* obj) {
|
||||
return IsWrapper(obj) &&
|
||||
Wrapper::wrapperHandler(obj) == &ChromeObjectWrapper::singleton;
|
||||
|
|
|
@ -67,6 +67,8 @@ class WrapperFactory {
|
|||
js::GetProxyHandler(obj) == &CrossOriginObjectWrapper::singleton);
|
||||
}
|
||||
|
||||
static bool IsOpaqueWrapper(JSObject* obj);
|
||||
|
||||
static bool HasWaiveXrayFlag(JSObject* wrapper) {
|
||||
return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче