зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1706937 - Cleanup JS source-element callback. r=jandem
Rename the JSGetElementCallback hook to JSSourceElementCallback to avoid confusion with GetElement operations. Differential Revision: https://phabricator.services.mozilla.com/D113985
This commit is contained in:
Родитель
be9de47e53
Коммит
89afad4d44
|
@ -50,33 +50,33 @@
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
JSObject* GetElementCallback(JSContext* aCx, JS::HandleValue aValue) {
|
||||
JS::RootedValue privateValue(aCx, aValue);
|
||||
MOZ_ASSERT(!privateValue.isObjectOrNull() && !privateValue.isUndefined());
|
||||
LoadedScript* script = static_cast<LoadedScript*>(privateValue.toPrivate());
|
||||
JSObject* SourceElementCallback(JSContext* aCx, JS::HandleValue aPrivateValue) {
|
||||
// NOTE: The result of this is only used by DevTools for matching sources, so
|
||||
// it is safe to silently ignore any errors and return nullptr for them.
|
||||
|
||||
LoadedScript* script = static_cast<LoadedScript*>(aPrivateValue.toPrivate());
|
||||
|
||||
if (!script->GetFetchOptions()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> elementValue(aCx);
|
||||
{
|
||||
nsCOMPtr<Element> domElement = script->GetFetchOptions()->mElement;
|
||||
if (!domElement) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSObject* globalObject =
|
||||
domElement->OwnerDoc()->GetScopeObject()->GetGlobalJSObject();
|
||||
JSAutoRealm ar(aCx, globalObject);
|
||||
|
||||
nsresult rv = nsContentUtils::WrapNative(aCx, domElement, &elementValue,
|
||||
/* aAllowWrapping = */ true);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<Element> domElement = script->GetFetchOptions()->mElement;
|
||||
if (!domElement) {
|
||||
return nullptr;
|
||||
}
|
||||
return elementValue.toObjectOrNull();
|
||||
|
||||
JSObject* globalObject =
|
||||
domElement->OwnerDoc()->GetScopeObject()->GetGlobalJSObject();
|
||||
JSAutoRealm ar(aCx, globalObject);
|
||||
|
||||
JS::Rooted<JS::Value> elementValue(aCx);
|
||||
nsresult rv = nsContentUtils::WrapNative(aCx, domElement, &elementValue,
|
||||
/* aAllowWrapping = */ true);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &elementValue.toObject();
|
||||
}
|
||||
|
||||
static MOZ_THREAD_LOCAL(ScriptSettingsStackEntry*) sScriptSettingsTLS;
|
||||
|
@ -340,7 +340,7 @@ void AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
|
|||
mOldWarningReporter.emplace(JS::GetWarningReporter(aCx));
|
||||
|
||||
JS::SetWarningReporter(aCx, WarningOnlyErrorReporter);
|
||||
JS::SetGetElementCallback(aCx, &GetElementCallback);
|
||||
JS::SetSourceElementCallback(aCx, SourceElementCallback);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (haveException) {
|
||||
|
|
|
@ -266,8 +266,13 @@ extern JS_PUBLIC_API bool UpdateDebugMetadata(
|
|||
HandleString elementAttributeName, HandleScript introScript,
|
||||
HandleScript scriptOrModule);
|
||||
|
||||
extern JS_PUBLIC_API void SetGetElementCallback(JSContext* cx,
|
||||
JSGetElementCallback callback);
|
||||
// The debugger API exposes an optional "element" property on DebuggerSource
|
||||
// objects. The callback defined here provides that value. SpiderMonkey
|
||||
// doesn't particularly care about this, but within Firefox the "element" is the
|
||||
// HTML script tag for the script which DevTools can use for a better debugging
|
||||
// experience.
|
||||
extern JS_PUBLIC_API void SetSourceElementCallback(
|
||||
JSContext* cx, JSSourceElementCallback callback);
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
|
|
|
@ -397,14 +397,14 @@ struct DebuggerSourceGetElementMatcher {
|
|||
|
||||
bool DebuggerSource::CallData::getElement() {
|
||||
DebuggerSourceGetElementMatcher matcher(cx);
|
||||
RootedValue elementValue(cx);
|
||||
if (JSObject* element = referent.match(matcher)) {
|
||||
args.rval().setObjectOrNull(element);
|
||||
if (!obj->owner()->wrapDebuggeeValue(cx, args.rval())) {
|
||||
elementValue.setObject(*element);
|
||||
if (!obj->owner()->wrapDebuggeeValue(cx, &elementValue)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
args.rval().setUndefined();
|
||||
}
|
||||
args.rval().set(elementValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,8 +99,11 @@ class MOZ_RAII JS_PUBLIC_API CustomAutoRooter : private AutoGCRooter {
|
|||
/* Callbacks and their arguments. */
|
||||
|
||||
/************************************************************************/
|
||||
using JSGetElementCallback = JSObject* (*)(JSContext* aCx,
|
||||
JS::HandleValue privateValue);
|
||||
|
||||
// Callback for the embedding to map from a ScriptSourceObject private-value to
|
||||
// an object that is exposed as the source "element" in debugger API. This hook
|
||||
// must be infallible, but can return nullptr if no such element exists.
|
||||
using JSSourceElementCallback = JSObject* (*)(JSContext*, JS::HandleValue);
|
||||
|
||||
using JSInterruptCallback = bool (*)(JSContext*);
|
||||
|
||||
|
|
|
@ -4717,8 +4717,8 @@ static void DestroyShellCompartmentPrivate(JSFreeOp* fop,
|
|||
static void SetWorkerContextOptions(JSContext* cx);
|
||||
static bool ShellBuildId(JS::BuildIdCharVector* buildId);
|
||||
|
||||
JSObject* GetElementCallback(JSContext* cx, JS::HandleValue value) {
|
||||
RootedValue privateValue(cx, value);
|
||||
static JSObject* ShellSourceElementCallback(JSContext* cx,
|
||||
JS::HandleValue privateValue) {
|
||||
if (!privateValue.isObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -4783,7 +4783,7 @@ static void WorkerMain(WorkerInput* input) {
|
|||
DummyHasReleasedWrapperCallback);
|
||||
JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
|
||||
JS_SetDestroyCompartmentCallback(cx, DestroyShellCompartmentPrivate);
|
||||
JS::SetGetElementCallback(cx, &GetElementCallback);
|
||||
JS::SetSourceElementCallback(cx, ShellSourceElementCallback);
|
||||
|
||||
js::SetWindowProxyClass(cx, &ShellWindowProxyClass);
|
||||
|
||||
|
@ -12421,7 +12421,7 @@ int main(int argc, char** argv) {
|
|||
JS_SetSecurityCallbacks(cx, &ShellPrincipals::securityCallbacks);
|
||||
JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
|
||||
JS_SetDestroyCompartmentCallback(cx, DestroyShellCompartmentPrivate);
|
||||
JS::SetGetElementCallback(cx, &GetElementCallback);
|
||||
JS::SetSourceElementCallback(cx, ShellSourceElementCallback);
|
||||
|
||||
js::SetWindowProxyClass(cx, &ShellWindowProxyClass);
|
||||
|
||||
|
|
|
@ -470,10 +470,10 @@ JS_PUBLIC_API bool JS::UpdateDebugMetadata(
|
|||
return true;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API void JS::SetGetElementCallback(JSContext* cx,
|
||||
JSGetElementCallback callback) {
|
||||
JS_PUBLIC_API void JS::SetSourceElementCallback(
|
||||
JSContext* cx, JSSourceElementCallback callback) {
|
||||
MOZ_ASSERT(cx->runtime());
|
||||
cx->runtime()->setElementCallback(cx->runtime(), callback);
|
||||
cx->runtime()->setSourceElementCallback(cx->runtime(), callback);
|
||||
}
|
||||
|
||||
MOZ_NEVER_INLINE static bool ExecuteScript(JSContext* cx, HandleObject envChain,
|
||||
|
|
|
@ -1741,8 +1741,11 @@ JSObject* ScriptSourceObject::unwrappedElement(JSContext* cx) const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(cx->runtime()->getElementCallback);
|
||||
return (*cx->runtime()->getElementCallback)(cx, privateValue);
|
||||
if (cx->runtime()->sourceElementCallback) {
|
||||
return (*cx->runtime()->sourceElementCallback)(cx, privateValue);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class ScriptSource::LoadSourceMatcher {
|
||||
|
|
|
@ -332,9 +332,9 @@ void JSRuntime::setTelemetryCallback(
|
|||
rt->telemetryCallback = callback;
|
||||
}
|
||||
|
||||
void JSRuntime::setElementCallback(JSRuntime* rt,
|
||||
JSGetElementCallback callback) {
|
||||
rt->getElementCallback = callback;
|
||||
void JSRuntime::setSourceElementCallback(JSRuntime* rt,
|
||||
JSSourceElementCallback callback) {
|
||||
rt->sourceElementCallback = callback;
|
||||
}
|
||||
|
||||
void JSRuntime::setUseCounter(JSObject* obj, JSUseCounter counter) {
|
||||
|
|
|
@ -307,7 +307,7 @@ struct JSRuntime {
|
|||
/* Call this to accumulate use counter data. */
|
||||
js::MainThreadData<JSSetUseCounterCallback> useCounterCallback;
|
||||
|
||||
js::MainThreadData<JSGetElementCallback> getElementCallback;
|
||||
js::MainThreadData<JSSourceElementCallback> sourceElementCallback;
|
||||
|
||||
public:
|
||||
// Accumulates data for Firefox telemetry. |id| is the ID of a JS_TELEMETRY_*
|
||||
|
@ -320,7 +320,8 @@ struct JSRuntime {
|
|||
void setTelemetryCallback(JSRuntime* rt,
|
||||
JSAccumulateTelemetryDataCallback callback);
|
||||
|
||||
void setElementCallback(JSRuntime* rt, JSGetElementCallback callback);
|
||||
void setSourceElementCallback(JSRuntime* rt,
|
||||
JSSourceElementCallback callback);
|
||||
|
||||
// Sets the use counter for a specific feature, measuring the presence or
|
||||
// absence of usage of a feature on a specific web page and document which
|
||||
|
|
Загрузка…
Ссылка в новой задаче