Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1137)

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 11824067: Support for embedded Dart scripts (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 16928)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -4030,17 +4030,13 @@
// which shows up because of the use of setjmp.
static void CompileSource(Isolate* isolate,
const Library& lib,
- const String& url,
- const String& source,
- RawScript::Kind kind,
+ const Script& script,
Dart_Handle* result) {
- bool update_lib_status = (kind == RawScript::kScriptTag ||
- kind == RawScript::kLibraryTag);
+ bool update_lib_status = (script.kind() == RawScript::kScriptTag ||
+ script.kind() == RawScript::kLibraryTag);
if (update_lib_status) {
lib.SetLoadInProgress();
}
- const Script& script =
- Script::Handle(isolate, Script::New(url, source, kind));
ASSERT(isolate != NULL);
const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script));
if (error.IsNull()) {
@@ -4081,17 +4077,60 @@
library.set_debuggable(true);
library.Register();
isolate->object_store()->set_root_library(library);
+
+ const Script& script = Script::Handle(
+ isolate, Script::New(url_str, source_str, RawScript::kScriptTag));
Dart_Handle result;
- CompileSource(isolate,
- library,
- url_str,
- source_str,
- RawScript::kScriptTag,
- &result);
+ CompileSource(isolate, library, script, &result);
return result;
}
+DART_EXPORT Dart_Handle Dart_LoadEmbeddedScript(Dart_Handle url,
+ Dart_Handle source,
+ intptr_t line_offset,
+ intptr_t col_offset) {
+ TIMERSCOPE(time_script_loading);
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ const String& url_str = Api::UnwrapStringHandle(isolate, url);
+ if (url_str.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, url, String);
+ }
+ const String& source_str = Api::UnwrapStringHandle(isolate, source);
+ if (source_str.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, source, String);
+ }
+ Library& library =
+ Library::Handle(isolate, isolate->object_store()->root_library());
+ if (!library.IsNull()) {
+ const String& library_url = String::Handle(isolate, library.url());
+ return Api::NewError("%s: A script has already been loaded from '%s'.",
+ CURRENT_FUNC, library_url.ToCString());
+ }
+ if (line_offset < 0) {
+ return Api::NewError("%s: argument 'line_offset' must be positive number",
+ CURRENT_FUNC);
+ }
+ if (col_offset < 0) {
+ return Api::NewError("%s: argument 'col_offset' must be positive number",
+ CURRENT_FUNC);
+ }
+
+ library = Library::New(url_str);
+ library.set_debuggable(true);
+ library.Register();
+ isolate->object_store()->set_root_library(library);
+
+ const Script& script = Script::Handle(
+ isolate, Script::New(url_str, source_str, RawScript::kScriptTag));
+ script.SetLocationOffset(line_offset, col_offset);
+ Dart_Handle result;
+ CompileSource(isolate, library, script, &result);
+ return result;
+}
+
+
DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
@@ -4288,13 +4327,10 @@
return Api::NewError("%s: library '%s' has already been loaded.",
CURRENT_FUNC, url_str.ToCString());
}
+ const Script& script = Script::Handle(
+ isolate, Script::New(url_str, source_str, RawScript::kLibraryTag));
Dart_Handle result;
- CompileSource(isolate,
- library,
- url_str,
- source_str,
- RawScript::kLibraryTag,
- &result);
+ CompileSource(isolate, library, script, &result);
// Propagate the error out right now.
if (::Dart_IsError(result)) {
return result;
@@ -4371,9 +4407,10 @@
if (source_str.IsNull()) {
RETURN_TYPE_ERROR(isolate, source, String);
}
+ const Script& script = Script::Handle(
+ isolate, Script::New(url_str, source_str, RawScript::kSourceTag));
Dart_Handle result;
- CompileSource(isolate, lib, url_str, source_str,
- RawScript::kSourceTag, &result);
+ CompileSource(isolate, lib, script, &result);
return result;
}
@@ -4396,9 +4433,10 @@
if (source_str.IsNull()) {
RETURN_TYPE_ERROR(isolate, patch_source, String);
}
+ const Script& script = Script::Handle(
+ isolate, Script::New(url_str, source_str, RawScript::kPatchTag));
Dart_Handle result;
- CompileSource(isolate, lib, url_str, source_str,
- RawScript::kPatchTag, &result);
+ CompileSource(isolate, lib, script, &result);
return result;
}
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698