Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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" |
| 11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
| 12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
| 13 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
| 14 #include "vm/debuginfo.h" | 14 #include "vm/debuginfo.h" |
| 15 #include "vm/exceptions.h" | 15 #include "vm/exceptions.h" |
| 16 #include "vm/growable_array.h" | 16 #include "vm/growable_array.h" |
| 17 #include "vm/longjump.h" | 17 #include "vm/longjump.h" |
| 18 #include "vm/native_entry.h" | 18 #include "vm/native_entry.h" |
| 19 #include "vm/object.h" | 19 #include "vm/object.h" |
| 20 #include "vm/object_store.h" | 20 #include "vm/object_store.h" |
| 21 #include "vm/port.h" | 21 #include "vm/port.h" |
| 22 #include "vm/resolver.h" | 22 #include "vm/resolver.h" |
| 23 #include "vm/snapshot.h" | 23 #include "vm/snapshot.h" |
| 24 #include "vm/stack_frame.h" | 24 #include "vm/stack_frame.h" |
| 25 #include "vm/timer.h" | 25 #include "vm/timer.h" |
| 26 #include "vm/verifier.h" | 26 #include "vm/verifier.h" |
| 27 | 27 |
| 28 namespace dart { | 28 namespace dart { |
| 29 | 29 |
| 30 #define UNWRAP_NONNULL(dart_handle, vm_handle, Type) \ | |
|
Ivan Posva
2011/11/10 00:12:55
How about adding a line like this here:
Type& vm_
turnidge
2011/11/10 17:48:57
I tried this and it was a bit too magical for me.
| |
| 31 do { \ | |
| 32 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \ | |
| 33 if (tmp.Is##Type()) { \ | |
| 34 (vm_handle) ^= tmp.raw(); \ | |
| 35 } else if (tmp.IsNull()) { \ | |
| 36 return Api::Error("%s expects argument '%s' to be non-null.", \ | |
| 37 __func__, #dart_handle); \ | |
| 38 } else if (tmp.IsApiFailure()) { \ | |
| 39 return dart_handle; \ | |
| 40 } else { \ | |
| 41 return Api::Error("%s expects argument '%s' to be of type %s.", \ | |
| 42 __func__, #dart_handle, #Type); \ | |
| 43 } \ | |
|
Ivan Posva
2011/11/10 00:12:55
\ at column 80.
turnidge
2011/11/10 17:48:57
Done.
| |
| 44 } while (0) | |
| 45 | |
| 46 | |
| 30 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { | 47 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { |
| 31 ASSERT(Isolate::Current() != NULL); | 48 ASSERT(Isolate::Current() != NULL); |
| 32 Zone zone; // Setup a VM zone as we are creating some handles. | 49 Zone zone; // Setup a VM zone as we are creating some handles. |
| 33 HandleScope scope; // Setup a VM handle scope. | 50 HandleScope scope; // Setup a VM handle scope. |
| 34 | 51 |
| 35 // Make sure that the object isn't an ApiFailure. | 52 // Make sure that the object isn't an ApiFailure. |
| 36 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 53 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 37 return !obj.IsApiFailure(); | 54 return !obj.IsApiFailure(); |
| 38 } | 55 } |
| 39 | 56 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 const Library& import = | 391 const Library& import = |
| 375 Library::CheckedHandle(Api::UnwrapHandle(import_in)); | 392 Library::CheckedHandle(Api::UnwrapHandle(import_in)); |
| 376 library.AddImport(import); | 393 library.AddImport(import); |
| 377 return Api::Success(); | 394 return Api::Success(); |
| 378 } | 395 } |
| 379 | 396 |
| 380 | 397 |
| 381 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 398 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
| 382 Zone zone; // Setup a VM zone as we are creating some handles. | 399 Zone zone; // Setup a VM zone as we are creating some handles. |
| 383 HandleScope scope; // Setup a VM handle scope. | 400 HandleScope scope; // Setup a VM handle scope. |
| 384 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); | 401 String& url_str = String::Handle(); |
| 402 UNWRAP_NONNULL(url, url_str, String); | |
| 385 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); | 403 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); |
| 386 if (library.IsNull()) { | 404 if (library.IsNull()) { |
| 387 return Api::Error("Unknown library"); | 405 return Api::Error("%s: library '%s' not found.", |
| 406 __func__, url_str.ToCString()); | |
| 388 } else { | 407 } else { |
| 389 return Api::NewLocalHandle(library); | 408 return Api::NewLocalHandle(library); |
| 390 } | 409 } |
| 391 } | 410 } |
| 392 | 411 |
| 393 | 412 |
| 394 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { | 413 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { |
| 395 Zone zone; // Setup a VM zone as we are creating some handles. | 414 Zone zone; // Setup a VM zone as we are creating some handles. |
| 396 HandleScope scope; // Setup a VM handle scope. | 415 HandleScope scope; // Setup a VM handle scope. |
| 397 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); | 416 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); |
| (...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2094 ASSERT(isolate != NULL); | 2113 ASSERT(isolate != NULL); |
| 2095 ApiState* state = isolate->api_state(); | 2114 ApiState* state = isolate->api_state(); |
| 2096 ASSERT(state != NULL); | 2115 ASSERT(state != NULL); |
| 2097 ApiLocalScope* scope = state->top_scope(); | 2116 ApiLocalScope* scope = state->top_scope(); |
| 2098 ASSERT(scope != NULL); | 2117 ASSERT(scope != NULL); |
| 2099 return scope->zone().Reallocate(ptr, old_size, new_size); | 2118 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2100 } | 2119 } |
| 2101 | 2120 |
| 2102 | 2121 |
| 2103 } // namespace dart | 2122 } // namespace dart |
| OLD | NEW |