| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 ptr, old_size, new_size); | 1503 ptr, old_size, new_size); |
| 1504 } | 1504 } |
| 1505 | 1505 |
| 1506 | 1506 |
| 1507 DART_EXPORT Dart_Handle Dart_CreateSnapshot( | 1507 DART_EXPORT Dart_Handle Dart_CreateSnapshot( |
| 1508 uint8_t** vm_isolate_snapshot_buffer, | 1508 uint8_t** vm_isolate_snapshot_buffer, |
| 1509 intptr_t* vm_isolate_snapshot_size, | 1509 intptr_t* vm_isolate_snapshot_size, |
| 1510 uint8_t** isolate_snapshot_buffer, | 1510 uint8_t** isolate_snapshot_buffer, |
| 1511 intptr_t* isolate_snapshot_size) { | 1511 intptr_t* isolate_snapshot_size) { |
| 1512 ASSERT(FLAG_load_deferred_eagerly); | 1512 ASSERT(FLAG_load_deferred_eagerly); |
| 1513 Isolate* isolate = Isolate::Current(); | 1513 Thread* thread = Thread::Current(); |
| 1514 Isolate* isolate = thread->isolate(); |
| 1514 DARTSCOPE(isolate); | 1515 DARTSCOPE(isolate); |
| 1515 TIMERSCOPE(isolate, time_creating_snapshot); | 1516 TIMERSCOPE(thread, time_creating_snapshot); |
| 1516 if (vm_isolate_snapshot_buffer != NULL && | 1517 if (vm_isolate_snapshot_buffer != NULL && |
| 1517 vm_isolate_snapshot_size == NULL) { | 1518 vm_isolate_snapshot_size == NULL) { |
| 1518 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 1519 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 1519 } | 1520 } |
| 1520 if (isolate_snapshot_buffer == NULL) { | 1521 if (isolate_snapshot_buffer == NULL) { |
| 1521 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 1522 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 1522 } | 1523 } |
| 1523 if (isolate_snapshot_size == NULL) { | 1524 if (isolate_snapshot_size == NULL) { |
| 1524 RETURN_NULL_ERROR(isolate_snapshot_size); | 1525 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 1525 } | 1526 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1542 writer.WriteFullSnapshot(); | 1543 writer.WriteFullSnapshot(); |
| 1543 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 1544 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 1544 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 1545 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 1545 return Api::Success(); | 1546 return Api::Success(); |
| 1546 } | 1547 } |
| 1547 | 1548 |
| 1548 | 1549 |
| 1549 static Dart_Handle createLibrarySnapshot(Dart_Handle library, | 1550 static Dart_Handle createLibrarySnapshot(Dart_Handle library, |
| 1550 uint8_t** buffer, | 1551 uint8_t** buffer, |
| 1551 intptr_t* size) { | 1552 intptr_t* size) { |
| 1552 Isolate* isolate = Isolate::Current(); | 1553 Thread* thread = Thread::Current(); |
| 1554 Isolate* isolate = thread->isolate(); |
| 1553 DARTSCOPE(isolate); | 1555 DARTSCOPE(isolate); |
| 1554 TIMERSCOPE(isolate, time_creating_snapshot); | 1556 TIMERSCOPE(thread, time_creating_snapshot); |
| 1555 if (buffer == NULL) { | 1557 if (buffer == NULL) { |
| 1556 RETURN_NULL_ERROR(buffer); | 1558 RETURN_NULL_ERROR(buffer); |
| 1557 } | 1559 } |
| 1558 if (size == NULL) { | 1560 if (size == NULL) { |
| 1559 RETURN_NULL_ERROR(size); | 1561 RETURN_NULL_ERROR(size); |
| 1560 } | 1562 } |
| 1561 // Finalize all classes if needed. | 1563 // Finalize all classes if needed. |
| 1562 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); | 1564 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
| 1563 if (::Dart_IsError(state)) { | 1565 if (::Dart_IsError(state)) { |
| 1564 return state; | 1566 return state; |
| (...skipping 2604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4169 return Api::NewError( | 4171 return Api::NewError( |
| 4170 "%s expects argument 'name' to be a valid constructor.", | 4172 "%s expects argument 'name' to be a valid constructor.", |
| 4171 CURRENT_FUNC); | 4173 CURRENT_FUNC); |
| 4172 } | 4174 } |
| 4173 | 4175 |
| 4174 | 4176 |
| 4175 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 4177 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
| 4176 Dart_Handle name, | 4178 Dart_Handle name, |
| 4177 int number_of_arguments, | 4179 int number_of_arguments, |
| 4178 Dart_Handle* arguments) { | 4180 Dart_Handle* arguments) { |
| 4179 Isolate* isolate = Isolate::Current(); | 4181 Thread* thread = Thread::Current(); |
| 4182 Isolate* isolate = thread->isolate(); |
| 4180 DARTSCOPE(isolate); | 4183 DARTSCOPE(isolate); |
| 4181 CHECK_CALLBACK_STATE(isolate); | 4184 CHECK_CALLBACK_STATE(isolate); |
| 4182 // TODO(turnidge): This is a bit simplistic. It overcounts when | 4185 // TODO(turnidge): This is a bit simplistic. It overcounts when |
| 4183 // other operations (gc, compilation) are active. | 4186 // other operations (gc, compilation) are active. |
| 4184 TIMERSCOPE(isolate, time_dart_execution); | 4187 TIMERSCOPE(thread, time_dart_execution); |
| 4185 | 4188 |
| 4186 const String& function_name = Api::UnwrapStringHandle(isolate, name); | 4189 const String& function_name = Api::UnwrapStringHandle(isolate, name); |
| 4187 if (function_name.IsNull()) { | 4190 if (function_name.IsNull()) { |
| 4188 RETURN_TYPE_ERROR(isolate, name, String); | 4191 RETURN_TYPE_ERROR(isolate, name, String); |
| 4189 } | 4192 } |
| 4190 if (number_of_arguments < 0) { | 4193 if (number_of_arguments < 0) { |
| 4191 return Api::NewError( | 4194 return Api::NewError( |
| 4192 "%s expects argument 'number_of_arguments' to be non-negative.", | 4195 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 4193 CURRENT_FUNC); | 4196 CURRENT_FUNC); |
| 4194 } | 4197 } |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5188 // as having failed to load without providing an error instance. | 5191 // as having failed to load without providing an error instance. |
| 5189 lib.SetLoadError(Object::null_instance()); | 5192 lib.SetLoadError(Object::null_instance()); |
| 5190 } | 5193 } |
| 5191 } | 5194 } |
| 5192 | 5195 |
| 5193 | 5196 |
| 5194 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 5197 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 5195 Dart_Handle source, | 5198 Dart_Handle source, |
| 5196 intptr_t line_offset, | 5199 intptr_t line_offset, |
| 5197 intptr_t column_offset) { | 5200 intptr_t column_offset) { |
| 5198 Isolate* isolate = Isolate::Current(); | 5201 Thread* thread = Thread::Current(); |
| 5202 Isolate* isolate = thread->isolate(); |
| 5199 DARTSCOPE(isolate); | 5203 DARTSCOPE(isolate); |
| 5200 TIMERSCOPE(isolate, time_script_loading); | 5204 TIMERSCOPE(thread, time_script_loading); |
| 5201 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 5205 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 5202 if (url_str.IsNull()) { | 5206 if (url_str.IsNull()) { |
| 5203 RETURN_TYPE_ERROR(isolate, url, String); | 5207 RETURN_TYPE_ERROR(isolate, url, String); |
| 5204 } | 5208 } |
| 5205 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 5209 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 5206 if (source_str.IsNull()) { | 5210 if (source_str.IsNull()) { |
| 5207 RETURN_TYPE_ERROR(isolate, source, String); | 5211 RETURN_TYPE_ERROR(isolate, source, String); |
| 5208 } | 5212 } |
| 5209 Library& library = | 5213 Library& library = |
| 5210 Library::Handle(isolate, isolate->object_store()->root_library()); | 5214 Library::Handle(isolate, isolate->object_store()->root_library()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5234 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); | 5238 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 5235 script.SetLocationOffset(line_offset, column_offset); | 5239 script.SetLocationOffset(line_offset, column_offset); |
| 5236 Dart_Handle result; | 5240 Dart_Handle result; |
| 5237 CompileSource(isolate, library, script, &result); | 5241 CompileSource(isolate, library, script, &result); |
| 5238 return result; | 5242 return result; |
| 5239 } | 5243 } |
| 5240 | 5244 |
| 5241 | 5245 |
| 5242 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 5246 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
| 5243 intptr_t buffer_len) { | 5247 intptr_t buffer_len) { |
| 5244 Isolate* isolate = Isolate::Current(); | 5248 Thread* thread = Thread::Current(); |
| 5249 Isolate* isolate = thread->isolate(); |
| 5245 DARTSCOPE(isolate); | 5250 DARTSCOPE(isolate); |
| 5246 TIMERSCOPE(isolate, time_script_loading); | 5251 TIMERSCOPE(thread, time_script_loading); |
| 5247 StackZone zone(isolate); | 5252 StackZone zone(isolate); |
| 5248 if (buffer == NULL) { | 5253 if (buffer == NULL) { |
| 5249 RETURN_NULL_ERROR(buffer); | 5254 RETURN_NULL_ERROR(buffer); |
| 5250 } | 5255 } |
| 5251 NoHeapGrowthControlScope no_growth_control; | 5256 NoHeapGrowthControlScope no_growth_control; |
| 5252 | 5257 |
| 5253 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 5258 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 5254 if (!snapshot->IsScriptSnapshot()) { | 5259 if (!snapshot->IsScriptSnapshot()) { |
| 5255 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 5260 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 5256 " snapshot.", CURRENT_FUNC); | 5261 " snapshot.", CURRENT_FUNC); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5447 } | 5452 } |
| 5448 } | 5453 } |
| 5449 return error_in; | 5454 return error_in; |
| 5450 } | 5455 } |
| 5451 | 5456 |
| 5452 | 5457 |
| 5453 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 5458 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
| 5454 Dart_Handle source, | 5459 Dart_Handle source, |
| 5455 intptr_t line_offset, | 5460 intptr_t line_offset, |
| 5456 intptr_t column_offset) { | 5461 intptr_t column_offset) { |
| 5457 Isolate* isolate = Isolate::Current(); | 5462 Thread* thread = Thread::Current(); |
| 5463 Isolate* isolate = thread->isolate(); |
| 5458 DARTSCOPE(isolate); | 5464 DARTSCOPE(isolate); |
| 5459 TIMERSCOPE(isolate, time_script_loading); | 5465 TIMERSCOPE(thread, time_script_loading); |
| 5460 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 5466 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 5461 if (url_str.IsNull()) { | 5467 if (url_str.IsNull()) { |
| 5462 RETURN_TYPE_ERROR(isolate, url, String); | 5468 RETURN_TYPE_ERROR(isolate, url, String); |
| 5463 } | 5469 } |
| 5464 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 5470 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 5465 if (source_str.IsNull()) { | 5471 if (source_str.IsNull()) { |
| 5466 RETURN_TYPE_ERROR(isolate, source, String); | 5472 RETURN_TYPE_ERROR(isolate, source, String); |
| 5467 } | 5473 } |
| 5468 if (line_offset < 0) { | 5474 if (line_offset < 0) { |
| 5469 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5475 return Api::NewError("%s: argument 'line_offset' must be positive number", |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5553 } | 5559 } |
| 5554 return Api::Success(); | 5560 return Api::Success(); |
| 5555 } | 5561 } |
| 5556 | 5562 |
| 5557 | 5563 |
| 5558 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 5564 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
| 5559 Dart_Handle url, | 5565 Dart_Handle url, |
| 5560 Dart_Handle source, | 5566 Dart_Handle source, |
| 5561 intptr_t line_offset, | 5567 intptr_t line_offset, |
| 5562 intptr_t column_offset) { | 5568 intptr_t column_offset) { |
| 5563 Isolate* isolate = Isolate::Current(); | 5569 Thread* thread = Thread::Current(); |
| 5570 Isolate* isolate = thread->isolate(); |
| 5564 DARTSCOPE(isolate); | 5571 DARTSCOPE(isolate); |
| 5565 TIMERSCOPE(isolate, time_script_loading); | 5572 TIMERSCOPE(thread, time_script_loading); |
| 5566 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 5573 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 5567 if (lib.IsNull()) { | 5574 if (lib.IsNull()) { |
| 5568 RETURN_TYPE_ERROR(isolate, library, Library); | 5575 RETURN_TYPE_ERROR(isolate, library, Library); |
| 5569 } | 5576 } |
| 5570 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 5577 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 5571 if (url_str.IsNull()) { | 5578 if (url_str.IsNull()) { |
| 5572 RETURN_TYPE_ERROR(isolate, url, String); | 5579 RETURN_TYPE_ERROR(isolate, url, String); |
| 5573 } | 5580 } |
| 5574 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 5581 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 5575 if (source_str.IsNull()) { | 5582 if (source_str.IsNull()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5592 script.SetLocationOffset(line_offset, column_offset); | 5599 script.SetLocationOffset(line_offset, column_offset); |
| 5593 Dart_Handle result; | 5600 Dart_Handle result; |
| 5594 CompileSource(isolate, lib, script, &result); | 5601 CompileSource(isolate, lib, script, &result); |
| 5595 return result; | 5602 return result; |
| 5596 } | 5603 } |
| 5597 | 5604 |
| 5598 | 5605 |
| 5599 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 5606 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
| 5600 Dart_Handle url, | 5607 Dart_Handle url, |
| 5601 Dart_Handle patch_source) { | 5608 Dart_Handle patch_source) { |
| 5602 Isolate* isolate = Isolate::Current(); | 5609 Thread* thread = Thread::Current(); |
| 5610 Isolate* isolate = thread->isolate(); |
| 5603 DARTSCOPE(isolate); | 5611 DARTSCOPE(isolate); |
| 5604 TIMERSCOPE(isolate, time_script_loading); | 5612 TIMERSCOPE(thread, time_script_loading); |
| 5605 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 5613 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 5606 if (lib.IsNull()) { | 5614 if (lib.IsNull()) { |
| 5607 RETURN_TYPE_ERROR(isolate, library, Library); | 5615 RETURN_TYPE_ERROR(isolate, library, Library); |
| 5608 } | 5616 } |
| 5609 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 5617 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 5610 if (url_str.IsNull()) { | 5618 if (url_str.IsNull()) { |
| 5611 RETURN_TYPE_ERROR(isolate, url, String); | 5619 RETURN_TYPE_ERROR(isolate, url, String); |
| 5612 } | 5620 } |
| 5613 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 5621 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); |
| 5614 if (source_str.IsNull()) { | 5622 if (source_str.IsNull()) { |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6021 ASSERT(stream != NULL); | 6029 ASSERT(stream != NULL); |
| 6022 TimelineEvent* event = stream->StartEvent(); | 6030 TimelineEvent* event = stream->StartEvent(); |
| 6023 if (event != NULL) { | 6031 if (event != NULL) { |
| 6024 event->AsyncEnd(label, async_id); | 6032 event->AsyncEnd(label, async_id); |
| 6025 event->Complete(); | 6033 event->Complete(); |
| 6026 } | 6034 } |
| 6027 return Api::Success(); | 6035 return Api::Success(); |
| 6028 } | 6036 } |
| 6029 | 6037 |
| 6030 } // namespace dart | 6038 } // namespace dart |
| OLD | NEW |