Commit 0ea75a24 authored by Alfonso Castaño's avatar Alfonso Castaño Committed by Commit Bot

Move descriptionForTrustedType to Blink

Now the description for Trusted Type objects is generated in Blink rather than in V8 what makes it simpler and safer.
The description will be generated from the original toString() method, avoiding calling into potential redefinitions of toString() by the user.

Corresponding V8 CL: https://chromium-review.googlesource.com/c/v8/v8/+/2502342
Follow-up V8 CL: https://chromium-review.googlesource.com/c/v8/v8/+/2502869

Screenshot: https://i.imgur.com/tDZoRtv.png
Bug: chromium:1048143
Change-Id: I3254e97f0cdc967e51a6d06b2460cc140066be08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2502589
Commit-Queue: Alfonso Castaño <alcastano@google.com>
Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Reviewed-by: default avatarDaniel Vogelheim <vogelheim@chromium.org>
Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822615}
parent 88eeebe4
......@@ -191,6 +191,25 @@ std::unique_ptr<v8_inspector::StringBuffer> ThreadDebugger::valueSubtype(
return nullptr;
}
std::unique_ptr<v8_inspector::StringBuffer>
ThreadDebugger::descriptionForValueSubtype(v8::Local<v8::Context> context,
v8::Local<v8::Value> value) {
if (V8TrustedHTML::HasInstance(value, isolate_)) {
TrustedHTML* trustedHTML =
V8TrustedHTML::ToImplWithTypeCheck(isolate_, value);
return ToV8InspectorStringBuffer(trustedHTML->toString());
} else if (V8TrustedScript::HasInstance(value, isolate_)) {
TrustedScript* trustedScript =
V8TrustedScript::ToImplWithTypeCheck(isolate_, value);
return ToV8InspectorStringBuffer(trustedScript->toString());
} else if (V8TrustedScriptURL::HasInstance(value, isolate_)) {
TrustedScriptURL* trustedScriptURL =
V8TrustedScriptURL::ToImplWithTypeCheck(isolate_, value);
return ToV8InspectorStringBuffer(trustedScriptURL->toString());
}
return nullptr;
}
bool ThreadDebugger::formatAccessorsAsProperties(v8::Local<v8::Value> value) {
return V8DOMWrapper::IsWrapper(isolate_, value);
}
......
......@@ -85,6 +85,9 @@ class CORE_EXPORT ThreadDebugger : public v8_inspector::V8InspectorClient,
void beginUserGesture() override;
std::unique_ptr<v8_inspector::StringBuffer> valueSubtype(
v8::Local<v8::Value>) override;
std::unique_ptr<v8_inspector::StringBuffer> descriptionForValueSubtype(
v8::Local<v8::Context>,
v8::Local<v8::Value>) override;
bool formatAccessorsAsProperties(v8::Local<v8::Value>) override;
double currentTimeMS() override;
bool isInspectableHeapObject(v8::Local<v8::Object>) override;
......
Test description generation for Trusted Types.
{
className : TrustedHTML
description : <foo>
objectId : <string>
subtype : trustedtype
type : object
}
(async function testRemoteObjects(testRunner) {
const {dp} = await testRunner.startBlank('Test description generation for Trusted Types.');
dp.Runtime.enable();
await dp.Runtime.evaluate({ expression:
`policy = trustedTypes.createPolicy("generalPolicy", {
createHTML: string => string
});`
});
// The description should not use an overridden version of toString()
const result = await dp.Runtime.evaluate({ expression:
`x = policy.createHTML("<foo>"); x.toString = () => ""; x`
});
testRunner.log(result.result.result);
testRunner.completeTest();
});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment