| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 4012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4023 isolate->set_library_tag_handler(handler); | 4023 isolate->set_library_tag_handler(handler); |
| 4024 return Api::Success(isolate); | 4024 return Api::Success(isolate); |
| 4025 } | 4025 } |
| 4026 | 4026 |
| 4027 | 4027 |
| 4028 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 4028 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 4029 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 4029 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 4030 // which shows up because of the use of setjmp. | 4030 // which shows up because of the use of setjmp. |
| 4031 static void CompileSource(Isolate* isolate, | 4031 static void CompileSource(Isolate* isolate, |
| 4032 const Library& lib, | 4032 const Library& lib, |
| 4033 const String& url, | 4033 const Script& script, |
| 4034 const String& source, | |
| 4035 RawScript::Kind kind, | |
| 4036 Dart_Handle* result) { | 4034 Dart_Handle* result) { |
| 4037 bool update_lib_status = (kind == RawScript::kScriptTag || | 4035 bool update_lib_status = (script.kind() == RawScript::kScriptTag || |
| 4038 kind == RawScript::kLibraryTag); | 4036 script.kind() == RawScript::kLibraryTag); |
| 4039 if (update_lib_status) { | 4037 if (update_lib_status) { |
| 4040 lib.SetLoadInProgress(); | 4038 lib.SetLoadInProgress(); |
| 4041 } | 4039 } |
| 4042 const Script& script = | |
| 4043 Script::Handle(isolate, Script::New(url, source, kind)); | |
| 4044 ASSERT(isolate != NULL); | 4040 ASSERT(isolate != NULL); |
| 4045 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); | 4041 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); |
| 4046 if (error.IsNull()) { | 4042 if (error.IsNull()) { |
| 4047 *result = Api::NewHandle(isolate, lib.raw()); | 4043 *result = Api::NewHandle(isolate, lib.raw()); |
| 4048 if (update_lib_status) { | 4044 if (update_lib_status) { |
| 4049 lib.SetLoaded(); | 4045 lib.SetLoaded(); |
| 4050 } | 4046 } |
| 4051 } else { | 4047 } else { |
| 4052 *result = Api::NewHandle(isolate, error.raw()); | 4048 *result = Api::NewHandle(isolate, error.raw()); |
| 4053 if (update_lib_status) { | 4049 if (update_lib_status) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4074 Library::Handle(isolate, isolate->object_store()->root_library()); | 4070 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 4075 if (!library.IsNull()) { | 4071 if (!library.IsNull()) { |
| 4076 const String& library_url = String::Handle(isolate, library.url()); | 4072 const String& library_url = String::Handle(isolate, library.url()); |
| 4077 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4073 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 4078 CURRENT_FUNC, library_url.ToCString()); | 4074 CURRENT_FUNC, library_url.ToCString()); |
| 4079 } | 4075 } |
| 4080 library = Library::New(url_str); | 4076 library = Library::New(url_str); |
| 4081 library.set_debuggable(true); | 4077 library.set_debuggable(true); |
| 4082 library.Register(); | 4078 library.Register(); |
| 4083 isolate->object_store()->set_root_library(library); | 4079 isolate->object_store()->set_root_library(library); |
| 4080 |
| 4081 const Script& script = Script::Handle( |
| 4082 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 4084 Dart_Handle result; | 4083 Dart_Handle result; |
| 4085 CompileSource(isolate, | 4084 CompileSource(isolate, library, script, &result); |
| 4086 library, | 4085 return result; |
| 4087 url_str, | 4086 } |
| 4088 source_str, | 4087 |
| 4089 RawScript::kScriptTag, | 4088 |
| 4090 &result); | 4089 DART_EXPORT Dart_Handle Dart_LoadEmbeddedScript(Dart_Handle url, |
| 4090 Dart_Handle source, |
| 4091 intptr_t line_offset, |
| 4092 intptr_t col_offset) { |
| 4093 TIMERSCOPE(time_script_loading); |
| 4094 Isolate* isolate = Isolate::Current(); |
| 4095 DARTSCOPE(isolate); |
| 4096 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4097 if (url_str.IsNull()) { |
| 4098 RETURN_TYPE_ERROR(isolate, url, String); |
| 4099 } |
| 4100 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4101 if (source_str.IsNull()) { |
| 4102 RETURN_TYPE_ERROR(isolate, source, String); |
| 4103 } |
| 4104 Library& library = |
| 4105 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 4106 if (!library.IsNull()) { |
| 4107 const String& library_url = String::Handle(isolate, library.url()); |
| 4108 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 4109 CURRENT_FUNC, library_url.ToCString()); |
| 4110 } |
| 4111 if (line_offset < 0) { |
| 4112 return Api::NewError("%s: argument 'line_offset' must be positive number", |
| 4113 CURRENT_FUNC); |
| 4114 } |
| 4115 if (col_offset < 0) { |
| 4116 return Api::NewError("%s: argument 'col_offset' must be positive number", |
| 4117 CURRENT_FUNC); |
| 4118 } |
| 4119 |
| 4120 library = Library::New(url_str); |
| 4121 library.set_debuggable(true); |
| 4122 library.Register(); |
| 4123 isolate->object_store()->set_root_library(library); |
| 4124 |
| 4125 const Script& script = Script::Handle( |
| 4126 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 4127 script.SetLocationOffset(line_offset, col_offset); |
| 4128 Dart_Handle result; |
| 4129 CompileSource(isolate, library, script, &result); |
| 4091 return result; | 4130 return result; |
| 4092 } | 4131 } |
| 4093 | 4132 |
| 4094 | 4133 |
| 4095 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { | 4134 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { |
| 4096 Isolate* isolate = Isolate::Current(); | 4135 Isolate* isolate = Isolate::Current(); |
| 4097 DARTSCOPE(isolate); | 4136 DARTSCOPE(isolate); |
| 4098 TIMERSCOPE(time_script_loading); | 4137 TIMERSCOPE(time_script_loading); |
| 4099 if (buffer == NULL) { | 4138 if (buffer == NULL) { |
| 4100 RETURN_NULL_ERROR(buffer); | 4139 RETURN_NULL_ERROR(buffer); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4281 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); | 4320 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); |
| 4282 if (library.IsNull()) { | 4321 if (library.IsNull()) { |
| 4283 library = Library::New(url_str); | 4322 library = Library::New(url_str); |
| 4284 library.Register(); | 4323 library.Register(); |
| 4285 } else if (!library.LoadNotStarted()) { | 4324 } else if (!library.LoadNotStarted()) { |
| 4286 // The source for this library has either been loaded or is in the | 4325 // The source for this library has either been loaded or is in the |
| 4287 // process of loading. Return an error. | 4326 // process of loading. Return an error. |
| 4288 return Api::NewError("%s: library '%s' has already been loaded.", | 4327 return Api::NewError("%s: library '%s' has already been loaded.", |
| 4289 CURRENT_FUNC, url_str.ToCString()); | 4328 CURRENT_FUNC, url_str.ToCString()); |
| 4290 } | 4329 } |
| 4330 const Script& script = Script::Handle( |
| 4331 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); |
| 4291 Dart_Handle result; | 4332 Dart_Handle result; |
| 4292 CompileSource(isolate, | 4333 CompileSource(isolate, library, script, &result); |
| 4293 library, | |
| 4294 url_str, | |
| 4295 source_str, | |
| 4296 RawScript::kLibraryTag, | |
| 4297 &result); | |
| 4298 // Propagate the error out right now. | 4334 // Propagate the error out right now. |
| 4299 if (::Dart_IsError(result)) { | 4335 if (::Dart_IsError(result)) { |
| 4300 return result; | 4336 return result; |
| 4301 } | 4337 } |
| 4302 | 4338 |
| 4303 // If this is the dart:builtin library, register it with the VM. | 4339 // If this is the dart:builtin library, register it with the VM. |
| 4304 if (url_str.Equals("dart:builtin")) { | 4340 if (url_str.Equals("dart:builtin")) { |
| 4305 isolate->object_store()->set_builtin_library(library); | 4341 isolate->object_store()->set_builtin_library(library); |
| 4306 const char* msg = CheckIsolateState(isolate); | 4342 const char* msg = CheckIsolateState(isolate); |
| 4307 if (msg != NULL) { | 4343 if (msg != NULL) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4364 RETURN_TYPE_ERROR(isolate, library, Library); | 4400 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4365 } | 4401 } |
| 4366 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4402 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4367 if (url_str.IsNull()) { | 4403 if (url_str.IsNull()) { |
| 4368 RETURN_TYPE_ERROR(isolate, url, String); | 4404 RETURN_TYPE_ERROR(isolate, url, String); |
| 4369 } | 4405 } |
| 4370 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4406 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4371 if (source_str.IsNull()) { | 4407 if (source_str.IsNull()) { |
| 4372 RETURN_TYPE_ERROR(isolate, source, String); | 4408 RETURN_TYPE_ERROR(isolate, source, String); |
| 4373 } | 4409 } |
| 4410 const Script& script = Script::Handle( |
| 4411 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); |
| 4374 Dart_Handle result; | 4412 Dart_Handle result; |
| 4375 CompileSource(isolate, lib, url_str, source_str, | 4413 CompileSource(isolate, lib, script, &result); |
| 4376 RawScript::kSourceTag, &result); | |
| 4377 return result; | 4414 return result; |
| 4378 } | 4415 } |
| 4379 | 4416 |
| 4380 | 4417 |
| 4381 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, | 4418 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, |
| 4382 Dart_Handle url, | 4419 Dart_Handle url, |
| 4383 Dart_Handle patch_source) { | 4420 Dart_Handle patch_source) { |
| 4384 TIMERSCOPE(time_script_loading); | 4421 TIMERSCOPE(time_script_loading); |
| 4385 Isolate* isolate = Isolate::Current(); | 4422 Isolate* isolate = Isolate::Current(); |
| 4386 DARTSCOPE(isolate); | 4423 DARTSCOPE(isolate); |
| 4387 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4424 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4388 if (lib.IsNull()) { | 4425 if (lib.IsNull()) { |
| 4389 RETURN_TYPE_ERROR(isolate, library, Library); | 4426 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4390 } | 4427 } |
| 4391 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4428 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4392 if (url_str.IsNull()) { | 4429 if (url_str.IsNull()) { |
| 4393 RETURN_TYPE_ERROR(isolate, url, String); | 4430 RETURN_TYPE_ERROR(isolate, url, String); |
| 4394 } | 4431 } |
| 4395 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 4432 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); |
| 4396 if (source_str.IsNull()) { | 4433 if (source_str.IsNull()) { |
| 4397 RETURN_TYPE_ERROR(isolate, patch_source, String); | 4434 RETURN_TYPE_ERROR(isolate, patch_source, String); |
| 4398 } | 4435 } |
| 4436 const Script& script = Script::Handle( |
| 4437 isolate, Script::New(url_str, source_str, RawScript::kPatchTag)); |
| 4399 Dart_Handle result; | 4438 Dart_Handle result; |
| 4400 CompileSource(isolate, lib, url_str, source_str, | 4439 CompileSource(isolate, lib, script, &result); |
| 4401 RawScript::kPatchTag, &result); | |
| 4402 return result; | 4440 return result; |
| 4403 } | 4441 } |
| 4404 | 4442 |
| 4405 | 4443 |
| 4406 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 4444 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
| 4407 Dart_Handle library, | 4445 Dart_Handle library, |
| 4408 Dart_NativeEntryResolver resolver) { | 4446 Dart_NativeEntryResolver resolver) { |
| 4409 Isolate* isolate = Isolate::Current(); | 4447 Isolate* isolate = Isolate::Current(); |
| 4410 DARTSCOPE(isolate); | 4448 DARTSCOPE(isolate); |
| 4411 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4449 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4465 } | 4503 } |
| 4466 { | 4504 { |
| 4467 NoGCScope no_gc; | 4505 NoGCScope no_gc; |
| 4468 RawObject* raw_obj = obj.raw(); | 4506 RawObject* raw_obj = obj.raw(); |
| 4469 isolate->heap()->SetPeer(raw_obj, peer); | 4507 isolate->heap()->SetPeer(raw_obj, peer); |
| 4470 } | 4508 } |
| 4471 return Api::Success(isolate); | 4509 return Api::Success(isolate); |
| 4472 } | 4510 } |
| 4473 | 4511 |
| 4474 } // namespace dart | 4512 } // namespace dart |
| OLD | NEW |