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

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, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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) {
751 Zone zone; // Setup a VM zone as we are creating some handles. 767 Zone zone; // Setup a VM zone as we are creating some handles.
752 HandleScope scope; // Setup a VM handle scope. 768 HandleScope scope; // Setup a VM handle scope.
753 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 769 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
754 if (obj.IsOneByteString()) { 770 if (obj.IsOneByteString()) {
755 OneByteString& string_obj = OneByteString::Handle(); 771 OneByteString& string_obj = OneByteString::Handle();
756 string_obj ^= obj.raw(); 772 string_obj ^= obj.raw();
757 intptr_t str_len = string_obj.Length(); 773 intptr_t str_len = string_obj.Length();
758 intptr_t copy_len = (str_len > length) ? length : str_len; 774 intptr_t copy_len = (str_len > *length) ? *length : str_len;
759 for (intptr_t i = 0; i < copy_len; i++) { 775 for (intptr_t i = 0; i < copy_len; i++) {
760 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); 776 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
761 } 777 }
762 RETURN_CINT(copy_len); 778 *length= copy_len;
779 return Api::Success();
763 } 780 }
764 RETURN_FAILURE(obj.IsString() ? "Object is not a String8" : 781 return Api::Error(obj.IsString()
765 "Object is not a String"); 782 ? "Object is not a String8"
783 : "Object is not a String");
766 } 784 }
767 785
768 786
769 DART_EXPORT Dart_Result Dart_StringGet16(Dart_Handle str, 787 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
770 uint16_t* codepoints, 788 uint16_t* codepoints,
771 intptr_t length) { 789 intptr_t* length) {
772 Zone zone; // Setup a VM zone as we are creating some handles. 790 Zone zone; // Setup a VM zone as we are creating some handles.
773 HandleScope scope; // Setup a VM handle scope. 791 HandleScope scope; // Setup a VM handle scope.
774 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 792 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
775 if (obj.IsOneByteString() || obj.IsTwoByteString()) { 793 if (obj.IsOneByteString() || obj.IsTwoByteString()) {
776 String& string_obj = String::Handle(); 794 String& string_obj = String::Handle();
777 string_obj ^= obj.raw(); 795 string_obj ^= obj.raw();
778 intptr_t str_len = string_obj.Length(); 796 intptr_t str_len = string_obj.Length();
779 intptr_t copy_len = (str_len > length) ? length : str_len; 797 intptr_t copy_len = (str_len > *length) ? *length : str_len;
780 for (intptr_t i = 0; i < copy_len; i++) { 798 for (intptr_t i = 0; i < copy_len; i++) {
781 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); 799 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
782 } 800 }
783 RETURN_CINT(copy_len); 801 *length = copy_len;
802 return Api::Success();
784 } 803 }
785 RETURN_FAILURE(obj.IsString() ? "Object is not a String16" : 804 return Api::Error(obj.IsString()
786 "Object is not a String"); 805 ? "Object is not a String16"
806 : "Object is not a String");
787 } 807 }
788 808
789 809
790 DART_EXPORT Dart_Result Dart_StringGet32(Dart_Handle str, 810 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str,
791 uint32_t* codepoints, 811 uint32_t* codepoints,
792 intptr_t length) { 812 intptr_t* length) {
793 Zone zone; // Setup a VM zone as we are creating some handles. 813 Zone zone; // Setup a VM zone as we are creating some handles.
794 HandleScope scope; // Setup a VM handle scope. 814 HandleScope scope; // Setup a VM handle scope.
795 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 815 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
796 if (obj.IsString()) { 816 if (obj.IsString()) {
797 String& string_obj = String::Handle(); 817 String& string_obj = String::Handle();
798 string_obj ^= obj.raw(); 818 string_obj ^= obj.raw();
799 intptr_t str_len = string_obj.Length(); 819 intptr_t str_len = string_obj.Length();
800 intptr_t copy_len = (str_len > length) ? length : str_len; 820 intptr_t copy_len = (str_len > *length) ? *length : str_len;
801 for (intptr_t i = 0; i < copy_len; i++) { 821 for (intptr_t i = 0; i < copy_len; i++) {
802 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i)); 822 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i));
803 } 823 }
804 RETURN_CINT(copy_len); 824 *length = copy_len;
825 return Api::Success();
805 } 826 }
806 RETURN_FAILURE("Object is not a String"); 827 return Api::Error("Object is not a String");
807 } 828 }
808 829
809 830
810 DART_EXPORT Dart_Result Dart_StringToCString(Dart_Handle object) { 831 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
832 const char** result) {
811 Zone zone; // Setup a VM zone as we are creating some handles. 833 Zone zone; // Setup a VM zone as we are creating some handles.
812 HandleScope scope; // Setup a VM handle scope. 834 HandleScope scope; // Setup a VM handle scope.
813 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 835 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
814 if (obj.IsString()) { 836 if (obj.IsString()) {
815 const char* string_value = obj.ToCString(); 837 const char* string_value = obj.ToCString();
816 intptr_t string_length = strlen(string_value); 838 intptr_t string_length = strlen(string_value);
817 char* result = reinterpret_cast<char*>(Api::Allocate(string_length + 1)); 839 char* res = reinterpret_cast<char*>(Api::Allocate(string_length + 1));
818 if (result == NULL) { 840 if (res == NULL) {
819 RETURN_FAILURE("Unable to allocate memory"); 841 return Api::Error("Unable to allocate memory");
820 } 842 }
821 strncpy(result, string_value, string_length + 1); 843 strncpy(res, string_value, string_length + 1);
822 ASSERT(result[string_length] == '\0'); 844 ASSERT(res[string_length] == '\0');
823 RETURN_CSTRING(result); 845 *result = res;
846 return Api::Success();
824 } 847 }
825 RETURN_FAILURE("Object is not a String"); 848 return Api::Error("Object is not a String");
826 } 849 }
827 850
828 851
829 DART_EXPORT bool Dart_IsArray(Dart_Handle object) { 852 DART_EXPORT bool Dart_IsArray(Dart_Handle object) {
830 Zone zone; // Setup a VM zone as we are creating some handles. 853 Zone zone; // Setup a VM zone as we are creating some handles.
831 HandleScope scope; // Setup a VM handle scope. 854 HandleScope scope; // Setup a VM handle scope.
832 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 855 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
833 return obj.IsArray(); 856 return obj.IsArray();
834 } 857 }
835 858
836 859
837 DART_EXPORT Dart_Handle Dart_NewArray(intptr_t length) { 860 DART_EXPORT Dart_Handle Dart_NewArray(intptr_t length) {
838 Zone zone; // Setup a VM zone as we are creating some handles. 861 Zone zone; // Setup a VM zone as we are creating some handles.
839 HandleScope scope; // Setup a VM handle scope. 862 HandleScope scope; // Setup a VM handle scope.
840 const Array& obj = Array::Handle(Array::New(length)); 863 const Array& obj = Array::Handle(Array::New(length));
841 return Api::NewLocalHandle(obj); 864 return Api::NewLocalHandle(obj);
842 } 865 }
843 866
844 867
845 DART_EXPORT Dart_Result Dart_GetLength(Dart_Handle array) { 868 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. 869 Zone zone; // Setup a VM zone as we are creating some handles.
847 HandleScope scope; // Setup a VM handle scope. 870 HandleScope scope; // Setup a VM handle scope.
848 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 871 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
849 if (obj.IsArray()) { 872 if (obj.IsArray()) {
850 Array& array_obj = Array::Handle(); 873 Array& array_obj = Array::Handle();
851 array_obj ^= obj.raw(); 874 array_obj ^= obj.raw();
852 RETURN_CINT(array_obj.Length()); 875 *len = array_obj.Length();
876 return Api::Success();
853 } 877 }
854 RETURN_FAILURE("Object is not an Array"); 878 return Api::Error("Object is not an Array");
855 } 879 }
856 880
857 881
858 DART_EXPORT Dart_Result Dart_ArrayGet(Dart_Handle array, 882 DART_EXPORT Dart_Handle Dart_ArrayGet(Dart_Handle array,
859 intptr_t offset, 883 intptr_t offset,
860 uint8_t* native_array, 884 uint8_t* native_array,
861 intptr_t length) { 885 intptr_t length) {
862 Zone zone; // Setup a VM zone as we are creating some handles. 886 Zone zone; // Setup a VM zone as we are creating some handles.
863 HandleScope scope; // Setup a VM handle scope. 887 HandleScope scope; // Setup a VM handle scope.
864 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 888 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
865 if (obj.IsArray()) { 889 if (obj.IsArray()) {
866 Array& array_obj = Array::Handle(); 890 Array& array_obj = Array::Handle();
867 array_obj ^= obj.raw(); 891 array_obj ^= obj.raw();
868 if ((offset + length) <= array_obj.Length()) { 892 if ((offset + length) <= array_obj.Length()) {
869 Object& element = Object::Handle(); 893 Object& element = Object::Handle();
870 Integer& integer = Integer::Handle(); 894 Integer& integer = Integer::Handle();
871 for (int i = 0; i < length; i++) { 895 for (int i = 0; i < length; i++) {
872 element = array_obj.At(offset + i); 896 element = array_obj.At(offset + i);
873 integer ^= element.raw(); 897 integer ^= element.raw();
874 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); 898 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff);
875 ASSERT(integer.AsInt64Value() <= 0xff); 899 ASSERT(integer.AsInt64Value() <= 0xff);
876 // TODO(hpayer): value should always be smaller then 0xff. Add error 900 // TODO(hpayer): value should always be smaller then 0xff. Add error
877 // handling. 901 // handling.
878 } 902 }
879 RETURN_CINT(0); 903 return Api::Success();
880 } 904 }
881 RETURN_FAILURE("Invalid length passed in to access array elements"); 905 return Api::Error("Invalid length passed in to access array elements");
882 } 906 }
883 RETURN_FAILURE("Object is not an Array"); 907 return Api::Error("Object is not an Array");
884 } 908 }
885 909
886 910
887 DART_EXPORT Dart_Result Dart_ArrayGetAt(Dart_Handle array, intptr_t index) { 911 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. 912 Zone zone; // Setup a VM zone as we are creating some handles.
889 HandleScope scope; // Setup a VM handle scope. 913 HandleScope scope; // Setup a VM handle scope.
890 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 914 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
891 if (obj.IsArray()) { 915 if (obj.IsArray()) {
892 Array& array_obj = Array::Handle(); 916 Array& array_obj = Array::Handle();
893 array_obj ^= obj.raw(); 917 array_obj ^= obj.raw();
894 if ((index >= 0) && (index < array_obj.Length())) { 918 if ((index >= 0) && (index < array_obj.Length())) {
895 const Object& element = Object::Handle(array_obj.At(index)); 919 const Object& element = Object::Handle(array_obj.At(index));
896 RETURN_OBJECT(element); 920 return Api::NewLocalHandle(element);
897 } 921 }
898 RETURN_FAILURE("Invalid index passed in to access array element"); 922 return Api::Error("Invalid index passed in to access array element");
899 } 923 }
900 RETURN_FAILURE("Object is not an Array"); 924 return Api::Error("Object is not an Array");
901 } 925 }
902 926
903 927
904 DART_EXPORT Dart_Result Dart_ArraySet(Dart_Handle array, 928 DART_EXPORT Dart_Handle Dart_ArraySet(Dart_Handle array,
905 intptr_t offset, 929 intptr_t offset,
906 uint8_t* native_array, 930 uint8_t* native_array,
907 intptr_t length) { 931 intptr_t length) {
908 Zone zone; 932 Zone zone;
909 HandleScope scope; 933 HandleScope scope;
910 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 934 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
911 if (obj.IsArray()) { 935 if (obj.IsArray()) {
912 Array& array_obj = Array::Handle(); 936 Array& array_obj = Array::Handle();
913 array_obj ^= obj.raw(); 937 array_obj ^= obj.raw();
914 Integer& integer = Integer::Handle(); 938 Integer& integer = Integer::Handle();
915 if ((offset + length) <= array_obj.Length()) { 939 if ((offset + length) <= array_obj.Length()) {
916 for (int i = 0; i < length; i++) { 940 for (int i = 0; i < length; i++) {
917 integer ^= Integer::New(native_array[i]); 941 integer ^= Integer::New(native_array[i]);
918 array_obj.SetAt(offset + i, integer); 942 array_obj.SetAt(offset + i, integer);
919 } 943 }
920 RETURN_CINT(0); 944 return Api::Success();
921 } 945 }
922 RETURN_FAILURE("Invalid length passed in to set array elements"); 946 return Api::Error("Invalid length passed in to set array elements");
923 } 947 }
924 RETURN_FAILURE("Object is not an Array"); 948 return Api::Error("Object is not an Array");
925 } 949 }
926 950
927 DART_EXPORT Dart_Result Dart_ArraySetAt(Dart_Handle array, 951 DART_EXPORT Dart_Handle Dart_ArraySetAt(Dart_Handle array,
928 intptr_t index, 952 intptr_t index,
929 Dart_Handle value) { 953 Dart_Handle value) {
930 Zone zone; // Setup a VM zone as we are creating some handles. 954 Zone zone; // Setup a VM zone as we are creating some handles.
931 HandleScope scope; // Setup a VM handle scope. 955 HandleScope scope; // Setup a VM handle scope.
932 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); 956 const Object& obj = Object::Handle(Api::UnwrapHandle(array));
933 if (obj.IsArray()) { 957 if (obj.IsArray()) {
934 Array& array_obj = Array::Handle(); 958 Array& array_obj = Array::Handle();
935 array_obj ^= obj.raw(); 959 array_obj ^= obj.raw();
936 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 960 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
937 if ((index >= 0) && (index < array_obj.Length())) { 961 if ((index >= 0) && (index < array_obj.Length())) {
938 array_obj.SetAt(index, value_obj); 962 array_obj.SetAt(index, value_obj);
939 RETURN_CINT(0); 963 return Api::Success();
940 } 964 }
941 RETURN_FAILURE("Invalid index passed in to set array element"); 965 return Api::Error("Invalid index passed in to set array element");
942 } 966 }
943 RETURN_FAILURE("Object is not an Array"); 967 return Api::Error("Object is not an Array");
944 } 968 }
945 969
946 970
947 // NOTE: Need to pass 'result' as a parameter here in order to avoid 971 // NOTE: Need to pass 'result' as a parameter here in order to avoid
948 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 972 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
949 // which shows up because of the use of setjmp. 973 // which shows up because of the use of setjmp.
950 static void InvokeStatic(const Function& function, 974 static void InvokeStatic(const Function& function,
951 GrowableArray<const Object*>& args, 975 GrowableArray<const Object*>& args,
952 Dart_Result* result) { 976 Dart_Handle* result) {
953 Isolate* isolate = Isolate::Current(); 977 Isolate* isolate = Isolate::Current();
954 ASSERT(isolate != NULL); 978 ASSERT(isolate != NULL);
955 LongJump* base = isolate->long_jump_base(); 979 LongJump* base = isolate->long_jump_base();
956 LongJump jump; 980 LongJump jump;
957 isolate->set_long_jump_base(&jump); 981 isolate->set_long_jump_base(&jump);
958 if (setjmp(*jump.Set()) == 0) { 982 if (setjmp(*jump.Set()) == 0) {
959 const Array& kNoArgumentNames = Array::Handle(); 983 const Array& kNoArgumentNames = Array::Handle();
960 const Instance& retval = Instance::Handle( 984 const Instance& retval = Instance::Handle(
961 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); 985 DartEntry::InvokeStatic(function, args, kNoArgumentNames));
962 result->type_ = kRetObject; 986 *result = Api::NewLocalHandle(retval);
963 result->retval_.obj_value = Api::NewLocalHandle(retval);
964 } else { 987 } else {
965 SetupErrorResult(result); 988 SetupErrorResult(result);
966 } 989 }
967 isolate->set_long_jump_base(base); 990 isolate->set_long_jump_base(base);
968 } 991 }
969 992
970 993
971 // NOTE: Need to pass 'result' as a parameter here in order to avoid 994 // NOTE: Need to pass 'result' as a parameter here in order to avoid
972 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 995 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
973 // which shows up because of the use of setjmp. 996 // which shows up because of the use of setjmp.
974 static void InvokeDynamic(const Instance& receiver, 997 static void InvokeDynamic(const Instance& receiver,
975 const Function& function, 998 const Function& function,
976 GrowableArray<const Object*>& args, 999 GrowableArray<const Object*>& args,
977 Dart_Result* result) { 1000 Dart_Handle* result) {
978 Isolate* isolate = Isolate::Current(); 1001 Isolate* isolate = Isolate::Current();
979 ASSERT(isolate != NULL); 1002 ASSERT(isolate != NULL);
980 LongJump* base = isolate->long_jump_base(); 1003 LongJump* base = isolate->long_jump_base();
981 LongJump jump; 1004 LongJump jump;
982 isolate->set_long_jump_base(&jump); 1005 isolate->set_long_jump_base(&jump);
983 if (setjmp(*jump.Set()) == 0) { 1006 if (setjmp(*jump.Set()) == 0) {
984 const Array& kNoArgumentNames = Array::Handle(); 1007 const Array& kNoArgumentNames = Array::Handle();
985 const Instance& retval = Instance::Handle( 1008 const Instance& retval = Instance::Handle(
986 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); 1009 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames));
987 result->type_ = kRetObject; 1010 *result = Api::NewLocalHandle(retval);
988 result->retval_.obj_value = Api::NewLocalHandle(retval);
989 } else { 1011 } else {
990 SetupErrorResult(result); 1012 SetupErrorResult(result);
991 } 1013 }
992 isolate->set_long_jump_base(base); 1014 isolate->set_long_jump_base(base);
993 } 1015 }
994 1016
995 1017
996 // NOTE: Need to pass 'result' as a parameter here in order to avoid 1018 // NOTE: Need to pass 'result' as a parameter here in order to avoid
997 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 1019 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
998 // which shows up because of the use of setjmp. 1020 // which shows up because of the use of setjmp.
999 static void InvokeClosure(const Closure& closure, 1021 static void InvokeClosure(const Closure& closure,
1000 GrowableArray<const Object*>& args, 1022 GrowableArray<const Object*>& args,
1001 Dart_Result* result) { 1023 Dart_Handle* result) {
1002 Isolate* isolate = Isolate::Current(); 1024 Isolate* isolate = Isolate::Current();
1003 ASSERT(isolate != NULL); 1025 ASSERT(isolate != NULL);
1004 LongJump* base = isolate->long_jump_base(); 1026 LongJump* base = isolate->long_jump_base();
1005 LongJump jump; 1027 LongJump jump;
1006 isolate->set_long_jump_base(&jump); 1028 isolate->set_long_jump_base(&jump);
1007 if (setjmp(*jump.Set()) == 0) { 1029 if (setjmp(*jump.Set()) == 0) {
1008 const Array& kNoArgumentNames = Array::Handle(); 1030 const Array& kNoArgumentNames = Array::Handle();
1009 const Instance& retval = Instance::Handle( 1031 const Instance& retval = Instance::Handle(
1010 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); 1032 DartEntry::InvokeClosure(closure, args, kNoArgumentNames));
1011 result->type_ = kRetObject; 1033 *result = Api::NewLocalHandle(retval);
1012 result->retval_.obj_value = Api::NewLocalHandle(retval);
1013 } else { 1034 } else {
1014 SetupErrorResult(result); 1035 SetupErrorResult(result);
1015 } 1036 }
1016 isolate->set_long_jump_base(base); 1037 isolate->set_long_jump_base(base);
1017 } 1038 }
1018 1039
1019 1040
1020 DART_EXPORT Dart_Result Dart_InvokeStatic(Dart_Handle library_in, 1041 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in,
1021 Dart_Handle class_name_in, 1042 Dart_Handle class_name_in,
1022 Dart_Handle function_name_in, 1043 Dart_Handle function_name_in,
1023 int number_of_arguments, 1044 int number_of_arguments,
1024 Dart_Handle* arguments) { 1045 Dart_Handle* arguments) {
1025 Zone zone; // Setup a VM zone as we are creating some handles. 1046 Zone zone; // Setup a VM zone as we are creating some handles.
1026 HandleScope scope; // Setup a VM handle scope. 1047 HandleScope scope; // Setup a VM handle scope.
1027 // Finalize all classes. 1048 // Finalize all classes.
1028 const char* msg = CheckIsolateState(); 1049 const char* msg = CheckIsolateState();
1029 if (msg != NULL) { 1050 if (msg != NULL) {
1030 RETURN_FAILURE(msg); 1051 return Api::Error(msg);
1031 } 1052 }
1032 1053
1033 // Now try to resolve and invoke the static function. 1054 // Now try to resolve and invoke the static function.
1034 const Library& library = 1055 const Library& library =
1035 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 1056 Library::CheckedHandle(Api::UnwrapHandle(library_in));
1036 if (library.IsNull()) { 1057 if (library.IsNull()) {
1037 RETURN_FAILURE("No library specified"); 1058 return Api::Error("No library specified");
1038 } 1059 }
1039 const String& class_name = 1060 const String& class_name =
1040 String::CheckedHandle(Api::UnwrapHandle(class_name_in)); 1061 String::CheckedHandle(Api::UnwrapHandle(class_name_in));
1041 const String& function_name = 1062 const String& function_name =
1042 String::CheckedHandle(Api::UnwrapHandle(function_name_in)); 1063 String::CheckedHandle(Api::UnwrapHandle(function_name_in));
1043 const Function& function = Function::Handle( 1064 const Function& function = Function::Handle(
1044 Resolver::ResolveStatic(library, 1065 Resolver::ResolveStatic(library,
1045 class_name, 1066 class_name,
1046 function_name, 1067 function_name,
1047 number_of_arguments, 1068 number_of_arguments,
1048 Array::Handle(), // Named arguments are not yet 1069 Array::Handle(), // Named arguments are not yet
1049 // supported in the API. 1070 // supported in the API.
1050 Resolver::kIsQualified)); 1071 Resolver::kIsQualified));
1051 if (function.IsNull()) { 1072 if (function.IsNull()) {
1052 char* msg; 1073 char* msg;
1053 if (class_name.IsNull()) { 1074 if (class_name.IsNull()) {
1054 const char* format = "Unable to find entrypoint: %s()"; 1075 const char* format = "Unable to find entrypoint: %s()";
1055 intptr_t length = OS::SNPrint(NULL, 0, format, function_name.ToCString()); 1076 intptr_t length = OS::SNPrint(NULL, 0, format, function_name.ToCString());
1056 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); 1077 msg = reinterpret_cast<char*>(Api::Allocate(length + 1));
1057 OS::SNPrint(msg, (length + 1), format, function_name.ToCString()); 1078 OS::SNPrint(msg, (length + 1), format, function_name.ToCString());
1058 } else { 1079 } else {
1059 const char* format = "Unable to find entrypoint: static %s.%s()"; 1080 const char* format = "Unable to find entrypoint: static %s.%s()";
1060 intptr_t length = OS::SNPrint(NULL, 0, format, 1081 intptr_t length = OS::SNPrint(NULL, 0, format,
1061 class_name.ToCString(), 1082 class_name.ToCString(),
1062 function_name.ToCString()); 1083 function_name.ToCString());
1063 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); 1084 msg = reinterpret_cast<char*>(Api::Allocate(length + 1));
1064 OS::SNPrint(msg, (length + 1), format, 1085 OS::SNPrint(msg, (length + 1), format,
1065 class_name.ToCString(), function_name.ToCString()); 1086 class_name.ToCString(), function_name.ToCString());
1066 } 1087 }
1067 RETURN_FAILURE(msg); 1088 return Api::Error(msg);
1068 } 1089 }
1069 Dart_Result retval; 1090 Dart_Handle retval;
1070 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1091 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1071 for (int i = 0; i < number_of_arguments; i++) { 1092 for (int i = 0; i < number_of_arguments; i++) {
1072 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1093 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1073 dart_arguments.Add(&arg); 1094 dart_arguments.Add(&arg);
1074 } 1095 }
1075 InvokeStatic(function, dart_arguments, &retval); 1096 InvokeStatic(function, dart_arguments, &retval);
1076 return retval; 1097 return retval;
1077 } 1098 }
1078 1099
1079 1100
1080 DART_EXPORT Dart_Result Dart_InvokeDynamic(Dart_Handle object, 1101 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object,
1081 Dart_Handle function_name, 1102 Dart_Handle function_name,
1082 int number_of_arguments, 1103 int number_of_arguments,
1083 Dart_Handle* arguments) { 1104 Dart_Handle* arguments) {
1084 Zone zone; // Setup a VM zone as we are creating some handles. 1105 Zone zone; // Setup a VM zone as we are creating some handles.
1085 HandleScope scope; // Setup a VM handle scope. 1106 HandleScope scope; // Setup a VM handle scope.
1086 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1107 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1087 // Let the resolver figure out the correct target for null receiver. 1108 // Let the resolver figure out the correct target for null receiver.
1088 // E.g., (null).toString() should execute correctly. 1109 // E.g., (null).toString() should execute correctly.
1089 if (!obj.IsNull() && !obj.IsInstance()) { 1110 if (!obj.IsNull() && !obj.IsInstance()) {
1090 RETURN_FAILURE("Invalid receiver (not instance) passed to invoke dynamic"); 1111 return Api::Error(
1112 "Invalid receiver (not instance) passed to invoke dynamic");
1091 } 1113 }
1092 if (function_name == NULL) { 1114 if (function_name == NULL) {
1093 RETURN_FAILURE("Invalid function name specified"); 1115 return Api::Error("Invalid function name specified");
1094 } 1116 }
1095 ASSERT(ClassFinalizer::AllClassesFinalized()); 1117 ASSERT(ClassFinalizer::AllClassesFinalized());
1096 1118
1097 // Now try to resolve and invoke the dynamic function on this object. 1119 // Now try to resolve and invoke the dynamic function on this object.
1098 Instance& receiver = Instance::Handle(); 1120 Instance& receiver = Instance::Handle();
1099 receiver ^= obj.raw(); 1121 receiver ^= obj.raw();
1100 const String& name = String::CheckedHandle(Api::UnwrapHandle(function_name)); 1122 const String& name = String::CheckedHandle(Api::UnwrapHandle(function_name));
1101 const Function& function = Function::Handle( 1123 const Function& function = Function::Handle(
1102 Resolver::ResolveDynamic(receiver, 1124 Resolver::ResolveDynamic(receiver,
1103 name, 1125 name,
1104 (number_of_arguments + 1), 1126 (number_of_arguments + 1),
1105 0)); // Named args not yet supported in API. 1127 0)); // Named args not yet supported in API.
1106 if (function.IsNull()) { 1128 if (function.IsNull()) {
1107 // TODO(5415268): Invoke noSuchMethod instead of failing. 1129 // TODO(5415268): Invoke noSuchMethod instead of failing.
1108 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); 1130 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString());
1109 RETURN_FAILURE("Unable to find instance function"); 1131 return Api::Error("Unable to find instance function");
1110 } 1132 }
1111 Dart_Result retval; 1133 Dart_Handle retval;
1112 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1134 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1113 for (int i = 0; i < number_of_arguments; i++) { 1135 for (int i = 0; i < number_of_arguments; i++) {
1114 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1136 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1115 dart_arguments.Add(&arg); 1137 dart_arguments.Add(&arg);
1116 } 1138 }
1117 InvokeDynamic(receiver, function, dart_arguments, &retval); 1139 InvokeDynamic(receiver, function, dart_arguments, &retval);
1118 return retval; 1140 return retval;
1119 } 1141 }
1120 1142
1121 1143
1122 DART_EXPORT Dart_Result Dart_InvokeClosure(Dart_Handle closure, 1144 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
1123 int number_of_arguments, 1145 int number_of_arguments,
1124 Dart_Handle* arguments) { 1146 Dart_Handle* arguments) {
1125 Zone zone; // Setup a VM zone as we are creating some handles. 1147 Zone zone; // Setup a VM zone as we are creating some handles.
1126 HandleScope scope; // Setup a VM handle scope. 1148 HandleScope scope; // Setup a VM handle scope.
1127 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); 1149 const Object& obj = Object::Handle(Api::UnwrapHandle(closure));
1128 if (obj.IsNull()) { 1150 if (obj.IsNull()) {
1129 RETURN_FAILURE("Null object passed in to invoke closure"); 1151 return Api::Error("Null object passed in to invoke closure");
1130 } 1152 }
1131 if (!obj.IsClosure()) { 1153 if (!obj.IsClosure()) {
1132 RETURN_FAILURE("Invalid closure passed to invoke closure"); 1154 return Api::Error("Invalid closure passed to invoke closure");
1133 } 1155 }
1134 ASSERT(ClassFinalizer::AllClassesFinalized()); 1156 ASSERT(ClassFinalizer::AllClassesFinalized());
1135 1157
1136 // Now try to invoke the closure. 1158 // Now try to invoke the closure.
1137 Closure& closure_obj = Closure::Handle(); 1159 Closure& closure_obj = Closure::Handle();
1138 closure_obj ^= obj.raw(); 1160 closure_obj ^= obj.raw();
1139 Dart_Result retval; 1161 Dart_Handle retval;
1140 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1162 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1141 for (int i = 0; i < number_of_arguments; i++) { 1163 for (int i = 0; i < number_of_arguments; i++) {
1142 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1164 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1143 dart_arguments.Add(&arg); 1165 dart_arguments.Add(&arg);
1144 } 1166 }
1145 InvokeClosure(closure_obj, dart_arguments, &retval); 1167 InvokeClosure(closure_obj, dart_arguments, &retval);
1146 return retval; 1168 return retval;
1147 } 1169 }
1148 1170
1149 1171
(...skipping 23 matching lines...) Expand all
1173 1195
1174 1196
1175 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle result) { 1197 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle result) {
1176 Zone zone; // Setup a VM zone as we are creating some handles. 1198 Zone zone; // Setup a VM zone as we are creating some handles.
1177 HandleScope scope; // Setup a VM handle scope. 1199 HandleScope scope; // Setup a VM handle scope.
1178 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); 1200 const Object& retval = Object::Handle(Api::UnwrapHandle(result));
1179 return retval.IsUnhandledException(); 1201 return retval.IsUnhandledException();
1180 } 1202 }
1181 1203
1182 1204
1183 DART_EXPORT Dart_Result Dart_GetException(Dart_Handle result) { 1205 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle result) {
1184 Zone zone; // Setup a VM zone as we are creating some handles. 1206 Zone zone; // Setup a VM zone as we are creating some handles.
1185 HandleScope scope; // Setup a VM handle scope. 1207 HandleScope scope; // Setup a VM handle scope.
1186 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); 1208 const Object& retval = Object::Handle(Api::UnwrapHandle(result));
1187 if (retval.IsUnhandledException()) { 1209 if (retval.IsUnhandledException()) {
1188 const UnhandledException& unhandled = UnhandledException::Handle( 1210 const UnhandledException& unhandled = UnhandledException::Handle(
1189 reinterpret_cast<RawUnhandledException*>(retval.raw())); 1211 reinterpret_cast<RawUnhandledException*>(retval.raw()));
1190 const Object& exception = Object::Handle(unhandled.exception()); 1212 const Object& exception = Object::Handle(unhandled.exception());
1191 RETURN_OBJECT(exception); 1213 return Api::NewLocalHandle(exception);
1192 } 1214 }
1193 RETURN_FAILURE("Object is not an unhandled exception object"); 1215 return Api::Error("Object is not an unhandled exception object");
1194 } 1216 }
1195 1217
1196 1218
1197 DART_EXPORT Dart_Result Dart_GetStacktrace(Dart_Handle unhandled_excp) { 1219 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle unhandled_excp) {
1198 Zone zone; // Setup a VM zone as we are creating some handles. 1220 Zone zone; // Setup a VM zone as we are creating some handles.
1199 HandleScope scope; // Setup a VM handle scope. 1221 HandleScope scope; // Setup a VM handle scope.
1200 const Object& retval = Object::Handle(Api::UnwrapHandle(unhandled_excp)); 1222 const Object& retval = Object::Handle(Api::UnwrapHandle(unhandled_excp));
1201 if (retval.IsUnhandledException()) { 1223 if (retval.IsUnhandledException()) {
1202 const UnhandledException& unhandled = UnhandledException::Handle( 1224 const UnhandledException& unhandled = UnhandledException::Handle(
1203 reinterpret_cast<RawUnhandledException*>(retval.raw())); 1225 reinterpret_cast<RawUnhandledException*>(retval.raw()));
1204 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); 1226 const Object& stacktrace = Object::Handle(unhandled.stacktrace());
1205 RETURN_OBJECT(stacktrace); 1227 return Api::NewLocalHandle(stacktrace);
1206 } 1228 }
1207 RETURN_FAILURE("Object is not an unhandled exception object"); 1229 return Api::Error("Object is not an unhandled exception object");
1208 } 1230 }
1209 1231
1210 1232
1211 DART_EXPORT Dart_Result Dart_ThrowException(Dart_Handle exception) { 1233 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
1212 Isolate* isolate = Isolate::Current(); 1234 Isolate* isolate = Isolate::Current();
1213 ASSERT(isolate != NULL); 1235 ASSERT(isolate != NULL);
1214 Zone zone; // Setup a VM zone as we are creating some handles. 1236 Zone zone; // Setup a VM zone as we are creating some handles.
1215 HandleScope scope; // Setup a VM handle scope. 1237 HandleScope scope; // Setup a VM handle scope.
1216 if (isolate->top_exit_frame_info() == 0) { 1238 if (isolate->top_exit_frame_info() == 0) {
1217 // There are no dart frames on the stack so it would be illegal to 1239 // There are no dart frames on the stack so it would be illegal to
1218 // throw an exception here. 1240 // throw an exception here.
1219 RETURN_FAILURE("No Dart frames on stack, cannot throw exception"); 1241 return Api::Error("No Dart frames on stack, cannot throw exception");
1220 } 1242 }
1221 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); 1243 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
1222 // Unwind all the API scopes till the exit frame before throwing an 1244 // Unwind all the API scopes till the exit frame before throwing an
1223 // exception. 1245 // exception.
1224 ApiState* state = isolate->api_state(); 1246 ApiState* state = isolate->api_state();
1225 ASSERT(state != NULL); 1247 ASSERT(state != NULL);
1226 state->UnwindScopes(isolate->top_exit_frame_info()); 1248 state->UnwindScopes(isolate->top_exit_frame_info());
1227 Exceptions::Throw(excp); 1249 Exceptions::Throw(excp);
1228 RETURN_FAILURE("Exception was not thrown, internal error"); 1250 return Api::Error("Exception was not thrown, internal error");
1229 } 1251 }
1230 1252
1231 1253
1232 DART_EXPORT Dart_Result Dart_ReThrowException(Dart_Handle exception, 1254 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
1233 Dart_Handle stacktrace) { 1255 Dart_Handle stacktrace) {
1234 Isolate* isolate = Isolate::Current(); 1256 Isolate* isolate = Isolate::Current();
1235 ASSERT(isolate != NULL); 1257 ASSERT(isolate != NULL);
1236 if (isolate->top_exit_frame_info() == 0) { 1258 if (isolate->top_exit_frame_info() == 0) {
1237 // There are no dart frames on the stack so it would be illegal to 1259 // There are no dart frames on the stack so it would be illegal to
1238 // throw an exception here. 1260 // throw an exception here.
1239 RETURN_FAILURE("No Dart frames on stack, cannot throw exception"); 1261 return Api::Error("No Dart frames on stack, cannot throw exception");
1240 } 1262 }
1241 Zone zone; // Setup a VM zone as we are creating some handles. 1263 Zone zone; // Setup a VM zone as we are creating some handles.
1242 HandleScope scope; // Setup a VM handle scope. 1264 HandleScope scope; // Setup a VM handle scope.
1243 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); 1265 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
1244 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace)); 1266 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace));
1245 // Unwind all the API scopes till the exit frame before throwing an 1267 // Unwind all the API scopes till the exit frame before throwing an
1246 // exception. 1268 // exception.
1247 ApiState* state = isolate->api_state(); 1269 ApiState* state = isolate->api_state();
1248 ASSERT(state != NULL); 1270 ASSERT(state != NULL);
1249 state->UnwindScopes(isolate->top_exit_frame_info()); 1271 state->UnwindScopes(isolate->top_exit_frame_info());
1250 Exceptions::ReThrow(excp, stk); 1272 Exceptions::ReThrow(excp, stk);
1251 RETURN_FAILURE("Exception was not re thrown, internal error"); 1273 return Api::Error("Exception was not re thrown, internal error");
1252 } 1274 }
1253 1275
1254 1276
1255 DART_EXPORT void Dart_EnterScope() { 1277 DART_EXPORT void Dart_EnterScope() {
1256 Isolate* isolate = Isolate::Current(); 1278 Isolate* isolate = Isolate::Current();
1257 ASSERT(isolate != NULL); 1279 ASSERT(isolate != NULL);
1258 ApiState* state = isolate->api_state(); 1280 ApiState* state = isolate->api_state();
1259 ASSERT(state != NULL); 1281 ASSERT(state != NULL);
1260 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(), 1282 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(),
1261 reinterpret_cast<uword>(&state)); 1283 reinterpret_cast<uword>(&state));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 return NULL; 1321 return NULL;
1300 } 1322 }
1301 1323
1302 1324
1303 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { 1325 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
1304 Isolate* isolate = Isolate::Current(); 1326 Isolate* isolate = Isolate::Current();
1305 ASSERT(isolate != NULL); 1327 ASSERT(isolate != NULL);
1306 ApiState* state = isolate->api_state(); 1328 ApiState* state = isolate->api_state();
1307 ASSERT(state != NULL); 1329 ASSERT(state != NULL);
1308 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); 1330 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
1309 ref->FreeHandle(state->persistent_handles().free_list()); 1331 state->persistent_handles().FreeHandle(ref);
1310 state->persistent_handles().set_free_list(ref);
1311 } 1332 }
1312 1333
1313 1334
1314 static const bool kGetter = true; 1335 static const bool kGetter = true;
1315 static const bool kSetter = false; 1336 static const bool kSetter = false;
1316 1337
1317 1338
1318 static bool UseGetterForStaticField(const Field& fld) { 1339 static bool UseGetterForStaticField(const Field& fld) {
1319 if (fld.IsNull()) { 1340 if (fld.IsNull()) {
1320 return true; 1341 return true;
1321 } 1342 }
1322 1343
1323 // Return getter method for uninitialized fields, rather than the 1344 // Return getter method for uninitialized fields, rather than the
1324 // field object, since the value in the field object will not be 1345 // field object, since the value in the field object will not be
1325 // initialized until the first time the getter is invoked. 1346 // initialized until the first time the getter is invoked.
1326 const Instance& value = Instance::Handle(fld.value()); 1347 const Instance& value = Instance::Handle(fld.value());
1327 ASSERT(value.raw() != Object::transition_sentinel()); 1348 ASSERT(value.raw() != Object::transition_sentinel());
1328 return value.raw() == Object::sentinel(); 1349 return value.raw() == Object::sentinel();
1329 } 1350 }
1330 1351
1331 1352
1332 static Dart_Result LookupStaticField(Dart_Handle clazz, 1353 static Dart_Handle LookupStaticField(Dart_Handle clazz,
1333 Dart_Handle field_name, 1354 Dart_Handle field_name,
1334 bool is_getter) { 1355 bool is_getter) {
1335 const Object& param1 = Object::Handle(Api::UnwrapHandle(clazz)); 1356 const Object& param1 = Object::Handle(Api::UnwrapHandle(clazz));
1336 const Object& param2 = Object::Handle(Api::UnwrapHandle(field_name)); 1357 const Object& param2 = Object::Handle(Api::UnwrapHandle(field_name));
1337 if (param1.IsNull() || !param1.IsClass()) { 1358 if (param1.IsNull() || !param1.IsClass()) {
1338 RETURN_FAILURE("Invalid class specified"); 1359 return Api::Error("Invalid class specified");
1339 } 1360 }
1340 if (param2.IsNull() || !param2.IsString()) { 1361 if (param2.IsNull() || !param2.IsString()) {
1341 RETURN_FAILURE("Invalid field name specified"); 1362 return Api::Error("Invalid field name specified");
1342 } 1363 }
1343 Class& cls = Class::Handle(); 1364 Class& cls = Class::Handle();
1344 cls ^= param1.raw(); 1365 cls ^= param1.raw();
1345 String& fld_name = String::Handle(); 1366 String& fld_name = String::Handle();
1346 fld_name ^= param2.raw(); 1367 fld_name ^= param2.raw();
1347 const Field& fld = Field::Handle(cls.LookupStaticField(fld_name)); 1368 const Field& fld = Field::Handle(cls.LookupStaticField(fld_name));
1348 if (is_getter && UseGetterForStaticField(fld)) { 1369 if (is_getter && UseGetterForStaticField(fld)) {
1349 const String& func_name = String::Handle(Field::GetterName(fld_name)); 1370 const String& func_name = String::Handle(Field::GetterName(fld_name));
1350 const Function& function = 1371 const Function& function =
1351 Function::Handle(cls.LookupStaticFunction(func_name)); 1372 Function::Handle(cls.LookupStaticFunction(func_name));
1352 if (!function.IsNull()) { 1373 if (!function.IsNull()) {
1353 RETURN_OBJECT(function); 1374 return Api::NewLocalHandle(function);
1354 } 1375 }
1355 RETURN_FAILURE("Specified field is not found in the class"); 1376 return Api::Error("Specified field is not found in the class");
1356 } 1377 }
1357 if (fld.IsNull()) { 1378 if (fld.IsNull()) {
1358 RETURN_FAILURE("Specified field is not found in the class"); 1379 return Api::Error("Specified field is not found in the class");
1359 } 1380 }
1360 RETURN_OBJECT(fld); 1381 return Api::NewLocalHandle(fld);
1361 } 1382 }
1362 1383
1363 1384
1364 static Dart_Result LookupInstanceField(const Object& object, 1385 static Dart_Handle LookupInstanceField(const Object& object,
1365 Dart_Handle name, 1386 Dart_Handle name,
1366 bool is_getter) { 1387 bool is_getter) {
1367 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 1388 const Object& param = Object::Handle(Api::UnwrapHandle(name));
1368 if (param.IsNull() || !param.IsString()) { 1389 if (param.IsNull() || !param.IsString()) {
1369 RETURN_FAILURE("Invalid field name specified"); 1390 return Api::Error("Invalid field name specified");
1370 } 1391 }
1371 String& field_name = String::Handle(); 1392 String& field_name = String::Handle();
1372 field_name ^= param.raw(); 1393 field_name ^= param.raw();
1373 String& func_name = String::Handle(); 1394 String& func_name = String::Handle();
1374 Field& fld = Field::Handle(); 1395 Field& fld = Field::Handle();
1375 Class& cls = Class::Handle(object.clazz()); 1396 Class& cls = Class::Handle(object.clazz());
1376 while (!cls.IsNull()) { 1397 while (!cls.IsNull()) {
1377 fld = cls.LookupInstanceField(field_name); 1398 fld = cls.LookupInstanceField(field_name);
1378 if (!fld.IsNull()) { 1399 if (!fld.IsNull()) {
1379 if (!is_getter && fld.is_final()) { 1400 if (!is_getter && fld.is_final()) {
1380 RETURN_FAILURE("Cannot set value of final fields"); 1401 return Api::Error("Cannot set value of final fields");
1381 } 1402 }
1382 func_name = is_getter ? Field::GetterName(field_name) : 1403 func_name = (is_getter
1383 Field::SetterName(field_name); 1404 ? Field::GetterName(field_name)
1405 : Field::SetterName(field_name));
1384 const Function& function = Function::Handle( 1406 const Function& function = Function::Handle(
1385 cls.LookupDynamicFunction(func_name)); 1407 cls.LookupDynamicFunction(func_name));
1386 if (function.IsNull()) { 1408 if (function.IsNull()) {
1387 RETURN_FAILURE("Unable to find accessor function in the class"); 1409 return Api::Error("Unable to find accessor function in the class");
1388 } 1410 }
1389 RETURN_OBJECT(function); 1411 return Api::NewLocalHandle(function);
1390 } 1412 }
1391 cls = cls.SuperClass(); 1413 cls = cls.SuperClass();
1392 } 1414 }
1393 RETURN_FAILURE("Unable to find field in the class"); 1415 return Api::Error("Unable to find field in the class");
1394 } 1416 }
1395 1417
1396 1418
1397 DART_EXPORT Dart_Result Dart_GetStaticField(Dart_Handle cls, 1419 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls,
1398 Dart_Handle name) { 1420 Dart_Handle name) {
1399 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.
1400 HandleScope scope; // Setup a VM handle scope. 1422 HandleScope scope; // Setup a VM handle scope.
1401 Dart_Result result = LookupStaticField(cls, name, kGetter); 1423 Dart_Handle result = LookupStaticField(cls, name, kGetter);
1402 if (!::Dart_IsValidResult(result)) { 1424 if (!::Dart_IsValid(result)) {
1403 return result; 1425 return result;
1404 } 1426 }
1405 Object& retval = Object::Handle(); 1427 Object& retval = Object::Handle();
1406 const Object& obj = Object::Handle(Api::UnwrapHandle(Dart_GetResult(result))); 1428 const Object& obj = Object::Handle(Api::UnwrapHandle(result));
1407 if (obj.IsField()) { 1429 if (obj.IsField()) {
1408 Field& fld = Field::Handle(); 1430 Field& fld = Field::Handle();
1409 fld ^= obj.raw(); 1431 fld ^= obj.raw();
1410 retval = fld.value(); 1432 retval = fld.value();
1411 RETURN_OBJECT(retval); 1433 return Api::NewLocalHandle(retval);
1412 } else { 1434 } else {
1413 Function& func = Function::Handle(); 1435 Function& func = Function::Handle();
1414 func ^= obj.raw(); 1436 func ^= obj.raw();
1415 GrowableArray<const Object*> args; 1437 GrowableArray<const Object*> args;
1416 InvokeStatic(func, args, &result); 1438 InvokeStatic(func, args, &result);
1417 if (::Dart_IsValidResult(result)) { 1439 if (::Dart_IsValid(result)) {
1418 Dart_Handle result_obj = Dart_GetResult(result); 1440 if (Dart_ExceptionOccurred(result)) {
1419 if (Dart_ExceptionOccurred(result_obj)) { 1441 return Api::Error(
1420 RETURN_FAILURE("An exception occurred when getting the static field"); 1442 "An exception occurred when getting the static field");
1421 } 1443 }
1422 } 1444 }
1423 return result; 1445 return result;
1424 } 1446 }
1425 } 1447 }
1426 1448
1427 1449
1428 // 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.
1429 DART_EXPORT Dart_Result Dart_SetStaticField(Dart_Handle cls, 1451 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls,
1430 Dart_Handle name, 1452 Dart_Handle name,
1431 Dart_Handle value) { 1453 Dart_Handle value) {
1432 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.
1433 HandleScope scope; // Setup a VM handle scope. 1455 HandleScope scope; // Setup a VM handle scope.
1434 Dart_Result result = LookupStaticField(cls, name, kSetter); 1456 Dart_Handle result = LookupStaticField(cls, name, kSetter);
1435 if (!::Dart_IsValidResult(result)) { 1457 if (!::Dart_IsValid(result)) {
1436 return result; 1458 return result;
1437 } 1459 }
1438 Field& fld = Field::Handle(); 1460 Field& fld = Field::Handle();
1439 fld ^= Api::UnwrapHandle(Dart_GetResult(result)); 1461 fld ^= Api::UnwrapHandle(result);
1440 if (fld.is_final()) { 1462 if (fld.is_final()) {
1441 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");
1442 } 1464 }
1443 const Object& val = Object::Handle(Api::UnwrapHandle(value)); 1465 const Object& val = Object::Handle(Api::UnwrapHandle(value));
1444 Instance& instance = Instance::Handle(); 1466 Instance& instance = Instance::Handle();
1445 instance ^= val.raw(); 1467 instance ^= val.raw();
1446 fld.set_value(instance); 1468 fld.set_value(instance);
1447 RETURN_OBJECT(val); 1469 return Api::NewLocalHandle(val);
1448 } 1470 }
1449 1471
1450 1472
1451 DART_EXPORT Dart_Result Dart_GetInstanceField(Dart_Handle obj, 1473 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj,
1452 Dart_Handle name) { 1474 Dart_Handle name) {
1453 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.
1454 HandleScope scope; // Setup a VM handle scope. 1476 HandleScope scope; // Setup a VM handle scope.
1455 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1477 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1456 if (param.IsNull() || !param.IsInstance()) { 1478 if (param.IsNull() || !param.IsInstance()) {
1457 RETURN_FAILURE("Invalid object passed in to access instance field"); 1479 return Api::Error("Invalid object passed in to access instance field");
1458 } 1480 }
1459 Instance& object = Instance::Handle(); 1481 Instance& object = Instance::Handle();
1460 object ^= param.raw(); 1482 object ^= param.raw();
1461 Dart_Result result = LookupInstanceField(object, name, kGetter); 1483 Dart_Handle result = LookupInstanceField(object, name, kGetter);
1462 if (!::Dart_IsValidResult(result)) { 1484 if (!::Dart_IsValid(result)) {
1463 return result; 1485 return result;
1464 } 1486 }
1465 Function& func = Function::Handle(); 1487 Function& func = Function::Handle();
1466 func ^= Api::UnwrapHandle(Dart_GetResult(result)); 1488 func ^= Api::UnwrapHandle(result);
1467 GrowableArray<const Object*> arguments; 1489 GrowableArray<const Object*> arguments;
1468 InvokeDynamic(object, func, arguments, &result); 1490 InvokeDynamic(object, func, arguments, &result);
1469 if (::Dart_IsValidResult(result)) { 1491 if (::Dart_IsValid(result)) {
1470 Dart_Handle result_obj = Dart_GetResult(result); 1492 if (Dart_ExceptionOccurred(result)) {
1471 if (Dart_ExceptionOccurred(result_obj)) { 1493 return Api::Error(
1472 RETURN_FAILURE("An exception occurred when accessing the instance field"); 1494 "An exception occurred when accessing the instance field");
1473 } 1495 }
1474 } 1496 }
1475 return result; 1497 return result;
1476 } 1498 }
1477 1499
1478 1500
1479 DART_EXPORT Dart_Result Dart_SetInstanceField(Dart_Handle obj, 1501 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj,
1480 Dart_Handle name, 1502 Dart_Handle name,
1481 Dart_Handle value) { 1503 Dart_Handle value) {
1482 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.
1483 HandleScope scope; // Setup a VM handle scope. 1505 HandleScope scope; // Setup a VM handle scope.
1484 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1506 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1485 if (param.IsNull() || !param.IsInstance()) { 1507 if (param.IsNull() || !param.IsInstance()) {
1486 RETURN_FAILURE("Invalid object passed in to access instance field"); 1508 return Api::Error("Invalid object passed in to access instance field");
1487 } 1509 }
1488 Instance& object = Instance::Handle(); 1510 Instance& object = Instance::Handle();
1489 object ^= param.raw(); 1511 object ^= param.raw();
1490 Dart_Result result = LookupInstanceField(object, name, kSetter); 1512 Dart_Handle result = LookupInstanceField(object, name, kSetter);
1491 if (!::Dart_IsValidResult(result)) { 1513 if (!::Dart_IsValid(result)) {
1492 return result; 1514 return result;
1493 } 1515 }
1494 Function& func = Function::Handle(); 1516 Function& func = Function::Handle();
1495 func ^= Api::UnwrapHandle(Dart_GetResult(result)); 1517 func ^= Api::UnwrapHandle(result);
1496 GrowableArray<const Object*> arguments(1); 1518 GrowableArray<const Object*> arguments(1);
1497 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); 1519 const Object& arg = Object::Handle(Api::UnwrapHandle(value));
1498 arguments.Add(&arg); 1520 arguments.Add(&arg);
1499 InvokeDynamic(object, func, arguments, &result); 1521 InvokeDynamic(object, func, arguments, &result);
1500 if (::Dart_IsValidResult(result)) { 1522 if (::Dart_IsValid(result)) {
1501 Dart_Handle result_obj = Dart_GetResult(result); 1523 if (Dart_ExceptionOccurred(result)) {
1502 if (Dart_ExceptionOccurred(result_obj)) { 1524 return Api::Error(
1503 RETURN_FAILURE("An exception occurred when setting the instance field"); 1525 "An exception occurred when setting the instance field");
1504 } 1526 }
1505 } 1527 }
1506 return result; 1528 return result;
1507 } 1529 }
1508 1530
1509 1531
1510 DART_EXPORT Dart_Result Dart_CreateNativeWrapperClass(Dart_Handle library, 1532 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library,
1511 Dart_Handle name, 1533 Dart_Handle name,
1512 int field_count) { 1534 int field_count) {
1513 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.
1514 HandleScope scope; // Setup a VM handle scope. 1536 HandleScope scope; // Setup a VM handle scope.
1515 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 1537 const Object& param = Object::Handle(Api::UnwrapHandle(name));
1516 if (param.IsNull() || !param.IsString() || field_count <= 0) { 1538 if (param.IsNull() || !param.IsString() || field_count <= 0) {
1517 RETURN_FAILURE("Invalid arguments passed to Dart_CreateNativeWrapperClass"); 1539 return Api::Error(
1540 "Invalid arguments passed to Dart_CreateNativeWrapperClass");
1518 } 1541 }
1519 String& cls_name = String::Handle(); 1542 String& cls_name = String::Handle();
1520 cls_name ^= param.raw(); 1543 cls_name ^= param.raw();
1521 cls_name = String::NewSymbol(cls_name); 1544 cls_name = String::NewSymbol(cls_name);
1522 Library& lib = Library::Handle(); 1545 Library& lib = Library::Handle();
1523 lib ^= Api::UnwrapHandle(library); 1546 lib ^= Api::UnwrapHandle(library);
1524 if (lib.IsNull()) { 1547 if (lib.IsNull()) {
1525 RETURN_FAILURE("Invalid arguments passed to Dart_CreateNativeWrapperClass"); 1548 return Api::Error(
1549 "Invalid arguments passed to Dart_CreateNativeWrapperClass");
1526 } 1550 }
1527 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib, 1551 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib,
1528 cls_name, 1552 cls_name,
1529 field_count)); 1553 field_count));
1530 if (cls.IsNull()) { 1554 if (cls.IsNull()) {
1531 RETURN_FAILURE("Unable to create native wrapper class : already exists"); 1555 return Api::Error(
1556 "Unable to create native wrapper class : already exists");
1532 } 1557 }
1533 RETURN_OBJECT(cls); 1558 return Api::NewLocalHandle(cls);
1534 } 1559 }
1535 1560
1536 1561
1537 DART_EXPORT Dart_Result Dart_GetNativeInstanceField(Dart_Handle obj, 1562 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj,
1538 int index) { 1563 int index,
1564 intptr_t* value) {
1539 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.
1540 HandleScope scope; // Setup a VM handle scope. 1566 HandleScope scope; // Setup a VM handle scope.
1541 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1567 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1542 if (param.IsNull() || !param.IsInstance()) { 1568 if (param.IsNull() || !param.IsInstance()) {
1543 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");
1544 } 1571 }
1545 Instance& object = Instance::Handle(); 1572 Instance& object = Instance::Handle();
1546 object ^= param.raw(); 1573 object ^= param.raw();
1547 if (!object.IsValidNativeIndex(index)) { 1574 if (!object.IsValidNativeIndex(index)) {
1548 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");
1549 } 1577 }
1550 RETURN_CINT(object.GetNativeField(index)); 1578 *value = object.GetNativeField(index);
1579 return Api::Success();
1551 } 1580 }
1552 1581
1553 1582
1554 DART_EXPORT Dart_Result Dart_SetNativeInstanceField(Dart_Handle obj, 1583 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj,
1555 int index, 1584 int index,
1556 intptr_t value) { 1585 intptr_t value) {
1557 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.
1558 HandleScope scope; // Setup a VM handle scope. 1587 HandleScope scope; // Setup a VM handle scope.
1559 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1588 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1560 if (param.IsNull() || !param.IsInstance()) { 1589 if (param.IsNull() || !param.IsInstance()) {
1561 RETURN_FAILURE("Invalid object passed in to set native instance field"); 1590 return Api::Error("Invalid object passed in to set native instance field");
1562 } 1591 }
1563 Instance& object = Instance::Handle(); 1592 Instance& object = Instance::Handle();
1564 object ^= param.raw(); 1593 object ^= param.raw();
1565 if (!object.IsValidNativeIndex(index)) { 1594 if (!object.IsValidNativeIndex(index)) {
1566 RETURN_FAILURE("Invalid index passed in to set native instance field"); 1595 return Api::Error("Invalid index passed in to set native instance field");
1567 } 1596 }
1568 object.SetNativeField(index, value); 1597 object.SetNativeField(index, value);
1569 RETURN_CINT(value); 1598 return Api::Success();
1570 } 1599 }
1571 1600
1572 1601
1573 static uint8_t* ApiAllocator(uint8_t* ptr, 1602 static uint8_t* ApiAllocator(uint8_t* ptr,
1574 intptr_t old_size, 1603 intptr_t old_size,
1575 intptr_t new_size) { 1604 intptr_t new_size) {
1576 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr), 1605 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr),
1577 old_size, 1606 old_size,
1578 new_size); 1607 new_size);
1579 return reinterpret_cast<uint8_t*>(new_ptr); 1608 return reinterpret_cast<uint8_t*>(new_ptr);
1580 } 1609 }
1581 1610
1582 1611
1583 DART_EXPORT Dart_Result Dart_CreateSnapshot(uint8_t** snapshot_buffer, 1612 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snapshot_buffer,
1584 intptr_t* snapshot_size) { 1613 intptr_t* snapshot_size) {
1585 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.
1586 HandleScope scope; // Setup a VM handle scope. 1615 HandleScope scope; // Setup a VM handle scope.
1587 if (snapshot_buffer == NULL || snapshot_size == NULL) { 1616 if (snapshot_buffer == NULL || snapshot_size == NULL) {
1588 RETURN_FAILURE("Invalid input parameters to Dart_CreateSnapshot"); 1617 return Api::Error("Invalid input parameters to Dart_CreateSnapshot");
1589 } 1618 }
1590 const char* msg = CheckIsolateState(); 1619 const char* msg = CheckIsolateState();
1591 if (msg != NULL) { 1620 if (msg != NULL) {
1592 RETURN_FAILURE(msg); 1621 return Api::Error(msg);
1593 } 1622 }
1594 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator); 1623 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator);
1595 writer.WriteFullSnapshot(); 1624 writer.WriteFullSnapshot();
1596 *snapshot_size = writer.Size(); 1625 *snapshot_size = writer.Size();
1597 RETURN_CBOOLEAN(true); 1626 return Api::Success();
1598 } 1627 }
1599 1628
1600 1629
1601 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) {
1602 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 1631 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
1603 return reinterpret_cast<uint8_t*>(new_ptr); 1632 return reinterpret_cast<uint8_t*>(new_ptr);
1604 } 1633 }
1605 1634
1606 1635
1607 DART_EXPORT Dart_Result Dart_PostIntArray(Dart_Port port, 1636 DART_EXPORT bool Dart_PostIntArray(Dart_Port port,
1608 int field_count, 1637 int field_count,
1609 intptr_t* data) { 1638 intptr_t* data) {
1610 uint8_t* buffer = NULL; 1639 uint8_t* buffer = NULL;
1611 MessageWriter writer(&buffer, &allocator); 1640 MessageWriter writer(&buffer, &allocator);
1612 1641
1613 writer.WriteMessage(field_count, data); 1642 writer.WriteMessage(field_count, data);
1614 1643
1615 // Post the message at the given port. 1644 // Post the message at the given port.
1616 bool result = PortMap::PostMessage(port, kNoReplyPort, buffer); 1645 return PortMap::PostMessage(port, kNoReplyPort, buffer);
1617 RETURN_CBOOLEAN(result);
1618 } 1646 }
1619 1647
1620 1648
1621 DART_EXPORT Dart_Result Dart_Post(Dart_Port port, Dart_Handle handle) { 1649 DART_EXPORT bool Dart_Post(Dart_Port port, Dart_Handle handle) {
1622 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.
1623 HandleScope scope; // Setup a VM handle scope. 1651 HandleScope scope; // Setup a VM handle scope.
1624 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); 1652 const Object& object = Object::Handle(Api::UnwrapHandle(handle));
1625 uint8_t* data = NULL; 1653 uint8_t* data = NULL;
1626 SnapshotWriter writer(false, &data, &allocator); 1654 SnapshotWriter writer(false, &data, &allocator);
1627 writer.WriteObject(object.raw()); 1655 writer.WriteObject(object.raw());
1628 writer.FinalizeBuffer(); 1656 writer.FinalizeBuffer();
1629 bool result = PortMap::PostMessage(port, kNoReplyPort, data); 1657 return PortMap::PostMessage(port, kNoReplyPort, data);
1630 RETURN_CBOOLEAN(result);
1631 } 1658 }
1632 1659
1633 1660
1634 DART_EXPORT void Dart_InitPprofSupport() { 1661 DART_EXPORT void Dart_InitPprofSupport() {
1635 DebugInfo* pprof_symbol_generator = DebugInfo::NewGenerator(); 1662 DebugInfo* pprof_symbol_generator = DebugInfo::NewGenerator();
1636 ASSERT(pprof_symbol_generator != NULL); 1663 ASSERT(pprof_symbol_generator != NULL);
1637 Dart::set_pprof_symbol_generator(pprof_symbol_generator); 1664 Dart::set_pprof_symbol_generator(pprof_symbol_generator);
1638 } 1665 }
1639 1666
1640 1667
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 } 1731 }
1705 1732
1706 1733
1707 PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state, 1734 PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state,
1708 Dart_Handle object) { 1735 Dart_Handle object) {
1709 ASSERT(state.IsValidPersistentHandle(object)); 1736 ASSERT(state.IsValidPersistentHandle(object));
1710 return reinterpret_cast<PersistentHandle*>(object); 1737 return reinterpret_cast<PersistentHandle*>(object);
1711 } 1738 }
1712 1739
1713 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
1714 uword Api::Allocate(intptr_t size) { 1760 uword Api::Allocate(intptr_t size) {
1715 Isolate* isolate = Isolate::Current(); 1761 Isolate* isolate = Isolate::Current();
1716 ASSERT(isolate != NULL); 1762 ASSERT(isolate != NULL);
1717 ApiState* state = isolate->api_state(); 1763 ApiState* state = isolate->api_state();
1718 ASSERT(state != NULL); 1764 ASSERT(state != NULL);
1719 ApiLocalScope* scope = state->top_scope(); 1765 ApiLocalScope* scope = state->top_scope();
1720 ASSERT(scope != NULL); 1766 ASSERT(scope != NULL);
1721 return scope->zone().Allocate(size); 1767 return scope->zone().Allocate(size);
1722 } 1768 }
1723 1769
1724 1770
1725 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) {
1726 Isolate* isolate = Isolate::Current(); 1772 Isolate* isolate = Isolate::Current();
1727 ASSERT(isolate != NULL); 1773 ASSERT(isolate != NULL);
1728 ApiState* state = isolate->api_state(); 1774 ApiState* state = isolate->api_state();
1729 ASSERT(state != NULL); 1775 ASSERT(state != NULL);
1730 ApiLocalScope* scope = state->top_scope(); 1776 ApiLocalScope* scope = state->top_scope();
1731 ASSERT(scope != NULL); 1777 ASSERT(scope != NULL);
1732 return scope->zone().Reallocate(ptr, old_size, new_size); 1778 return scope->zone().Reallocate(ptr, old_size, new_size);
1733 } 1779 }
1734 1780
1735 1781
1736 } // namespace dart 1782 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698