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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 302143004: - Add Dart_EmptyString to return the canonical empty string similar to how (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 DEFINE_FLAG(bool, check_function_fingerprints, false, 44 DEFINE_FLAG(bool, check_function_fingerprints, false,
45 "Check function fingerprints"); 45 "Check function fingerprints");
46 DEFINE_FLAG(bool, trace_api, false, 46 DEFINE_FLAG(bool, trace_api, false,
47 "Trace invocation of API calls (debug mode only)"); 47 "Trace invocation of API calls (debug mode only)");
48 DEFINE_FLAG(bool, load_async, true, "load source code asynchronously"); 48 DEFINE_FLAG(bool, load_async, true, "load source code asynchronously");
49 49
50 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; 50 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey;
51 Dart_Handle Api::true_handle_ = NULL; 51 Dart_Handle Api::true_handle_ = NULL;
52 Dart_Handle Api::false_handle_ = NULL; 52 Dart_Handle Api::false_handle_ = NULL;
53 Dart_Handle Api::null_handle_ = NULL; 53 Dart_Handle Api::null_handle_ = NULL;
54 Dart_Handle Api::empty_string_handle_ = NULL;
54 55
55 56
56 const char* CanonicalFunction(const char* func) { 57 const char* CanonicalFunction(const char* func) {
57 if (strncmp(func, "dart::", 6) == 0) { 58 if (strncmp(func, "dart::", 6) == 0) {
58 return func + 6; 59 return func + 6;
59 } else { 60 } else {
60 return func; 61 return func;
61 } 62 }
62 } 63 }
63 64
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 366
366 Dart_Handle Api::AcquiredError(Isolate* isolate) { 367 Dart_Handle Api::AcquiredError(Isolate* isolate) {
367 ASSERT(isolate != NULL); 368 ASSERT(isolate != NULL);
368 ApiState* state = isolate->api_state(); 369 ApiState* state = isolate->api_state();
369 ASSERT(state != NULL); 370 ASSERT(state != NULL);
370 PersistentHandle* acquired_error_handle = state->AcquiredError(); 371 PersistentHandle* acquired_error_handle = state->AcquiredError();
371 return reinterpret_cast<Dart_Handle>(acquired_error_handle); 372 return reinterpret_cast<Dart_Handle>(acquired_error_handle);
372 } 373 }
373 374
374 375
375 Dart_Handle Api::Null() {
376 return null_handle_;
377 }
378
379
380 Dart_Handle Api::True() {
381 return true_handle_;
382 }
383
384
385 Dart_Handle Api::False() {
386 return false_handle_;
387 }
388
389
390 ApiLocalScope* Api::TopScope(Isolate* isolate) { 376 ApiLocalScope* Api::TopScope(Isolate* isolate) {
391 ASSERT(isolate != NULL); 377 ASSERT(isolate != NULL);
392 ApiState* state = isolate->api_state(); 378 ApiState* state = isolate->api_state();
393 ASSERT(state != NULL); 379 ASSERT(state != NULL);
394 ApiLocalScope* scope = state->top_scope(); 380 ApiLocalScope* scope = state->top_scope();
395 ASSERT(scope != NULL); 381 ASSERT(scope != NULL);
396 return scope; 382 return scope;
397 } 383 }
398 384
399 385
(...skipping 11 matching lines...) Expand all
411 ApiState* state = isolate->api_state(); 397 ApiState* state = isolate->api_state();
412 ASSERT(state != NULL); 398 ASSERT(state != NULL);
413 ASSERT(true_handle_ == NULL); 399 ASSERT(true_handle_ == NULL);
414 true_handle_ = Api::InitNewHandle(isolate, Bool::True().raw()); 400 true_handle_ = Api::InitNewHandle(isolate, Bool::True().raw());
415 401
416 ASSERT(false_handle_ == NULL); 402 ASSERT(false_handle_ == NULL);
417 false_handle_ = Api::InitNewHandle(isolate, Bool::False().raw()); 403 false_handle_ = Api::InitNewHandle(isolate, Bool::False().raw());
418 404
419 ASSERT(null_handle_ == NULL); 405 ASSERT(null_handle_ == NULL);
420 null_handle_ = Api::InitNewHandle(isolate, Object::null()); 406 null_handle_ = Api::InitNewHandle(isolate, Object::null());
407
408 ASSERT(empty_string_handle_ == NULL);
409 empty_string_handle_ = Api::InitNewHandle(isolate, Symbols::Empty().raw());
421 } 410 }
422 411
423 412
424 bool Api::StringGetPeerHelper(NativeArguments* arguments, 413 bool Api::StringGetPeerHelper(NativeArguments* arguments,
425 int arg_index, 414 int arg_index,
426 void** peer) { 415 void** peer) {
427 NoGCScope no_gc_scope; 416 NoGCScope no_gc_scope;
428 RawObject* raw_obj = arguments->NativeArgAt(arg_index); 417 RawObject* raw_obj = arguments->NativeArgAt(arg_index);
429 if (!raw_obj->IsHeapObject()) { 418 if (!raw_obj->IsHeapObject()) {
430 return false; 419 return false;
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 if (scope == NULL) return NULL; 1655 if (scope == NULL) return NULL;
1667 zone = scope->zone(); 1656 zone = scope->zone();
1668 } 1657 }
1669 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size)); 1658 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size));
1670 } 1659 }
1671 1660
1672 1661
1673 // --- Objects ---- 1662 // --- Objects ----
1674 1663
1675 DART_EXPORT Dart_Handle Dart_Null() { 1664 DART_EXPORT Dart_Handle Dart_Null() {
1676 Isolate* isolate = Isolate::Current(); 1665 ASSERT(Isolate::Current() != NULL);
1677 CHECK_ISOLATE(isolate);
1678 return Api::Null(); 1666 return Api::Null();
1679 } 1667 }
1680 1668
1681 1669
1670 DART_EXPORT Dart_Handle Dart_EmptyString() {
1671 ASSERT(Isolate::Current() != NULL);
1672 return Api::EmptyString();
1673 }
1674
1675
1682 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { 1676 DART_EXPORT bool Dart_IsNull(Dart_Handle object) {
1683 return Api::UnwrapHandle(object) == Object::null(); 1677 return Api::UnwrapHandle(object) == Object::null();
1684 } 1678 }
1685 1679
1686 1680
1687 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, 1681 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2,
1688 bool* value) { 1682 bool* value) {
1689 Isolate* isolate = Isolate::Current(); 1683 Isolate* isolate = Isolate::Current();
1690 DARTSCOPE(isolate); 1684 DARTSCOPE(isolate);
1691 CHECK_CALLBACK_STATE(isolate); 1685 CHECK_CALLBACK_STATE(isolate);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 RETURN_TYPE_ERROR(isolate, double_obj, Double); 2043 RETURN_TYPE_ERROR(isolate, double_obj, Double);
2050 } 2044 }
2051 *value = obj.value(); 2045 *value = obj.value();
2052 return Api::Success(); 2046 return Api::Success();
2053 } 2047 }
2054 2048
2055 2049
2056 // --- Booleans ---- 2050 // --- Booleans ----
2057 2051
2058 DART_EXPORT Dart_Handle Dart_True() { 2052 DART_EXPORT Dart_Handle Dart_True() {
2059 Isolate* isolate = Isolate::Current(); 2053 ASSERT(Isolate::Current() != NULL);
2060 CHECK_ISOLATE(isolate);
2061 return Api::True(); 2054 return Api::True();
2062 } 2055 }
2063 2056
2064 2057
2065 DART_EXPORT Dart_Handle Dart_False() { 2058 DART_EXPORT Dart_Handle Dart_False() {
2066 Isolate* isolate = Isolate::Current(); 2059 ASSERT(Isolate::Current() != NULL);
2067 CHECK_ISOLATE(isolate);
2068 return Api::False(); 2060 return Api::False();
2069 } 2061 }
2070 2062
2071 2063
2072 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { 2064 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) {
2073 Isolate* isolate = Isolate::Current(); 2065 Isolate* isolate = Isolate::Current();
2074 CHECK_ISOLATE(isolate); 2066 CHECK_ISOLATE(isolate);
2075 return value ? Api::True() : Api::False(); 2067 return value ? Api::True() : Api::False();
2076 } 2068 }
2077 2069
(...skipping 3003 matching lines...) Expand 10 before | Expand all | Expand 10 after
5081 5073
5082 5074
5083 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5075 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5084 const char* name, 5076 const char* name,
5085 Dart_ServiceRequestCallback callback, 5077 Dart_ServiceRequestCallback callback,
5086 void* user_data) { 5078 void* user_data) {
5087 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5079 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5088 } 5080 }
5089 5081
5090 } // namespace dart 5082 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698