Remove Script::SetData and the script_data parameter from Script::(Compile|New).

This feature makes it possible to associate data with a script and get it back
when the script is compiled or when an event is handled. It was historically
used by Chromium Dev Tools, but not any more. It is not used by node.js.

Note: this has nothing to do with the preparse data, despite the confusing name.
The preparse data is passed as ScriptData*.

R=svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/184403002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19616 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
marja@chromium.org 2014-02-28 13:54:14 +00:00
parent 99c6ba1399
commit 55750b1c62
19 changed files with 13 additions and 182 deletions

View File

@ -1011,16 +1011,12 @@ class V8_EXPORT Script {
* \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
* using pre_data speeds compilation if it's done multiple times.
* Owned by caller, no references are kept when New() returns.
* \param script_data Arbitrary data associated with script. Using
* this has same effect as calling SetData(), but allows data to be
* available to compile event handlers.
* \return Compiled script object (context independent; when run it
* will use the currently entered context).
*/
static Local<Script> New(Handle<String> source,
ScriptOrigin* origin = NULL,
ScriptData* pre_data = NULL,
Handle<String> script_data = Handle<String>());
ScriptData* pre_data = NULL);
/**
* Compiles the specified script using the specified file name
@ -1044,17 +1040,13 @@ class V8_EXPORT Script {
* \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
* using pre_data speeds compilation if it's done multiple times.
* Owned by caller, no references are kept when Compile() returns.
* \param script_data Arbitrary data associated with script. Using
* this has same effect as calling SetData(), but makes data available
* earlier (i.e. to compile event handlers).
* \return Compiled script object, bound to the context that was active
* when this function was called. When run it will always use this
* context.
*/
static Local<Script> Compile(Handle<String> source,
ScriptOrigin* origin = NULL,
ScriptData* pre_data = NULL,
Handle<String> script_data = Handle<String>());
ScriptData* pre_data = NULL);
/**
* Compiles the specified script using the specified file name
@ -1062,16 +1054,12 @@ class V8_EXPORT Script {
*
* \param source Script source code.
* \param file_name File name to use as script's origin
* \param script_data Arbitrary data associated with script. Using
* this has same effect as calling SetData(), but makes data available
* earlier (i.e. to compile event handlers).
* \return Compiled script object, bound to the context that was active
* when this function was called. When run it will always use this
* context.
*/
static Local<Script> Compile(Handle<String> source,
Handle<Value> file_name,
Handle<String> script_data = Handle<String>());
Handle<Value> file_name);
/**
* Runs the script returning the resulting value. If the script is
@ -1087,13 +1075,6 @@ class V8_EXPORT Script {
*/
int GetId();
/**
* Associate an additional data object with the script. This is mainly used
* with the debugger as this data object is only available through the
* debugger API.
*/
void SetData(Handle<String> data);
/**
* Returns the name value of one Script.
*/

View File

@ -350,26 +350,6 @@ const AccessorDescriptor Accessors::ScriptColumnOffset = {
};
//
// Accessors::ScriptData
//
MaybeObject* Accessors::ScriptGetData(Isolate* isolate,
Object* object,
void*) {
Object* script = JSValue::cast(object)->value();
return Script::cast(script)->data();
}
const AccessorDescriptor Accessors::ScriptData = {
ScriptGetData,
IllegalSetter,
0
};
//
// Accessors::ScriptType
//

View File

