From eaae397c42d6744153bf8b520077875deab58108 Mon Sep 17 00:00:00 2001 From: kozyatinskiy Date: Thu, 29 Jan 2015 06:01:13 -0800 Subject: [PATCH] [V8] Added Script::is_debugger_script flag for embedders In DevTools we need one more flag for script origin - is debugger script. We already have "is shared origin" flag. The new flag added by analogy with the old but new has accessor in script object. R=yurys@chromium.org Review URL: https://codereview.chromium.org/879553002 Cr-Commit-Position: refs/heads/master@{#26324} --- include/v8.h | 19 ++++++++++++-- src/accessors.cc | 34 ++++++++++++++++++++++++ src/accessors.h | 1 + src/api.cc | 32 +++++++++++++++-------- src/bootstrapper.cc | 13 ++++++++-- src/compilation-cache.cc | 50 +++++++++++++++--------------------- src/compilation-cache.h | 18 ++++++------- src/compiler.cc | 8 +++--- src/compiler.h | 6 ++--- src/debug.cc | 2 +- src/objects-inl.h | 2 ++ src/objects.h | 9 ++++++- test/cctest/compiler/test-linkage.cc | 2 +- test/cctest/test-api.cc | 24 +++++++++++------ test/cctest/test-compiler.cc | 2 +- test/cctest/test-heap.cc | 22 ++++++++-------- test/cctest/test-serialize.cc | 32 +++++++++++------------ 17 files changed, 178 insertions(+), 98 deletions(-) diff --git a/include/v8.h b/include/v8.h index 1df17bb..bd4cb4e 100644 --- a/include/v8.h +++ b/include/v8.h @@ -976,21 +976,29 @@ class ScriptOrigin { Handle resource_line_offset = Handle(), Handle resource_column_offset = Handle(), Handle resource_is_shared_cross_origin = Handle(), - Handle script_id = Handle()) + Handle script_id = Handle(), + Handle resource_is_embedder_debug_script = Handle()) : resource_name_(resource_name), resource_line_offset_(resource_line_offset), resource_column_offset_(resource_column_offset), + resource_is_embedder_debug_script_(resource_is_embedder_debug_script), resource_is_shared_cross_origin_(resource_is_shared_cross_origin), - script_id_(script_id) { } + script_id_(script_id) {} V8_INLINE Handle ResourceName() const; V8_INLINE Handle ResourceLineOffset() const; V8_INLINE Handle ResourceColumnOffset() const; + /** + * Returns true for embedder's debugger scripts + */ + V8_INLINE Handle ResourceIsEmbedderDebugScript() const; V8_INLINE Handle ResourceIsSharedCrossOrigin() const; V8_INLINE Handle ScriptID() const; + private: Handle resource_name_; Handle resource_line_offset_; Handle resource_column_offset_; + Handle resource_is_embedder_debug_script_; Handle resource_is_shared_cross_origin_; Handle script_id_; }; @@ -1136,6 +1144,7 @@ class V8_EXPORT ScriptCompiler { Handle resource_name; Handle resource_line_offset; Handle resource_column_offset; + Handle resource_is_embedder_debug_script; Handle resource_is_shared_cross_origin; // Cached data from previous compilation (if a kConsume*Cache flag is @@ -6726,6 +6735,11 @@ Handle ScriptOrigin::ResourceColumnOffset() const { } +Handle ScriptOrigin::ResourceIsEmbedderDebugScript() const { + return resource_is_embedder_debug_script_; +} + + Handle ScriptOrigin::ResourceIsSharedCrossOrigin() const { return resource_is_shared_cross_origin_; } @@ -6742,6 +6756,7 @@ ScriptCompiler::Source::Source(Local string, const ScriptOrigin& origin, resource_name(origin.ResourceName()), resource_line_offset(origin.ResourceLineOffset()), resource_column_offset(origin.ResourceColumnOffset()), + resource_is_embedder_debug_script(origin.ResourceIsEmbedderDebugScript()), resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()), cached_data(data) {} diff --git a/src/accessors.cc b/src/accessors.cc index 662a9e1..1e8abd9 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -787,6 +787,40 @@ Handle Accessors::ScriptSourceMappingUrlInfo( // +// Accessors::ScriptIsEmbedderDebugScript +// + + +void Accessors::ScriptIsEmbedderDebugScriptGetter( + v8::Local name, const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); + DisallowHeapAllocation no_allocation; + HandleScope scope(isolate); + Object* object = *Utils::OpenHandle(*info.This()); + bool is_embedder_debug_script = + Script::cast(JSValue::cast(object)->value())->is_embedder_debug_script(); + Object* res = *isolate->factory()->ToBoolean(is_embedder_debug_script); + info.GetReturnValue().Set(Utils::ToLocal(Handle(res, isolate))); +} + + +void Accessors::ScriptIsEmbedderDebugScriptSetter( + v8::Local name, v8::Local value, + const v8::PropertyCallbackInfo& info) { + UNREACHABLE(); +} + + +Handle Accessors::ScriptIsEmbedderDebugScriptInfo( + Isolate* isolate, PropertyAttributes attributes) { + Handle name(isolate->factory()->InternalizeOneByteString( + STATIC_CHAR_VECTOR("is_debugger_script"))); + return MakeAccessor(isolate, name, &ScriptIsEmbedderDebugScriptGetter, + &ScriptIsEmbedderDebugScriptSetter, attributes); +} + + +// // Accessors::ScriptGetContextData // diff --git a/src/accessors.h b/src/accessors.h index 0210d53..bf0c4e4 100644 --- a/src/accessors.h +++ b/src/accessors.h @@ -36,6 +36,7 @@ namespace internal { V(ScriptType) \ V(ScriptSourceUrl) \ V(ScriptSourceMappingUrl) \ + V(ScriptIsEmbedderDebugScript) \ V(StringLength) // Accessors contains all predefined proxy accessors. diff --git a/src/api.cc b/src/api.cc index 9b6be9a..fd84341 100644 --- a/src/api.cc +++ b/src/api.cc @@ -1602,6 +1602,7 @@ Local ScriptCompiler::CompileUnbound( i::Handle name_obj; int line_offset = 0; int column_offset = 0; + bool is_embedder_debug_script = false; bool is_shared_cross_origin = false; if (!source->resource_name.IsEmpty()) { name_obj = Utils::OpenHandle(*(source->resource_name)); @@ -1614,15 +1615,18 @@ Local ScriptCompiler::CompileUnbound( static_cast(source->resource_column_offset->Value()); } if (!source->resource_is_shared_cross_origin.IsEmpty()) { - v8::Isolate* v8_isolate = reinterpret_cast(isolate); is_shared_cross_origin = - source->resource_is_shared_cross_origin == v8::True(v8_isolate); + source->resource_is_shared_cross_origin->IsTrue(); + } + if (!source->resource_is_embedder_debug_script.IsEmpty()) { + is_embedder_debug_script = + source->resource_is_embedder_debug_script->IsTrue(); } EXCEPTION_PREAMBLE(isolate); i::Handle result = i::Compiler::CompileScript( - str, name_obj, line_offset, column_offset, is_shared_cross_origin, - isolate->native_context(), NULL, &script_data, options, - i::NOT_NATIVES_CODE); + str, name_obj, line_offset, column_offset, is_embedder_debug_script, + is_shared_cross_origin, isolate->native_context(), NULL, &script_data, + options, i::NOT_NATIVES_CODE); has_pending_exception = result.is_null(); if (has_pending_exception && script_data != NULL) { // This case won't happen during normal operation; we have compiled @@ -1700,8 +1704,12 @@ Local