Chromium Code Reviews| 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 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "vm/timer.h" | 29 #include "vm/timer.h" |
| 30 #include "vm/unicode.h" | 30 #include "vm/unicode.h" |
| 31 #include "vm/verifier.h" | 31 #include "vm/verifier.h" |
| 32 #include "vm/version.h" | 32 #include "vm/version.h" |
| 33 | 33 |
| 34 namespace dart { | 34 namespace dart { |
| 35 | 35 |
| 36 DECLARE_FLAG(bool, print_class_table); | 36 DECLARE_FLAG(bool, print_class_table); |
| 37 | 37 |
| 38 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; | 38 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; |
| 39 Dart_Handle Api::true_handle_ = NULL; | |
| 40 Dart_Handle Api::false_handle_ = NULL; | |
| 41 Dart_Handle Api::null_handle_ = NULL; | |
| 39 | 42 |
| 40 | 43 |
| 41 const char* CanonicalFunction(const char* func) { | 44 const char* CanonicalFunction(const char* func) { |
| 42 if (strncmp(func, "dart::", 6) == 0) { | 45 if (strncmp(func, "dart::", 6) == 0) { |
| 43 return func + 6; | 46 return func + 6; |
| 44 } else { | 47 } else { |
| 45 return func; | 48 return func; |
| 46 } | 49 } |
| 47 } | 50 } |
| 48 | 51 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 return reinterpret_cast<Dart_Handle>(ref); | 91 return reinterpret_cast<Dart_Handle>(ref); |
| 89 } | 92 } |
| 90 | 93 |
| 91 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 94 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
| 92 #if defined(DEBUG) | 95 #if defined(DEBUG) |
| 93 Isolate* isolate = Isolate::Current(); | 96 Isolate* isolate = Isolate::Current(); |
| 94 ASSERT(isolate != NULL); | 97 ASSERT(isolate != NULL); |
| 95 ApiState* state = isolate->api_state(); | 98 ApiState* state = isolate->api_state(); |
| 96 ASSERT(state != NULL); | 99 ASSERT(state != NULL); |
| 97 ASSERT(state->IsValidLocalHandle(object) || | 100 ASSERT(state->IsValidLocalHandle(object) || |
| 98 state->IsValidPersistentHandle(object) || | 101 Dart::vm_isolate()->api_state()->IsValidLocalHandle(object)); |
| 99 state->IsValidWeakPersistentHandle(object) || | |
| 100 state->IsValidPrologueWeakPersistentHandle(object)); | |
| 101 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && | 102 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && |
| 102 PersistentHandle::raw_offset() == 0 && | 103 PersistentHandle::raw_offset() == 0 && |
| 103 LocalHandle::raw_offset() == 0); | 104 LocalHandle::raw_offset() == 0); |
| 104 #endif | 105 #endif |
| 105 return (reinterpret_cast<LocalHandle*>(object))->raw(); | 106 return (reinterpret_cast<LocalHandle*>(object))->raw(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 #define DEFINE_UNWRAP(type) \ | 109 #define DEFINE_UNWRAP(type) \ |
| 109 const type& Api::Unwrap##type##Handle(Isolate* iso, \ | 110 const type& Api::Unwrap##type##Handle(Isolate* iso, \ |
| 110 Dart_Handle dart_handle) { \ | 111 Dart_Handle dart_handle) { \ |
| 111 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ | 112 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ |
| 112 if (obj.Is##type()) { \ | 113 if (obj.Is##type()) { \ |
| 113 return type::Cast(obj); \ | 114 return type::Cast(obj); \ |
| 114 } \ | 115 } \ |
| 115 return type::Handle(iso); \ | 116 return type::Handle(iso); \ |
| 116 } | 117 } |
| 117 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) | 118 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) |
| 118 #undef DEFINE_UNWRAP | 119 #undef DEFINE_UNWRAP |
| 119 | 120 |
| 120 | 121 |
| 121 LocalHandle* Api::UnwrapAsLocalHandle(const ApiState& state, | 122 PersistentHandle* Api::UnwrapAsPersistentHandle(Dart_PersistentHandle object) { |
| 122 Dart_Handle object) { | 123 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(object)); |
| 123 ASSERT(state.IsValidLocalHandle(object)); | |
| 124 return reinterpret_cast<LocalHandle*>(object); | |
| 125 } | |
| 126 | |
| 127 | |
| 128 PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state, | |
| 129 Dart_Handle object) { | |
| 130 ASSERT(state.IsValidPersistentHandle(object)); | |
| 131 return reinterpret_cast<PersistentHandle*>(object); | 124 return reinterpret_cast<PersistentHandle*>(object); |
| 132 } | 125 } |
| 133 | 126 |
| 134 | 127 |
| 135 FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle( | 128 FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle( |
| 136 const ApiState& state, | 129 Dart_WeakPersistentHandle object) { |
| 137 Dart_Handle object) { | 130 ASSERT(Isolate::Current()->api_state()->IsValidWeakPersistentHandle(object)); |
| 138 ASSERT(state.IsValidWeakPersistentHandle(object)); | |
| 139 return reinterpret_cast<FinalizablePersistentHandle*>(object); | 131 return reinterpret_cast<FinalizablePersistentHandle*>(object); |
| 140 } | 132 } |
| 141 | 133 |
| 142 | 134 |
| 143 FinalizablePersistentHandle* Api::UnwrapAsPrologueWeakPersistentHandle( | 135 FinalizablePersistentHandle* Api::UnwrapAsPrologueWeakPersistentHandle( |
| 144 const ApiState& state, | 136 Dart_WeakPersistentHandle object) { |
| 145 Dart_Handle object) { | 137 ASSERT(Isolate::Current()->api_state()->IsValidPrologueWeakPersistentHandle(ob ject)); |
| 146 ASSERT(state.IsValidPrologueWeakPersistentHandle(object)); | |
| 147 return reinterpret_cast<FinalizablePersistentHandle*>(object); | 138 return reinterpret_cast<FinalizablePersistentHandle*>(object); |
| 148 } | 139 } |
| 149 | 140 |
| 150 | 141 |
| 151 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { | 142 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { |
| 152 if (ClassFinalizer::FinalizePendingClasses() && | 143 if (ClassFinalizer::FinalizePendingClasses() && |
| 153 isolate->object_store()->PreallocateObjects()) { | 144 isolate->object_store()->PreallocateObjects()) { |
| 154 return Api::Success(isolate); | 145 return Api::Success(isolate); |
| 155 } | 146 } |
| 156 ASSERT(isolate->object_store()->sticky_error() != Object::null()); | 147 ASSERT(isolate->object_store()->sticky_error() != Object::null()); |
| 157 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); | 148 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); |
| 158 } | 149 } |
| 159 | 150 |
| 160 | 151 |
| 161 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 152 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
| 162 return reinterpret_cast<Dart_Isolate>(isolate); | 153 return reinterpret_cast<Dart_Isolate>(isolate); |
| 163 } | 154 } |
| 164 | 155 |
| 165 | 156 |
| 166 Dart_Handle Api::Success(Isolate* isolate) { | 157 Dart_Handle Api::Success(Isolate* isolate) { |
| 167 ASSERT(isolate != NULL); | 158 ASSERT(isolate != NULL); |
| 168 ApiState* state = isolate->api_state(); | 159 ApiState* state = isolate->api_state(); |
| 169 ASSERT(state != NULL); | 160 ASSERT(state != NULL); |
| 170 PersistentHandle* true_handle = state->True(); | 161 return Api::True(isolate); |
| 171 return reinterpret_cast<Dart_Handle>(true_handle); | |
| 172 } | 162 } |
| 173 | 163 |
| 174 | 164 |
| 175 Dart_Handle Api::NewError(const char* format, ...) { | 165 Dart_Handle Api::NewError(const char* format, ...) { |
| 176 Isolate* isolate = Isolate::Current(); | 166 Isolate* isolate = Isolate::Current(); |
| 177 DARTSCOPE(isolate); | 167 DARTSCOPE(isolate); |
| 178 CHECK_CALLBACK_STATE(isolate); | 168 CHECK_CALLBACK_STATE(isolate); |
| 179 | 169 |
| 180 va_list args; | 170 va_list args; |
| 181 va_start(args, format); | 171 va_start(args, format); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 203 | 193 |
| 204 Dart_Handle Api::AcquiredError(Isolate* isolate) { | 194 Dart_Handle Api::AcquiredError(Isolate* isolate) { |
| 205 ASSERT(isolate != NULL); | 195 ASSERT(isolate != NULL); |
| 206 ApiState* state = isolate->api_state(); | 196 ApiState* state = isolate->api_state(); |
| 207 ASSERT(state != NULL); | 197 ASSERT(state != NULL); |
| 208 PersistentHandle* acquired_error_handle = state->AcquiredError(); | 198 PersistentHandle* acquired_error_handle = state->AcquiredError(); |
| 209 return reinterpret_cast<Dart_Handle>(acquired_error_handle); | 199 return reinterpret_cast<Dart_Handle>(acquired_error_handle); |
| 210 } | 200 } |
| 211 | 201 |
| 212 | 202 |
| 213 Dart_Handle Api::Null(Isolate* isolate) { | 203 Dart_Handle Api::Null(Isolate* isolate) { |
|
siva
2013/05/28 17:37:18
Is the isolate parameter still needed for these ha
Ivan Posva
2013/05/28 21:12:20
Removed the isolate parameter as well as the unuse
| |
| 214 ASSERT(isolate != NULL); | 204 return null_handle_; |
| 215 ApiState* state = isolate->api_state(); | |
| 216 ASSERT(state != NULL); | |
| 217 PersistentHandle* null_handle = state->Null(); | |
| 218 return reinterpret_cast<Dart_Handle>(null_handle); | |
| 219 } | 205 } |
| 220 | 206 |
| 221 | 207 |
| 222 Dart_Handle Api::True(Isolate* isolate) { | 208 Dart_Handle Api::True(Isolate* isolate) { |
| 223 ASSERT(isolate != NULL); | 209 return true_handle_; |
| 224 ApiState* state = isolate->api_state(); | |
| 225 ASSERT(state != NULL); | |
| 226 PersistentHandle* true_handle = state->True(); | |
| 227 return reinterpret_cast<Dart_Handle>(true_handle); | |
| 228 } | 210 } |
| 229 | 211 |
| 230 | 212 |
| 231 Dart_Handle Api::False(Isolate* isolate) { | 213 Dart_Handle Api::False(Isolate* isolate) { |
| 232 ASSERT(isolate != NULL); | 214 return false_handle_; |
| 233 ApiState* state = isolate->api_state(); | |
| 234 ASSERT(state != NULL); | |
| 235 PersistentHandle* false_handle = state->False(); | |
| 236 return reinterpret_cast<Dart_Handle>(false_handle); | |
| 237 } | 215 } |
| 238 | 216 |
| 239 | 217 |
| 240 ApiLocalScope* Api::TopScope(Isolate* isolate) { | 218 ApiLocalScope* Api::TopScope(Isolate* isolate) { |
| 241 ASSERT(isolate != NULL); | 219 ASSERT(isolate != NULL); |
| 242 ApiState* state = isolate->api_state(); | 220 ApiState* state = isolate->api_state(); |
| 243 ASSERT(state != NULL); | 221 ASSERT(state != NULL); |
| 244 ApiLocalScope* scope = state->top_scope(); | 222 ApiLocalScope* scope = state->top_scope(); |
| 245 ASSERT(scope != NULL); | 223 ASSERT(scope != NULL); |
| 246 return scope; | 224 return scope; |
| 247 } | 225 } |
| 248 | 226 |
| 249 | 227 |
| 250 void Api::InitOnce() { | 228 void Api::InitOnce() { |
| 251 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); | 229 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); |
| 252 api_native_key_ = Thread::CreateThreadLocal(); | 230 api_native_key_ = Thread::CreateThreadLocal(); |
| 253 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); | 231 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); |
| 254 } | 232 } |
| 255 | 233 |
| 256 | 234 |
| 235 void Api::InitHandles() { | |
| 236 Isolate* isolate = Isolate::Current(); | |
| 237 ASSERT(isolate != NULL); | |
| 238 ASSERT(isolate == Dart::vm_isolate()); | |
| 239 ApiState* state = isolate->api_state(); | |
| 240 ASSERT(state != NULL); | |
| 241 ASSERT(true_handle_ == NULL); | |
| 242 true_handle_ = Api::NewHandle(isolate, Bool::True().raw()); | |
| 243 | |
| 244 ASSERT(false_handle_ == NULL); | |
| 245 false_handle_ = Api::NewHandle(isolate, Bool::False().raw()); | |
| 246 | |
| 247 ASSERT(null_handle_ == NULL); | |
| 248 null_handle_ = Api::NewHandle(isolate, Object::null()); | |
| 249 } | |
| 250 | |
| 251 | |
| 257 bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) { | 252 bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) { |
| 258 NoGCScope no_gc_scope; | 253 NoGCScope no_gc_scope; |
| 259 RawObject* raw_obj = Api::UnwrapHandle(object); | 254 RawObject* raw_obj = Api::UnwrapHandle(object); |
| 260 switch (Api::ClassId(object)) { | 255 switch (Api::ClassId(object)) { |
| 261 case kExternalOneByteStringCid: { | 256 case kExternalOneByteStringCid: { |
| 262 RawExternalOneByteString* raw_string = | 257 RawExternalOneByteString* raw_string = |
| 263 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); | 258 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); |
| 264 ExternalStringData<uint8_t>* data = raw_string->external_data_; | 259 ExternalStringData<uint8_t>* data = raw_string->external_data_; |
| 265 *peer = data->peer(); | 260 *peer = data->peer(); |
| 266 return true; | 261 return true; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 512 |
| 518 | 513 |
| 519 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 514 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
| 520 Isolate* isolate = Isolate::Current(); | 515 Isolate* isolate = Isolate::Current(); |
| 521 CHECK_ISOLATE(isolate); | 516 CHECK_ISOLATE(isolate); |
| 522 NoGCScope ngc; | 517 NoGCScope ngc; |
| 523 return Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2); | 518 return Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2); |
| 524 } | 519 } |
| 525 | 520 |
| 526 | 521 |
| 527 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { | 522 DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object) { |
| 523 Isolate* isolate = Isolate::Current(); | |
| 524 DARTSCOPE(isolate); | |
| 525 ApiState* state = isolate->api_state(); | |
| 526 ASSERT(state != NULL); | |
| 527 ASSERT(state->IsValidPersistentHandle(object)); | |
| 528 return Api::NewHandle(isolate, reinterpret_cast<PersistentHandle*>(object)->ra w()); | |
| 529 } | |
| 530 | |
| 531 | |
| 532 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object) { | |
| 533 Isolate* isolate = Isolate::Current(); | |
| 534 DARTSCOPE(isolate); | |
| 535 ApiState* state = isolate->api_state(); | |
| 536 ASSERT(state != NULL); | |
| 537 ASSERT(state->IsValidWeakPersistentHandle(object) || | |
| 538 state->IsValidPrologueWeakPersistentHandle(object)); | |
| 539 return Api::NewHandle(isolate, reinterpret_cast<FinalizablePersistentHandle*>( object)->raw()); | |
| 540 } | |
| 541 | |
| 542 | |
| 543 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { | |
| 528 Isolate* isolate = Isolate::Current(); | 544 Isolate* isolate = Isolate::Current(); |
| 529 DARTSCOPE(isolate); | 545 DARTSCOPE(isolate); |
| 530 ApiState* state = isolate->api_state(); | 546 ApiState* state = isolate->api_state(); |
| 531 ASSERT(state != NULL); | 547 ASSERT(state != NULL); |
| 532 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); | 548 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 533 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); | 549 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); |
| 534 new_ref->set_raw(old_ref); | 550 new_ref->set_raw(old_ref); |
| 535 return reinterpret_cast<Dart_Handle>(new_ref); | 551 return reinterpret_cast<Dart_PersistentHandle>(new_ref); |
| 536 } | 552 } |
| 537 | 553 |
| 538 static Dart_Handle AllocateFinalizableHandle( | 554 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
| 539 Isolate* isolate, | 555 Isolate* isolate, |
| 540 FinalizablePersistentHandles* handles, | 556 FinalizablePersistentHandles* handles, |
| 541 Dart_Handle object, | 557 Dart_Handle object, |
| 542 void* peer, | 558 void* peer, |
| 543 Dart_WeakPersistentHandleFinalizer callback) { | 559 Dart_WeakPersistentHandleFinalizer callback) { |
| 544 const Object& ref = Object::Handle(isolate, Api::UnwrapHandle(object)); | 560 const Object& ref = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 545 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); | 561 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); |
| 546 finalizable_ref->set_raw(ref); | 562 finalizable_ref->set_raw(ref); |
| 547 finalizable_ref->set_peer(peer); | 563 finalizable_ref->set_peer(peer); |
| 548 finalizable_ref->set_callback(callback); | 564 finalizable_ref->set_callback(callback); |
| 549 return reinterpret_cast<Dart_Handle>(finalizable_ref); | 565 return reinterpret_cast<Dart_WeakPersistentHandle>(finalizable_ref); |
| 550 } | 566 } |
| 551 | 567 |
| 552 | 568 |
| 553 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( | 569 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
| 554 Dart_Handle object, | 570 Dart_Handle object, |
| 555 void* peer, | 571 void* peer, |
| 556 Dart_WeakPersistentHandleFinalizer callback) { | 572 Dart_WeakPersistentHandleFinalizer callback) { |
| 557 Isolate* isolate = Isolate::Current(); | 573 Isolate* isolate = Isolate::Current(); |
| 558 DARTSCOPE(isolate); | 574 DARTSCOPE(isolate); |
| 559 ApiState* state = isolate->api_state(); | 575 ApiState* state = isolate->api_state(); |
| 560 ASSERT(state != NULL); | 576 ASSERT(state != NULL); |
| 561 return AllocateFinalizableHandle(isolate, | 577 return AllocateFinalizableHandle(isolate, |
| 562 &state->weak_persistent_handles(), | 578 &state->weak_persistent_handles(), |
| 563 object, | 579 object, |
| 564 peer, | 580 peer, |
| 565 callback); | 581 callback); |
| 566 } | 582 } |
| 567 | 583 |
| 568 | 584 |
| 569 DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle( | 585 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( |
| 570 Dart_Handle object, | 586 Dart_Handle object, |
| 571 void* peer, | 587 void* peer, |
| 572 Dart_WeakPersistentHandleFinalizer callback) { | 588 Dart_WeakPersistentHandleFinalizer callback) { |
| 573 Isolate* isolate = Isolate::Current(); | 589 Isolate* isolate = Isolate::Current(); |
| 574 DARTSCOPE(isolate); | 590 DARTSCOPE(isolate); |
| 575 ApiState* state = isolate->api_state(); | 591 ApiState* state = isolate->api_state(); |
| 576 ASSERT(state != NULL); | 592 ASSERT(state != NULL); |
| 577 return AllocateFinalizableHandle(isolate, | 593 return AllocateFinalizableHandle(isolate, |
| 578 &state->prologue_weak_persistent_handles(), | 594 &state->prologue_weak_persistent_handles(), |
| 579 object, | 595 object, |
| 580 peer, | 596 peer, |
| 581 callback); | 597 callback); |
| 582 } | 598 } |
| 583 | 599 |
| 584 | 600 |
| 585 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { | 601 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
| 586 Isolate* isolate = Isolate::Current(); | 602 Isolate* isolate = Isolate::Current(); |
| 587 CHECK_ISOLATE(isolate); | 603 CHECK_ISOLATE(isolate); |
| 588 ApiState* state = isolate->api_state(); | 604 ApiState* state = isolate->api_state(); |
| 589 ASSERT(state != NULL); | 605 ASSERT(state != NULL); |
| 590 if (state->IsValidPrologueWeakPersistentHandle(object)) { | 606 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(object); |
| 591 FinalizablePersistentHandle* prologue_weak_ref = | |
| 592 Api::UnwrapAsPrologueWeakPersistentHandle(*state, object); | |
| 593 state->prologue_weak_persistent_handles().FreeHandle(prologue_weak_ref); | |
| 594 return; | |
| 595 } | |
| 596 if (state->IsValidWeakPersistentHandle(object)) { | |
| 597 FinalizablePersistentHandle* weak_ref = | |
| 598 Api::UnwrapAsWeakPersistentHandle(*state, object); | |
| 599 state->weak_persistent_handles().FreeHandle(weak_ref); | |
| 600 return; | |
| 601 } | |
| 602 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); | |
| 603 ASSERT(!state->IsProtectedHandle(ref)); | 607 ASSERT(!state->IsProtectedHandle(ref)); |
| 604 if (!state->IsProtectedHandle(ref)) { | 608 if (!state->IsProtectedHandle(ref)) { |
| 605 state->persistent_handles().FreeHandle(ref); | 609 state->persistent_handles().FreeHandle(ref); |
| 606 } | 610 } |
| 607 } | 611 } |
| 608 | 612 |
| 609 | 613 |
| 610 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) { | 614 DART_EXPORT void Dart_DeleteWeakPersistentHandle(Dart_WeakPersistentHandle objec t) { |
| 611 Isolate* isolate = Isolate::Current(); | 615 Isolate* isolate = Isolate::Current(); |
| 612 CHECK_ISOLATE(isolate); | 616 CHECK_ISOLATE(isolate); |
| 613 ApiState* state = isolate->api_state(); | 617 ApiState* state = isolate->api_state(); |
| 614 ASSERT(state != NULL); | 618 ASSERT(state != NULL); |
| 615 return state->IsValidWeakPersistentHandle(object); | 619 if (state->IsValidPrologueWeakPersistentHandle(object)) { |
| 620 FinalizablePersistentHandle* prologue_weak_ref = | |
| 621 Api::UnwrapAsPrologueWeakPersistentHandle(object); | |
| 622 state->prologue_weak_persistent_handles().FreeHandle(prologue_weak_ref); | |
| 623 return; | |
| 624 } | |
| 625 FinalizablePersistentHandle* weak_ref = | |
| 626 Api::UnwrapAsWeakPersistentHandle(object); | |
| 627 state->weak_persistent_handles().FreeHandle(weak_ref); | |
| 628 return; | |
| 616 } | 629 } |
| 617 | 630 |
| 618 | 631 |
| 619 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_Handle object) { | 632 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_WeakPersistentHandle o bject) { |
| 620 Isolate* isolate = Isolate::Current(); | 633 Isolate* isolate = Isolate::Current(); |
| 621 CHECK_ISOLATE(isolate); | 634 CHECK_ISOLATE(isolate); |
| 622 ApiState* state = isolate->api_state(); | 635 ApiState* state = isolate->api_state(); |
| 623 ASSERT(state != NULL); | 636 ASSERT(state != NULL); |
| 624 return state->IsValidPrologueWeakPersistentHandle(object); | 637 return state->IsValidPrologueWeakPersistentHandle(object); |
| 625 } | 638 } |
| 626 | 639 |
| 627 | 640 |
| 628 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(Dart_Handle* keys, | 641 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(Dart_Handle* keys, |
| 629 intptr_t num_keys, | 642 intptr_t num_keys, |
| (...skipping 1851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2481 | 2494 |
| 2482 static Dart_Handle NewTypedData(Isolate* isolate, | 2495 static Dart_Handle NewTypedData(Isolate* isolate, |
| 2483 intptr_t cid, | 2496 intptr_t cid, |
| 2484 intptr_t length) { | 2497 intptr_t length) { |
| 2485 CHECK_LENGTH(length, TypedData::MaxElements(cid)); | 2498 CHECK_LENGTH(length, TypedData::MaxElements(cid)); |
| 2486 return Api::NewHandle(isolate, TypedData::New(cid, length)); | 2499 return Api::NewHandle(isolate, TypedData::New(cid, length)); |
| 2487 } | 2500 } |
| 2488 | 2501 |
| 2489 | 2502 |
| 2490 static Dart_Handle NewExternalTypedData( | 2503 static Dart_Handle NewExternalTypedData( |
| 2491 Isolate* isolate, | 2504 Isolate* isolate, intptr_t cid, void* data, intptr_t length) { |
| 2492 intptr_t cid, | |
| 2493 void* data, | |
| 2494 intptr_t length, | |
| 2495 void* peer, | |
| 2496 Dart_WeakPersistentHandleFinalizer callback) { | |
| 2497 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); | 2505 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); |
| 2498 const ExternalTypedData& result = ExternalTypedData::Handle( | 2506 const ExternalTypedData& result = ExternalTypedData::Handle( |
| 2499 isolate, | 2507 isolate, |
| 2500 ExternalTypedData::New(cid, reinterpret_cast<uint8_t*>(data), length)); | 2508 ExternalTypedData::New(cid, reinterpret_cast<uint8_t*>(data), length)); |
| 2501 result.AddFinalizer(peer, callback); | |
| 2502 return Api::NewHandle(isolate, result.raw()); | 2509 return Api::NewHandle(isolate, result.raw()); |
| 2503 } | 2510 } |
| 2504 | 2511 |
| 2505 | 2512 |
| 2506 static Dart_Handle NewExternalByteData(Isolate* isolate, | 2513 static Dart_Handle NewExternalByteData( |
| 2507 void* data, | 2514 Isolate* isolate, void* data, intptr_t length) { |
| 2508 intptr_t length, | 2515 Dart_Handle ext_data = NewExternalTypedData( |
| 2509 void* peer, | 2516 isolate, kExternalTypedDataUint8ArrayCid, data, length); |
| 2510 Dart_WeakPersistentHandleFinalizer cb) { | |
| 2511 Dart_Handle ext_data = NewExternalTypedData(isolate, | |
| 2512 kExternalTypedDataUint8ArrayCid, | |
| 2513 data, | |
| 2514 length, | |
| 2515 peer, | |
| 2516 cb); | |
| 2517 if (::Dart_IsError(ext_data)) { | 2517 if (::Dart_IsError(ext_data)) { |
| 2518 return ext_data; | 2518 return ext_data; |
| 2519 } | 2519 } |
| 2520 Object& result = Object::Handle(isolate); | 2520 Object& result = Object::Handle(isolate); |
| 2521 result = GetByteDataConstructor(isolate, Symbols::ByteDataDotview(), 3); | 2521 result = GetByteDataConstructor(isolate, Symbols::ByteDataDotview(), 3); |
| 2522 ASSERT(!result.IsNull()); | 2522 ASSERT(!result.IsNull()); |
| 2523 ASSERT(result.IsFunction()); | 2523 ASSERT(result.IsFunction()); |
| 2524 const Function& factory = Function::Cast(result); | 2524 const Function& factory = Function::Cast(result); |
| 2525 ASSERT(!factory.IsConstructor()); | 2525 ASSERT(!factory.IsConstructor()); |
| 2526 | 2526 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2582 CURRENT_FUNC); | 2582 CURRENT_FUNC); |
| 2583 } | 2583 } |
| 2584 UNREACHABLE(); | 2584 UNREACHABLE(); |
| 2585 return Api::Null(isolate); | 2585 return Api::Null(isolate); |
| 2586 } | 2586 } |
| 2587 | 2587 |
| 2588 | 2588 |
| 2589 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( | 2589 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( |
| 2590 Dart_TypedData_Type type, | 2590 Dart_TypedData_Type type, |
| 2591 void* data, | 2591 void* data, |
| 2592 intptr_t length, | 2592 intptr_t length) { |
| 2593 void* peer, | |
| 2594 Dart_WeakPersistentHandleFinalizer callback) { | |
| 2595 Isolate* isolate = Isolate::Current(); | 2593 Isolate* isolate = Isolate::Current(); |
| 2596 DARTSCOPE(isolate); | 2594 DARTSCOPE(isolate); |
| 2597 if (data == NULL && length != 0) { | 2595 if (data == NULL && length != 0) { |
| 2598 RETURN_NULL_ERROR(data); | 2596 RETURN_NULL_ERROR(data); |
| 2599 } | 2597 } |
| 2600 CHECK_CALLBACK_STATE(isolate); | 2598 CHECK_CALLBACK_STATE(isolate); |
| 2601 switch (type) { | 2599 switch (type) { |
| 2602 case kByteData: | 2600 case kByteData: |
| 2603 return NewExternalByteData(isolate, data, length, peer, callback); | 2601 return NewExternalByteData(isolate, data, length); |
| 2604 case kInt8: | 2602 case kInt8: |
| 2605 return NewExternalTypedData(isolate, | 2603 return NewExternalTypedData(isolate, |
| 2606 kExternalTypedDataInt8ArrayCid, | 2604 kExternalTypedDataInt8ArrayCid, |
| 2607 data, | 2605 data, |
| 2608 length, | 2606 length); |
| 2609 peer, | |
| 2610 callback); | |
| 2611 case kUint8: | 2607 case kUint8: |
| 2612 return NewExternalTypedData(isolate, | 2608 return NewExternalTypedData(isolate, |
| 2613 kExternalTypedDataUint8ArrayCid, | 2609 kExternalTypedDataUint8ArrayCid, |
| 2614 data, | 2610 data, |
| 2615 length, | 2611 length); |
| 2616 peer, | |
| 2617 callback); | |
| 2618 case kUint8Clamped: | 2612 case kUint8Clamped: |
| 2619 return NewExternalTypedData(isolate, | 2613 return NewExternalTypedData(isolate, |
| 2620 kExternalTypedDataUint8ClampedArrayCid, | 2614 kExternalTypedDataUint8ClampedArrayCid, |
| 2621 data, | 2615 data, |
| 2622 length, | 2616 length); |
| 2623 peer, | |
| 2624 callback); | |
| 2625 case kInt16: | 2617 case kInt16: |
| 2626 return NewExternalTypedData(isolate, | 2618 return NewExternalTypedData(isolate, |
| 2627 kExternalTypedDataInt16ArrayCid, | 2619 kExternalTypedDataInt16ArrayCid, |
| 2628 data, | 2620 data, |
| 2629 length, | 2621 length); |
| 2630 peer, | |
| 2631 callback); | |
| 2632 case kUint16: | 2622 case kUint16: |
| 2633 return NewExternalTypedData(isolate, | 2623 return NewExternalTypedData(isolate, |
| 2634 kExternalTypedDataUint16ArrayCid, | 2624 kExternalTypedDataUint16ArrayCid, |
| 2635 data, | 2625 data, |
| 2636 length, | 2626 length); |
| 2637 peer, | |
| 2638 callback); | |
| 2639 case kInt32: | 2627 case kInt32: |
| 2640 return NewExternalTypedData(isolate, | 2628 return NewExternalTypedData(isolate, |
| 2641 kExternalTypedDataInt32ArrayCid, | 2629 kExternalTypedDataInt32ArrayCid, |
| 2642 data, | 2630 data, |
| 2643 length, | 2631 length); |
| 2644 peer, | |
| 2645 callback); | |
| 2646 case kUint32: | 2632 case kUint32: |
| 2647 return NewExternalTypedData(isolate, | 2633 return NewExternalTypedData(isolate, |
| 2648 kExternalTypedDataUint32ArrayCid, | 2634 kExternalTypedDataUint32ArrayCid, |
| 2649 data, | 2635 data, |
| 2650 length, | 2636 length); |
| 2651 peer, | |
| 2652 callback); | |
| 2653 case kInt64: | 2637 case kInt64: |
| 2654 return NewExternalTypedData(isolate, | 2638 return NewExternalTypedData(isolate, |
| 2655 kExternalTypedDataInt64ArrayCid, | 2639 kExternalTypedDataInt64ArrayCid, |
| 2656 data, | 2640 data, |
| 2657 length, | 2641 length); |
| 2658 peer, | |
| 2659 callback); | |
| 2660 case kUint64: | 2642 case kUint64: |
| 2661 return NewExternalTypedData(isolate, | 2643 return NewExternalTypedData(isolate, |
| 2662 kExternalTypedDataUint64ArrayCid, | 2644 kExternalTypedDataUint64ArrayCid, |
| 2663 data, | 2645 data, |
| 2664 length, | 2646 length); |
| 2665 peer, | |
| 2666 callback); | |
| 2667 case kFloat32: | 2647 case kFloat32: |
| 2668 return NewExternalTypedData(isolate, | 2648 return NewExternalTypedData(isolate, |
| 2669 kExternalTypedDataFloat32ArrayCid, | 2649 kExternalTypedDataFloat32ArrayCid, |
| 2670 data, | 2650 data, |
| 2671 length, | 2651 length); |
| 2672 peer, | |
| 2673 callback); | |
| 2674 case kFloat64: | 2652 case kFloat64: |
| 2675 return NewExternalTypedData(isolate, | 2653 return NewExternalTypedData(isolate, |
| 2676 kExternalTypedDataFloat64ArrayCid, | 2654 kExternalTypedDataFloat64ArrayCid, |
| 2677 data, | 2655 data, |
| 2678 length, | 2656 length); |
| 2679 peer, | |
| 2680 callback); | |
| 2681 case kFloat32x4: | 2657 case kFloat32x4: |
| 2682 return NewExternalTypedData(isolate, | 2658 return NewExternalTypedData(isolate, |
| 2683 kExternalTypedDataFloat32x4ArrayCid, | 2659 kExternalTypedDataFloat32x4ArrayCid, |
| 2684 data, | 2660 data, |
| 2685 length, | 2661 length); |
| 2686 peer, | |
| 2687 callback); | |
| 2688 default: | 2662 default: |
| 2689 return Api::NewError("%s expects argument 'type' to be of" | 2663 return Api::NewError("%s expects argument 'type' to be of" |
| 2690 " 'external TypedData'", CURRENT_FUNC); | 2664 " 'external TypedData'", CURRENT_FUNC); |
| 2691 } | 2665 } |
| 2692 UNREACHABLE(); | 2666 UNREACHABLE(); |
| 2693 return Api::Null(isolate); | 2667 return Api::Null(isolate); |
| 2694 } | 2668 } |
| 2695 | 2669 |
| 2696 | 2670 |
| 2697 DART_EXPORT Dart_Handle Dart_ExternalTypedDataGetPeer(Dart_Handle object, | |
| 2698 void** peer) { | |
| 2699 Isolate* isolate = Isolate::Current(); | |
| 2700 DARTSCOPE(isolate); | |
| 2701 const ExternalTypedData& array = | |
| 2702 Api::UnwrapExternalTypedDataHandle(isolate, object); | |
| 2703 if (array.IsNull()) { | |
| 2704 RETURN_TYPE_ERROR(isolate, object, ExternalTypedData); | |
| 2705 } | |
| 2706 if (peer == NULL) { | |
| 2707 RETURN_NULL_ERROR(peer); | |
| 2708 } | |
| 2709 *peer = array.GetPeer(); | |
| 2710 return Api::Success(isolate); | |
| 2711 } | |
| 2712 | |
|
siva
2013/05/28 17:37:18
Why is this not needed anymore?
| |
| 2713 | |
| 2714 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, | 2671 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, |
| 2715 Dart_TypedData_Type* type, | 2672 Dart_TypedData_Type* type, |
| 2716 void** data, | 2673 void** data, |
| 2717 intptr_t* len) { | 2674 intptr_t* len) { |
| 2718 Isolate* isolate = Isolate::Current(); | 2675 Isolate* isolate = Isolate::Current(); |
| 2719 DARTSCOPE(isolate); | 2676 DARTSCOPE(isolate); |
| 2720 intptr_t class_id = Api::ClassId(object); | 2677 intptr_t class_id = Api::ClassId(object); |
| 2721 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 2678 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
| 2722 !RawObject::IsTypedDataViewClassId(class_id) && | 2679 !RawObject::IsTypedDataViewClassId(class_id) && |
| 2723 !RawObject::IsTypedDataClassId(class_id)) { | 2680 !RawObject::IsTypedDataClassId(class_id)) { |
| (...skipping 2156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4880 } | 4837 } |
| 4881 { | 4838 { |
| 4882 NoGCScope no_gc; | 4839 NoGCScope no_gc; |
| 4883 RawObject* raw_obj = obj.raw(); | 4840 RawObject* raw_obj = obj.raw(); |
| 4884 isolate->heap()->SetPeer(raw_obj, peer); | 4841 isolate->heap()->SetPeer(raw_obj, peer); |
| 4885 } | 4842 } |
| 4886 return Api::Success(isolate); | 4843 return Api::Success(isolate); |
| 4887 } | 4844 } |
| 4888 | 4845 |
| 4889 } // namespace dart | 4846 } // namespace dart |
| OLD | NEW |