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

Side by Side Diff: vm/dart_api_impl.cc

Issue 9939014: Temp hax. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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 | « vm/dart_api_impl.h ('k') | 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) 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 ASSERT(state != NULL); 93 ASSERT(state != NULL);
94 ApiLocalScope* scope = state->top_scope(); 94 ApiLocalScope* scope = state->top_scope();
95 ASSERT(scope != NULL); 95 ASSERT(scope != NULL);
96 LocalHandles* local_handles = scope->local_handles(); 96 LocalHandles* local_handles = scope->local_handles();
97 ASSERT(local_handles != NULL); 97 ASSERT(local_handles != NULL);
98 LocalHandle* ref = local_handles->AllocateHandle(); 98 LocalHandle* ref = local_handles->AllocateHandle();
99 ref->set_raw(object); 99 ref->set_raw(object);
100 return reinterpret_cast<Dart_Handle>(ref); 100 return reinterpret_cast<Dart_Handle>(ref);
101 } 101 }
102 102
103 Dart_Handle Api::NewLocalHandle(Isolate* isolate, RawObject* object) {
104 ASSERT(isolate != NULL);
105 ApiState* state = isolate->api_state();
106 ASSERT(state != NULL);
107 ApiLocalScope* scope = state->top_scope();
108 ASSERT(scope != NULL);
109 LocalHandles* local_handles = scope->local_handles();
110 ASSERT(local_handles != NULL);
111 LocalHandle* ref = local_handles->AllocateHandle();
112 ref->set_raw(object);
113 return reinterpret_cast<Dart_Handle>(ref);
114 }
115
103 RawObject* Api::UnwrapHandle(Dart_Handle object) { 116 RawObject* Api::UnwrapHandle(Dart_Handle object) {
104 #ifdef DEBUG 117 #ifdef DEBUG
105 Isolate* isolate = Isolate::Current(); 118 Isolate* isolate = Isolate::Current();
106 ASSERT(isolate != NULL); 119 ASSERT(isolate != NULL);
107 ApiState* state = isolate->api_state(); 120 ApiState* state = isolate->api_state();
108 ASSERT(state != NULL); 121 ASSERT(state != NULL);
109 ASSERT(state->IsValidPrologueWeakPersistentHandle(object) || 122 ASSERT(state->IsValidPrologueWeakPersistentHandle(object) ||
110 state->IsValidWeakPersistentHandle(object) || 123 state->IsValidWeakPersistentHandle(object) ||
111 state->IsValidPersistentHandle(object) || 124 state->IsValidPersistentHandle(object) ||
112 state->IsValidLocalHandle(object)); 125 state->IsValidLocalHandle(object));
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); 263 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey);
251 api_native_key_ = Thread::CreateThreadLocal(); 264 api_native_key_ = Thread::CreateThreadLocal();
252 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); 265 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey);
253 } 266 }
254 267
255 268
256 // --- Handles --- 269 // --- Handles ---
257 270
258 271
259 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { 272 DART_EXPORT bool Dart_IsError(Dart_Handle handle) {
273 RawObject* raw_obj = ((LocalHandle*)handle)->raw();
274 if (!raw_obj->IsHeapObject()) {
275 return false;
276 }
277 uword raw_addr = RawObject::ToAddr(raw_obj);
278 RawClass* header = (RawClass*)*reinterpret_cast<uword*>(raw_addr);
279 return (header == Object::language_error_class() ||
280 header == Object::api_error_class() ||
281 header == Object::unhandled_exception_class() ||
282 header == Object::unwind_error_class());
283 #if 0
260 Isolate* isolate = Isolate::Current(); 284 Isolate* isolate = Isolate::Current();
261 DARTSCOPE(isolate); 285 DARTSCOPE(isolate);
262 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 286 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
263 return obj.IsError(); 287 return obj.IsError();
288 #endif
264 } 289 }
265 290
266 291
267 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { 292 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) {
268 Isolate* isolate = Isolate::Current(); 293 Isolate* isolate = Isolate::Current();
269 DARTSCOPE(isolate); 294 DARTSCOPE(isolate);
270 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 295 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
271 if (obj.IsError()) { 296 if (obj.IsError()) {
272 Error& error = Error::Handle(isolate); 297 Error& error = Error::Handle(isolate);
273 error ^= obj.raw(); 298 error ^= obj.raw();
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 DARTSCOPE(isolate); 1118 DARTSCOPE(isolate);
1094 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1119 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
1095 return obj.IsNumber(); 1120 return obj.IsNumber();
1096 } 1121 }
1097 1122
1098 1123
1099 // --- Integers ---- 1124 // --- Integers ----
1100 1125
1101 1126
1102 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { 1127 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) {
1128 RawObject* raw_obj = ((LocalHandle*)object)->raw();
1129 if (!raw_obj->IsHeapObject()) {
1130 return true;
1131 }
1103 Isolate* isolate = Isolate::Current(); 1132 Isolate* isolate = Isolate::Current();
1104 DARTSCOPE(isolate); 1133 DARTSCOPE(isolate);
1105 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1134 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
1106 return obj.IsInteger(); 1135 return obj.IsInteger();
1107 } 1136 }
1108 1137
1109 1138
1110 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, 1139 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
1111 bool* fits) { 1140 bool* fits) {
1112 Isolate* isolate = Isolate::Current(); 1141 Isolate* isolate = Isolate::Current();
1142 RawObject* raw_obj = ((LocalHandle*)integer)->raw();
1143 if (!raw_obj->IsHeapObject()) {
1144 *fits = true;
1145 return Api::Success(isolate);
1146 }
1113 DARTSCOPE(isolate); 1147 DARTSCOPE(isolate);
1114 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 1148 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
1115 if (int_obj.IsNull()) { 1149 if (int_obj.IsNull()) {
1116 RETURN_TYPE_ERROR(isolate, integer, Integer); 1150 RETURN_TYPE_ERROR(isolate, integer, Integer);
1117 } 1151 }
1118 if (int_obj.IsSmi() || int_obj.IsMint()) { 1152 if (int_obj.IsSmi() || int_obj.IsMint()) {
1119 *fits = true; 1153 *fits = true;
1120 } else { 1154 } else {
1121 ASSERT(int_obj.IsBigint()); 1155 ASSERT(int_obj.IsBigint());
1122 #if defined(DEBUG) 1156 #if defined(DEBUG)
(...skipping 22 matching lines...) Expand all
1145 Bigint& bigint = Bigint::Handle(isolate); 1179 Bigint& bigint = Bigint::Handle(isolate);
1146 bigint ^= int_obj.raw(); 1180 bigint ^= int_obj.raw();
1147 *fits = BigintOperations::FitsIntoUint64(bigint); 1181 *fits = BigintOperations::FitsIntoUint64(bigint);
1148 } 1182 }
1149 return Api::Success(isolate); 1183 return Api::Success(isolate);
1150 } 1184 }
1151 1185
1152 1186
1153 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { 1187 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
1154 Isolate* isolate = Isolate::Current(); 1188 Isolate* isolate = Isolate::Current();
1189 #if 0
1155 DARTSCOPE(isolate); 1190 DARTSCOPE(isolate);
1156 const Integer& obj = Integer::Handle(isolate, Integer::New(value)); 1191 const Integer& obj = Integer::Handle(isolate, Integer::New(value));
1157 return Api::NewLocalHandle(isolate, obj); 1192 return Api::NewLocalHandle(isolate, obj);
1193 #endif
1194 return Api::NewLocalHandle(isolate, Integer::New(value));
1158 } 1195 }
1159 1196
1160 1197
1161 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 1198 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
1162 Isolate* isolate = Isolate::Current(); 1199 Isolate* isolate = Isolate::Current();
1163 DARTSCOPE(isolate); 1200 DARTSCOPE(isolate);
1164 const String& str_obj = String::Handle(isolate, String::New(str)); 1201 const String& str_obj = String::Handle(isolate, String::New(str));
1165 const Integer& obj = Integer::Handle(isolate, Integer::New(str_obj)); 1202 const Integer& obj = Integer::Handle(isolate, Integer::New(str_obj));
1166 return Api::NewLocalHandle(isolate, obj); 1203 return Api::NewLocalHandle(isolate, obj);
1167 } 1204 }
1168 1205
1169 1206
1170 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, 1207 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
1171 int64_t* value) { 1208 int64_t* value) {
1172 Isolate* isolate = Isolate::Current(); 1209 Isolate* isolate = Isolate::Current();
1210 RawObject* raw_obj = ((LocalHandle*)integer)->raw();
1211 if (!raw_obj->IsHeapObject()) {
1212 *value = ((int64_t)raw_obj) >> kSmiTagShift;
1213 return Api::Success(isolate);
1214 }
1173 DARTSCOPE(isolate); 1215 DARTSCOPE(isolate);
1174 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 1216 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
1175 if (int_obj.IsNull()) { 1217 if (int_obj.IsNull()) {
1176 RETURN_TYPE_ERROR(isolate, integer, Integer); 1218 RETURN_TYPE_ERROR(isolate, integer, Integer);
1177 } 1219 }
1178 if (int_obj.IsSmi() || int_obj.IsMint()) { 1220 if (int_obj.IsSmi() || int_obj.IsMint()) {
1179 *value = int_obj.AsInt64Value(); 1221 *value = int_obj.AsInt64Value();
1180 return Api::Success(isolate); 1222 return Api::Success(isolate);
1181 } else { 1223 } else {
1182 ASSERT(int_obj.IsBigint()); 1224 ASSERT(int_obj.IsBigint());
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after
3046 3088
3047 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, 3089 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
3048 int index) { 3090 int index) {
3049 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3091 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3050 if (index < 0 || index >= arguments->Count()) { 3092 if (index < 0 || index >= arguments->Count()) {
3051 return Api::NewError( 3093 return Api::NewError(
3052 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 3094 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
3053 CURRENT_FUNC, arguments->Count() - 1, index); 3095 CURRENT_FUNC, arguments->Count() - 1, index);
3054 } 3096 }
3055 Isolate* isolate = arguments->isolate(); 3097 Isolate* isolate = arguments->isolate();
3098 return Api::NewLocalHandle(isolate, arguments->At(index));
3099 #if 0
3100 Isolate* isolate = arguments->isolate();
3056 DARTSCOPE(isolate); 3101 DARTSCOPE(isolate);
3057 const Object& obj = Object::Handle(isolate, arguments->At(index)); 3102 const Object& obj = Object::Handle(isolate, arguments->At(index));
3058 return Api::NewLocalHandle(isolate, obj); 3103 return Api::NewLocalHandle(isolate, obj);
3104 #endif
3059 } 3105 }
3060 3106
3061 3107
3062 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { 3108 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) {
3063 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3109 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3064 CHECK_ISOLATE(arguments->isolate()); 3110 CHECK_ISOLATE(arguments->isolate());
3065 return arguments->Count(); 3111 return arguments->Count();
3066 } 3112 }
3067 3113
3068 3114
3069 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 3115 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
3070 Dart_Handle retval) { 3116 Dart_Handle retval) {
3071 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3117 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3118 #if 0
3072 Isolate* isolate = arguments->isolate(); 3119 Isolate* isolate = arguments->isolate();
3073 DARTSCOPE(isolate); 3120 DARTSCOPE(isolate);
3074 arguments->SetReturn(Object::Handle(isolate, Api::UnwrapHandle(retval))); 3121 arguments->SetReturn(Object::Handle(isolate, Api::UnwrapHandle(retval)));
3122 #endif
3123 arguments->SetReturn(Api::UnwrapHandle(retval));
3075 } 3124 }
3076 3125
3077 3126
3078 // --- Scripts and Libraries --- 3127 // --- Scripts and Libraries ---
3079 3128
3080 3129
3081 // NOTE: Need to pass 'result' as a parameter here in order to avoid 3130 // NOTE: Need to pass 'result' as a parameter here in order to avoid
3082 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 3131 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
3083 // which shows up because of the use of setjmp. 3132 // which shows up because of the use of setjmp.
3084 static void CompileSource(Isolate* isolate, 3133 static void CompileSource(Isolate* isolate,
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
3406 *buffer = NULL; 3455 *buffer = NULL;
3407 } 3456 }
3408 delete debug_region; 3457 delete debug_region;
3409 } else { 3458 } else {
3410 *buffer = NULL; 3459 *buffer = NULL;
3411 *buffer_size = 0; 3460 *buffer_size = 0;
3412 } 3461 }
3413 } 3462 }
3414 3463
3415 } // namespace dart 3464 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_impl.h ('k') | vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698