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

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

Issue 8380020: Refactor the dart api a bit: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 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
OLDNEW
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 DART_EXPORT bool Dart_IsValidResult(const Dart_Result& result) { 30 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) {
31 ASSERT(Isolate::Current() != NULL); 31 ASSERT(Isolate::Current() != NULL);
32 if (result.type_ == kRetObject) { 32 Zone zone; // Setup a VM zone as we are creating some handles.
33 Zone zone; // Setup a VM zone as we are creating some handles. 33 HandleScope scope; // Setup a VM handle scope.
34 HandleScope scope; // Setup a VM handle scope.
35 34
36 // Make sure that the object isn't an ApiFailure. 35 // Make sure that the object isn't an ApiFailure.
37 const Object& obj = 36 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
38 Object::Handle(Api::UnwrapHandle(result.retval_.obj_value)); 37 return !obj.IsApiFailure();
39 return !obj.IsApiFailure();
40 }
41 return true;
42 } 38 }
43 39
44 DART_EXPORT const char* Dart_GetErrorCString(const Dart_Result& result) { 40 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) {
45 ASSERT(Isolate::Current() != NULL); 41 ASSERT(Isolate::Current() != NULL);
46 ASSERT(result.type_ == kRetObject);
47 Zone zone; // Setup a VM zone as we are creating some handles. 42 Zone zone; // Setup a VM zone as we are creating some handles.
48 HandleScope scope; // Setup a VM handle scope. 43 HandleScope scope; // Setup a VM handle scope.
49 const Object& obj = Object::Handle( 44 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
50 Api::UnwrapHandle(result.retval_.obj_value));
51 if (!obj.IsApiFailure()) { 45 if (!obj.IsApiFailure()) {
52 return ""; 46 return "";
53 } 47 }
54 ApiFailure& failure = ApiFailure::Handle(); 48 ApiFailure& failure = ApiFailure::Handle();
55 failure ^= obj.raw(); 49 failure ^= obj.raw();
56 const String& message = String::Handle(failure.message()); 50 const String& message = String::Handle(failure.message());
57 const char* msg = message.ToCString(); 51 const char* msg = message.ToCString();
58 intptr_t len = strlen(msg) + 1; 52 intptr_t len = strlen(msg) + 1;
59 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); 53 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len));
60 OS::SNPrint(msg_copy, len, "%s", msg); 54 OS::SNPrint(msg_copy, len, "%s", msg);
61 return msg_copy; 55 return msg_copy;
62 } 56 }
63 57
64 58
65 DART_EXPORT Dart_Result Dart_ErrorResult(const char* value) { 59 DART_EXPORT Dart_Handle Dart_Error(const char* value) {
66 ASSERT(Isolate::Current() != NULL); 60 return Api::Error(value);
67
68 Zone zone; // Setup a VM zone as we are creating some handles.
69 HandleScope scope; // Setup a VM handle scope.
70 const String& message = String::Handle(String::New(value));
71 const Object& obj = Object::Handle(ApiFailure::New(message));
72
73 Dart_Result result;
74 result.type_ = kRetObject;
75 result.retval_.obj_value = Api::NewLocalHandle(obj);
76 return result;
77 } 61 }
78 62
79 63
80 // TODO(iposva): This is a placeholder for the eventual external Dart API. 64 // TODO(iposva): This is a placeholder for the eventual external Dart API.
81 DART_EXPORT bool Dart_Initialize(int argc, 65 DART_EXPORT bool Dart_Initialize(int argc,
82 char** argv, 66 char** argv,
83 Dart_IsolateInitCallback callback) { 67 Dart_IsolateInitCallback callback) {
84 return Dart::InitOnce(argc, argv, callback); 68 return Dart::InitOnce(argc, argv, callback);
85 } 69 }
86 70
(...skipping 25 matching lines...) Expand all
112 Isolate::SetCurrent(isolate); 96 Isolate::SetCurrent(isolate);
113 } 97 }
114 98
115 99
116 DART_EXPORT void Dart_ExitIsolate() { 100 DART_EXPORT void Dart_ExitIsolate() {
117 ASSERT(Isolate::Current() != NULL); 101 ASSERT(Isolate::Current() != NULL);
118 Isolate::SetCurrent(NULL); 102 Isolate::SetCurrent(NULL);
119 } 103 }
120 104
121 105
122 static void SetupErrorResult(Dart_Result* result) { 106 static void SetupErrorResult(Dart_Handle* handle) {
123 // Make a copy of the error message as the original message string 107 // Make a copy of the error message as the original message string
124 // may get deallocated when we return back from the Dart API call. 108 // may get deallocated when we return back from the Dart API call.
125 const String& error = String::Handle( 109 const String& error = String::Handle(
126 Isolate::Current()->object_store()->sticky_error()); 110 Isolate::Current()->object_store()->sticky_error());
127 const Object& obj = Object::Handle(ApiFailure::New(error)); 111 const Object& obj = Object::Handle(ApiFailure::New(error));
128 result->type_ = kRetObject; 112 *handle = Api::NewLocalHandle(obj);
129 result->retval_.obj_value = Api::NewLocalHandle(obj);
130 } 113 }
131 114
132 115
133 DART_EXPORT void Dart_SetMessageCallbacks( 116 DART_EXPORT void Dart_SetMessageCallbacks(
134 Dart_PostMessageCallback post_message_callback, 117 Dart_PostMessageCallback post_message_callback,
135 Dart_ClosePortCallback close_port_callback) { 118 Dart_ClosePortCallback close_port_callback) {
136 Isolate* isolate = Isolate::Current(); 119 Isolate* isolate = Isolate::Current();
137 ASSERT(isolate != NULL); 120 ASSERT(isolate != NULL);
138 ASSERT(post_message_callback != NULL); 121 ASSERT(post_message_callback != NULL);
139 ASSERT(close_port_callback != NULL); 122 ASSERT(close_port_callback != NULL);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 uhe ^= result.raw(); 182 uhe ^= result.raw();
200 // TODO(turnidge): Instead of exiting here, just return the 183 // TODO(turnidge): Instead of exiting here, just return the
201 // exception so that the embedder can choose how to handle this 184 // exception so that the embedder can choose how to handle this
202 // case. 185 // case.
203 ProcessUnhandledException(uhe); 186 ProcessUnhandledException(uhe);
204 } 187 }
205 ASSERT(result.IsNull()); 188 ASSERT(result.IsNull());
206 } 189 }
207 190
208 191
209 DART_EXPORT Dart_Result Dart_RunLoop() { 192 DART_EXPORT Dart_Handle Dart_RunLoop() {
193 Zone zone; // Setup a VM zone as we are creating some handles.
194 HandleScope scope; // Setup a VM handle scope.
195
210 Isolate* isolate = Isolate::Current(); 196 Isolate* isolate = Isolate::Current();
211 LongJump* base = isolate->long_jump_base(); 197 LongJump* base = isolate->long_jump_base();
212 LongJump jump; 198 LongJump jump;
213 Dart_Result result; 199 Dart_Handle result;
214 isolate->set_long_jump_base(&jump); 200 isolate->set_long_jump_base(&jump);
215 if (setjmp(*jump.Set()) == 0) { 201 if (setjmp(*jump.Set()) == 0) {
216 isolate->StandardRunLoop(); 202 isolate->StandardRunLoop();
217 result.type_ = kRetCBool; 203 result = Api::Success();
218 result.retval_.bool_value = true;
219 } else { 204 } else {
220 Zone zone;
221 HandleScope handle_scope;
222 SetupErrorResult(&result); 205 SetupErrorResult(&result);
223 } 206 }
224 isolate->set_long_jump_base(base); 207 isolate->set_long_jump_base(base);
225 return result; 208 return result;
226 } 209 }
227 210
228 211
229 // NOTE: Need to pass 'result' as a parameter here in order to avoid 212 // NOTE: Need to pass 'result' as a parameter here in order to avoid
230 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 213 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
231 // which shows up because of the use of setjmp. 214 // which shows up because of the use of setjmp.
232 static void CompileSource(const Library& lib, 215 static void CompileSource(const Library& lib,
233 const String& url, 216 const String& url,
234 const String& source, 217 const String& source,
235 RawScript::Kind kind, 218 RawScript::Kind kind,
236 Dart_Result* result) { 219 Dart_Handle* result) {
237 const Script& script = Script::Handle(Script::New(url, source, kind)); 220 const Script& script = Script::Handle(Script::New(url, source, kind));
238 Isolate* isolate = Isolate::Current(); 221 Isolate* isolate = Isolate::Current();
239 ASSERT(isolate != NULL); 222 ASSERT(isolate != NULL);
240 LongJump* base = isolate->long_jump_base(); 223 LongJump* base = isolate->long_jump_base();
241 LongJump jump; 224 LongJump jump;
242 isolate->set_long_jump_base(&jump); 225 isolate->set_long_jump_base(&jump);
243 if (setjmp(*jump.Set()) == 0) { 226 if (setjmp(*jump.Set()) == 0) {
244 Compiler::Compile(lib, script); 227 Compiler::Compile(lib, script);
245 result->type_ = kRetObject; 228 *result = Api::NewLocalHandle(lib);
246 result->retval_.obj_value = Api::NewLocalHandle(lib);
247 } else { 229 } else {
248 SetupErrorResult(result); 230 SetupErrorResult(result);
249 } 231 }
250 isolate->set_long_jump_base(base); 232 isolate->set_long_jump_base(base);
251 } 233 }
252 234
253 235
254 DART_EXPORT Dart_Result Dart_LoadScript(Dart_Handle url, 236 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
255 Dart_Handle source, 237 Dart_Handle source,
256 Dart_LibraryTagHandler handler) { 238 Dart_LibraryTagHandler handler) {
257 Isolate* isolate = Isolate::Current(); 239 Isolate* isolate = Isolate::Current();
258 ASSERT(isolate != NULL); 240 ASSERT(isolate != NULL);
259 Zone zone; // Setup a VM zone as we are creating some handles. 241 Zone zone; // Setup a VM zone as we are creating some handles.
260 HandleScope scope; // Setup a VM handle scope. 242 HandleScope scope; // Setup a VM handle scope.
261 TIMERSCOPE(time_script_loading); 243 TIMERSCOPE(time_script_loading);
262 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 244 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url));
263 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source)); 245 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source));
264 Library& library = Library::Handle(isolate->object_store()->root_library()); 246 Library& library = Library::Handle(isolate->object_store()->root_library());
265 if (!library.IsNull()) { 247 if (!library.IsNull()) {
266 RETURN_FAILURE("Script already loaded"); 248 return Api::Error("Script already loaded");
267 } 249 }
268 isolate->set_library_tag_handler(handler); 250 isolate->set_library_tag_handler(handler);
269 library = Library::New(url_str); 251 library = Library::New(url_str);
270 library.Register(); 252 library.Register();
271 isolate->object_store()->set_root_library(library); 253 isolate->object_store()->set_root_library(library);
272 Dart_Result result; 254 Dart_Handle result;
273 CompileSource(library, url_str, source_str, RawScript::kScript, &result); 255 CompileSource(library, url_str, source_str, RawScript::kScript, &result);
274 return result; 256 return result;
275 } 257 }
276 258
277 259
278 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code."); 260 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code.");
279 261
280 static void CompileAll(Dart_Result* result) { 262 static void CompileAll(Dart_Handle* result) {
281 result->type_ = kRetCBool; 263 *result = Api::Success();
282 result->retval_.bool_value = true;
283 if (FLAG_compile_all) { 264 if (FLAG_compile_all) {
284 Isolate* isolate = Isolate::Current(); 265 Isolate* isolate = Isolate::Current();
285 ASSERT(isolate != NULL); 266 ASSERT(isolate != NULL);
286 LongJump* base = isolate->long_jump_base(); 267 LongJump* base = isolate->long_jump_base();
287 LongJump jump; 268 LongJump jump;
288 isolate->set_long_jump_base(&jump); 269 isolate->set_long_jump_base(&jump);
289 if (setjmp(*jump.Set()) == 0) { 270 if (setjmp(*jump.Set()) == 0) {
290 Library::CompileAll(); 271 Library::CompileAll();
291 } else { 272 } else {
292 SetupErrorResult(result); 273 SetupErrorResult(result);
(...skipping 14 matching lines...) Expand all
307 const char* errmsg = err.ToCString(); 288 const char* errmsg = err.ToCString();
308 intptr_t errlen = strlen(errmsg) + 1; 289 intptr_t errlen = strlen(errmsg) + 1;
309 char* msg = reinterpret_cast<char*>(Api::Allocate(errlen)); 290 char* msg = reinterpret_cast<char*>(Api::Allocate(errlen));
310 OS::SNPrint(msg, errlen, "%s", errmsg); 291 OS::SNPrint(msg, errlen, "%s", errmsg);
311 return msg; 292 return msg;
312 } 293 }
313 return NULL; 294 return NULL;
314 } 295 }
315 296
316 297
317 DART_EXPORT Dart_Result Dart_CompileAll() { 298 DART_EXPORT Dart_Handle Dart_CompileAll() {
318 Zone zone; // Setup a VM zone as we are creating some handles. 299 Zone zone; // Setup a VM zone as we are creating some handles.
319 HandleScope scope; // Setup a VM handle scope. 300 HandleScope scope; // Setup a VM handle scope.
320 Dart_Result result; 301 Dart_Handle result;
321 const char* msg = CheckIsolateState(); 302 const char* msg = CheckIsolateState();
322 if (msg != NULL) { 303 if (msg != NULL) {
323 RETURN_FAILURE(msg); 304 return Api::Error(msg);
324 } 305 }
325 CompileAll(&result); 306 CompileAll(&result);
326 return result; 307 return result;
327 } 308 }
328 309
329 310
330 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { 311 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) {
331 Zone zone; // Setup a VM zone as we are creating some handles. 312 Zone zone; // Setup a VM zone as we are creating some handles.
332 HandleScope scope; // Setup a VM handle scope. 313 HandleScope scope; // Setup a VM handle scope.
333 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 314 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
334 return obj.IsLibrary(); 315 return obj.IsLibrary();
335 } 316 }
336 317
337 318
338 DART_EXPORT Dart_Result Dart_LibraryUrl(Dart_Handle library) { 319 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) {
339 Zone zone; // Setup a VM zone as we are creating some handles. 320 Zone zone; // Setup a VM zone as we are creating some handles.
340 HandleScope scope; // Setup a VM handle scope. 321 HandleScope scope; // Setup a VM handle scope.
341 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 322 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library));
342 if (lib.IsNull()) { 323 if (lib.IsNull()) {
343 RETURN_FAILURE("Null library"); 324 return Api::Error("Null library");
344 } 325 }
345 const String& url = String::Handle(lib.url()); 326 const String& url = String::Handle(lib.url());
346 ASSERT(!url.IsNull()); 327 ASSERT(!url.IsNull());
347 RETURN_OBJECT(url); 328 return Api::NewLocalHandle(url);
348 } 329 }
349 330
350 331
351 DART_EXPORT Dart_Result Dart_LibraryImportLibrary(Dart_Handle library_in, 332 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library_in,
352 Dart_Handle import_in) { 333 Dart_Handle import_in) {
353 Zone zone; // Setup a VM zone as we are creating some handles. 334 Zone zone; // Setup a VM zone as we are creating some handles.
354 HandleScope scope; // Setup a VM handle scope. 335 HandleScope scope; // Setup a VM handle scope.
355 const Library& library = 336 const Library& library =
356 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 337 Library::CheckedHandle(Api::UnwrapHandle(library_in));
357 if (library.IsNull()) { 338 if (library.IsNull()) {
358 RETURN_FAILURE("Null library"); 339 return Api::Error("Null library");
359 } 340 }
360 const Library& import = 341 const Library& import =
361 Library::CheckedHandle(Api::UnwrapHandle(import_in)); 342 Library::CheckedHandle(Api::UnwrapHandle(import_in));
362 library.AddImport(import); 343 library.AddImport(import);
363 RETURN_CBOOLEAN(true); 344 return Api::Success();
364 } 345 }
365 346
366 347
367 DART_EXPORT Dart_Result Dart_LookupLibrary(Dart_Handle url) { 348 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
368 Zone zone; // Setup a VM zone as we are creating some handles. 349 Zone zone; // Setup a VM zone as we are creating some handles.
369 HandleScope scope; // Setup a VM handle scope. 350 HandleScope scope; // Setup a VM handle scope.
370 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 351 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url));
371 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); 352 const Library& library = Library::Handle(Library::LookupLibrary(url_str));
372 if (library.IsNull()) { 353 if (library.IsNull()) {
373 RETURN_FAILURE("Unknown library"); 354 return Api::Error("Unknown library");
374 } else { 355 } else {
375 RETURN_OBJECT(library); 356 return Api::NewLocalHandle(library);
376 } 357 }
377 } 358 }
378 359
379 360
380 DART_EXPORT Dart_Result Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { 361 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) {
381 Zone zone; // Setup a VM zone as we are creating some handles. 362 Zone zone; // Setup a VM zone as we are creating some handles.
382 HandleScope scope; // Setup a VM handle scope. 363 HandleScope scope; // Setup a VM handle scope.
383 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 364 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url));
384 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source)); 365 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source));
385 Library& library = Library::Handle(Library::LookupLibrary(url_str)); 366 Library& library = Library::Handle(Library::LookupLibrary(url_str));
386 if (library.IsNull()) { 367 if (library.IsNull()) {
387 library = Library::New(url_str); 368 library = Library::New(url_str);
388 library.Register(); 369 library.Register();
389 } 370 }
390 Dart_Result result; 371 Dart_Handle result;
391 CompileSource(library, url_str, source_str, RawScript::kLibrary, &result); 372 CompileSource(library, url_str, source_str, RawScript::kLibrary, &result);
392 return result; 373 return result;
393 } 374 }
394 375
395 376
396 DART_EXPORT Dart_Result Dart_LoadSource(Dart_Handle library_in, 377 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library_in,
397 Dart_Handle url_in, 378 Dart_Handle url_in,
398 Dart_Handle source_in) { 379 Dart_Handle source_in) {
399 Zone zone; // Setup a VM zone as we are creating some handles. 380 Zone zone; // Setup a VM zone as we are creating some handles.
400 HandleScope scope; // Setup a VM handle scope. 381 HandleScope scope; // Setup a VM handle scope.
401 const String& url = String::CheckedHandle(Api::UnwrapHandle(url_in)); 382 const String& url = String::CheckedHandle(Api::UnwrapHandle(url_in));
402 const String& source = String::CheckedHandle(Api::UnwrapHandle(source_in)); 383 const String& source = String::CheckedHandle(Api::UnwrapHandle(source_in));
403 const Library& library = 384 const Library& library =
404 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 385 Library::CheckedHandle(Api::UnwrapHandle(library_in));
405 Dart_Result result; 386 Dart_Handle result;
406 CompileSource(library, url, source, RawScript::kSource, &result); 387 CompileSource(library, url, source, RawScript::kSource, &result);
407 return result; 388 return result;
408 } 389 }
409 390
410 391
411 DART_EXPORT Dart_Result Dart_SetNativeResolver( 392 DART_EXPORT Dart_Handle Dart_SetNativeResolver(
412 Dart_Handle library, 393 Dart_Handle library,
413 Dart_NativeEntryResolver resolver) { 394 Dart_NativeEntryResolver resolver) {
414 Zone zone; // Setup a VM zone as we are creating some handles. 395 Zone zone; // Setup a VM zone as we are creating some handles.
415 HandleScope scope; // Setup a VM handle scope. 396 HandleScope scope; // Setup a VM handle scope.
416 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 397 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library));
417 if (lib.IsNull()) { 398 if (lib.IsNull()) {
418 RETURN_FAILURE("Invalid parameter, Unknown library specified"); 399 return Api::Error("Invalid parameter, Unknown library specified");
419 } 400 }
420 lib.set_native_entry_resolver(resolver); 401 lib.set_native_entry_resolver(resolver);
421 RETURN_CBOOLEAN(true); 402 return Api::Success();
422 } 403 }
423 404
424 405
425 DART_EXPORT Dart_Result Dart_ObjectToString(Dart_Handle object) { 406 DART_EXPORT Dart_Handle Dart_ObjectToString(Dart_Handle object) {
426 Zone zone; // Setup a VM zone as we are creating some handles. 407 Zone zone; // Setup a VM zone as we are creating some handles.
427 HandleScope scope; // Setup a VM handle scope. 408 HandleScope scope; // Setup a VM handle scope.
428 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 409 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
429 Object& result = Object::Handle(); 410 Object& result = Object::Handle();
430 if (obj.IsString()) { 411 if (obj.IsString()) {
431 result = obj.raw(); 412 result = obj.raw();
432 } else if (obj.IsInstance()) { 413 } else if (obj.IsInstance()) {
433 Instance& receiver = Instance::Handle(); 414 Instance& receiver = Instance::Handle();
434 receiver ^= obj.raw(); 415 receiver ^= obj.raw();
435 result = DartLibraryCalls::ToString(receiver); 416 result = DartLibraryCalls::ToString(receiver);
436 if (result.IsUnhandledException()) { 417 if (result.IsUnhandledException()) {
437 RETURN_FAILURE("An exception occurred when converting to string"); 418 return Api::Error("An exception occurred when converting to string");
438 } 419 }
439 } else { 420 } else {
440 // This is a VM internal object. Call the C++ method of printing. 421 // This is a VM internal object. Call the C++ method of printing.
441 result = String::New(obj.ToCString()); 422 result = String::New(obj.ToCString());
442 } 423 }
443 RETURN_OBJECT(result); 424 return Api::NewLocalHandle(result);
444 } 425 }
445 426
446 427
447 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { 428 DART_EXPORT bool Dart_IsNull(Dart_Handle object) {
448 Zone zone; // Setup a VM zone as we are creating some handles. 429 Zone zone; // Setup a VM zone as we are creating some handles.
449 HandleScope scope; // Setup a VM handle scope. 430 HandleScope scope; // Setup a VM handle scope.
450 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 431 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
451 return obj.IsNull(); 432 return obj.IsNull();
452 } 433 }
453 434
454 435
455 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 436 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
456 Zone zone; // Setup a VM zone as we are creating some handles. 437 Zone zone; // Setup a VM zone as we are creating some handles.
457 HandleScope scope; // Setup a VM handle scope. 438 HandleScope scope; // Setup a VM handle scope.
458 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 439 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
459 return obj.IsClosure(); 440 return obj.IsClosure();
460 } 441 }
461 442
462 443
463 DART_EXPORT Dart_Result Dart_ClosureSmrck(Dart_Handle object) { 444 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) {
464 Zone zone; 445 Zone zone;
465 HandleScope scope; 446 HandleScope scope;
466 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 447 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
467 const Integer& smrck = Integer::Handle(obj.smrck()); 448 const Integer& smrck = Integer::Handle(obj.smrck());
468 RETURN_CINT64(smrck.IsNull() ? 0 : smrck.AsInt64Value()); 449 return smrck.IsNull() ? 0 : smrck.AsInt64Value();
469 } 450 }
470 451
471 452
472 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) { 453 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) {
473 Zone zone; 454 Zone zone;
474 HandleScope scope; 455 HandleScope scope;
475 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 456 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
476 const Integer& smrck = Integer::Handle(Integer::New(value)); 457 const Integer& smrck = Integer::Handle(Integer::New(value));
477 obj.set_smrck(smrck); 458 obj.set_smrck(smrck);
478 } 459 }
479 460
480 461
481 DART_EXPORT Dart_Result Dart_Objects_Equal(Dart_Handle obj1, Dart_Handle obj2) { 462 DART_EXPORT Dart_Handle Dart_Objects_Equal(Dart_Handle obj1, Dart_Handle obj2,
463 bool* value) {
482 Zone zone; // Setup a VM zone as we are creating some handles. 464 Zone zone; // Setup a VM zone as we are creating some handles.
483 HandleScope scope; // Setup a VM handle scope. 465 HandleScope scope; // Setup a VM handle scope.
484 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); 466 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1));
485 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); 467 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2));
486 const Instance& result = 468 const Instance& result =
487 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); 469 Instance::Handle(DartLibraryCalls::Equals(expected, actual));
488 if (result.IsBool()) { 470 if (result.IsBool()) {
489 Bool& b = Bool::Handle(); 471 Bool& b = Bool::Handle();
490 b ^= result.raw(); 472 b ^= result.raw();
491 RETURN_CBOOLEAN(b.value()); 473 *value = b.value();
474 return Api::Success();
492 } else { 475 } else {
493 RETURN_FAILURE("An exception occured when calling '=='"); 476 return Api::Error("An exception occured when calling '=='");
494 } 477 }
495 } 478 }
496 479
497 480
498 DART_EXPORT Dart_Result Dart_GetClass(Dart_Handle library, Dart_Handle name) { 481 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) {
499 Zone zone; // Setup a VM zone as we are creating some handles. 482 Zone zone; // Setup a VM zone as we are creating some handles.
500 HandleScope scope; // Setup a VM handle scope. 483 HandleScope scope; // Setup a VM handle scope.
501 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 484 const Object& param = Object::Handle(Api::UnwrapHandle(name));
502 if (param.IsNull() || !param.IsString()) { 485 if (param.IsNull() || !param.IsString()) {
503 RETURN_FAILURE("Invalid class name specified"); 486 return Api::Error("Invalid class name specified");
504 } 487 }
505 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 488 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library));
506 if (lib.IsNull()) { 489 if (lib.IsNull()) {
507 RETURN_FAILURE("Invalid parameter, Unknown library specified"); 490 return Api::Error("Invalid parameter, Unknown library specified");
508 } 491 }
509 String& cls_name = String::Handle(); 492 String& cls_name = String::Handle();
510 cls_name ^= param.raw(); 493 cls_name ^= param.raw();
511 const Class& cls = Class::Handle(lib.LookupClass(cls_name)); 494 const Class& cls = Class::Handle(lib.LookupClass(cls_name));
512 if (cls.IsNull()) { 495 if (cls.IsNull()) {
513 RETURN_FAILURE("Specified class does not exist"); 496 return Api::Error("Specified class does not exist");
514 } 497 }
515 RETURN_OBJECT(cls); 498 return Api::NewLocalHandle(cls);
516 } 499 }
517 500
518 501
519 // TODO(iposva): This call actually implements IsInstanceOfClass. 502 // TODO(iposva): This call actually implements IsInstanceOfClass.
520 // Do we also need a real Dart_IsInstanceOf, which should take an instance 503 // Do we also need a real Dart_IsInstanceOf, which should take an instance
521 // rather than an object and a type rather than a class? 504 // rather than an object and a type rather than a class?
522 DART_EXPORT Dart_Result Dart_IsInstanceOf(Dart_Handle object, 505 DART_EXPORT Dart_Handle Dart_IsInstanceOf(Dart_Handle object,
523 Dart_Handle clazz) { 506 Dart_Handle clazz,
507 bool* value) {
524 Zone zone; // Setup a VM zone as we are creating some handles. 508 Zone zone; // Setup a VM zone as we are creating some handles.
525 HandleScope scope; // Setup a VM handle scope. 509 HandleScope scope; // Setup a VM handle scope.
526 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz)); 510 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz));
527 if (cls.IsNull()) { 511 if (cls.IsNull()) {
528 RETURN_FAILURE("instanceof check against null class"); 512 return Api::Error("instanceof check against null class");
529 } 513 }
530 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 514 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
531 Instance& instance = Instance::Handle(); 515 Instance& instance = Instance::Handle();
532 instance ^= obj.raw(); 516 instance ^= obj.raw();
533 // Finalize all classes. 517 // Finalize all classes.
534 const char* msg = CheckIsolateState(); 518 const char* msg = CheckIsolateState();
535 if (msg != NULL) { 519 if (msg != NULL) {
536 RETURN_FAILURE(msg); 520 return Api::Error(msg);
537 } 521 }
538 const Type& type = Type::Handle(Type::NewNonParameterizedType(cls)); 522 const Type& type = Type::Handle(Type::NewNonParameterizedType(cls));
539 RETURN_CBOOLEAN(instance.Is(type)); 523 *value = instance.Is(type);
524 return Api::Success();
540 } 525 }
541 526
542 527
543 // TODO(iposva): The argument should be an instance. 528 // TODO(iposva): The argument should be an instance.
544 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { 529 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) {
545 Zone zone; // Setup a VM zone as we are creating some handles. 530 Zone zone; // Setup a VM zone as we are creating some handles.
546 HandleScope scope; // Setup a VM handle scope. 531 HandleScope scope; // Setup a VM handle scope.
547 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 532 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
548 return obj.IsNumber(); 533 return obj.IsNumber();
549 } 534 }
(...skipping 17 matching lines...) Expand all
567 552
568 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 553 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
569 Zone zone; // Setup a VM zone as we are creating some handles. 554 Zone zone; // Setup a VM zone as we are creating some handles.
570 HandleScope scope; // Setup a VM handle scope. 555 HandleScope scope; // Setup a VM handle scope.
571 const String& str_obj = String::Handle(String::New(str)); 556 const String& str_obj = String::Handle(String::New(str));
572 const Integer& obj = Integer::Handle(Integer::New(str_obj)); 557 const Integer& obj = Integer::Handle(Integer::New(str_obj));
573 return Api::NewLocalHandle(obj); 558 return Api::NewLocalHandle(obj);
574 } 559 }
575 560
576 561
577 DART_EXPORT Dart_Result Dart_IntegerValue(Dart_Handle integer) { 562 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) {
578 Zone zone; // Setup a VM zone as we are creating some handles. 563 Zone zone; // Setup a VM zone as we are creating some handles.
579 HandleScope scope; // Setup a VM handle scope. 564 HandleScope scope; // Setup a VM handle scope.
580 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 565 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
581 if (obj.IsSmi() || obj.IsMint()) { 566 if (obj.IsSmi() || obj.IsMint()) {
582 Integer& integer = Integer::Handle(); 567 Integer& integer = Integer::Handle();
583 integer ^= obj.raw(); 568 integer ^= obj.raw();
584 RETURN_CINT64(integer.AsInt64Value()); 569 *value = integer.AsInt64Value();
570 return Api::Success();
585 } 571 }
586 if (obj.IsBigint()) { 572 if (obj.IsBigint()) {
587 Bigint& bigint = Bigint::Handle(); 573 Bigint& bigint = Bigint::Handle();
588 bigint ^= obj.raw(); 574 bigint ^= obj.raw();
589 if (BigintOperations::FitsIntoInt64(bigint)) { 575 if (BigintOperations::FitsIntoInt64(bigint)) {
590 RETURN_CINT64(BigintOperations::ToInt64(bigint)); 576 *value = BigintOperations::ToInt64(bigint);
577 return Api::Success();
591 } else { 578 } else {
592 RETURN_CSTRING(BigintOperations::ToHexCString(bigint, &Api::Allocate)); 579 return Api::Error("Integer too big to fit in int64_t");
593 } 580 }
594 } 581 }
595 RETURN_FAILURE("Object is not a Integer"); 582 return Api::Error("Object is not a Integer");
596 } 583 }
597 584
598 585
599 DART_EXPORT Dart_Result Dart_IntegerFitsIntoInt64(Dart_Handle integer) { 586 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer,
587 const char** value) {
588 Zone zone; // Setup a VM zone as we are creating some handles.
589 HandleScope scope; // Setup a VM handle scope.
590 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
591 Bigint& bigint = Bigint::Handle();
592 if (obj.IsSmi() || obj.IsMint()) {
593 Integer& integer = Integer::Handle();
594 integer ^= obj.raw();
595 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value());
596 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
597 return Api::Success();
598 }
599 if (obj.IsBigint()) {
600 bigint ^= obj.raw();
601 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
602 return Api::Success();
603 }
604 return Api::Error("Object is not a Integer");
605 }
606
607
608 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
609 bool* fits) {
600 Zone zone; // Setup a VM zone as we are creating some handles. 610 Zone zone; // Setup a VM zone as we are creating some handles.
601 HandleScope scope; // Setup a VM handle scope. 611 HandleScope scope; // Setup a VM handle scope.
602 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 612 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
603 if (obj.IsSmi() || obj.IsMint()) { 613 if (obj.IsSmi() || obj.IsMint()) {
604 RETURN_CBOOLEAN(true); 614 *fits = true;
615 return Api::Success();
605 } else if (obj.IsBigint()) { 616 } else if (obj.IsBigint()) {
606 #if defined(DEBUG) 617 #if defined(DEBUG)
607 Bigint& bigint = Bigint::Handle(); 618 Bigint& bigint = Bigint::Handle();
608 bigint ^= obj.raw(); 619 bigint ^= obj.raw();
609 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); 620 ASSERT(!BigintOperations::FitsIntoInt64(bigint));
610 #endif 621 #endif
611 RETURN_CBOOLEAN(false); 622 *fits = false;
623 return Api::Success();
612 } 624 }
613 RETURN_FAILURE("Object is not a Integer"); 625 return Api::Error("Object is not a Integer");
614 } 626 }
615 627
616 628
617 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { 629 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) {
618 Zone zone; // Setup a VM zone as we are creating some handles. 630 Zone zone; // Setup a VM zone as we are creating some handles.
619 HandleScope scope; // Setup a VM handle scope. 631 HandleScope scope; // Setup a VM handle scope.
620 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 632 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
621 return obj.IsBool(); 633 return obj.IsBool();
622 } 634 }
623 635
624 636
625 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { 637 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) {
626 Zone zone; // Setup a VM zone as we are creating some handles. 638 Zone zone; // Setup a VM zone as we are creating some handles.
627 HandleScope scope; // Setup a VM handle scope. 639 HandleScope scope; // Setup a VM handle scope.
628 const Bool& obj = Bool::Handle(Bool::Get(value)); 640 const Bool& obj = Bool::Handle(Bool::Get(value));
629 return Api::NewLocalHandle(obj); 641 return Api::NewLocalHandle(obj);
630 } 642 }
631 643
632 644
633 DART_EXPORT Dart_Result Dart_BooleanValue(Dart_Handle bool_object) { 645 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object,
646 bool* value) {
634 Zone zone; // Setup a VM zone as we are creating some handles. 647 Zone zone; // Setup a VM zone as we are creating some handles.
635 HandleScope scope; // Setup a VM handle scope. 648 HandleScope scope; // Setup a VM handle scope.
636 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object)); 649 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object));
637 if (obj.IsBool()) { 650 if (obj.IsBool()) {
638 Bool& bool_obj = Bool::Handle(); 651 Bool& bool_obj = Bool::Handle();
639 bool_obj ^= obj.raw(); 652 bool_obj ^= obj.raw();
640 RETURN_CBOOLEAN(bool_obj.value()); 653 *value = bool_obj.value();
654 return Api::Success();
641 } 655 }
642 RETURN_FAILURE("Object is not a Boolean"); 656 return Api::Error("Object is not a Boolean");
643 } 657 }
644 658
645 659
646 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { 660 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) {
647 Zone zone; // Setup a VM zone as we are creating some handles. 661 Zone zone; // Setup a VM zone as we are creating some handles.
648 HandleScope scope; // Setup a VM handle scope. 662 HandleScope scope; // Setup a VM handle scope.
649 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 663 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
650 return obj.IsDouble(); 664 return obj.IsDouble();
651 } 665 }
652 666
653 667
654 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { 668 DART_EXPORT Dart_Handle Dart_NewDouble(double value) {
655 Zone zone; // Setup a VM zone as we are creating some handles. 669 Zone zone; // Setup a VM zone as we are creating some handles.
656 HandleScope scope; // Setup a VM handle scope. 670 HandleScope scope; // Setup a VM handle scope.
657 const Double& obj = Double::Handle(Double::New(value)); 671 const Double& obj = Double::Handle(Double::New(value));
658 return Api::NewLocalHandle(obj); 672 return Api::NewLocalHandle(obj);
659 } 673 }
660 674
661 675
662 DART_EXPORT Dart_Result Dart_DoubleValue(Dart_Handle integer) { 676 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle integer, double* result) {
663 Zone zone; // Setup a VM zone as we are creating some handles. 677 Zone zone; // Setup a VM zone as we are creating some handles.
664 HandleScope scope; // Setup a VM handle scope. 678 HandleScope scope; // Setup a VM handle scope.
665 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 679 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
666 if (obj.IsDouble()) { 680 if (obj.IsDouble()) {
667 Double& double_obj = Double::Handle(); 681 Double& double_obj = Double::Handle();
668 double_obj ^= obj.raw(); 682 double_obj ^= obj.raw();
669 RETURN_CDOUBLE(double_obj.value()); 683 *result = double_obj.value();
684 return Api::Success();
670 } 685 }
671 RETURN_FAILURE("Object is not a Double"); 686 return Api::Error("Object is not a Double");
672 } 687 }
673 688
674 689
675 DART_EXPORT bool Dart_IsString(Dart_Handle object) { 690 DART_EXPORT bool Dart_IsString(Dart_Handle object) {
676 Zone zone; // Setup a VM zone as we are creating some handles. 691 Zone zone; // Setup a VM zone as we are creating some handles.
677 HandleScope scope; // Setup a VM handle scope. 692 HandleScope scope; // Setup a VM handle scope.
678 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 693 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
679 return obj.IsString(); 694 return obj.IsString();
680 } 695 }
681 696
682 697
683 DART_EXPORT Dart_Result Dart_StringLength(Dart_Handle str) { 698 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
684 Zone zone; // Setup a VM zone as we are creating some handles. 699 Zone zone; // Setup a VM zone as we are creating some handles.
685 HandleScope scope; // Setup a VM handle scope. 700 HandleScope scope; // Setup a VM handle scope.
686 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 701 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
687 if (obj.IsString()) { 702 if (obj.IsString()) {
688 String& string_obj = String::Handle(); 703 String& string_obj = String::Handle();
689 string_obj ^= obj.raw(); 704 string_obj ^= obj.raw();
690 RETURN_CINT(string_obj.Length()); 705 *len = string_obj.Length();
706 return Api::Success();
691 } 707 }
692 RETURN_FAILURE("Object is not a String"); 708 return Api::Error("Object is not a String");
693 } 709 }
694 710
695 711
696 DART_EXPORT Dart_Handle Dart_NewString(const char* str) { 712 DART_EXPORT Dart_Handle Dart_NewString(const char* str) {
697 Zone zone; // Setup a VM zone as we are creating some handles. 713 Zone zone; // Setup a VM zone as we are creating some handles.
698 HandleScope scope; // Setup a VM handle scope. 714 HandleScope scope; // Setup a VM handle scope.
699 const String& obj = String::Handle(String::New(str)); 715 const String& obj = String::Handle(String::New(str));
700 return Api::NewLocalHandle(obj); 716 return Api::NewLocalHandle(obj);
701 } 717 }
702 718
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 754
739 755
740 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { 756 DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
741 Zone zone; // Setup a VM zone as we are creating some handles. 757 Zone zone; // Setup a VM zone as we are creating some handles.
742 HandleScope scope; // Setup a VM handle scope. 758 HandleScope scope; // Setup a VM handle scope.
743 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 759 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
744 return obj.IsOneByteString() || obj.IsTwoByteString(); 760 return obj.IsOneByteString() || obj.IsTwoByteString();
745 } 761 }
746 762
747 763
748 DART_EXPORT Dart_Result Dart_StringGet8(Dart_Handle str, 764 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
749 uint8_t* codepoints, 765 uint8_t* codepoints,
750 intptr_t length) { 766 intptr_t length,
767 intptr_t* used) {
751 Zone zone; // Setup a VM zone as we are creating some handles. 768 Zone zone; // Setup a VM zone as we are creating some handles.
752 HandleScope scope; // Setup a VM handle scope. 769 HandleScope scope; // Setup a VM handle scope.
753 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 770 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
754 if (obj.IsOneByteString()) { 771 if (obj.IsOneByteString()) {
755 OneByteString& string_obj = OneByteString::Handle(); 772 OneByteString& string_obj = OneByteString::Handle();
756 string_obj ^= obj.raw(); 773 string_obj ^= obj.raw();
757 intptr_t str_len = string_obj.Length(); 774 intptr_t str_len = string_obj.Length();
758 intptr_t copy_len = (str_len > length) ? length : str_len; 775 intptr_t copy_len = (str_len > length) ? length : str_len;
759 for (intptr_t i = 0; i < copy_len; i++) { 776 for (intptr_t i = 0; i < copy_len; i++) {
760 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); 777 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
761 } 778 }
762 RETURN_CINT(copy_len); 779 if (used) {
780 *used = copy_len;
781 }
782 return Api::Success();
763 } 783 }
764 RETURN_FAILURE(obj.IsString() ? "Object is not a String8" : 784 return Api::Error(obj.IsString() ? "Object is not a String8" :
765 "Object is not a String"); 785 "Object is not a String");
Ivan Posva 2011/10/25 21:50:53 Weird alignment here and similar places.
turnidge 2011/10/25 22:07:23 Fixed.
766 } 786 }
767 787
768 788
769 DART_EXPORT Dart_Result Dart_StringGet16(Dart_Handle str, 789 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
770 uint16_t* codepoints, 790 uint16_t* codepoints,
771 intptr_t length) { 791 intptr_t length,
792 intptr_t* used) {
772 Zone zone; // Setup a VM zone as we are creating some handles. 793 Zone zone; // Setup a VM zone as we are creating some handles.
773 HandleScope scope; // Setup a VM handle scope. 794 HandleScope scope; // Setup a VM handle scope.
774 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 795 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
775 if (obj.IsOneByteString() || obj.IsTwoByteString()) { 796 if (obj.IsOneByteString() || obj.IsTwoByteString()) {
776 String& string_obj = String::Handle(); 797 String& string_obj = String::Handle();
777 string_obj ^= obj.raw(); 798 string_obj ^= obj.raw();
778 intptr_t str_len = string_obj.Length(); 799 intptr_t str_len = string_obj.Length();
779 intptr_t copy_len = (str_len > length) ? length : str_len; 800 intptr_t copy_len = (str_len > length) ? length : str_len;
780 for (intptr_t i = 0; i < copy_len; i++) { 801 for (intptr_t i = 0; i < copy_len; i++) {
781 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); 802 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
782 } 803 }
783 RETURN_CINT(copy_len); 804 if (used) {
805 *used = copy_len;
806 }
807 return Api::Success();
784 } 808 }
785 RETURN_FAILURE(obj.IsString() ? "Object is not a String16" : 809 return Api::Error(obj.IsString() ? "Object is not a String16" :
786 "Object is not a String"); 810 "Object is not a String");
787 } 811 }
788 812
789 813
790 DART_EXPORT Dart_Result Dart_StringGet32(Dart_Handle str, 814 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str,
791 uint32_t* codepoints, 815 uint32_t* codepoints,
792 intptr_t length) { 816 intptr_t length,
817 intptr_t* used) {
793 Zone zone; // Setup a VM zone as we are creating some handles. 818 Zone zone; // Setup a VM zone as we are creating some handles.
794 HandleScope scope; // Setup a VM handle scope. 819 HandleScope scope; // Setup a VM handle scope.
795 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 820 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
796 if (obj.IsString()) { 821 if (obj.IsString()) {
797 String& string_obj = String::Handle(); 822 String& string_obj = String::Handle();
798 string_obj ^= obj.raw(); 823 string_obj ^= obj.raw();
799 intptr_t str_len = string_obj.Length(); 824 intptr_t str_len = string_obj.Length();
800 intptr_t copy_len = (str_len > length) ? length : str_len; 825 intptr_t copy_len = (str_len > length) ? length : str_len;
801 for (intptr_t i = 0; i < copy_len; i++) { 826 for (intptr_t i = 0; i < copy_len; i++) {
802 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i)); 827 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i));
803 } 828 }
804 RETURN_CINT(copy_len); 829 if (used) {
830 *used = copy_len;
831 }
832 return Api::Success();
805 } 833 }
806 RETURN_FAILURE("Object is not a String"); 834 return Api::Error("Object is not a String");
807 } 835 }
808 836
809 837
810 DART_EXPORT Dart_Result Dart_StringToCString(Dart_Handle object) { 838 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
839 const char** result) {
811 Zone zone; // Setup a VM zone as we are creating some handles. 840 Zone zone; // Setup a VM zone as we are creating some handles.
812 HandleScope scope; // Setup a VM handle scope. 841 HandleScope scope; // Setup a VM handle scope.
813 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 842 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
814 if (obj.IsString()) { 843 if (obj.IsString()) {
815 const char* string_value = obj.ToCString(); 844 const char* string_value = obj.ToCString();
816 intptr_t string_length = strlen(string_value); 845 intptr_t string_length = strlen(string_value);
817 char* result = reinterpret_cast<char*>(Api::Allocate(string_length + 1)); 846 char* res = reinterpret_cast<char*>(Api::Allocate(string_length + 1));
818 if (result == NULL) { 847 if (res == NULL) {
819 RETURN_FAILURE("Unable to allocate memory"); 848 return Api::Error("Unable to allocate memory");
820 } 849 }
821 strncpy(result, string_value, string_length + 1); 850 strncpy(res, string_value, string_length + 1);
822 ASSERT(result[string_length] == '\0'); 851 ASSERT(res[string_length] == '\0');
823 RETURN_CSTRING(result); 852 *result = res;
853 return Api::Success();
824 } 854 }
825 RETURN_FAILURE("Object is not a String"); 855 return Api::Error("Object is not a String");
826 } 856 }
827 857
828 858
829 DART_EXPORT bool Dart_IsArray(Dart_Handle object) { 859 DART_EXPORT bool Dart_IsArray(Dart_Handle object) {
830 Zone zone; // Setup a VM zone as we are creating some handles. 860 Zone zone; // Setup a VM zone as we are creating some handles.
831 HandleScope scope; // Setup a VM handle scope. 861 HandleScope scope; // Setup a VM handle scope.
832 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 862 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
833 return obj.IsArray(); 863 return obj.IsArray();
834 } 864 }
835 865
836 866
837 DART_EXPORT Dart_Handle Dart_NewArray(intptr_t length) { 867 DART_EXPORT Dart_Handle Dart_NewArray(intptr_t length) {
838 Zone zone; // Setup a VM zone as we are creating some handles. 868 Zone zone; // Setup a VM zone as we are creating some handles.
839 HandleScope scope; // Setup a VM handle scope. 869 HandleScope scope; // Setup a VM handle scope.
840 const Array& obj = Array::Handle(Array::New(length)); 870 const Array& obj = Array::Handle(Array::New(length));
841 return Api::NewLocalHandle(obj); 871 return Api::NewLocalHandle(obj);
842 } 872 }
843 873
844 874
845 DART_EXPORT Dart_Result Dart_GetLength(Dart_Handle array) { 875 DART_EXPORT Dart_Handle Dart_GetLength(Dart_Handle array, intptr_t* len) {
846 Zone zone; // Setup a VM zone as we are creating some handles. 876 Zone zone; // Setup a VM zone as we are creating some handles.
847 HandleScope scope; // Setup a VM handle scope. 877 HandleScope scope; // Setup a VM handle scope.
848 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 878 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
849 if (obj.IsArray()) { 879 if (obj.IsArray()) {
850 Array& array_obj = Array::Handle(); 880 Array& array_obj = Array::Handle();
851 array_obj ^= obj.raw(); 881 array_obj ^= obj.raw();
852 RETURN_CINT(array_obj.Length()); 882 *len = array_obj.Length();
883 return Api::Success();
853 } 884 }
854 RETURN_FAILURE("Object is not an Array"); 885 return Api::Error("Object is not an Array");
855 } 886 }
856 887
857 888
858 DART_EXPORT Dart_Result Dart_ArrayGet(Dart_Handle array, 889 DART_EXPORT Dart_Handle Dart_ArrayGet(Dart_Handle array,
859 intptr_t offset, 890 intptr_t offset,
860 uint8_t* native_array, 891 uint8_t* native_array,
861 intptr_t length) { 892 intptr_t length) {
862 Zone zone; // Setup a VM zone as we are creating some handles. 893 Zone zone; // Setup a VM zone as we are creating some handles.
863 HandleScope scope; // Setup a VM handle scope. 894 HandleScope scope; // Setup a VM handle scope.
864 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 895 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
865 if (obj.IsArray()) { 896 if (obj.IsArray()) {
866 Array& array_obj = Array::Handle(); 897 Array& array_obj = Array::Handle();
867 array_obj ^= obj.raw(); 898 array_obj ^= obj.raw();
868 if ((offset + length) <= array_obj.Length()) { 899 if ((offset + length) <= array_obj.Length()) {
869 Object& element = Object::Handle(); 900 Object& element = Object::Handle();
870 Integer& integer = Integer::Handle(); 901 Integer& integer = Integer::Handle();
871 for (int i = 0; i < length; i++) { 902 for (int i = 0; i < length; i++) {
872 element = array_obj.At(offset + i); 903 element = array_obj.At(offset + i);
873 integer ^= element.raw(); 904 integer ^= element.raw();
874 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); 905 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff);
875 ASSERT(integer.AsInt64Value() <= 0xff); 906 ASSERT(integer.AsInt64Value() <= 0xff);
876 // TODO(hpayer): value should always be smaller then 0xff. Add error 907 // TODO(hpayer): value should always be smaller then 0xff. Add error
877 // handling. 908 // handling.
878 } 909 }
879 RETURN_CINT(0); 910 return Api::Success();
880 } 911 }
881 RETURN_FAILURE("Invalid length passed in to access array elements"); 912 return Api::Error("Invalid length passed in to access array elements");
882 } 913 }
883 RETURN_FAILURE("Object is not an Array"); 914 return Api::Error("Object is not an Array");
884 } 915 }
885 916
886 917
887 DART_EXPORT Dart_Result Dart_ArrayGetAt(Dart_Handle array, intptr_t index) { 918 DART_EXPORT Dart_Handle Dart_ArrayGetAt(Dart_Handle array, intptr_t index) {
888 Zone zone; // Setup a VM zone as we are creating some handles. 919 Zone zone; // Setup a VM zone as we are creating some handles.
889 HandleScope scope; // Setup a VM handle scope. 920 HandleScope scope; // Setup a VM handle scope.
890 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 921 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
891 if (obj.IsArray()) { 922 if (obj.IsArray()) {
892 Array& array_obj = Array::Handle(); 923 Array& array_obj = Array::Handle();
893 array_obj ^= obj.raw(); 924 array_obj ^= obj.raw();
894 if ((index >= 0) && (index < array_obj.Length())) { 925 if ((index >= 0) && (index < array_obj.Length())) {
895 const Object& element = Object::Handle(array_obj.At(index)); 926 const Object& element = Object::Handle(array_obj.At(index));
896 RETURN_OBJECT(element); 927 return Api::NewLocalHandle(element);
897 } 928 }
898 RETURN_FAILURE("Invalid index passed in to access array element"); 929 return Api::Error("Invalid index passed in to access array element");
899 } 930 }
900 RETURN_FAILURE("Object is not an Array"); 931 return Api::Error("Object is not an Array");
901 } 932 }
902 933
903 934
904 DART_EXPORT Dart_Result Dart_ArraySet(Dart_Handle array, 935 DART_EXPORT Dart_Handle Dart_ArraySet(Dart_Handle array,
905 intptr_t offset, 936 intptr_t offset,
906 uint8_t* native_array, 937 uint8_t* native_array,
907 intptr_t length) { 938 intptr_t length) {
908 Zone zone; 939 Zone zone;
909 HandleScope scope; 940 HandleScope scope;
910 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 941 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
911 if (obj.IsArray()) { 942 if (obj.IsArray()) {
912 Array& array_obj = Array::Handle(); 943 Array& array_obj = Array::Handle();
913 array_obj ^= obj.raw(); 944 array_obj ^= obj.raw();
914 Integer& integer = Integer::Handle(); 945 Integer& integer = Integer::Handle();
915 if ((offset + length) <= array_obj.Length()) { 946 if ((offset + length) <= array_obj.Length()) {
916 for (int i = 0; i < length; i++) { 947 for (int i = 0; i < length; i++) {
917 integer ^= Integer::New(native_array[i]); 948 integer ^= Integer::New(native_array[i]);
918 array_obj.SetAt(offset + i, integer); 949 array_obj.SetAt(offset + i, integer);
919 } 950 }
920 RETURN_CINT(0); 951 return Api::Success();
921 } 952 }
922 RETURN_FAILURE("Invalid length passed in to set array elements"); 953 return Api::Error("Invalid length passed in to set array elements");
923 } 954 }
924 RETURN_FAILURE("Object is not an Array"); 955 return Api::Error("Object is not an Array");
925 } 956 }
926 957
927 DART_EXPORT Dart_Result Dart_ArraySetAt(Dart_Handle array, 958 DART_EXPORT Dart_Handle Dart_ArraySetAt(Dart_Handle array,
928 intptr_t index, 959 intptr_t index,
929 Dart_Handle value) { 960 Dart_Handle value) {
930 Zone zone; // Setup a VM zone as we are creating some handles. 961 Zone zone; // Setup a VM zone as we are creating some handles.
931 HandleScope scope; // Setup a VM handle scope. 962 HandleScope scope; // Setup a VM handle scope.
932 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 963 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
933 if (obj.IsArray()) { 964 if (obj.IsArray()) {
934 Array& array_obj = Array::Handle(); 965 Array& array_obj = Array::Handle();
935 array_obj ^= obj.raw(); 966 array_obj ^= obj.raw();
936 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 967 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
937 if ((index >= 0) && (index < array_obj.Length())) { 968 if ((index >= 0) && (index < array_obj.Length())) {
938 array_obj.SetAt(index, value_obj); 969 array_obj.SetAt(index, value_obj);
939 RETURN_CINT(0); 970 return Api::Success();
940 } 971 }
941 RETURN_FAILURE("Invalid index passed in to set array element"); 972 return Api::Error("Invalid index passed in to set array element");
942 } 973 }
943 RETURN_FAILURE("Object is not an Array"); 974 return Api::Error("Object is not an Array");
944 } 975 }
945 976
946 977
947 // NOTE: Need to pass 'result' as a parameter here in order to avoid 978 // NOTE: Need to pass 'result' as a parameter here in order to avoid
948 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 979 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
949 // which shows up because of the use of setjmp. 980 // which shows up because of the use of setjmp.
950 static void InvokeStatic(const Function& function, 981 static void InvokeStatic(const Function& function,
951 GrowableArray<const Object*>& args, 982 GrowableArray<const Object*>& args,
952 Dart_Result* result) { 983 Dart_Handle* result) {
953 Isolate* isolate = Isolate::Current(); 984 Isolate* isolate = Isolate::Current();
954 ASSERT(isolate != NULL); 985 ASSERT(isolate != NULL);
955 LongJump* base = isolate->long_jump_base(); 986 LongJump* base = isolate->long_jump_base();
956 LongJump jump; 987 LongJump jump;
957 isolate->set_long_jump_base(&jump); 988 isolate->set_long_jump_base(&jump);
958 if (setjmp(*jump.Set()) == 0) { 989 if (setjmp(*jump.Set()) == 0) {
959 const Array& kNoArgumentNames = Array::Handle(); 990 const Array& kNoArgumentNames = Array::Handle();
960 const Instance& retval = Instance::Handle( 991 const Instance& retval = Instance::Handle(
961 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); 992 DartEntry::InvokeStatic(function, args, kNoArgumentNames));
962 result->type_ = kRetObject; 993 *result = Api::NewLocalHandle(retval);
963 result->retval_.obj_value = Api::NewLocalHandle(retval);
964 } else { 994 } else {
965 SetupErrorResult(result); 995 SetupErrorResult(result);
966 } 996 }
967 isolate->set_long_jump_base(base); 997 isolate->set_long_jump_base(base);
968 } 998 }
969 999
970 1000
971 // NOTE: Need to pass 'result' as a parameter here in order to avoid 1001 // NOTE: Need to pass 'result' as a parameter here in order to avoid
972 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 1002 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
973 // which shows up because of the use of setjmp. 1003 // which shows up because of the use of setjmp.
974 static void InvokeDynamic(const Instance& receiver, 1004 static void InvokeDynamic(const Instance& receiver,
975 const Function& function, 1005 const Function& function,
976 GrowableArray<const Object*>& args, 1006 GrowableArray<const Object*>& args,
977 Dart_Result* result) { 1007 Dart_Handle* result) {
978 Isolate* isolate = Isolate::Current(); 1008 Isolate* isolate = Isolate::Current();
979 ASSERT(isolate != NULL); 1009 ASSERT(isolate != NULL);
980 LongJump* base = isolate->long_jump_base(); 1010 LongJump* base = isolate->long_jump_base();
981 LongJump jump; 1011 LongJump jump;
982 isolate->set_long_jump_base(&jump); 1012 isolate->set_long_jump_base(&jump);
983 if (setjmp(*jump.Set()) == 0) { 1013 if (setjmp(*jump.Set()) == 0) {
984 const Array& kNoArgumentNames = Array::Handle(); 1014 const Array& kNoArgumentNames = Array::Handle();
985 const Instance& retval = Instance::Handle( 1015 const Instance& retval = Instance::Handle(
986 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); 1016 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames));
987 result->type_ = kRetObject; 1017 *result = Api::NewLocalHandle(retval);
988 result->retval_.obj_value = Api::NewLocalHandle(retval);
989 } else { 1018 } else {
990 SetupErrorResult(result); 1019 SetupErrorResult(result);
991 } 1020 }
992 isolate->set_long_jump_base(base); 1021 isolate->set_long_jump_base(base);
993 } 1022 }
994 1023
995 1024
996 // NOTE: Need to pass 'result' as a parameter here in order to avoid 1025 // NOTE: Need to pass 'result' as a parameter here in order to avoid
997 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 1026 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
998 // which shows up because of the use of setjmp. 1027 // which shows up because of the use of setjmp.
999 static void InvokeClosure(const Closure& closure, 1028 static void InvokeClosure(const Closure& closure,
1000 GrowableArray<const Object*>& args, 1029 GrowableArray<const Object*>& args,
1001 Dart_Result* result) { 1030 Dart_Handle* result) {
1002 Isolate* isolate = Isolate::Current(); 1031 Isolate* isolate = Isolate::Current();
1003 ASSERT(isolate != NULL); 1032 ASSERT(isolate != NULL);
1004 LongJump* base = isolate->long_jump_base(); 1033 LongJump* base = isolate->long_jump_base();
1005 LongJump jump; 1034 LongJump jump;
1006 isolate->set_long_jump_base(&jump); 1035 isolate->set_long_jump_base(&jump);
1007 if (setjmp(*jump.Set()) == 0) { 1036 if (setjmp(*jump.Set()) == 0) {
1008 const Array& kNoArgumentNames = Array::Handle(); 1037 const Array& kNoArgumentNames = Array::Handle();
1009 const Instance& retval = Instance::Handle( 1038 const Instance& retval = Instance::Handle(
1010 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); 1039 DartEntry::InvokeClosure(closure, args, kNoArgumentNames));
1011 result->type_ = kRetObject; 1040 *result = Api::NewLocalHandle(retval);
1012 result->retval_.obj_value = Api::NewLocalHandle(retval);
1013 } else { 1041 } else {
1014 SetupErrorResult(result); 1042 SetupErrorResult(result);
1015 } 1043 }
1016 isolate->set_long_jump_base(base); 1044 isolate->set_long_jump_base(base);
1017 } 1045 }
1018 1046
1019 1047
1020 DART_EXPORT Dart_Result Dart_InvokeStatic(Dart_Handle library_in, 1048 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in,
1021 Dart_Handle class_name_in, 1049 Dart_Handle class_name_in,
1022 Dart_Handle function_name_in, 1050 Dart_Handle function_name_in,
1023 int number_of_arguments, 1051 int number_of_arguments,
1024 Dart_Handle* arguments) { 1052 Dart_Handle* arguments) {
1025 Zone zone; // Setup a VM zone as we are creating some handles. 1053 Zone zone; // Setup a VM zone as we are creating some handles.
1026 HandleScope scope; // Setup a VM handle scope. 1054 HandleScope scope; // Setup a VM handle scope.
1027 // Finalize all classes. 1055 // Finalize all classes.
1028 const char* msg = CheckIsolateState(); 1056 const char* msg = CheckIsolateState();
1029 if (msg != NULL) { 1057 if (msg != NULL) {
1030 RETURN_FAILURE(msg); 1058 return Api::Error(msg);
1031 } 1059 }
1032 1060
1033 // Now try to resolve and invoke the static function. 1061 // Now try to resolve and invoke the static function.
1034 const Library& library = 1062 const Library& library =
1035 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 1063 Library::CheckedHandle(Api::UnwrapHandle(library_in));
1036 if (library.IsNull()) { 1064 if (library.IsNull()) {
1037 RETURN_FAILURE("No library specified"); 1065 return Api::Error("No library specified");
1038 } 1066 }
1039 const String& class_name = 1067 const String& class_name =
1040 String::CheckedHandle(Api::UnwrapHandle(class_name_in)); 1068 String::CheckedHandle(Api::UnwrapHandle(class_name_in));
1041 const String& function_name = 1069 const String& function_name =
1042 String::CheckedHandle(Api::UnwrapHandle(function_name_in)); 1070 String::CheckedHandle(Api::UnwrapHandle(function_name_in));
1043 const Function& function = Function::Handle( 1071 const Function& function = Function::Handle(
1044 Resolver::ResolveStatic(library, 1072 Resolver::ResolveStatic(library,
1045 class_name, 1073 class_name,
1046 function_name, 1074 function_name,
1047 number_of_arguments, 1075 number_of_arguments,
1048 Array::Handle(), // Named arguments are not yet 1076 Array::Handle(), // Named arguments are not yet
1049 // supported in the API. 1077 // supported in the API.
1050 Resolver::kIsQualified)); 1078 Resolver::kIsQualified));
1051 if (function.IsNull()) { 1079 if (function.IsNull()) {
1052 char* msg; 1080 char* msg;
1053 if (class_name.IsNull()) { 1081 if (class_name.IsNull()) {
1054 const char* format = "Unable to find entrypoint: %s()"; 1082 const char* format = "Unable to find entrypoint: %s()";
1055 intptr_t length = OS::SNPrint(NULL, 0, format, function_name.ToCString()); 1083 intptr_t length = OS::SNPrint(NULL, 0, format, function_name.ToCString());
1056 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); 1084 msg = reinterpret_cast<char*>(Api::Allocate(length + 1));
1057 OS::SNPrint(msg, (length + 1), format, function_name.ToCString()); 1085 OS::SNPrint(msg, (length + 1), format, function_name.ToCString());
1058 } else { 1086 } else {
1059 const char* format = "Unable to find entrypoint: static %s.%s()"; 1087 const char* format = "Unable to find entrypoint: static %s.%s()";
1060 intptr_t length = OS::SNPrint(NULL, 0, format, 1088 intptr_t length = OS::SNPrint(NULL, 0, format,
1061 class_name.ToCString(), 1089 class_name.ToCString(),
1062 function_name.ToCString()); 1090 function_name.ToCString());
1063 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); 1091 msg = reinterpret_cast<char*>(Api::Allocate(length + 1));
1064 OS::SNPrint(msg, (length + 1), format, 1092 OS::SNPrint(msg, (length + 1), format,
1065 class_name.ToCString(), function_name.ToCString()); 1093 class_name.ToCString(), function_name.ToCString());
1066 } 1094 }
1067 RETURN_FAILURE(msg); 1095 return Api::Error(msg);
1068 } 1096 }
1069 Dart_Result retval; 1097 Dart_Handle retval;
1070 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1098 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1071 for (int i = 0; i < number_of_arguments; i++) { 1099 for (int i = 0; i < number_of_arguments; i++) {
1072 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1100 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1073 dart_arguments.Add(&arg); 1101 dart_arguments.Add(&arg);
1074 } 1102 }
1075 InvokeStatic(function, dart_arguments, &retval); 1103 InvokeStatic(function, dart_arguments, &retval);
1076 return retval; 1104 return retval;
1077 } 1105 }
1078 1106
1079 1107
1080 DART_EXPORT Dart_Result Dart_InvokeDynamic(Dart_Handle object, 1108 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object,
1081 Dart_Handle function_name, 1109 Dart_Handle function_name,
1082 int number_of_arguments, 1110 int number_of_arguments,
1083 Dart_Handle* arguments) { 1111 Dart_Handle* arguments) {
1084 Zone zone; // Setup a VM zone as we are creating some handles. 1112 Zone zone; // Setup a VM zone as we are creating some handles.
1085 HandleScope scope; // Setup a VM handle scope. 1113 HandleScope scope; // Setup a VM handle scope.
1086 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1114 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1087 // Let the resolver figure out the correct target for null receiver. 1115 // Let the resolver figure out the correct target for null receiver.
1088 // E.g., (null).toString() should execute correctly. 1116 // E.g., (null).toString() should execute correctly.
1089 if (!obj.IsNull() && !obj.IsInstance()) { 1117 if (!obj.IsNull() && !obj.IsInstance()) {
1090 RETURN_FAILURE("Invalid receiver (not instance) passed to invoke dynamic"); 1118 return Api::Error(
1119 "Invalid receiver (not instance) passed to invoke dynamic");
1091 } 1120 }
1092 if (function_name == NULL) { 1121 if (function_name == NULL) {
1093 RETURN_FAILURE("Invalid function name specified"); 1122 return Api::Error("Invalid function name specified");
1094 } 1123 }
1095 ASSERT(ClassFinalizer::AllClassesFinalized()); 1124 ASSERT(ClassFinalizer::AllClassesFinalized());
1096 1125
1097 // Now try to resolve and invoke the dynamic function on this object. 1126 // Now try to resolve and invoke the dynamic function on this object.
1098 Instance& receiver = Instance::Handle(); 1127 Instance& receiver = Instance::Handle();
1099 receiver ^= obj.raw(); 1128 receiver ^= obj.raw();
1100 const String& name = String::CheckedHandle(Api::UnwrapHandle(function_name)); 1129 const String& name = String::CheckedHandle(Api::UnwrapHandle(function_name));
1101 const Function& function = Function::Handle( 1130 const Function& function = Function::Handle(
1102 Resolver::ResolveDynamic(receiver, 1131 Resolver::ResolveDynamic(receiver,
1103 name, 1132 name,
1104 (number_of_arguments + 1), 1133 (number_of_arguments + 1),
1105 0)); // Named args not yet supported in API. 1134 0)); // Named args not yet supported in API.
1106 if (function.IsNull()) { 1135 if (function.IsNull()) {
1107 // TODO(5415268): Invoke noSuchMethod instead of failing. 1136 // TODO(5415268): Invoke noSuchMethod instead of failing.
1108 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); 1137 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString());
1109 RETURN_FAILURE("Unable to find instance function"); 1138 return Api::Error("Unable to find instance function");
1110 } 1139 }
1111 Dart_Result retval; 1140 Dart_Handle retval;
1112 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1141 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1113 for (int i = 0; i < number_of_arguments; i++) { 1142 for (int i = 0; i < number_of_arguments; i++) {
1114 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1143 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1115 dart_arguments.Add(&arg); 1144 dart_arguments.Add(&arg);
1116 } 1145 }
1117 InvokeDynamic(receiver, function, dart_arguments, &retval); 1146 InvokeDynamic(receiver, function, dart_arguments, &retval);
1118 return retval; 1147 return retval;
1119 } 1148 }
1120 1149
1121 1150
1122 DART_EXPORT Dart_Result Dart_InvokeClosure(Dart_Handle closure, 1151 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
1123 int number_of_arguments, 1152 int number_of_arguments,
1124 Dart_Handle* arguments) { 1153 Dart_Handle* arguments) {
1125 Zone zone; // Setup a VM zone as we are creating some handles. 1154 Zone zone; // Setup a VM zone as we are creating some handles.
1126 HandleScope scope; // Setup a VM handle scope. 1155 HandleScope scope; // Setup a VM handle scope.
1127 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); 1156 const Object& obj = Object::Handle(Api::UnwrapHandle(closure));
1128 if (obj.IsNull()) { 1157 if (obj.IsNull()) {
1129 RETURN_FAILURE("Null object passed in to invoke closure"); 1158 return Api::Error("Null object passed in to invoke closure");
1130 } 1159 }
1131 if (!obj.IsClosure()) { 1160 if (!obj.IsClosure()) {
1132 RETURN_FAILURE("Invalid closure passed to invoke closure"); 1161 return Api::Error("Invalid closure passed to invoke closure");
1133 } 1162 }
1134 ASSERT(ClassFinalizer::AllClassesFinalized()); 1163 ASSERT(ClassFinalizer::AllClassesFinalized());
1135 1164
1136 // Now try to invoke the closure. 1165 // Now try to invoke the closure.
1137 Closure& closure_obj = Closure::Handle(); 1166 Closure& closure_obj = Closure::Handle();
1138 closure_obj ^= obj.raw(); 1167 closure_obj ^= obj.raw();
1139 Dart_Result retval; 1168 Dart_Handle retval;
1140 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1169 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1141 for (int i = 0; i < number_of_arguments; i++) { 1170 for (int i = 0; i < number_of_arguments; i++) {
1142 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1171 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1143 dart_arguments.Add(&arg); 1172 dart_arguments.Add(&arg);
1144 } 1173 }
1145 InvokeClosure(closure_obj, dart_arguments, &retval); 1174 InvokeClosure(closure_obj, dart_arguments, &retval);
1146 return retval; 1175 return retval;
1147 } 1176 }
1148 1177
1149 1178
(...skipping 17 matching lines...) Expand all
1167 1196
1168 1197
1169 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle result) { 1198 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle result) {
1170 Zone zone; // Setup a VM zone as we are creating some handles. 1199 Zone zone; // Setup a VM zone as we are creating some handles.
1171 HandleScope scope; // Setup a VM handle scope. 1200 HandleScope scope; // Setup a VM handle scope.
1172 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); 1201 const Object& retval = Object::Handle(Api::UnwrapHandle(result));
1173 return retval.IsUnhandledException(); 1202 return retval.IsUnhandledException();
1174 } 1203 }
1175 1204
1176 1205
1177 DART_EXPORT Dart_Result Dart_GetException(Dart_Handle result) { 1206 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle result) {
1178 Zone zone; // Setup a VM zone as we are creating some handles. 1207 Zone zone; // Setup a VM zone as we are creating some handles.
1179 HandleScope scope; // Setup a VM handle scope. 1208 HandleScope scope; // Setup a VM handle scope.
1180 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); 1209 const Object& retval = Object::Handle(Api::UnwrapHandle(result));
1181 if (retval.IsUnhandledException()) { 1210 if (retval.IsUnhandledException()) {
1182 const UnhandledException& unhandled = UnhandledException::Handle( 1211 const UnhandledException& unhandled = UnhandledException::Handle(
1183 reinterpret_cast<RawUnhandledException*>(retval.raw())); 1212 reinterpret_cast<RawUnhandledException*>(retval.raw()));
1184 const Object& exception = Object::Handle(unhandled.exception()); 1213 const Object& exception = Object::Handle(unhandled.exception());
1185 RETURN_OBJECT(exception); 1214 return Api::NewLocalHandle(exception);
1186 } 1215 }
1187 RETURN_FAILURE("Object is not an unhandled exception object"); 1216 return Api::Error("Object is not an unhandled exception object");
1188 } 1217 }
1189 1218
1190 1219
1191 DART_EXPORT Dart_Result Dart_GetStacktrace(Dart_Handle unhandled_excp) { 1220 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle unhandled_excp) {
1192 Zone zone; // Setup a VM zone as we are creating some handles. 1221 Zone zone; // Setup a VM zone as we are creating some handles.
1193 HandleScope scope; // Setup a VM handle scope. 1222 HandleScope scope; // Setup a VM handle scope.
1194 const Object& retval = Object::Handle(Api::UnwrapHandle(unhandled_excp)); 1223 const Object& retval = Object::Handle(Api::UnwrapHandle(unhandled_excp));
1195 if (retval.IsUnhandledException()) { 1224 if (retval.IsUnhandledException()) {
1196 const UnhandledException& unhandled = UnhandledException::Handle( 1225 const UnhandledException& unhandled = UnhandledException::Handle(
1197 reinterpret_cast<RawUnhandledException*>(retval.raw())); 1226 reinterpret_cast<RawUnhandledException*>(retval.raw()));
1198 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); 1227 const Object& stacktrace = Object::Handle(unhandled.stacktrace());
1199 RETURN_OBJECT(stacktrace); 1228 return Api::NewLocalHandle(stacktrace);
1200 } 1229 }
1201 RETURN_FAILURE("Object is not an unhandled exception object"); 1230 return Api::Error("Object is not an unhandled exception object");
1202 } 1231 }
1203 1232
1204 1233
1205 DART_EXPORT Dart_Result Dart_ThrowException(Dart_Handle exception) { 1234 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
1206 Isolate* isolate = Isolate::Current(); 1235 Isolate* isolate = Isolate::Current();
1207 ASSERT(isolate != NULL); 1236 ASSERT(isolate != NULL);
1208 Zone zone; // Setup a VM zone as we are creating some handles. 1237 Zone zone; // Setup a VM zone as we are creating some handles.
1209 HandleScope scope; // Setup a VM handle scope. 1238 HandleScope scope; // Setup a VM handle scope.
1210 if (isolate->top_exit_frame_info() == 0) { 1239 if (isolate->top_exit_frame_info() == 0) {
1211 // There are no dart frames on the stack so it would be illegal to 1240 // There are no dart frames on the stack so it would be illegal to
1212 // throw an exception here. 1241 // throw an exception here.
1213 RETURN_FAILURE("No Dart frames on stack, cannot throw exception"); 1242 return Api::Error("No Dart frames on stack, cannot throw exception");
1214 } 1243 }
1215 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); 1244 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
1216 // Unwind all the API scopes till the exit frame before throwing an 1245 // Unwind all the API scopes till the exit frame before throwing an
1217 // exception. 1246 // exception.
1218 ApiState* state = isolate->api_state(); 1247 ApiState* state = isolate->api_state();
1219 ASSERT(state != NULL); 1248 ASSERT(state != NULL);
1220 state->UnwindScopes(isolate->top_exit_frame_info()); 1249 state->UnwindScopes(isolate->top_exit_frame_info());
1221 Exceptions::Throw(excp); 1250 Exceptions::Throw(excp);
1222 RETURN_FAILURE("Exception was not thrown, internal error"); 1251 return Api::Error("Exception was not thrown, internal error");
1223 } 1252 }
1224 1253
1225 1254
1226 DART_EXPORT Dart_Result Dart_ReThrowException(Dart_Handle exception, 1255 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
1227 Dart_Handle stacktrace) { 1256 Dart_Handle stacktrace) {
1228 Isolate* isolate = Isolate::Current(); 1257 Isolate* isolate = Isolate::Current();
1229 ASSERT(isolate != NULL); 1258 ASSERT(isolate != NULL);
1230 if (isolate->top_exit_frame_info() == 0) { 1259 if (isolate->top_exit_frame_info() == 0) {
1231 // There are no dart frames on the stack so it would be illegal to 1260 // There are no dart frames on the stack so it would be illegal to
1232 // throw an exception here. 1261 // throw an exception here.
1233 RETURN_FAILURE("No Dart frames on stack, cannot throw exception"); 1262 return Api::Error("No Dart frames on stack, cannot throw exception");
1234 } 1263 }
1235 Zone zone; // Setup a VM zone as we are creating some handles. 1264 Zone zone; // Setup a VM zone as we are creating some handles.
1236 HandleScope scope; // Setup a VM handle scope. 1265 HandleScope scope; // Setup a VM handle scope.
1237 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); 1266 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
1238 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace)); 1267 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace));
1239 // Unwind all the API scopes till the exit frame before throwing an 1268 // Unwind all the API scopes till the exit frame before throwing an
1240 // exception. 1269 // exception.
1241 ApiState* state = isolate->api_state(); 1270 ApiState* state = isolate->api_state();
1242 ASSERT(state != NULL); 1271 ASSERT(state != NULL);
1243 state->UnwindScopes(isolate->top_exit_frame_info()); 1272 state->UnwindScopes(isolate->top_exit_frame_info());
1244 Exceptions::ReThrow(excp, stk); 1273 Exceptions::ReThrow(excp, stk);
1245 RETURN_FAILURE("Exception was not re thrown, internal error"); 1274 return Api::Error("Exception was not re thrown, internal error");
1246 } 1275 }
1247 1276
1248 1277
1249 DART_EXPORT void Dart_EnterScope() { 1278 DART_EXPORT void Dart_EnterScope() {
1250 Isolate* isolate = Isolate::Current(); 1279 Isolate* isolate = Isolate::Current();
1251 ASSERT(isolate != NULL); 1280 ASSERT(isolate != NULL);
1252 ApiState* state = isolate->api_state(); 1281 ApiState* state = isolate->api_state();
1253 ASSERT(state != NULL); 1282 ASSERT(state != NULL);
1254 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(), 1283 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(),
1255 reinterpret_cast<uword>(&state)); 1284 reinterpret_cast<uword>(&state));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 return NULL; 1322 return NULL;
1294 } 1323 }
1295 1324
1296 1325
1297 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { 1326 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
1298 Isolate* isolate = Isolate::Current(); 1327 Isolate* isolate = Isolate::Current();
1299 ASSERT(isolate != NULL); 1328 ASSERT(isolate != NULL);
1300 ApiState* state = isolate->api_state(); 1329 ApiState* state = isolate->api_state();
1301 ASSERT(state != NULL); 1330 ASSERT(state != NULL);
1302 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); 1331 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
1303 ref->FreeHandle(state->persistent_handles().free_list()); 1332 state->persistent_handles().FreeHandle(ref);
1304 state->persistent_handles().set_free_list(ref);
1305 } 1333 }
1306 1334
1307 1335
1308 static const bool kGetter = true; 1336 static const bool kGetter = true;
1309 static const bool kSetter = false; 1337 static const bool kSetter = false;
1310 1338
1311 1339
1312 static bool UseGetterForStaticField(const Field& fld) { 1340 static bool UseGetterForStaticField(const Field& fld) {
1313 if (fld.IsNull()) { 1341 if (fld.IsNull()) {
1314 return true; 1342 return true;
1315 } 1343 }
1316 1344
1317 // Return getter method for uninitialized fields, rather than the 1345 // Return getter method for uninitialized fields, rather than the
1318 // field object, since the value in the field object will not be 1346 // field object, since the value in the field object will not be
1319 // initialized until the first time the getter is invoked. 1347 // initialized until the first time the getter is invoked.
1320 const Instance& value = Instance::Handle(fld.value()); 1348 const Instance& value = Instance::Handle(fld.value());
1321 ASSERT(value.raw() != Object::transition_sentinel()); 1349 ASSERT(value.raw() != Object::transition_sentinel());
1322 return value.raw() == Object::sentinel(); 1350 return value.raw() == Object::sentinel();
1323 } 1351 }
1324 1352
1325 1353
1326 static Dart_Result LookupStaticField(Dart_Handle clazz, 1354 static Dart_Handle LookupStaticField(Dart_Handle clazz,
1327 Dart_Handle field_name, 1355 Dart_Handle field_name,
1328 bool is_getter) { 1356 bool is_getter) {
1329 const Object& param1 = Object::Handle(Api::UnwrapHandle(clazz)); 1357 const Object& param1 = Object::Handle(Api::UnwrapHandle(clazz));
1330 const Object& param2 = Object::Handle(Api::UnwrapHandle(field_name)); 1358 const Object& param2 = Object::Handle(Api::UnwrapHandle(field_name));
1331 if (param1.IsNull() || !param1.IsClass()) { 1359 if (param1.IsNull() || !param1.IsClass()) {
1332 RETURN_FAILURE("Invalid class specified"); 1360 return Api::Error("Invalid class specified");
1333 } 1361 }
1334 if (param2.IsNull() || !param2.IsString()) { 1362 if (param2.IsNull() || !param2.IsString()) {
1335 RETURN_FAILURE("Invalid field name specified"); 1363 return Api::Error("Invalid field name specified");
1336 } 1364 }
1337 Class& cls = Class::Handle(); 1365 Class& cls = Class::Handle();
1338 cls ^= param1.raw(); 1366 cls ^= param1.raw();
1339 String& fld_name = String::Handle(); 1367 String& fld_name = String::Handle();
1340 fld_name ^= param2.raw(); 1368 fld_name ^= param2.raw();
1341 const Field& fld = Field::Handle(cls.LookupStaticField(fld_name)); 1369 const Field& fld = Field::Handle(cls.LookupStaticField(fld_name));
1342 if (is_getter && UseGetterForStaticField(fld)) { 1370 if (is_getter && UseGetterForStaticField(fld)) {
1343 const String& func_name = String::Handle(Field::GetterName(fld_name)); 1371 const String& func_name = String::Handle(Field::GetterName(fld_name));
1344 const Function& function = 1372 const Function& function =
1345 Function::Handle(cls.LookupStaticFunction(func_name)); 1373 Function::Handle(cls.LookupStaticFunction(func_name));
1346 if (!function.IsNull()) { 1374 if (!function.IsNull()) {
1347 RETURN_OBJECT(function); 1375 return Api::NewLocalHandle(function);
1348 } 1376 }
1349 RETURN_FAILURE("Specified field is not found in the class"); 1377 return Api::Error("Specified field is not found in the class");
1350 } 1378 }
1351 if (fld.IsNull()) { 1379 if (fld.IsNull()) {
1352 RETURN_FAILURE("Specified field is not found in the class"); 1380 return Api::Error("Specified field is not found in the class");
1353 } 1381 }
1354 RETURN_OBJECT(fld); 1382 return Api::NewLocalHandle(fld);
1355 } 1383 }
1356 1384
1357 1385
1358 static Dart_Result LookupInstanceField(const Object& object, 1386 static Dart_Handle LookupInstanceField(const Object& object,
1359 Dart_Handle name, 1387 Dart_Handle name,
1360 bool is_getter) { 1388 bool is_getter) {
1361 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 1389 const Object& param = Object::Handle(Api::UnwrapHandle(name));
1362 if (param.IsNull() || !param.IsString()) { 1390 if (param.IsNull() || !param.IsString()) {
1363 RETURN_FAILURE("Invalid field name specified"); 1391 return Api::Error("Invalid field name specified");
1364 } 1392 }
1365 String& field_name = String::Handle(); 1393 String& field_name = String::Handle();
1366 field_name ^= param.raw(); 1394 field_name ^= param.raw();
1367 String& func_name = String::Handle(); 1395 String& func_name = String::Handle();
1368 Field& fld = Field::Handle(); 1396 Field& fld = Field::Handle();
1369 Class& cls = Class::Handle(object.clazz()); 1397 Class& cls = Class::Handle(object.clazz());
1370 while (!cls.IsNull()) { 1398 while (!cls.IsNull()) {
1371 fld = cls.LookupInstanceField(field_name); 1399 fld = cls.LookupInstanceField(field_name);
1372 if (!fld.IsNull()) { 1400 if (!fld.IsNull()) {
1373 if (!is_getter && fld.is_final()) { 1401 if (!is_getter && fld.is_final()) {
1374 RETURN_FAILURE("Cannot set value of final fields"); 1402 return Api::Error("Cannot set value of final fields");
1375 } 1403 }
1376 func_name = is_getter ? Field::GetterName(field_name) : 1404 func_name = is_getter ? Field::GetterName(field_name) :
1377 Field::SetterName(field_name); 1405 Field::SetterName(field_name);
1378 const Function& function = Function::Handle( 1406 const Function& function = Function::Handle(
1379 cls.LookupDynamicFunction(func_name)); 1407 cls.LookupDynamicFunction(func_name));
1380 if (function.IsNull()) { 1408 if (function.IsNull()) {
1381 RETURN_FAILURE("Unable to find accessor function in the class"); 1409 return Api::Error("Unable to find accessor function in the class");
1382 } 1410 }
1383 RETURN_OBJECT(function); 1411 return Api::NewLocalHandle(function);
1384 } 1412 }
1385 cls = cls.SuperClass(); 1413 cls = cls.SuperClass();
1386 } 1414 }
1387 RETURN_FAILURE("Unable to find field in the class"); 1415 return Api::Error("Unable to find field in the class");
1388 } 1416 }
1389 1417
1390 1418
1391 DART_EXPORT Dart_Result Dart_GetStaticField(Dart_Handle cls, 1419 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls,
1392 Dart_Handle name) { 1420 Dart_Handle name) {
1393 Zone zone; // Setup a VM zone as we are creating some handles. 1421 Zone zone; // Setup a VM zone as we are creating some handles.
1394 HandleScope scope; // Setup a VM handle scope. 1422 HandleScope scope; // Setup a VM handle scope.
1395 Dart_Result result = LookupStaticField(cls, name, kGetter); 1423 Dart_Handle result = LookupStaticField(cls, name, kGetter);
1396 if (!::Dart_IsValidResult(result)) { 1424 if (!::Dart_IsValid(result)) {
1397 return result; 1425 return result;
1398 } 1426 }
1399 Object& retval = Object::Handle(); 1427 Object& retval = Object::Handle();
1400 const Object& obj = Object::Handle(Api::UnwrapHandle(Dart_GetResult(result))); 1428 const Object& obj = Object::Handle(Api::UnwrapHandle(result));
1401 if (obj.IsField()) { 1429 if (obj.IsField()) {
1402 Field& fld = Field::Handle(); 1430 Field& fld = Field::Handle();
1403 fld ^= obj.raw(); 1431 fld ^= obj.raw();
1404 retval = fld.value(); 1432 retval = fld.value();
1405 RETURN_OBJECT(retval); 1433 return Api::NewLocalHandle(retval);
1406 } else { 1434 } else {
1407 Function& func = Function::Handle(); 1435 Function& func = Function::Handle();
1408 func ^= obj.raw(); 1436 func ^= obj.raw();
1409 GrowableArray<const Object*> args; 1437 GrowableArray<const Object*> args;
1410 InvokeStatic(func, args, &result); 1438 InvokeStatic(func, args, &result);
1411 if (::Dart_IsValidResult(result)) { 1439 if (::Dart_IsValid(result)) {
1412 Dart_Handle result_obj = Dart_GetResult(result); 1440 if (Dart_ExceptionOccurred(result)) {
1413 if (Dart_ExceptionOccurred(result_obj)) { 1441 return Api::Error(
1414 RETURN_FAILURE("An exception occurred when getting the static field"); 1442 "An exception occurred when getting the static field");
1415 } 1443 }
1416 } 1444 }
1417 return result; 1445 return result;
1418 } 1446 }
1419 } 1447 }
1420 1448
1421 1449
1422 // TODO(iposva): The value parameter should be documented as being an instance. 1450 // TODO(iposva): The value parameter should be documented as being an instance.
1423 DART_EXPORT Dart_Result Dart_SetStaticField(Dart_Handle cls, 1451 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls,
1424 Dart_Handle name, 1452 Dart_Handle name,
1425 Dart_Handle value) { 1453 Dart_Handle value) {
1426 Zone zone; // Setup a VM zone as we are creating some handles. 1454 Zone zone; // Setup a VM zone as we are creating some handles.
1427 HandleScope scope; // Setup a VM handle scope. 1455 HandleScope scope; // Setup a VM handle scope.
1428 Dart_Result result = LookupStaticField(cls, name, kSetter); 1456 Dart_Handle result = LookupStaticField(cls, name, kSetter);
1429 if (!::Dart_IsValidResult(result)) { 1457 if (!::Dart_IsValid(result)) {
1430 return result; 1458 return result;
1431 } 1459 }
1432 Field& fld = Field::Handle(); 1460 Field& fld = Field::Handle();
1433 fld ^= Api::UnwrapHandle(Dart_GetResult(result)); 1461 fld ^= Api::UnwrapHandle(result);
1434 if (fld.is_final()) { 1462 if (fld.is_final()) {
1435 RETURN_FAILURE("Specified field is a static final field in the class"); 1463 return Api::Error("Specified field is a static final field in the class");
1436 } 1464 }
1437 const Object& val = Object::Handle(Api::UnwrapHandle(value)); 1465 const Object& val = Object::Handle(Api::UnwrapHandle(value));
1438 Instance& instance = Instance::Handle(); 1466 Instance& instance = Instance::Handle();
1439 instance ^= val.raw(); 1467 instance ^= val.raw();
1440 fld.set_value(instance); 1468 fld.set_value(instance);
1441 RETURN_OBJECT(val); 1469 return Api::NewLocalHandle(val);
1442 } 1470 }
1443 1471
1444 1472
1445 DART_EXPORT Dart_Result Dart_GetInstanceField(Dart_Handle obj, 1473 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj,
1446 Dart_Handle name) { 1474 Dart_Handle name) {
1447 Zone zone; // Setup a VM zone as we are creating some handles. 1475 Zone zone; // Setup a VM zone as we are creating some handles.
1448 HandleScope scope; // Setup a VM handle scope. 1476 HandleScope scope; // Setup a VM handle scope.
1449 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1477 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1450 if (param.IsNull() || !param.IsInstance()) { 1478 if (param.IsNull() || !param.IsInstance()) {
1451 RETURN_FAILURE("Invalid object passed in to access instance field"); 1479 return Api::Error("Invalid object passed in to access instance field");
1452 } 1480 }
1453 Instance& object = Instance::Handle(); 1481 Instance& object = Instance::Handle();
1454 object ^= param.raw(); 1482 object ^= param.raw();
1455 Dart_Result result = LookupInstanceField(object, name, kGetter); 1483 Dart_Handle result = LookupInstanceField(object, name, kGetter);
1456 if (!::Dart_IsValidResult(result)) { 1484 if (!::Dart_IsValid(result)) {
1457 return result; 1485 return result;
1458 } 1486 }
1459 Function& func = Function::Handle(); 1487 Function& func = Function::Handle();
1460 func ^= Api::UnwrapHandle(Dart_GetResult(result)); 1488 func ^= Api::UnwrapHandle(result);
1461 GrowableArray<const Object*> arguments; 1489 GrowableArray<const Object*> arguments;
1462 InvokeDynamic(object, func, arguments, &result); 1490 InvokeDynamic(object, func, arguments, &result);
1463 if (::Dart_IsValidResult(result)) { 1491 if (::Dart_IsValid(result)) {
1464 Dart_Handle result_obj = Dart_GetResult(result); 1492 if (Dart_ExceptionOccurred(result)) {
1465 if (Dart_ExceptionOccurred(result_obj)) { 1493 return Api::Error(
1466 RETURN_FAILURE("An exception occurred when accessing the instance field"); 1494 "An exception occurred when accessing the instance field");
1467 } 1495 }
1468 } 1496 }
1469 return result; 1497 return result;
1470 } 1498 }
1471 1499
1472 1500
1473 DART_EXPORT Dart_Result Dart_SetInstanceField(Dart_Handle obj, 1501 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj,
1474 Dart_Handle name, 1502 Dart_Handle name,
1475 Dart_Handle value) { 1503 Dart_Handle value) {
1476 Zone zone; // Setup a VM zone as we are creating some handles. 1504 Zone zone; // Setup a VM zone as we are creating some handles.
1477 HandleScope scope; // Setup a VM handle scope. 1505 HandleScope scope; // Setup a VM handle scope.
1478 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1506 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1479 if (param.IsNull() || !param.IsInstance()) { 1507 if (param.IsNull() || !param.IsInstance()) {
1480 RETURN_FAILURE("Invalid object passed in to access instance field"); 1508 return Api::Error("Invalid object passed in to access instance field");
1481 } 1509 }
1482 Instance& object = Instance::Handle(); 1510 Instance& object = Instance::Handle();
1483 object ^= param.raw(); 1511 object ^= param.raw();
1484 Dart_Result result = LookupInstanceField(object, name, kSetter); 1512 Dart_Handle result = LookupInstanceField(object, name, kSetter);
1485 if (!::Dart_IsValidResult(result)) { 1513 if (!::Dart_IsValid(result)) {
1486 return result; 1514 return result;
1487 } 1515 }
1488 Function& func = Function::Handle(); 1516 Function& func = Function::Handle();
1489 func ^= Api::UnwrapHandle(Dart_GetResult(result)); 1517 func ^= Api::UnwrapHandle(result);
1490 GrowableArray<const Object*> arguments(1); 1518 GrowableArray<const Object*> arguments(1);
1491 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); 1519 const Object& arg = Object::Handle(Api::UnwrapHandle(value));
1492 arguments.Add(&arg); 1520 arguments.Add(&arg);
1493 InvokeDynamic(object, func, arguments, &result); 1521 InvokeDynamic(object, func, arguments, &result);
1494 if (::Dart_IsValidResult(result)) { 1522 if (::Dart_IsValid(result)) {
1495 Dart_Handle result_obj = Dart_GetResult(result); 1523 if (Dart_ExceptionOccurred(result)) {
1496 if (Dart_ExceptionOccurred(result_obj)) { 1524 return Api::Error(
1497 RETURN_FAILURE("An exception occurred when setting the instance field"); 1525 "An exception occurred when setting the instance field");
1498 } 1526 }
1499 } 1527 }
1500 return result; 1528 return result;
1501 } 1529 }
1502 1530
1503 1531
1504 DART_EXPORT Dart_Result Dart_CreateNativeWrapperClass(Dart_Handle library, 1532 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library,
1505 Dart_Handle name, 1533 Dart_Handle name,
1506 int field_count) { 1534 int field_count) {
1507 Zone zone; // Setup a VM zone as we are creating some handles. 1535 Zone zone; // Setup a VM zone as we are creating some handles.
1508 HandleScope scope; // Setup a VM handle scope. 1536 HandleScope scope; // Setup a VM handle scope.
1509 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 1537 const Object& param = Object::Handle(Api::UnwrapHandle(name));
1510 if (param.IsNull() || !param.IsString() || field_count <= 0) { 1538 if (param.IsNull() || !param.IsString() || field_count <= 0) {
1511 RETURN_FAILURE("Invalid arguments passed to Dart_CreateNativeWrapperClass"); 1539 return Api::Error(
1540 "Invalid arguments passed to Dart_CreateNativeWrapperClass");
1512 } 1541 }
1513 String& cls_name = String::Handle(); 1542 String& cls_name = String::Handle();
1514 cls_name ^= param.raw(); 1543 cls_name ^= param.raw();
1515 cls_name = String::NewSymbol(cls_name); 1544 cls_name = String::NewSymbol(cls_name);
1516 Library& lib = Library::Handle(); 1545 Library& lib = Library::Handle();
1517 lib ^= Api::UnwrapHandle(library); 1546 lib ^= Api::UnwrapHandle(library);
1518 if (lib.IsNull()) { 1547 if (lib.IsNull()) {
1519 RETURN_FAILURE("Invalid arguments passed to Dart_CreateNativeWrapperClass"); 1548 return Api::Error(
1549 "Invalid arguments passed to Dart_CreateNativeWrapperClass");
1520 } 1550 }
1521 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib, 1551 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib,
1522 cls_name, 1552 cls_name,
1523 field_count)); 1553 field_count));
1524 if (cls.IsNull()) { 1554 if (cls.IsNull()) {
1525 RETURN_FAILURE("Unable to create native wrapper class : already exists"); 1555 return Api::Error(
1556 "Unable to create native wrapper class : already exists");
1526 } 1557 }
1527 RETURN_OBJECT(cls); 1558 return Api::NewLocalHandle(cls);
1528 } 1559 }
1529 1560
1530 1561
1531 DART_EXPORT Dart_Result Dart_GetNativeInstanceField(Dart_Handle obj, 1562 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj,
1532 int index) { 1563 int index,
1564 intptr_t* value) {
1533 Zone zone; // Setup a VM zone as we are creating some handles. 1565 Zone zone; // Setup a VM zone as we are creating some handles.
1534 HandleScope scope; // Setup a VM handle scope. 1566 HandleScope scope; // Setup a VM handle scope.
1535 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1567 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1536 if (param.IsNull() || !param.IsInstance()) { 1568 if (param.IsNull() || !param.IsInstance()) {
1537 RETURN_FAILURE("Invalid object passed in to access native instance field"); 1569 return Api::Error(
1570 "Invalid object passed in to access native instance field");
1538 } 1571 }
1539 Instance& object = Instance::Handle(); 1572 Instance& object = Instance::Handle();
1540 object ^= param.raw(); 1573 object ^= param.raw();
1541 if (!object.IsValidNativeIndex(index)) { 1574 if (!object.IsValidNativeIndex(index)) {
1542 RETURN_FAILURE("Invalid index passed in to access native instance field"); 1575 return Api::Error(
1576 "Invalid index passed in to access native instance field");
1543 } 1577 }
1544 RETURN_CINT(object.GetNativeField(index)); 1578 *value = object.GetNativeField(index);
1579 return Api::Success();
1545 } 1580 }
1546 1581
1547 1582
1548 DART_EXPORT Dart_Result Dart_SetNativeInstanceField(Dart_Handle obj, 1583 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj,
1549 int index, 1584 int index,
1550 intptr_t value) { 1585 intptr_t value) {
1551 Zone zone; // Setup a VM zone as we are creating some handles. 1586 Zone zone; // Setup a VM zone as we are creating some handles.
1552 HandleScope scope; // Setup a VM handle scope. 1587 HandleScope scope; // Setup a VM handle scope.
1553 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1588 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1554 if (param.IsNull() || !param.IsInstance()) { 1589 if (param.IsNull() || !param.IsInstance()) {
1555 RETURN_FAILURE("Invalid object passed in to set native instance field"); 1590 return Api::Error("Invalid object passed in to set native instance field");
1556 } 1591 }
1557 Instance& object = Instance::Handle(); 1592 Instance& object = Instance::Handle();
1558 object ^= param.raw(); 1593 object ^= param.raw();
1559 if (!object.IsValidNativeIndex(index)) { 1594 if (!object.IsValidNativeIndex(index)) {
1560 RETURN_FAILURE("Invalid index passed in to set native instance field"); 1595 return Api::Error("Invalid index passed in to set native instance field");
1561 } 1596 }
1562 object.SetNativeField(index, value); 1597 object.SetNativeField(index, value);
1563 RETURN_CINT(value); 1598 return Api::Success();
1564 } 1599 }
1565 1600
1566 1601
1567 static uint8_t* ApiAllocator(uint8_t* ptr, 1602 static uint8_t* ApiAllocator(uint8_t* ptr,
1568 intptr_t old_size, 1603 intptr_t old_size,
1569 intptr_t new_size) { 1604 intptr_t new_size) {
1570 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr), 1605 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr),
1571 old_size, 1606 old_size,
1572 new_size); 1607 new_size);
1573 return reinterpret_cast<uint8_t*>(new_ptr); 1608 return reinterpret_cast<uint8_t*>(new_ptr);
1574 } 1609 }
1575 1610
1576 1611
1577 DART_EXPORT Dart_Result Dart_CreateSnapshot(uint8_t** snapshot_buffer, 1612 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snapshot_buffer,
1578 intptr_t* snapshot_size) { 1613 intptr_t* snapshot_size) {
1579 Zone zone; // Setup a VM zone as we are creating some handles. 1614 Zone zone; // Setup a VM zone as we are creating some handles.
1580 HandleScope scope; // Setup a VM handle scope. 1615 HandleScope scope; // Setup a VM handle scope.
1581 if (snapshot_buffer == NULL || snapshot_size == NULL) { 1616 if (snapshot_buffer == NULL || snapshot_size == NULL) {
1582 RETURN_FAILURE("Invalid input parameters to Dart_CreateSnapshot"); 1617 return Api::Error("Invalid input parameters to Dart_CreateSnapshot");
1583 } 1618 }
1584 const char* msg = CheckIsolateState(); 1619 const char* msg = CheckIsolateState();
1585 if (msg != NULL) { 1620 if (msg != NULL) {
1586 RETURN_FAILURE(msg); 1621 return Api::Error(msg);
1587 } 1622 }
1588 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator); 1623 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator);
1589 writer.WriteFullSnapshot(); 1624 writer.WriteFullSnapshot();
1590 *snapshot_size = writer.Size(); 1625 *snapshot_size = writer.Size();
1591 RETURN_CBOOLEAN(true); 1626 return Api::Success();
1592 } 1627 }
1593 1628
1594 1629
1595 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 1630 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
1596 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 1631 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
1597 return reinterpret_cast<uint8_t*>(new_ptr); 1632 return reinterpret_cast<uint8_t*>(new_ptr);
1598 } 1633 }
1599 1634
1600 1635
1601 DART_EXPORT Dart_Result Dart_PostIntArray(Dart_Port port, 1636 DART_EXPORT bool Dart_PostIntArray(Dart_Port port,
1602 int field_count, 1637 int field_count,
1603 intptr_t* data) { 1638 intptr_t* data) {
1604 uint8_t* buffer = NULL; 1639 uint8_t* buffer = NULL;
1605 MessageWriter writer(&buffer, &allocator); 1640 MessageWriter writer(&buffer, &allocator);
1606 1641
1607 writer.WriteMessage(field_count, data); 1642 writer.WriteMessage(field_count, data);
1608 1643
1609 // Post the message at the given port. 1644 // Post the message at the given port.
1610 bool result = PortMap::PostMessage(port, kNoReplyPort, buffer); 1645 return PortMap::PostMessage(port, kNoReplyPort, buffer);
1611 RETURN_CBOOLEAN(result);
1612 } 1646 }
1613 1647
1614 1648
1615 DART_EXPORT Dart_Result Dart_Post(Dart_Port port, Dart_Handle handle) { 1649 DART_EXPORT bool Dart_Post(Dart_Port port, Dart_Handle handle) {
1616 Zone zone; // Setup a VM zone as we are creating some handles. 1650 Zone zone; // Setup a VM zone as we are creating some handles.
1617 HandleScope scope; // Setup a VM handle scope. 1651 HandleScope scope; // Setup a VM handle scope.
1618 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); 1652 const Object& object = Object::Handle(Api::UnwrapHandle(handle));
1619 uint8_t* data = NULL; 1653 uint8_t* data = NULL;
1620 SnapshotWriter writer(false, &data, &allocator); 1654 SnapshotWriter writer(false, &data, &allocator);
1621 writer.WriteObject(object.raw()); 1655 writer.WriteObject(object.raw());
1622 writer.FinalizeBuffer(); 1656 writer.FinalizeBuffer();
1623 bool result = PortMap::PostMessage(port, kNoReplyPort, data); 1657 return PortMap::PostMessage(port, kNoReplyPort, data);
1624 RETURN_CBOOLEAN(result);
1625 } 1658 }
1626 1659
1627 1660
1628 DART_EXPORT void Dart_InitPprofSupport() { 1661 DART_EXPORT void Dart_InitPprofSupport() {
1629 DebugInfo* pprof_symbol_generator = DebugInfo::NewGenerator(); 1662 DebugInfo* pprof_symbol_generator = DebugInfo::NewGenerator();
1630 ASSERT(pprof_symbol_generator != NULL); 1663 ASSERT(pprof_symbol_generator != NULL);
1631 Dart::set_pprof_symbol_generator(pprof_symbol_generator); 1664 Dart::set_pprof_symbol_generator(pprof_symbol_generator);
1632 } 1665 }
1633 1666
1634 1667
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 } 1731 }
1699 1732
1700 1733
1701 PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state, 1734 PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state,
1702 Dart_Handle object) { 1735 Dart_Handle object) {
1703 ASSERT(state.IsValidPersistentHandle(object)); 1736 ASSERT(state.IsValidPersistentHandle(object));
1704 return reinterpret_cast<PersistentHandle*>(object); 1737 return reinterpret_cast<PersistentHandle*>(object);
1705 } 1738 }
1706 1739
1707 1740
1741 Dart_Handle Api::Success() {
1742 Isolate* isolate = Isolate::Current();
1743 ASSERT(isolate != NULL);
1744 ApiState* state = isolate->api_state();
1745 ASSERT(state != NULL);
1746 PersistentHandle* true_handle = state->True();
1747 return reinterpret_cast<Dart_Handle>(true_handle);
1748 }
1749
1750
1751 Dart_Handle Api::Error(const char* text) {
1752 Zone zone; // Setup a VM zone as we are creating some handles.
1753 HandleScope scope; // Setup a VM handle scope.
1754 const String& message = String::Handle(String::New(text));
1755 const Object& obj = Object::Handle(ApiFailure::New(message));
1756 return Api::NewLocalHandle(obj);
1757 }
1758
1759
1708 uword Api::Allocate(intptr_t size) { 1760 uword Api::Allocate(intptr_t size) {
1709 Isolate* isolate = Isolate::Current(); 1761 Isolate* isolate = Isolate::Current();
1710 ASSERT(isolate != NULL); 1762 ASSERT(isolate != NULL);
1711 ApiState* state = isolate->api_state(); 1763 ApiState* state = isolate->api_state();
1712 ASSERT(state != NULL); 1764 ASSERT(state != NULL);
1713 ApiLocalScope* scope = state->top_scope(); 1765 ApiLocalScope* scope = state->top_scope();
1714 ASSERT(scope != NULL); 1766 ASSERT(scope != NULL);
1715 return scope->zone().Allocate(size); 1767 return scope->zone().Allocate(size);
1716 } 1768 }
1717 1769
1718 1770
1719 uword Api::Reallocate(uword ptr, intptr_t old_size, intptr_t new_size) { 1771 uword Api::Reallocate(uword ptr, intptr_t old_size, intptr_t new_size) {
1720 Isolate* isolate = Isolate::Current(); 1772 Isolate* isolate = Isolate::Current();
1721 ASSERT(isolate != NULL); 1773 ASSERT(isolate != NULL);
1722 ApiState* state = isolate->api_state(); 1774 ApiState* state = isolate->api_state();
1723 ASSERT(state != NULL); 1775 ASSERT(state != NULL);
1724 ApiLocalScope* scope = state->top_scope(); 1776 ApiLocalScope* scope = state->top_scope();
1725 ASSERT(scope != NULL); 1777 ASSERT(scope != NULL);
1726 return scope->zone().Reallocate(ptr, old_size, new_size); 1778 return scope->zone().Reallocate(ptr, old_size, new_size);
1727 } 1779 }
1728 1780
1729 1781
1730 } // namespace dart 1782 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698