Commit 6b2c7337 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[blink] Add ScriptState::EscapableScope

The EscapableScope is the related to V8's EscapableHandleScope where a
a Local value can be returned to an existing outer HandleScope.

This is a preparatory CL to support top-level await modules.

Bug: 1022182, v8:9344
Change-Id: Icadad0169977b7c2b2edc266f6884c2094426bfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105297Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750889}
parent 58bc5e3c
......@@ -75,7 +75,7 @@ class V8PerContextData;
// all V8 proxy objects that have references to the ScriptState are destructed.
class PLATFORM_EXPORT ScriptState final : public GarbageCollected<ScriptState> {
public:
class Scope {
class Scope final {
STACK_ALLOCATED();
public:
......@@ -95,6 +95,32 @@ class PLATFORM_EXPORT ScriptState final : public GarbageCollected<ScriptState> {
v8::Local<v8::Context> context_;
};
// Use EscapableScope if you have to return a v8::Local to an outer scope.
// See v8::EscapableHandleScope.
class EscapableScope final {
STACK_ALLOCATED();
public:
// You need to make sure that scriptState->context() is not empty before
// creating a Scope.
explicit EscapableScope(ScriptState* script_state)
: handle_scope_(script_state->GetIsolate()),
context_(script_state->GetContext()) {
DCHECK(script_state->ContextIsValid());
context_->Enter();
}
~EscapableScope() { context_->Exit(); }
v8::Local<v8::Value> Escape(v8::Local<v8::Value> value) {
return handle_scope_.Escape(value);
}
private:
v8::EscapableHandleScope handle_scope_;
v8::Local<v8::Context> context_;
};
ScriptState(v8::Local<v8::Context>, scoped_refptr<DOMWrapperWorld>);
~ScriptState();
......
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