@ -49,7 +49,6 @@ namespace internal {
V(ScriptId) \
V(ScriptLineOffset) \
V(ScriptColumnOffset) \
V(ScriptData) \
V(ScriptType) \
V(ScriptCompilationType) \
V(ScriptLineEnds) \
@ -128,7 +127,6 @@ class Accessors : public AllStatic {
static MaybeObject* ScriptGetColumnOffset(Isolate* isolate,
Object* object,
void*);
static MaybeObject* ScriptGetData(Isolate* isolate, Object* object, void*);
static MaybeObject* ScriptGetType(Isolate* isolate, Object* object, void*);
static MaybeObject* ScriptGetCompilationType(Isolate* isolate,
Object* object,

View File

@ -1616,8 +1616,7 @@ ScriptData* ScriptData::New(const char* data, int length) {
Local<Script> Script::New(v8::Handle<String> source,
v8::ScriptOrigin* origin,
v8::ScriptData* pre_data,
v8::Handle<String> script_data) {
v8::ScriptData* pre_data) {
i::Handle<i::String> str = Utils::OpenHandle(*source);
i::Isolate* isolate = str->GetIsolate();
ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>());
@ -1665,7 +1664,6 @@ Local<Script> Script::New(v8::Handle<String> source,
isolate->global_context(),
NULL,
pre_data_impl,
Utils::OpenHandle(*script_data, true),
i::NOT_NATIVES_CODE);
has_pending_exception = result.is_null();
EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
@ -1685,14 +1683,13 @@ Local<Script> Script::New(v8::Handle<String> source,
Local<Script> Script::Compile(v8::Handle<String> source,
v8::ScriptOrigin* origin,
v8::ScriptData* pre_data,
v8::Handle<String> script_data) {
v8::ScriptData* pre_data) {
i::Handle<i::String> str = Utils::OpenHandle(*source);
i::Isolate* isolate = str->GetIsolate();
ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>());
LOG_API(isolate, "Script::Compile");
ENTER_V8(isolate);
Local<Script> generic = New(source, origin, pre_data, script_data);
Local<Script> generic = New(source, origin, pre_data);
if (generic.IsEmpty())
return generic;
i::Handle<i::Object> obj = Utils::OpenHandle(*generic);
@ -1707,10 +1704,9 @@ Local<Script> Script::Compile(v8::Handle<String> source,
Local<Script> Script::Compile(v8::Handle<String> source,
v8::Handle<Value> file_name,
v8::Handle<String> script_data) {
v8::Handle<Value> file_name) {
ScriptOrigin origin(file_name);
return Compile(source, &origin, 0, script_data);
return Compile(source, &origin);
}
@ -1809,22 +1805,6 @@ Handle<Value> Script::GetScriptName() {
}
void Script::SetData(v8::Handle<String> data) {
i::Handle<i::HeapObject> obj =
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate();
ON_BAILOUT(isolate, "v8::Script::SetData()", return);
LOG_API(isolate, "Script::SetData");
{
i::HandleScope scope(isolate);
i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
i::Handle<i::Object> raw_data = Utils::OpenHandle(*data);
i::Handle<i::Script> script(i::Script::cast(function_info->script()));
script->set_data(*raw_data);
}
}
// --- E x c e p t i o n s ---
@ -1980,21 +1960,6 @@ v8::Handle<Value> Message::GetScriptResourceName() const {
}
v8::Handle<Value> Message::GetScriptData() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSMessageObject> message =
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
// Return this.script.data.
i::Handle<i::JSValue> script =
i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(),
isolate));
i::Handle<i::Object> data(i::Script::cast(script->value())->data(), isolate);
return scope.Escape(Utils::ToLocal(data));
}
v8::Handle<v8::StackTrace> Message::GetStackTrace() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);

View File

@ -1520,7 +1520,6 @@ bool Genesis::CompileScriptCached(Isolate* isolate,
top_context,
extension,
NULL,
Handle<String>::null(),
use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE);
if (function_info.is_null()) return false;
if (cache != NULL) cache->Add(name, function_info);
@ -1757,7 +1756,6 @@ bool Genesis::InstallNatives() {
factory()->NewForeign(&Accessors::ScriptColumnOffset));
Handle<String> data_string(factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("data")));
Handle<Foreign> script_data(factory()->NewForeign(&Accessors::ScriptData));
Handle<String> type_string(factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("type")));
Handle<Foreign> script_type(factory()->NewForeign(&Accessors::ScriptType));
@ -1821,11 +1819,6 @@ bool Genesis::InstallNatives() {
script_map->AppendDescriptor(&d, witness);
}
{
CallbacksDescriptor d(*data_string, *script_data, attribs);
script_map->AppendDescriptor(&d, witness);
}
{
CallbacksDescriptor d(*type_string, *script_type, attribs);
script_map->AppendDescriptor(&d, witness);

View File

@ -927,7 +927,6 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(Handle<String> source,
Handle<Context> context,
v8::Extension* extension,
ScriptDataImpl* pre_data,
Handle<Object> script_data,
NativesFlag natives) {
Isolate* isolate = source->GetIsolate();
int source_length = source->length();
@ -969,9 +968,6 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(Handle<String> source,
}
script->set_is_shared_cross_origin(is_shared_cross_origin);
script->set_data(script_data.is_null() ? isolate->heap()->undefined_value()
: *script_data);
// Compile the function and add it to the cache.
CompilationInfoWithZone info(script);
info.MarkAsGlobal();

View File

@ -631,7 +631,6 @@ class Compiler : public AllStatic {
Handle<Context> context,
v8::Extension* extension,
ScriptDataImpl* pre_data,
Handle<Object> script_data,
NativesFlag is_natives_code);
// Create a shared function info object (the code may be lazily compiled).

View File

@ -763,7 +763,6 @@ bool Debug::CompileDebuggerScript(Isolate* isolate, int index) {
false,
context,
NULL, NULL,
Handle<String>::null(),
NATIVES_CODE);
// Silently ignore stack overflows during compilation.

View File

@ -700,7 +700,6 @@ Handle<Script> Factory::NewScript(Handle<String> source) {
script->set_id(Smi::FromInt(id));
script->set_line_offset(Smi::FromInt(0));
script->set_column_offset(Smi::FromInt(0));
script->set_data(heap->undefined_value());
script->set_context_data(heap->undefined_value());
script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
script->set_wrapper(*wrapper);

View File

@ -1341,9 +1341,6 @@ void V8HeapExplorer::ExtractScriptReferences(int entry, Script* script) {
SetInternalReference(obj, entry,
"name", script->name(),
Script::kNameOffset);
SetInternalReference(obj, entry,
"data", script->data(),
Script::kDataOffset);
SetInternalReference(obj, entry,
"context_data", script->context_data(),
Script::kContextOffset);

View File

@ -1557,7 +1557,6 @@ static Handle<Script> CreateScriptCopy(Handle<Script> original) {
copy->set_name(original->name());
copy->set_line_offset(original->line_offset());
copy->set_column_offset(original->column_offset());
copy->set_data(original->data());
copy->set_type(original->type());
copy->set_context_data(original->context_data());
copy->set_eval_from_shared(original->eval_from_shared());

View File

@ -931,7 +931,6 @@ void Script::ScriptVerify() {
VerifyPointer(name());
line_offset()->SmiVerify();
column_offset()->SmiVerify();
VerifyPointer(data());
VerifyPointer(wrapper());
type()->SmiVerify();
VerifyPointer(line_ends());

View File

@ -4916,7 +4916,6 @@ ACCESSORS(Script, name, Object, kNameOffset)
ACCESSORS(Script, id, Smi, kIdOffset)
ACCESSORS_TO_SMI(Script, line_offset, kLineOffsetOffset)
ACCESSORS_TO_SMI(Script, column_offset, kColumnOffsetOffset)
ACCESSORS(Script, data, Object, kDataOffset)
ACCESSORS(Script, context_data, Object, kContextOffset)
ACCESSORS(Script, wrapper, Foreign, kWrapperOffset)
ACCESSORS_TO_SMI(Script, type, kTypeOffset)

View File

@ -1147,8 +1147,6 @@ void Script::ScriptPrint(FILE* out) {
type()->ShortPrint(out);
PrintF(out, "\n - id: ");
id()->ShortPrint(out);
PrintF(out, "\n - data: ");
data()->ShortPrint(out);
PrintF(out, "\n - context data: ");
context_data()->ShortPrint(out);
PrintF(out, "\n - wrapper: ");

View File

@ -6512,9 +6512,6 @@ class Script: public Struct {
// extracted.
DECL_ACCESSORS(column_offset, Smi)
// [data]: additional data associated with this script.
DECL_ACCESSORS(data, Object)
// [context_data]: context data for the context this script was compiled in.
DECL_ACCESSORS(context_data, Object)
@ -6568,8 +6565,7 @@ class Script: public Struct {
static const int kNameOffset = kSourceOffset + kPointerSize;
static const int kLineOffsetOffset = kNameOffset + kPointerSize;
static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
static const int kDataOffset = kColumnOffsetOffset + kPointerSize;
static const int kContextOffset = kDataOffset + kPointerSize;
static const int kContextOffset = kColumnOffsetOffset + kPointerSize;
static const int kWrapperOffset = kContextOffset + kPointerSize;
static const int kTypeOffset = kWrapperOffset + kPointerSize;
static const int kLineEndsOffset = kTypeOffset + kPointerSize;

View File

@ -3974,7 +3974,6 @@ static void check_message_0(v8::Handle<v8::Message> message,
v8::Handle<Value> data) {
CHECK_EQ(5.76, data->NumberValue());
CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
CHECK_EQ(7.56, message->GetScriptData()->NumberValue());
CHECK(!message->IsSharedCrossOrigin());
message_received = true;
}
@ -3990,7 +3989,6 @@ THREADED_TEST(MessageHandler0) {
v8::ScriptOrigin(v8_str("6.75"));
v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
&origin);
script->SetData(v8_str("7.56"));
script->Run();
CHECK(message_received);
// clear out the message listener

View File

@ -67,7 +67,6 @@ static Handle<JSFunction> Compile(const char* source) {
false,
Handle<Context>(isolate->native_context()),
NULL, NULL,
Handle<String>::null(),
NOT_NATIVES_CODE);
return isolate->factory()->NewFunctionFromSharedFunctionInfo(
shared_function, isolate->native_context());

View File

@ -581,24 +581,6 @@ const char* frame_script_name_source =
v8::Local<v8::Function> frame_script_name;
// Source for the JavaScript function which picks out the script data for the
// top frame.
const char* frame_script_data_source =
"function frame_script_data(exec_state) {"
" return exec_state.frame(0).func().script().data();"
"}";
v8::Local<v8::Function> frame_script_data;
// Source for the JavaScript function which picks out the script data from
// AfterCompile event
const char* compiled_script_data_source =
"function compiled_script_data(event_data) {"
" return event_data.script().data();"
"}";
v8::Local<v8::Function> compiled_script_data;
// Source for the JavaScript function which returns the number of frames.
static const char* frame_count_source =
"function frame_count(exec_state) {"
@ -610,10 +592,8 @@ v8::Handle<v8::Function> frame_count;
// Global variable to store the last function hit - used by some tests.
char last_function_hit[80];
// Global variable to store the name and data for last script hit - used by some
// tests.
// Global variable to store the name for last script hit - used by some tests.
char last_script_name_hit[80];
char last_script_data_hit[80];
// Global variables to store the last source position - used by some tests.
int last_source_line = -1;
@ -626,7 +606,6 @@ static void DebugEventBreakPointHitCount(
const v8::Debug::EventDetails& event_details) {
v8::DebugEvent event = event_details.GetEvent();
v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
v8::Handle<v8::Object> event_data = event_details.GetEventData();
v8::internal::Isolate* isolate = CcTest::i_isolate();
Debug* debug = isolate->debug();
// When hitting a debug event listener there must be a break set.
@ -687,40 +666,11 @@ static void DebugEventBreakPointHitCount(
}
}
if (!frame_script_data.IsEmpty()) {
// Get the script data of the function script.
const int argc = 1;
v8::Handle<v8::Value> argv[argc] = { exec_state };
v8::Handle<v8::Value> result = frame_script_data->Call(exec_state,
argc, argv);
if (result->IsUndefined()) {
last_script_data_hit[0] = '\0';
} else {
result = result->ToString();
CHECK(result->IsString());
v8::Handle<v8::String> script_data(result->ToString());
script_data->WriteUtf8(last_script_data_hit);
}
}
// Perform a full deoptimization when the specified number of
// breaks have been hit.
if (break_point_hit_count == break_point_hit_count_deoptimize) {
i::Deoptimizer::DeoptimizeAll(isolate);
}
} else if (event == v8::AfterCompile && !compiled_script_data.IsEmpty()) {
const int argc = 1;
v8::Handle<v8::Value> argv[argc] = { event_data };
v8::Handle<v8::Value> result = compiled_script_data->Call(exec_state,
argc, argv);
if (result->IsUndefined()) {
last_script_data_hit[0] = '\0';
} else {
result = result->ToString();
CHECK(result->IsString());
v8::Handle<v8::String> script_data(result->ToString());
script_data->WriteUtf8(last_script_data_hit);
}
}
}
@ -6249,12 +6199,6 @@ TEST(ScriptNameAndData) {
frame_script_name = CompileFunction(&env,
frame_script_name_source,
"frame_script_name");
frame_script_data = CompileFunction(&env,
frame_script_data_source,
"frame_script_data");
compiled_script_data = CompileFunction(&env,
compiled_script_data_source,
"compiled_script_data");
v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount);
@ -6267,7 +6211,6 @@ TEST(ScriptNameAndData) {
v8::ScriptOrigin origin1 =
v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name"));
v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1);
script1->SetData(v8::String::NewFromUtf8(env->GetIsolate(), "data"));
script1->Run();
v8::Local<v8::Function> f;
f = v8::Local<v8::Function>::Cast(
@ -6276,7 +6219,6 @@ TEST(ScriptNameAndData) {
f->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count);
CHECK_EQ("name", last_script_name_hit);
CHECK_EQ("data", last_script_data_hit);
// Compile the same script again without setting data. As the compilation
// cache is disabled when debugging expect the data to be missing.
@ -6286,7 +6228,6 @@ TEST(ScriptNameAndData) {
f->Call(env->Global(), 0, NULL);
CHECK_EQ(2, break_point_hit_count);
CHECK_EQ("name", last_script_name_hit);
CHECK_EQ("", last_script_data_hit); // Undefined results in empty string.
v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8(
env->GetIsolate(),
@ -6294,29 +6235,24 @@ TEST(ScriptNameAndData) {
" b: 123,\n"
" toString: function() { return this.a + ' ' + this.b; }\n"
"})\n");
v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run();
v8::Script::Compile(data_obj_source)->Run();
v8::ScriptOrigin origin2 =
v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name"));
v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
script2->Run();
script2->SetData(data_obj->ToString());
f = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
CHECK_EQ(3, break_point_hit_count);
CHECK_EQ("new name", last_script_name_hit);
CHECK_EQ("abc 123", last_script_data_hit);
v8::Handle<v8::Script> script3 = v8::Script::Compile(
script, &origin2, NULL,
v8::String::NewFromUtf8(env->GetIsolate(), "in compile"));
CHECK_EQ("in compile", last_script_data_hit);
script, &origin2, NULL);
script3->Run();
f = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
f->Call(env->Global(), 0, NULL);
CHECK_EQ(4, break_point_hit_count);
CHECK_EQ("in compile", last_script_data_hit);
}

View File

@ -223,7 +223,7 @@ TEST(Preparsing) {
ScriptResource* resource = new ScriptResource(source, source_length);
v8::Local<v8::String> script_source =
v8::String::NewExternal(isolate, resource);
v8::Script::New(script_source, NULL, preparse, v8::Local<v8::String>());
v8::Script::New(script_source, NULL, preparse);
}
delete preparse;
i::FLAG_lazy = lazy_flag;