зеркало из https://github.com/mozilla/gecko-dev.git
Bug 987669 - Implement Xray support for the data properties on ErrorObject instances. r=gabor
This commit is contained in:
Родитель
d2fd703dac
Коммит
d4e5d6b652
|
@ -87,6 +87,11 @@ const char* const XPCJSRuntime::mStrings[] = {
|
||||||
"name", // IDX_NAME
|
"name", // IDX_NAME
|
||||||
"undefined", // IDX_UNDEFINED
|
"undefined", // IDX_UNDEFINED
|
||||||
"", // IDX_EMPTYSTRING
|
"", // IDX_EMPTYSTRING
|
||||||
|
"fileName", // IDX_FILENAME
|
||||||
|
"lineNumber", // IDX_LINENUMBER
|
||||||
|
"columnNumber", // IDX_COLUMNNUMBER
|
||||||
|
"stack", // IDX_STACK
|
||||||
|
"message" // IDX_MESSAGE
|
||||||
};
|
};
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
|
@ -482,6 +482,11 @@ public:
|
||||||
IDX_NAME ,
|
IDX_NAME ,
|
||||||
IDX_UNDEFINED ,
|
IDX_UNDEFINED ,
|
||||||
IDX_EMPTYSTRING ,
|
IDX_EMPTYSTRING ,
|
||||||
|
IDX_FILENAME ,
|
||||||
|
IDX_LINENUMBER ,
|
||||||
|
IDX_COLUMNNUMBER ,
|
||||||
|
IDX_STACK ,
|
||||||
|
IDX_MESSAGE ,
|
||||||
IDX_TOTAL_COUNT // just a count of the above
|
IDX_TOTAL_COUNT // just a count of the above
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -693,6 +693,33 @@ JSXrayTraits::resolveOwnProperty(JSContext *cx, const Wrapper &jsWrapper,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (IsErrorObjectKey(key)) {
|
||||||
|
// The useful state of error objects is (unfortunately) represented
|
||||||
|
// as own data properties per-spec. This means that we can't have a
|
||||||
|
// a clean representation of the data (free from tampering) without
|
||||||
|
// doubling the slots of Error objects, which isn't great. So we
|
||||||
|
// forward these properties to the underlying object and then just
|
||||||
|
// censor any values with the wrong type. This limits the ability
|
||||||
|
// of content to do anything all that confusing.
|
||||||
|
bool isErrorIntProperty =
|
||||||
|
id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_LINENUMBER) ||
|
||||||
|
id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_COLUMNNUMBER);
|
||||||
|
bool isErrorStringProperty =
|
||||||
|
id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_FILENAME) ||
|
||||||
|
id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_STACK) ||
|
||||||
|
id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_MESSAGE);
|
||||||
|
if (isErrorIntProperty || isErrorStringProperty) {
|
||||||
|
RootedObject waiver(cx, wrapper);
|
||||||
|
if (!WrapperFactory::WaiveXrayAndWrap(cx, &waiver))
|
||||||
|
return false;
|
||||||
|
if (!JS_GetOwnPropertyDescriptorById(cx, waiver, id, desc))
|
||||||
|
return false;
|
||||||
|
bool valueMatchesType = (isErrorIntProperty && desc.value().isInt32()) ||
|
||||||
|
(isErrorStringProperty && desc.value().isString());
|
||||||
|
if (desc.hasGetterOrSetter() || !valueMatchesType)
|
||||||
|
FillPropertyDescriptor(desc, nullptr, 0, UndefinedValue());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The rest of this function applies only to prototypes.
|
// The rest of this function applies only to prototypes.
|
||||||
|
@ -960,6 +987,15 @@ JSXrayTraits::enumerateNames(JSContext *cx, HandleObject wrapper, unsigned flags
|
||||||
if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_PROTOTYPE)))
|
if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_PROTOTYPE)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (IsErrorObjectKey(key)) {
|
||||||
|
if (!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_FILENAME)) ||
|
||||||
|
!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_LINENUMBER)) ||
|
||||||
|
!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_COLUMNNUMBER)) ||
|
||||||
|
!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_STACK)) ||
|
||||||
|
!props.append(GetRTIdByIndex(cx, XPCJSRuntime::IDX_MESSAGE)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The rest of this function applies only to prototypes.
|
// The rest of this function applies only to prototypes.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче