Revision: 19882
Author: [email protected]
Date: Thu Mar 13 09:14:16 2014 UTC
Log: Revert "New Compilation API, part 1"
This reverts revision 19881.
Reason: WebKit build failure (will commit a fixed version shortly).
BUG=
Review URL: https://codereview.chromium.org/196793013
http://code.google.com/p/v8/source/detail?r=19882
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/samples/lineprocessor.cc
/branches/bleeding_edge/samples/shell.cc
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/api.h
/branches/bleeding_edge/src/d8.cc
/branches/bleeding_edge/src/heap.cc
/branches/bleeding_edge/src/profile-generator-inl.h
/branches/bleeding_edge/test/cctest/cctest.h
/branches/bleeding_edge/test/cctest/test-api.cc
/branches/bleeding_edge/test/cctest/test-cpu-profiler.cc
/branches/bleeding_edge/test/cctest/test-debug.cc
/branches/bleeding_edge/test/cctest/test-log.cc
/branches/bleeding_edge/test/cctest/test-parsing.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Thu Mar 13 08:54:11 2014 UTC
+++ /branches/bleeding_edge/include/v8.h Thu Mar 13 09:14:16 2014 UTC
@@ -108,7 +108,6 @@
class Platform;
class Primitive;
class RawOperationDescriptor;
-class Script;
class Signature;
class StackFrame;
class StackTrace;
@@ -1147,153 +1146,95 @@
/**
- * A compiled JavaScript script, not yet tied to a Context.
+ * A compiled JavaScript script.
*/
-class V8_EXPORT UnboundScript {
+class V8_EXPORT Script {
public:
/**
- * Binds the script to the currently entered context.
+ * Compiles the specified script (context-independent).
+ *
+ * \param source Script source code.
+ * \param origin Script origin, owned by caller, no references are kept
+ * when New() returns
+ * \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.
+ * \return Compiled script object (context independent; when run it
+ * will use the currently entered context).
*/
- Local<Script> BindToCurrentContext();
-
- int GetId();
- Handle<Value> GetScriptName();
+ static Local<Script> New(Handle<String> source,
+ ScriptOrigin* origin = NULL,
+ ScriptData* pre_data = NULL);
/**
- * Returns zero based line number of the code_pos location in the script.
- * -1 will be returned if no information available.
+ * Compiles the specified script using the specified file name
+ * object (typically a string) as the script's origin.
+ *
+ * \param source Script source code.
+ * \param file_name file name object (typically a string) to be used
+ * as the script's origin.
+ * \return Compiled script object (context independent; when run it
+ * will use the currently entered context).
*/
- int GetLineNumber(int code_pos);
-
- static const int kNoScriptId = 0;
-};
-
+ static Local<Script> New(Handle<String> source,
+ Handle<Value> file_name);
-/**
- * A compiled JavaScript script, tied to a Context which was active when
the
- * script was compiled.
- */
-class V8_EXPORT Script {
- public:
/**
- * A shorthand for ScriptCompiler::CompileBound().
+ * Compiles the specified script (bound to current context).
+ *
+ * \param source Script source code.
+ * \param origin Script origin, owned by caller, no references are kept
+ * when Compile() returns
+ * \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.
+ * \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);
+ ScriptOrigin* origin = NULL,
+ ScriptData* pre_data = NULL);
- // To be decprecated, use the Compile above.
+ /**
+ * Compiles the specified script using the specified file name
+ * object (typically a string) as the script's origin.
+ *
+ * \param source Script source code.
+ * \param file_name File name to use as script's origin
+ * \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<String> file_name);
+ Handle<Value> file_name);
/**
- * Runs the script returning the resulting value. It will be run in the
- * context in which it was created (ScriptCompiler::CompileBound or
- * UnboundScript::BindToGlobalContext()).
+ * Runs the script returning the resulting value. If the script is
+ * context independent (created using ::New) it will be run in the
+ * currently entered context. If it is context specific (created
+ * using ::Compile) it will be run in the context in which it was
+ * compiled.
*/
Local<Value> Run();
/**
- * Returns the corresponding context-unbound script.
+ * Returns the script id.
*/
- Local<UnboundScript> GetUnboundScript();
+ int GetId();
- // To be deprecated; use GetUnboundScript()->GetId();
- int GetId() {
- return GetUnboundScript()->GetId();
- }
-
- // Use GetUnboundScript()->GetId();
- V8_DEPRECATED("Use GetUnboundScript()->GetId()",
- Handle<Value> GetScriptName()) {
- return GetUnboundScript()->GetScriptName();
- }
+ /**
+ * Returns the name value of one Script.
+ */
+ Handle<Value> GetScriptName();
/**
* Returns zero based line number of the code_pos location in the script.
* -1 will be returned if no information available.
*/
- V8_DEPRECATED("Use GetUnboundScript()->GetLineNumber()",
- int GetLineNumber(int code_pos)) {
- return GetUnboundScript()->GetLineNumber(code_pos);
- }
-};
+ int GetLineNumber(int code_pos);
-
-/**
- * For compiling scripts.
- */
-class V8_EXPORT ScriptCompiler {
- public:
- /**
- * Compilation data that the embedder can cache and pass back to speed up
- * future compilations. The data is produced if the CompilerOptions
passed to
- * the compilation functions in ScriptCompiler contains
produce_data_to_cache
- * = true. The data to cache can then can be retrieved from
- * UnboundScript.
- */
- struct V8_EXPORT CachedData {
- CachedData() : data(NULL), length(0) {}
- // Caller keeps the ownership of data and guarantees that the data
stays
- // alive long enough.
- CachedData(const uint8_t* data, int length) : data(data),
length(length) {}
- // TODO(marja): Async compilation; add constructors which take a
callback
- // which will be called when V8 no longer needs the data.
- const uint8_t* data;
- int length;
- };
-
- /**
- * Source code which can be then compiled to a UnboundScript or
- * BoundScript.
- */
- struct V8_EXPORT Source {
- Source(Local<String> source_string, const ScriptOrigin& origin,
- const CachedData& cached_data = CachedData());
- Source(Local<String> source_string,
- const CachedData& cached_data = CachedData());
-
- Local<String> source_string;
-
- // Origin information
- Handle<Value> resource_name;
- Handle<Integer> resource_line_offset;
- Handle<Integer> resource_column_offset;
- Handle<Boolean> resource_is_shared_cross_origin;
-
- // Cached data from previous compilation (if any).
- CachedData cached_data;
- };
-
- enum CompileOptions {
- kNoCompileOptions,
- kProduceDataToCache = 1 << 0
- };
-
- /**
- * Compiles the specified script (context-independent).
- *
- * \param source Script source code.
- * \return Compiled script object (context independent; for running it
must be
- * bound to a context).
- */
- static Local<UnboundScript> CompileUnbound(
- Isolate* isolate, const Source& source,
- CompileOptions options = kNoCompileOptions);
-
- /**
- * Compiles the specified script (bound to current context).
- *
- * \param source Script source code.
- * \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 this function returns.
- * \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(
- Isolate* isolate, const Source& source,
- CompileOptions options = kNoCompileOptions);
+ static const int kNoScriptId = 0;
};
=======================================
--- /branches/bleeding_edge/samples/lineprocessor.cc Thu Mar 13 08:54:11
2014 UTC
+++ /branches/bleeding_edge/samples/lineprocessor.cc Thu Mar 13 09:14:16
2014 UTC
@@ -238,8 +238,7 @@
{
// Compile script in try/catch context.
v8::TryCatch try_catch;
- v8::ScriptOrigin origin(script_name);
- script = v8::Script::Compile(script_source, &origin);
+ script = v8::Script::Compile(script_source, script_name);
if (script.IsEmpty()) {
// Print errors that happened during compilation.
if (report_exceptions)
=======================================
--- /branches/bleeding_edge/samples/shell.cc Thu Mar 13 08:54:11 2014 UTC
+++ /branches/bleeding_edge/samples/shell.cc Thu Mar 13 09:14:16 2014 UTC
@@ -304,8 +304,7 @@
bool report_exceptions) {
v8::HandleScope handle_scope(isolate);
v8::TryCatch try_catch;
- v8::ScriptOrigin origin(name);
- v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin);
+ v8::Handle<v8::Script> script = v8::Script::Compile(source, name);
if (script.IsEmpty()) {
// Print errors that happened during compilation.
if (report_exceptions)
=======================================
--- /branches/bleeding_edge/src/api.cc Thu Mar 13 08:54:11 2014 UTC
+++ /branches/bleeding_edge/src/api.cc Thu Mar 13 09:14:16 2014 UTC
@@ -1611,89 +1611,107 @@
}
-// --- S c r i p t s ---
+// --- S c r i p t ---
-// Internally, UnboundScript is a SharedFunctionInfo, and Script is a
-// JSFunction.
-
-ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin&
origin,
- const CachedData& data)
- : source_string(string),
- resource_name(origin.ResourceName()),
- resource_line_offset(origin.ResourceLineOffset()),
- resource_column_offset(origin.ResourceColumnOffset()),
-
resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()),
- cached_data(data) {}
-
-
-ScriptCompiler::Source::Source(Local<String> string,
- const CachedData& data)
- : source_string(string), cached_data(data) {}
-
-
-Local<Script> UnboundScript::BindToCurrentContext() {
- i::Handle<i::HeapObject> obj =
- i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
- i::Handle<i::SharedFunctionInfo>
- function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate());
- i::Handle<i::JSFunction> function =
- obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo(
- function_info, obj->GetIsolate()->global_context());
- return ToApiHandle<Script>(function);
+Local<Script> Script::New(v8::Handle<String> source,
+ v8::ScriptOrigin* origin,
+ 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>());
+ LOG_API(isolate, "Script::New");
+ ENTER_V8(isolate);
+ i::SharedFunctionInfo* raw_result = NULL;
+ { i::HandleScope scope(isolate);
+ i::Handle<i::Object> name_obj;
+ int line_offset = 0;
+ int column_offset = 0;
+ bool is_shared_cross_origin = false;
+ if (origin != NULL) {
+ if (!origin->ResourceName().IsEmpty()) {
+ name_obj = Utils::OpenHandle(*origin->ResourceName());
+ }
+ if (!origin->ResourceLineOffset().IsEmpty()) {
+ line_offset =
static_cast<int>(origin->ResourceLineOffset()->Value());
+ }
+ if (!origin->ResourceColumnOffset().IsEmpty()) {
+ column_offset =
+ static_cast<int>(origin->ResourceColumnOffset()->Value());
+ }
+ if (!origin->ResourceIsSharedCrossOrigin().IsEmpty()) {
+ v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
+ is_shared_cross_origin =
+ origin->ResourceIsSharedCrossOrigin() == v8::True(v8_isolate);
+ }
+ }
+ EXCEPTION_PREAMBLE(isolate);
+ i::ScriptDataImpl* pre_data_impl =
+ static_cast<i::ScriptDataImpl*>(pre_data);
+ // We assert that the pre-data is sane, even though we can actually
+ // handle it if it turns out not to be in release mode.
+ ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck());
+ // If the pre-data isn't sane we simply ignore it
+ if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) {
+ pre_data_impl = NULL;
+ }
+ i::Handle<i::SharedFunctionInfo> result =
+ i::Compiler::CompileScript(str,
+ name_obj,
+ line_offset,
+ column_offset,
+ is_shared_cross_origin,
+ isolate->global_context(),
+ NULL,
+ pre_data_impl,
+ i::NOT_NATIVES_CODE);
+ has_pending_exception = result.is_null();
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
+ raw_result = *result;
+ }
+ i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
+ return ToApiHandle<Script>(result);
}
-int UnboundScript::GetId() {
- i::Handle<i::HeapObject> obj =
- i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
- i::Isolate* isolate = obj->GetIsolate();
- ON_BAILOUT(isolate, "v8::UnboundScript::GetId()", return -1);
- LOG_API(isolate, "v8::UnboundScript::GetId");
- {
- i::HandleScope scope(isolate);
- i::Handle<i::SharedFunctionInfo> function_info(
- i::SharedFunctionInfo::cast(*obj));
- i::Handle<i::Script> script(i::Script::cast(function_info->script()));
- return script->id()->value();
- }
+Local<Script> Script::New(v8::Handle<String> source,
+ v8::Handle<Value> file_name) {
+ ScriptOrigin origin(file_name);
+ return New(source, &origin);
}
-int UnboundScript::GetLineNumber(int code_pos) {
- i::Handle<i::HeapObject> obj =
- i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
- i::Isolate* isolate = obj->GetIsolate();
- ON_BAILOUT(isolate, "v8::UnboundScript::GetLineNumber()", return -1);
- LOG_API(isolate, "UnboundScript::GetLineNumber");
- if (obj->IsScript()) {
- i::Handle<i::Script> script(i::Script::cast(*obj));
- return i::GetScriptLineNumber(script, code_pos);
- } else {
- return -1;
- }
+Local<Script> Script::Compile(v8::Handle<String> source,
+ v8::ScriptOrigin* origin,
+ 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);
+ if (generic.IsEmpty())
+ return generic;
+ i::Handle<i::Object> obj = Utils::OpenHandle(*generic);
+ i::Handle<i::SharedFunctionInfo> function =
+ i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
+ i::Handle<i::JSFunction> result =
+ isolate->factory()->NewFunctionFromSharedFunctionInfo(
+ function,
+ isolate->global_context());
+ return ToApiHandle<Script>(result);
}
-Handle<Value> UnboundScript::GetScriptName() {
- i::Handle<i::HeapObject> obj =
- i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
- i::Isolate* isolate = obj->GetIsolate();
- ON_BAILOUT(isolate, "v8::UnboundScript::GetName()",
- return Handle<String>());
- LOG_API(isolate, "UnboundScript::GetName");
- if (obj->IsScript()) {
- i::Object* name = i::Script::cast(*obj)->name();
- return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
- } else {
- return Handle<String>();
- }
+Local<Script> Script::Compile(v8::Handle<String> source,
+ v8::Handle<Value> file_name) {
+ ScriptOrigin origin(file_name);
+ return Compile(source, &origin);
}
Local<Value> Script::Run() {
- // If execution is terminating, Compile(..)->Run() requires this
- // check.
+ // If execution is terminating, Compile(script)->Run() requires this
check.
if (this == NULL) return Local<Value>();
i::Handle<i::HeapObject> obj =
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
@@ -1706,8 +1724,15 @@
i::Object* raw_result = NULL;
{
i::HandleScope scope(isolate);
- i::Handle<i::JSFunction> fun =
- i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate);
+ i::Handle<i::JSFunction> fun;
+ if (obj->IsSharedFunctionInfo()) {
+ i::Handle<i::SharedFunctionInfo>
+ function_info(i::SharedFunctionInfo::cast(*obj), isolate);
+ fun = isolate->factory()->NewFunctionFromSharedFunctionInfo(
+ function_info, isolate->global_context());
+ } else {
+ fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate);
+ }
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> receiver(
isolate->context()->global_proxy(), isolate);
@@ -1721,117 +1746,62 @@
}
-Local<UnboundScript> Script::GetUnboundScript() {
- i::Handle<i::Object> obj = Utils::OpenHandle(this);
- return ToApiHandle<UnboundScript>(
-
i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
+static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) {
+ i::Handle<i::Object> obj = Utils::OpenHandle(script);
+ i::Handle<i::SharedFunctionInfo> result;
+ if (obj->IsSharedFunctionInfo()) {
+ result =
+
i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
+ } else {
+ result =
+
i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared());
+ }
+ return result;
}
-Local<UnboundScript> ScriptCompiler::CompileUnbound(
- Isolate* v8_isolate,
- const Source& source,
- CompileOptions options) {
- // FIXME(marja): This function cannot yet create cached data (if options
|
- // produce_data_to_cache is true), but the PreCompile function is still
there
- // for doing it.
- i::Handle<i::String> str = Utils::OpenHandle(*(source.source_string));
- i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
- ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()",
- return Local<UnboundScript>());
- LOG_API(isolate, "ScriptCompiler::CompileUnbound");
- ENTER_V8(isolate);
- i::SharedFunctionInfo* raw_result = NULL;
- { i::HandleScope scope(isolate);
- i::Handle<i::Object> name_obj;
- int line_offset = 0;
- int column_offset = 0;
- bool is_shared_cross_origin = false;
- if (!source.resource_name.IsEmpty()) {
- name_obj = Utils::OpenHandle(*source.resource_name);
- }
- if (!source.resource_line_offset.IsEmpty()) {
- line_offset = static_cast<int>(source.resource_line_offset->Value());
- }
- if (!source.resource_column_offset.IsEmpty()) {
- column_offset =
- static_cast<int>(source.resource_column_offset->Value());
- }
- if (!source.resource_is_shared_cross_origin.IsEmpty()) {
- v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
- is_shared_cross_origin =
- source.resource_is_shared_cross_origin == v8::True(v8_isolate);
- }
- EXCEPTION_PREAMBLE(isolate);
- i::ScriptDataImpl* pre_data_impl = NULL;
- if (source.cached_data.data) {
- // FIXME(marja): Make compiler use CachedData directly.
- pre_data_impl = static_cast<i::ScriptDataImpl*>(ScriptData::New(
- reinterpret_cast<const char*>(source.cached_data.data),
- source.cached_data.length));
- }
- // We assert that the pre-data is sane, even though we can actually
- // handle it if it turns out not to be in release mode.
- ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck());
- // If the pre-data isn't sane we simply ignore it
- if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) {
- delete pre_data_impl;
- pre_data_impl = NULL;
- }
- i::Handle<i::SharedFunctionInfo> result =
- i::Compiler::CompileScript(str,
- name_obj,
- line_offset,
- column_offset,
- is_shared_cross_origin,
- isolate->global_context(),
- NULL,
- pre_data_impl,
- i::NOT_NATIVES_CODE);
- has_pending_exception = result.is_null();
- EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>());
- raw_result = *result;
- delete pre_data_impl;
+int Script::GetId() {
+ i::Handle<i::HeapObject> obj =
+ i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
+ i::Isolate* isolate = obj->GetIsolate();
+ ON_BAILOUT(isolate, "v8::Script::Id()", return -1);
+ LOG_API(isolate, "Script::Id");
+ {
+ i::HandleScope scope(isolate);
+ i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
+ i::Handle<i::Script> script(i::Script::cast(function_info->script()));
+ return script->id()->value();
}
- i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
- return ToApiHandle<UnboundScript>(result);
}
-Local<Script> ScriptCompiler::Compile(
- Isolate* v8_isolate,
- const Source& source,
- CompileOptions options) {
- i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
- ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()",
- return Local<Script>());
- LOG_API(isolate, "ScriptCompiler::CompiletBound()");
- ENTER_V8(isolate);
- Local<UnboundScript> generic =
- CompileUnbound(v8_isolate, source, options);
- if (generic.IsEmpty()) return Local<Script>();
- return generic->BindToCurrentContext();
-}
-
-
-Local<Script> Script::Compile(v8::Handle<String> source,
- v8::ScriptOrigin* origin) {
- i::Handle<i::String> str = Utils::OpenHandle(*source);
- if (origin) {
- return ScriptCompiler::Compile(
- reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
- ScriptCompiler::Source(source, *origin));
+int Script::GetLineNumber(int code_pos) {
+ i::Handle<i::HeapObject> obj =
+ i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
+ i::Isolate* isolate = obj->GetIsolate();
+ ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1);
+ LOG_API(isolate, "Script::GetLineNumber");
+ if (obj->IsScript()) {
+ i::Handle<i::Script> script =
i::Handle<i::Script>(i::Script::cast(*obj));
+ return i::GetScriptLineNumber(script, code_pos);
+ } else {
+ return -1;
}
- return ScriptCompiler::Compile(
- reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
- ScriptCompiler::Source(source));
}
-Local<Script> Script::Compile(v8::Handle<String> source,
- v8::Handle<String> file_name) {
- ScriptOrigin origin(file_name);
- return Compile(source, &origin);
+Handle<Value> Script::GetScriptName() {
+ i::Handle<i::HeapObject> obj =
+ i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
+ i::Isolate* isolate = obj->GetIsolate();
+ ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>());
+ LOG_API(isolate, "Script::GetName");
+ if (obj->IsScript()) {
+ i::Object* name = i::Script::cast(*obj)->name();
+ return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
+ } else {
+ return Handle<String>();
+ }
}
@@ -4058,9 +4028,7 @@
int Function::ScriptId() const {
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
- if (!func->shared()->script()->IsScript()) {
- return v8::UnboundScript::kNoScriptId;
- }
+ if (!func->shared()->script()->IsScript()) return
v8::Script::kNoScriptId;
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
return script->id()->value();
}
=======================================
--- /branches/bleeding_edge/src/api.h Thu Mar 13 08:54:11 2014 UTC
+++ /branches/bleeding_edge/src/api.h Thu Mar 13 09:14:16 2014 UTC
@@ -183,8 +183,7 @@
V(DataView, JSDataView) \
V(String, String) \
V(Symbol, Symbol) \
- V(Script, JSFunction) \
- V(UnboundScript, SharedFunctionInfo) \
+ V(Script, Object) \
V(Function, JSFunction) \
V(Message, JSObject) \
V(Context, Context) \
=======================================
--- /branches/bleeding_edge/src/d8.cc Thu Mar 13 08:54:11 2014 UTC
+++ /branches/bleeding_edge/src/d8.cc Thu Mar 13 09:14:16 2014 UTC
@@ -205,9 +205,7 @@
// When debugging make exceptions appear to be uncaught.
try_catch.SetVerbose(true);
}
- ScriptOrigin origin(name);
- Handle<UnboundScript> script = ScriptCompiler::CompileUnbound(
- isolate, ScriptCompiler::Source(source, origin));
+ Handle<Script> script = Script::New(source, name);
if (script.IsEmpty()) {
// Print errors that happened during compilation.
if (report_exceptions && !FLAG_debugger)
@@ -218,7 +216,7 @@
Local<Context> realm =
Local<Context>::New(isolate, data->realms_[data->realm_current_]);
realm->Enter();
- Handle<Value> result = script->BindToCurrentContext()->Run();
+ Handle<Value> result = script->Run();
realm->Exit();
data->realm_current_ = data->realm_switch_;
if (result.IsEmpty()) {
@@ -407,12 +405,11 @@
Throw(args.GetIsolate(), "Invalid argument");
return;
}
- Handle<UnboundScript> script = ScriptCompiler::CompileUnbound(
- isolate, ScriptCompiler::Source(args[1]->ToString()));
+ Handle<Script> script = Script::New(args[1]->ToString());
if (script.IsEmpty()) return;
Local<Context> realm = Local<Context>::New(isolate,
data->realms_[index]);
realm->Enter();
- Handle<Value> result = script->BindToCurrentContext()->Run();
+ Handle<Value> result = script->Run();
realm->Exit();
args.GetReturnValue().Set(result);
}
@@ -809,8 +806,7 @@
Handle<String> name =
String::NewFromUtf8(isolate, shell_source_name.start(),
String::kNormalString,
shell_source_name.length());
- ScriptOrigin origin(name);
- Handle<Script> script = Script::Compile(source, &origin);
+ Handle<Script> script = Script::Compile(source, name);
script->Run();
// Mark the d8 shell script as native to avoid it showing up as normal
source
// in the debugger.
=======================================
--- /branches/bleeding_edge/src/heap.cc Thu Mar 13 08:54:11 2014 UTC
+++ /branches/bleeding_edge/src/heap.cc Thu Mar 13 09:14:16 2014 UTC
@@ -3347,7 +3347,7 @@
set_materialized_objects(FixedArray::cast(obj));
// Handling of script id generation is in Factory::NewScript.
- set_last_script_id(Smi::FromInt(v8::UnboundScript::kNoScriptId));
+ set_last_script_id(Smi::FromInt(v8::Script::kNoScriptId));
{ MaybeObject* maybe_obj = AllocateAllocationSitesScratchpad();
if (!maybe_obj->ToObject(&obj)) return false;
=======================================
--- /branches/bleeding_edge/src/profile-generator-inl.h Thu Mar 13 08:54:11
2014 UTC
+++ /branches/bleeding_edge/src/profile-generator-inl.h Thu Mar 13 09:14:16
2014 UTC
@@ -47,7 +47,7 @@
line_number_(line_number),
column_number_(column_number),
shared_id_(0),
- script_id_(v8::UnboundScript::kNoScriptId),
+ script_id_(v8::Script::kNoScriptId),
no_frame_ranges_(NULL),
bailout_reason_(kEmptyBailoutReason) { }
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.h Thu Mar 13 08:54:11 2014
UTC
+++ /branches/bleeding_edge/test/cctest/cctest.h Thu Mar 13 09:14:16 2014
UTC
@@ -313,23 +313,17 @@
}
-static inline v8::Local<v8::Script> CompileWithOrigin(
- v8::Local<v8::String> source, v8::Local<v8::String> origin_url) {
- v8::ScriptOrigin origin(origin_url);
- return v8::ScriptCompiler::Compile(
- v8::Isolate::GetCurrent(), v8::ScriptCompiler::Source(source,
origin));
+static inline v8::Local<v8::Script> CompileWithOrigin(const char* source,
+ const char*
origin_url) {
+ v8::ScriptOrigin origin(v8_str(origin_url));
+ return v8::Script::Compile(v8_str(source), &origin);
}
static inline v8::Local<v8::Script> CompileWithOrigin(
v8::Local<v8::String> source, const char* origin_url) {
- return CompileWithOrigin(source, v8_str(origin_url));
-}
-
-
-static inline v8::Local<v8::Script> CompileWithOrigin(const char* source,
- const char*
origin_url) {
- return CompileWithOrigin(v8_str(source), v8_str(origin_url));
+ v8::ScriptOrigin origin(v8_str(origin_url));
+ return v8::Script::Compile(source, &origin);
}
@@ -345,16 +339,11 @@
static inline v8::Local<v8::Value> PreCompileCompileRun(const char*
source) {
- v8::Isolate* isolate = v8::Isolate::GetCurrent();
- v8::Local<v8::String> source_string =
- v8::String::NewFromUtf8(isolate, source);
- v8::ScriptData* preparse = v8::ScriptData::PreCompile(source_string);
- v8::ScriptCompiler::Source script_source(
- source_string, v8::ScriptCompiler::CachedData(
- reinterpret_cast<const
uint8_t*>(preparse->Data()),
- preparse->Length()));
- v8::Local<v8::Script> script = v8::ScriptCompiler::Compile(
- isolate, v8::ScriptCompiler::Source(script_source));
+ v8::Local<v8::String> script_source =
+ v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), source);
+ v8::ScriptData* preparse = v8::ScriptData::PreCompile(script_source);
+ v8::Local<v8::Script> script =
+ v8::Script::Compile(script_source, NULL, preparse);
v8::Local<v8::Value> result = script->Run();
delete preparse;
return result;
@@ -370,24 +359,14 @@
v8::ScriptOrigin origin(v8_str(origin_url),
v8::Integer::New(isolate, line_number),
v8::Integer::New(isolate, column_number));
- return v8::ScriptCompiler::Compile(
- isolate, v8::ScriptCompiler::Source(v8_str(source), origin))
- ->Run();
-}
-
-
-static inline v8::Local<v8::Value> CompileRunWithOrigin(
- v8::Local<v8::String> source, const char* origin_url) {
- v8::ScriptOrigin origin(v8_str(origin_url));
- return v8::ScriptCompiler::Compile(
- v8::Isolate::GetCurrent(),
- v8::ScriptCompiler::Source(source, origin))->Run();
+ return v8::Script::Compile(v8_str(source), &origin)->Run();
}
static inline v8::Local<v8::Value> CompileRunWithOrigin(
const char* source, const char* origin_url) {
- return CompileRunWithOrigin(v8_str(source), origin_url);
+ v8::ScriptOrigin origin(v8_str(origin_url));
+ return v8::Script::Compile(v8_str(source), &origin)->Run();
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Thu Mar 13 08:54:11
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-api.cc Thu Mar 13 09:14:16
2014 UTC
@@ -14952,13 +14952,8 @@
sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset]
= 0;
v8::TryCatch try_catch;
- v8::ScriptCompiler::Source script_source(
- String::NewFromUtf8(isolate, script),
- v8::ScriptCompiler::CachedData(
- reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
- Local<v8::UnboundScript> compiled_script =
- v8::ScriptCompiler::CompileUnbound(isolate, script_source);
-
+ Local<String> source = String::NewFromUtf8(isolate, script);
+ Local<Script> compiled_script = Script::New(source, NULL, sd);
CHECK(try_catch.HasCaught());
String::Utf8Value exception_value(try_catch.Message()->Get());
CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
@@ -14975,12 +14970,7 @@
sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
sd_data[kHeaderSize + 1 * kFunctionEntrySize +
kFunctionEntryStartOffset] =
200;
- v8::ScriptCompiler::Source script_source2(
- String::NewFromUtf8(isolate, script),
- v8::ScriptCompiler::CachedData(
- reinterpret_cast<const uint8_t*>(sd->Data()), sd->Length()));
- compiled_script =
- v8::ScriptCompiler::CompileUnbound(isolate, script_source2);
+ compiled_script = Script::New(source, NULL, sd);
CHECK(!try_catch.HasCaught());
delete sd;
@@ -17091,19 +17081,17 @@
const char *source = "foo";
v8::Handle<v8::Script> dep =
v8_compile(source);
- v8::Handle<v8::UnboundScript> indep =
- v8::ScriptCompiler::CompileUnbound(
- c1->GetIsolate(),
v8::ScriptCompiler::Source(v8::String::NewFromUtf8(
- c1->GetIsolate(), source)));
+ v8::Handle<v8::Script> indep =
+ v8::Script::New(v8::String::NewFromUtf8(c1->GetIsolate(), source));
c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"),
v8::Integer::New(c1->GetIsolate(), 100));
CHECK_EQ(dep->Run()->Int32Value(), 100);
- CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100);
+ CHECK_EQ(indep->Run()->Int32Value(), 100);
LocalContext c2;
c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"),
v8::Integer::New(c2->GetIsolate(), 101));
CHECK_EQ(dep->Run()->Int32Value(), 100);
- CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101);
+ CHECK_EQ(indep->Run()->Int32Value(), 101);
}
@@ -17116,11 +17104,7 @@
v8::String::NewFromUtf8(context->GetIsolate(), source);
v8::Handle<v8::String> origin =
v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test");
- v8::ScriptCompiler::CompileUnbound(
- context->GetIsolate(),
- v8::ScriptCompiler::Source(src, v8::ScriptOrigin(origin)))
- ->BindToCurrentContext()
- ->Run();
+ v8::Script::New(src, origin)->Run();
CHECK(try_catch.HasCaught());
v8::String::Utf8Value stack(try_catch.StackTrace());
CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
@@ -17227,11 +17211,7 @@
v8::Handle<v8::String> overview_src =
v8::String::NewFromUtf8(isolate, overview_source);
v8::Handle<Value> overview_result(
- v8::ScriptCompiler::CompileUnbound(
- isolate,
- v8::ScriptCompiler::Source(overview_src,
v8::ScriptOrigin(origin)))
- ->BindToCurrentContext()
- ->Run());
+ v8::Script::New(overview_src, origin)->Run());
CHECK(!overview_result.IsEmpty());
CHECK(overview_result->IsObject());
@@ -17250,11 +17230,9 @@
v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3);
v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5);
v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
- v8::Handle<v8::UnboundScript> detailed_script(
- v8::ScriptCompiler::CompileUnbound(
- isolate, v8::ScriptCompiler::Source(detailed_src,
detailed_origin)));
- v8::Handle<Value> detailed_result(
- detailed_script->BindToCurrentContext()->Run());
+ v8::Handle<v8::Script> detailed_script(
+ v8::Script::New(detailed_src, &detailed_origin));
+ v8::Handle<Value> detailed_result(detailed_script->Run());
CHECK(!detailed_result.IsEmpty());
CHECK(detailed_result->IsObject());
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Thu Mar 13
08:54:11 2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Thu Mar 13
09:14:16 2014 UTC
@@ -1495,16 +1495,20 @@
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
v8::Context::Scope context_scope(env);
- v8::Handle<v8::Script> script_a = CompileWithOrigin(
+ v8::Handle<v8::Script> script_a = v8::Script::Compile(
+ v8::String::NewFromUtf8(
+ env->GetIsolate(),
" function foo\n() { try { bar(); } catch(e) {} }\n"
- " function bar() { startProfiling(); }\n",
- "script_a");
+ " function bar() { startProfiling(); }\n"),
+ v8::String::NewFromUtf8(env->GetIsolate(), "script_a"));
script_a->Run();
- v8::Handle<v8::Script> script_b = CompileWithOrigin(
+ v8::Handle<v8::Script> script_b = v8::Script::Compile(
+ v8::String::NewFromUtf8(
+ env->GetIsolate(),
"\n\n function baz() { try { foo(); } catch(e) {} }\n"
"\n\nbaz();\n"
- "stopProfiling();\n",
- "script_b");
+ "stopProfiling();\n"),
+ v8::String::NewFromUtf8(env->GetIsolate(), "script_b"));
script_b->Run();
const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
const v8::CpuProfileNode* current = profile->GetTopDownRoot();
=======================================
--- /branches/bleeding_edge/test/cctest/test-debug.cc Thu Mar 13 08:54:11
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-debug.cc Thu Mar 13 09:14:16
2014 UTC
@@ -2218,7 +2218,8 @@
v8::Local<v8::Function> f;
{
v8::HandleScope scope(env->GetIsolate());
- CompileRunWithOrigin(script, "test.html");
+ v8::Script::Compile(
+ script,
v8::String::NewFromUtf8(env->GetIsolate(), "test.html"))->Run();
}
f = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
@@ -2234,7 +2235,8 @@
// Recompile and run script and check that break point was hit.
break_point_hit_count = 0;
- CompileRunWithOrigin(script, "test.html");
+ v8::Script::Compile(
+ script,
v8::String::NewFromUtf8(env->GetIsolate(), "test.html"))->Run();
CHECK_EQ(1, break_point_hit_count);
// Call f and check that there are still no break points.
@@ -2269,7 +2271,9 @@
{
v8::HandleScope scope(env->GetIsolate());
break_point_hit_count = 0;
- CompileRunWithOrigin(script_source, "test.html");
+ v8::Script::Compile(script_source,
+
v8::String::NewFromUtf8(env->GetIsolate(), "test.html"))
+ ->Run();
CHECK_EQ(1, break_point_hit_count);
}
@@ -6242,7 +6246,8 @@
CHECK_EQ(3, break_point_hit_count);
CHECK_EQ("new name", last_script_name_hit);
- v8::Handle<v8::Script> script3 = v8::Script::Compile(script, &origin2);
+ v8::Handle<v8::Script> script3 = v8::Script::Compile(
+ script, &origin2, NULL);
script3->Run();
f = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
@@ -6983,7 +6988,7 @@
v8::Handle<v8::String> void0 =
v8::String::NewFromUtf8(env->GetIsolate(), "void(0)");
- v8::Handle<v8::Script> script = CompileWithOrigin(void0, void0);
+ v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0);
// Check backtrace from "void(0)" script.
BacktraceData::frame_counter = -10;
@@ -7003,20 +7008,18 @@
TEST(GetMirror) {
DebugLocalContext env;
- v8::Isolate* isolate = env->GetIsolate();
- v8::HandleScope scope(isolate);
+ v8::HandleScope scope(env->GetIsolate());
v8::Handle<v8::Value> obj =
- v8::Debug::GetMirror(v8::String::NewFromUtf8(isolate, "hodja"));
+
v8::Debug::GetMirror(v8::String::NewFromUtf8(env->GetIsolate(), "hodja"));
v8::Handle<v8::Function> run_test =
- v8::Handle<v8::Function>::Cast(
- v8::ScriptCompiler::CompileUnbound(
- isolate,
- v8::ScriptCompiler::Source(v8_str(
- "function runTest(mirror) {"
- " return mirror.isString() && (mirror.length() == 5);"
- "}"
- ""
- "runTest;")))->BindToCurrentContext()->Run());
+ v8::Handle<v8::Function>::Cast(v8::Script::New(
+ v8::String::NewFromUtf8(
+ env->GetIsolate(),
+ "function runTest(mirror) {"
+ " return mirror.isString() && (mirror.length() == 5);"
+ "}"
+ ""
+ "runTest;"))->Run());
v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj);
CHECK(result->IsTrue());
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-log.cc Thu Mar 13 08:54:11
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-log.cc Thu Mar 13 09:14:16
2014 UTC
@@ -310,7 +310,7 @@
// Script needs to have a name in order to trigger InitLineEnds
execution.
v8::Handle<v8::String> origin =
v8::String::NewFromUtf8(CcTest::isolate(), "issue-23768-test");
- v8::Handle<v8::Script> evil_script = CompileWithOrigin(source, origin);
+ v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin);
CHECK(!evil_script.IsEmpty());
CHECK(!evil_script->Run().IsEmpty());
i::Handle<i::ExternalTwoByteString> i_source(
@@ -468,7 +468,7 @@
CcTest::isolate(), reinterpret_cast<const char*>(source.start()),
v8::String::kNormalString, source.length());
v8::TryCatch try_catch;
- v8::Handle<v8::Script> script = CompileWithOrigin(source_str, "");
+ v8::Handle<v8::Script> script = v8::Script::Compile(source_str,
v8_str(""));
if (script.IsEmpty()) {
v8::String::Utf8Value exception(try_catch.Exception());
printf("compile: %s\n", *exception);
=======================================
--- /branches/bleeding_edge/test/cctest/test-parsing.cc Thu Mar 13 08:54:11
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-parsing.cc Thu Mar 13 09:14:16
2014 UTC
@@ -213,25 +213,18 @@
{
i::FLAG_lazy = true;
ScriptResource* resource = new ScriptResource(source, source_length);
- v8::ScriptCompiler::Source script_source(
- v8::String::NewExternal(isolate, resource),
- v8::ScriptCompiler::CachedData(
- reinterpret_cast<const uint8_t*>(preparse->Data()),
- preparse->Length()));
- v8::ScriptCompiler::Compile(isolate,
- v8::ScriptCompiler::Source(script_source));
+ v8::Local<v8::String> script_source =
+ v8::String::NewExternal(isolate, resource);
+ v8::Script::Compile(script_source, NULL, preparse);
}
{
i::FLAG_lazy = false;
ScriptResource* resource = new ScriptResource(source, source_length);
- v8::ScriptCompiler::Source script_source(
- v8::String::NewExternal(isolate, resource),
- v8::ScriptCompiler::CachedData(
- reinterpret_cast<const uint8_t*>(preparse->Data()),
- preparse->Length()));
- v8::ScriptCompiler::CompileUnbound(isolate, script_source);
+ v8::Local<v8::String> script_source =
+ v8::String::NewExternal(isolate, resource);
+ v8::Script::New(script_source, NULL, preparse);
}
delete preparse;
i::FLAG_lazy = lazy_flag;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.