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

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

Issue 8528010: Changes to pass the current isolate to all runtime and native calls. (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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } else if (tmp.IsApiError()) { \ 48 } else if (tmp.IsApiError()) { \
49 return dart_handle; \ 49 return dart_handle; \
50 } else { \ 50 } else { \
51 return Api::Error("%s expects argument '%s' to be of type %s.", \ 51 return Api::Error("%s expects argument '%s' to be of type %s.", \
52 CURRENT_FUNC, #dart_handle, #Type); \ 52 CURRENT_FUNC, #dart_handle, #Type); \
53 } \ 53 } \
54 } while (0) 54 } while (0)
55 55
56 56
57 DART_EXPORT bool Dart_IsError(const Dart_Handle& handle) { 57 DART_EXPORT bool Dart_IsError(const Dart_Handle& handle) {
58 ASSERT(Isolate::Current() != NULL); 58 DARTSCOPE(Isolate::Current());
59 Zone zone; // Setup a VM zone as we are creating some handles.
60 HandleScope scope; // Setup a VM handle scope.
61 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); 59 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
62 return obj.IsApiError(); 60 return obj.IsApiError();
63 } 61 }
64 62
65 63
66 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { 64 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) {
67 Zone zone; // Setup a VM zone as we are creating some handles. 65 DARTSCOPE(Isolate::Current());
68 HandleScope scope; // Setup a VM handle scope.
69 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); 66 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
70 if (obj.IsApiError()) { 67 if (obj.IsApiError()) {
71 const ApiError& error = ApiError::CheckedHandle(obj.raw()); 68 const ApiError& error = ApiError::CheckedHandle(obj.raw());
72 const Object& data = Object::Handle(error.data()); 69 const Object& data = Object::Handle(error.data());
73 return data.IsUnhandledException(); 70 return data.IsUnhandledException();
74 } 71 }
75 return false; 72 return false;
76 } 73 }
77 74
78 75
79 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { 76 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) {
80 Zone zone; // Setup a VM zone as we are creating some handles. 77 DARTSCOPE(Isolate::Current());
81 HandleScope scope; // Setup a VM handle scope.
82 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); 78 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
83 if (obj.IsApiError()) { 79 if (obj.IsApiError()) {
84 const ApiError& error = ApiError::CheckedHandle(obj.raw()); 80 const ApiError& error = ApiError::CheckedHandle(obj.raw());
85 const Object& data = Object::Handle(error.data()); 81 const Object& data = Object::Handle(error.data());
86 if (data.IsUnhandledException()) { 82 if (data.IsUnhandledException()) {
87 const UnhandledException& unhandled = UnhandledException::Handle( 83 const UnhandledException& unhandled = UnhandledException::Handle(
88 reinterpret_cast<RawUnhandledException*>(data.raw())); 84 reinterpret_cast<RawUnhandledException*>(data.raw()));
89 const Object& exception = Object::Handle(unhandled.exception()); 85 const Object& exception = Object::Handle(unhandled.exception());
90 return Api::NewLocalHandle(exception); 86 return Api::NewLocalHandle(exception);
91 } else { 87 } else {
92 return Api::Error("This error is not an unhandled exception error."); 88 return Api::Error("This error is not an unhandled exception error.");
93 } 89 }
94 } else { 90 } else {
95 return Api::Error("Can only get exceptions from error handles."); 91 return Api::Error("Can only get exceptions from error handles.");
96 } 92 }
97 } 93 }
98 94
99 95
100 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { 96 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) {
101 Zone zone; // Setup a VM zone as we are creating some handles. 97 DARTSCOPE(Isolate::Current());
102 HandleScope scope; // Setup a VM handle scope.
103 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); 98 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
104 if (obj.IsApiError()) { 99 if (obj.IsApiError()) {
105 ApiError& failure = ApiError::Handle(); 100 ApiError& failure = ApiError::Handle();
106 failure ^= obj.raw(); 101 failure ^= obj.raw();
107 const Object& data = Object::Handle(failure.data()); 102 const Object& data = Object::Handle(failure.data());
108 if (data.IsUnhandledException()) { 103 if (data.IsUnhandledException()) {
109 const UnhandledException& unhandled = UnhandledException::Handle( 104 const UnhandledException& unhandled = UnhandledException::Handle(
110 reinterpret_cast<RawUnhandledException*>(data.raw())); 105 reinterpret_cast<RawUnhandledException*>(data.raw()));
111 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); 106 const Object& stacktrace = Object::Handle(unhandled.stacktrace());
112 return Api::NewLocalHandle(stacktrace); 107 return Api::NewLocalHandle(stacktrace);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format) 146 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format)
152 - 4 // Two '%s' 147 - 4 // Two '%s'
153 + 1); // '\0' 148 + 1); // '\0'
154 char* buffer = reinterpret_cast<char*>(Api::Allocate(len)); 149 char* buffer = reinterpret_cast<char*>(Api::Allocate(len));
155 OS::SNPrint(buffer, len, format, exc_str, stack_str); 150 OS::SNPrint(buffer, len, format, exc_str, stack_str);
156 return buffer; 151 return buffer;
157 } 152 }
158 153
159 154
160 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { 155 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) {
161 ASSERT(Isolate::Current() != NULL); 156 DARTSCOPE(Isolate::Current());
162 Zone zone; // Setup a VM zone as we are creating some handles. 157
163 HandleScope scope; // Setup a VM handle scope.
164 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); 158 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
165 if (!obj.IsApiError()) { 159 if (!obj.IsApiError()) {
166 return ""; 160 return "";
167 } 161 }
168 ApiError& failure = ApiError::Handle(); 162 ApiError& failure = ApiError::Handle();
169 failure ^= obj.raw(); 163 failure ^= obj.raw();
170 const Object& data = Object::Handle(failure.data()); 164 const Object& data = Object::Handle(failure.data());
171 if (data.IsString()) { 165 if (data.IsString()) {
172 // Simple error message. 166 // Simple error message.
173 String& message = String::Handle(); 167 String& message = String::Handle();
(...skipping 11 matching lines...) Expand all
185 179
186 } else { 180 } else {
187 return "<Internal error in Dart_GetError: malformed error handle>"; 181 return "<Internal error in Dart_GetError: malformed error handle>";
188 } 182 }
189 } 183 }
190 184
191 185
192 // TODO(turnidge): This clonse Api::Error. I need to use va_copy to 186 // TODO(turnidge): This clonse Api::Error. I need to use va_copy to
193 // fix this but not sure if it available on all of our builds. 187 // fix this but not sure if it available on all of our builds.
194 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { 188 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) {
195 Zone zone; // Setup a VM zone as we are creating some handles. 189 DARTSCOPE(Isolate::Current());
196 HandleScope scope; // Setup a VM handle scope.
197 190
198 va_list args; 191 va_list args;
199 va_start(args, format); 192 va_start(args, format);
200 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 193 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
201 va_end(args); 194 va_end(args);
202 195
203 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); 196 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
204 va_list args2; 197 va_list args2;
205 va_start(args2, format); 198 va_start(args2, format);
206 OS::VSNPrint(buffer, (len + 1), format, args2); 199 OS::VSNPrint(buffer, (len + 1), format, args2);
(...skipping 20 matching lines...) Expand all
227 LongJump* base = isolate->long_jump_base(); 220 LongJump* base = isolate->long_jump_base();
228 LongJump jump; 221 LongJump jump;
229 isolate->set_long_jump_base(&jump); 222 isolate->set_long_jump_base(&jump);
230 if (setjmp(*jump.Set()) == 0) { 223 if (setjmp(*jump.Set()) == 0) {
231 Dart::InitializeIsolate(snapshot, data); 224 Dart::InitializeIsolate(snapshot, data);
232 START_TIMER(time_total_runtime); 225 START_TIMER(time_total_runtime);
233 isolate->set_long_jump_base(base); 226 isolate->set_long_jump_base(base);
234 return reinterpret_cast<Dart_Isolate>(isolate); 227 return reinterpret_cast<Dart_Isolate>(isolate);
235 } else { 228 } else {
236 { 229 {
237 Zone zone; // Setup a VM zone as we are creating some handles. 230 DARTSCOPE(isolate);
238 HandleScope scope; // Setup a VM handle scope.
239 const String& error = 231 const String& error =
240 String::Handle(Isolate::Current()->object_store()->sticky_error()); 232 String::Handle(isolate->object_store()->sticky_error());
241 // TODO(asiva): Need to return this as a error. 233 // TODO(asiva): Need to return this as a error.
242 OS::PrintErr(error.ToCString()); 234 OS::PrintErr(error.ToCString());
243 } 235 }
244 Dart::ShutdownIsolate(); 236 Dart::ShutdownIsolate();
245 } 237 }
246 return reinterpret_cast<Dart_Isolate>(NULL); 238 return reinterpret_cast<Dart_Isolate>(NULL);
247 } 239 }
248 240
249 241
250 DART_EXPORT void Dart_ShutdownIsolate() { 242 DART_EXPORT void Dart_ShutdownIsolate() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); 296 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
305 Instance& instance = Instance::Handle(); 297 Instance& instance = Instance::Handle();
306 instance ^= reader.ReadObject(); 298 instance ^= reader.ReadObject();
307 return instance.raw(); 299 return instance.raw();
308 } 300 }
309 301
310 302
311 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port, 303 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port,
312 Dart_Port reply_port, 304 Dart_Port reply_port,
313 Dart_Message dart_message) { 305 Dart_Message dart_message) {
314 Zone zone; // Setup a VM zone as we are creating some handles. 306 DARTSCOPE(Isolate::Current());
315 HandleScope scope; // Setup a VM handle scope. 307
316 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); 308 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message));
317 const String& class_name = 309 const String& class_name =
318 String::Handle(String::NewSymbol("ReceivePortImpl")); 310 String::Handle(String::NewSymbol("ReceivePortImpl"));
319 const String& function_name = 311 const String& function_name =
320 String::Handle(String::NewSymbol("handleMessage_")); 312 String::Handle(String::NewSymbol("handleMessage_"));
321 const int kNumArguments = 3; 313 const int kNumArguments = 3;
322 const Array& kNoArgumentNames = Array::Handle(); 314 const Array& kNoArgumentNames = Array::Handle();
323 const Function& function = Function::Handle( 315 const Function& function = Function::Handle(
324 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), 316 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
325 class_name, 317 class_name,
326 function_name, 318 function_name,
327 kNumArguments, 319 kNumArguments,
328 kNoArgumentNames, 320 kNoArgumentNames,
329 Resolver::kIsQualified)); 321 Resolver::kIsQualified));
330 GrowableArray<const Object*> arguments(kNumArguments); 322 GrowableArray<const Object*> arguments(kNumArguments);
331 arguments.Add(&Integer::Handle(Integer::New(dest_port))); 323 arguments.Add(&Integer::Handle(Integer::New(dest_port)));
332 arguments.Add(&Integer::Handle(Integer::New(reply_port))); 324 arguments.Add(&Integer::Handle(Integer::New(reply_port)));
333 arguments.Add(&msg); 325 arguments.Add(&msg);
334 const Object& result = Object::Handle( 326 const Object& result = Object::Handle(
335 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); 327 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
336 if (result.IsUnhandledException()) { 328 if (result.IsUnhandledException()) {
337 return Api::ErrorFromException(result); 329 return Api::ErrorFromException(result);
338 } 330 }
339 ASSERT(result.IsNull()); 331 ASSERT(result.IsNull());
340 return Api::Success(); 332 return Api::Success();
341 } 333 }
342 334
343 335
344 DART_EXPORT Dart_Handle Dart_RunLoop() { 336 DART_EXPORT Dart_Handle Dart_RunLoop() {
345 Zone zone; // Setup a VM zone as we are creating some handles. 337 Isolate* isolate = Isolate::Current();
346 HandleScope scope; // Setup a VM handle scope. 338 DARTSCOPE(isolate);
347 339
348 Isolate* isolate = Isolate::Current();
349 LongJump* base = isolate->long_jump_base(); 340 LongJump* base = isolate->long_jump_base();
350 LongJump jump; 341 LongJump jump;
351 Dart_Handle result; 342 Dart_Handle result;
352 isolate->set_long_jump_base(&jump); 343 isolate->set_long_jump_base(&jump);
353 if (setjmp(*jump.Set()) == 0) { 344 if (setjmp(*jump.Set()) == 0) {
354 isolate->StandardRunLoop(); 345 isolate->StandardRunLoop();
355 result = Api::Success(); 346 result = Api::Success();
356 } else { 347 } else {
357 SetupErrorResult(&result); 348 SetupErrorResult(&result);
358 } 349 }
359 isolate->set_long_jump_base(base); 350 isolate->set_long_jump_base(base);
360 return result; 351 return result;
361 } 352 }
362 353
363 354
364 // NOTE: Need to pass 'result' as a parameter here in order to avoid 355 // NOTE: Need to pass 'result' as a parameter here in order to avoid
365 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 356 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
366 // which shows up because of the use of setjmp. 357 // which shows up because of the use of setjmp.
367 static void CompileSource(const Library& lib, 358 static void CompileSource(Isolate* isolate,
359 const Library& lib,
368 const String& url, 360 const String& url,
369 const String& source, 361 const String& source,
370 RawScript::Kind kind, 362 RawScript::Kind kind,
371 Dart_Handle* result) { 363 Dart_Handle* result) {
372 const Script& script = Script::Handle(Script::New(url, source, kind)); 364 const Script& script = Script::Handle(Script::New(url, source, kind));
373 Isolate* isolate = Isolate::Current();
374 ASSERT(isolate != NULL); 365 ASSERT(isolate != NULL);
375 LongJump* base = isolate->long_jump_base(); 366 LongJump* base = isolate->long_jump_base();
376 LongJump jump; 367 LongJump jump;
377 isolate->set_long_jump_base(&jump); 368 isolate->set_long_jump_base(&jump);
378 if (setjmp(*jump.Set()) == 0) { 369 if (setjmp(*jump.Set()) == 0) {
379 Compiler::Compile(lib, script); 370 Compiler::Compile(lib, script);
380 *result = Api::NewLocalHandle(lib); 371 *result = Api::NewLocalHandle(lib);
381 } else { 372 } else {
382 SetupErrorResult(result); 373 SetupErrorResult(result);
383 } 374 }
384 isolate->set_long_jump_base(base); 375 isolate->set_long_jump_base(base);
385 } 376 }
386 377
387 378
388 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 379 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
389 Dart_Handle source, 380 Dart_Handle source,
390 Dart_LibraryTagHandler handler) { 381 Dart_LibraryTagHandler handler) {
391 Isolate* isolate = Isolate::Current(); 382 Isolate* isolate = Isolate::Current();
392 ASSERT(isolate != NULL); 383 DARTSCOPE(isolate);
393 Zone zone; // Setup a VM zone as we are creating some handles.
394 HandleScope scope; // Setup a VM handle scope.
395 TIMERSCOPE(time_script_loading); 384 TIMERSCOPE(time_script_loading);
396 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 385 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url));
397 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source)); 386 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source));
398 Library& library = Library::Handle(isolate->object_store()->root_library()); 387 Library& library = Library::Handle(isolate->object_store()->root_library());
399 if (!library.IsNull()) { 388 if (!library.IsNull()) {
400 return Api::Error("Script already loaded"); 389 return Api::Error("Script already loaded");
401 } 390 }
402 isolate->set_library_tag_handler(handler); 391 isolate->set_library_tag_handler(handler);
403 library = Library::New(url_str); 392 library = Library::New(url_str);
404 library.Register(); 393 library.Register();
405 isolate->object_store()->set_root_library(library); 394 isolate->object_store()->set_root_library(library);
406 Dart_Handle result; 395 Dart_Handle result;
407 CompileSource(library, url_str, source_str, RawScript::kScript, &result); 396 CompileSource(isolate,
397 library,
398 url_str,
399 source_str,
400 RawScript::kScript,
401 &result);
408 return result; 402 return result;
409 } 403 }
410 404
411 405
412 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code."); 406 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code.");
413 407
414 static void CompileAll(Dart_Handle* result) { 408 static void CompileAll(Isolate* isolate, Dart_Handle* result) {
415 *result = Api::Success(); 409 *result = Api::Success();
416 if (FLAG_compile_all) { 410 if (FLAG_compile_all) {
417 Isolate* isolate = Isolate::Current();
418 ASSERT(isolate != NULL); 411 ASSERT(isolate != NULL);
419 LongJump* base = isolate->long_jump_base(); 412 LongJump* base = isolate->long_jump_base();
420 LongJump jump; 413 LongJump jump;
421 isolate->set_long_jump_base(&jump); 414 isolate->set_long_jump_base(&jump);
422 if (setjmp(*jump.Set()) == 0) { 415 if (setjmp(*jump.Set()) == 0) {
423 Library::CompileAll(); 416 Library::CompileAll();
424 } else { 417 } else {
425 SetupErrorResult(result); 418 SetupErrorResult(result);
426 } 419 }
427 isolate->set_long_jump_base(base); 420 isolate->set_long_jump_base(base);
428 } 421 }
429 } 422 }
430 423
431 424
432 // Return error if isolate is in an inconsistent state. 425 // Return error if isolate is in an inconsistent state.
433 // Return NULL when no error condition exists. 426 // Return NULL when no error condition exists.
434 static const char* CheckIsolateState() { 427 static const char* CheckIsolateState(Isolate* isolate) {
435 if (!ClassFinalizer::FinalizePendingClasses()) { 428 if (!ClassFinalizer::FinalizePendingClasses()) {
436 // Make a copy of the error message as the original message string 429 // Make a copy of the error message as the original message string
437 // may get deallocated when we return back from the Dart API call. 430 // may get deallocated when we return back from the Dart API call.
438 const String& err = 431 const String& err =
439 String::Handle(Isolate::Current()->object_store()->sticky_error()); 432 String::Handle(isolate->object_store()->sticky_error());
440 const char* errmsg = err.ToCString(); 433 const char* errmsg = err.ToCString();
441 intptr_t errlen = strlen(errmsg) + 1; 434 intptr_t errlen = strlen(errmsg) + 1;
442 char* msg = reinterpret_cast<char*>(Api::Allocate(errlen)); 435 char* msg = reinterpret_cast<char*>(Api::Allocate(errlen));
443 OS::SNPrint(msg, errlen, "%s", errmsg); 436 OS::SNPrint(msg, errlen, "%s", errmsg);
444 return msg; 437 return msg;
445 } 438 }
446 return NULL; 439 return NULL;
447 } 440 }
448 441
449 442
450 DART_EXPORT Dart_Handle Dart_CompileAll() { 443 DART_EXPORT Dart_Handle Dart_CompileAll() {
451 Zone zone; // Setup a VM zone as we are creating some handles. 444 Isolate* isolate = Isolate::Current();
452 HandleScope scope; // Setup a VM handle scope. 445 DARTSCOPE(isolate);
453 Dart_Handle result; 446 Dart_Handle result;
454 const char* msg = CheckIsolateState(); 447 const char* msg = CheckIsolateState(isolate);
455 if (msg != NULL) { 448 if (msg != NULL) {
456 return Api::Error(msg); 449 return Api::Error(msg);
457 } 450 }
458 CompileAll(&result); 451 CompileAll(isolate, &result);
459 return result; 452 return result;
460 } 453 }
461 454
462 455
463 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { 456 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) {
464 Zone zone; // Setup a VM zone as we are creating some handles. 457 DARTSCOPE(Isolate::Current());
465 HandleScope scope; // Setup a VM handle scope.
466 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 458 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
467 return obj.IsLibrary(); 459 return obj.IsLibrary();
468 } 460 }
469 461
470 462
471 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { 463 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) {
472 Zone zone; // Setup a VM zone as we are creating some handles. 464 DARTSCOPE(Isolate::Current());
473 HandleScope scope; // Setup a VM handle scope.
474 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 465 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library));
475 if (lib.IsNull()) { 466 if (lib.IsNull()) {
476 return Api::Error("Null library"); 467 return Api::Error("Null library");
477 } 468 }
478 const String& url = String::Handle(lib.url()); 469 const String& url = String::Handle(lib.url());
479 ASSERT(!url.IsNull()); 470 ASSERT(!url.IsNull());
480 return Api::NewLocalHandle(url); 471 return Api::NewLocalHandle(url);
481 } 472 }
482 473
483 474
484 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library_in, 475 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library_in,
485 Dart_Handle import_in) { 476 Dart_Handle import_in) {
486 Zone zone; // Setup a VM zone as we are creating some handles. 477 DARTSCOPE(Isolate::Current());
487 HandleScope scope; // Setup a VM handle scope.
488 const Library& library = 478 const Library& library =
489 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 479 Library::CheckedHandle(Api::UnwrapHandle(library_in));
490 if (library.IsNull()) { 480 if (library.IsNull()) {
491 return Api::Error("Null library"); 481 return Api::Error("Null library");
492 } 482 }
493 const Library& import = 483 const Library& import =
494 Library::CheckedHandle(Api::UnwrapHandle(import_in)); 484 Library::CheckedHandle(Api::UnwrapHandle(import_in));
495 library.AddImport(import); 485 library.AddImport(import);
496 return Api::Success(); 486 return Api::Success();
497 } 487 }
498 488
499 489
500 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { 490 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
501 Zone zone; // Setup a VM zone as we are creating some handles. 491 DARTSCOPE(Isolate::Current());
502 HandleScope scope; // Setup a VM handle scope.
503 String& url_str = String::Handle(); 492 String& url_str = String::Handle();
504 UNWRAP_NONNULL(url, url_str, String); 493 UNWRAP_NONNULL(url, url_str, String);
505 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); 494 const Library& library = Library::Handle(Library::LookupLibrary(url_str));
506 if (library.IsNull()) { 495 if (library.IsNull()) {
507 return Api::Error("%s: library '%s' not found.", 496 return Api::Error("%s: library '%s' not found.",
508 CURRENT_FUNC, url_str.ToCString()); 497 CURRENT_FUNC, url_str.ToCString());
509 } else { 498 } else {
510 return Api::NewLocalHandle(library); 499 return Api::NewLocalHandle(library);
511 } 500 }
512 } 501 }
513 502
514 503
515 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { 504 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) {
516 Zone zone; // Setup a VM zone as we are creating some handles. 505 Isolate* isolate = Isolate::Current();
517 HandleScope scope; // Setup a VM handle scope. 506 DARTSCOPE(isolate);
518 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 507 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url));
519 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source)); 508 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source));
520 Library& library = Library::Handle(Library::LookupLibrary(url_str)); 509 Library& library = Library::Handle(Library::LookupLibrary(url_str));
521 if (library.IsNull()) { 510 if (library.IsNull()) {
522 library = Library::New(url_str); 511 library = Library::New(url_str);
523 library.Register(); 512 library.Register();
524 } 513 }
525 Dart_Handle result; 514 Dart_Handle result;
526 CompileSource(library, url_str, source_str, RawScript::kLibrary, &result); 515 CompileSource(isolate,
516 library,
517 url_str,
518 source_str,
519 RawScript::kLibrary,
520 &result);
527 return result; 521 return result;
528 } 522 }
529 523
530 524
531 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library_in, 525 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library_in,
532 Dart_Handle url_in, 526 Dart_Handle url_in,
533 Dart_Handle source_in) { 527 Dart_Handle source_in) {
534 Zone zone; // Setup a VM zone as we are creating some handles. 528 Isolate* isolate = Isolate::Current();
535 HandleScope scope; // Setup a VM handle scope. 529 DARTSCOPE(isolate);
536 const String& url = String::CheckedHandle(Api::UnwrapHandle(url_in)); 530 const String& url = String::CheckedHandle(Api::UnwrapHandle(url_in));
537 const String& source = String::CheckedHandle(Api::UnwrapHandle(source_in)); 531 const String& source = String::CheckedHandle(Api::UnwrapHandle(source_in));
538 const Library& library = 532 const Library& library =
539 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 533 Library::CheckedHandle(Api::UnwrapHandle(library_in));
540 Dart_Handle result; 534 Dart_Handle result;
541 CompileSource(library, url, source, RawScript::kSource, &result); 535 CompileSource(isolate, library, url, source, RawScript::kSource, &result);
542 return result; 536 return result;
543 } 537 }
544 538
545 539
546 DART_EXPORT Dart_Handle Dart_SetNativeResolver( 540 DART_EXPORT Dart_Handle Dart_SetNativeResolver(
547 Dart_Handle library, 541 Dart_Handle library,
548 Dart_NativeEntryResolver resolver) { 542 Dart_NativeEntryResolver resolver) {
549 Zone zone; // Setup a VM zone as we are creating some handles. 543 DARTSCOPE(Isolate::Current());
550 HandleScope scope; // Setup a VM handle scope.
551 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 544 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library));
552 if (lib.IsNull()) { 545 if (lib.IsNull()) {
553 return Api::Error("Invalid parameter, Unknown library specified"); 546 return Api::Error("Invalid parameter, Unknown library specified");
554 } 547 }
555 lib.set_native_entry_resolver(resolver); 548 lib.set_native_entry_resolver(resolver);
556 return Api::Success(); 549 return Api::Success();
557 } 550 }
558 551
559 552
560 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { 553 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) {
561 Zone zone; // Setup a VM zone as we are creating some handles. 554 DARTSCOPE(Isolate::Current());
562 HandleScope scope; // Setup a VM handle scope.
563 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 555 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
564 Object& result = Object::Handle(); 556 Object& result = Object::Handle();
565 if (obj.IsString()) { 557 if (obj.IsString()) {
566 result = obj.raw(); 558 result = obj.raw();
567 } else if (obj.IsInstance()) { 559 } else if (obj.IsInstance()) {
568 Instance& receiver = Instance::Handle(); 560 Instance& receiver = Instance::Handle();
569 receiver ^= obj.raw(); 561 receiver ^= obj.raw();
570 result = DartLibraryCalls::ToString(receiver); 562 result = DartLibraryCalls::ToString(receiver);
571 if (result.IsUnhandledException()) { 563 if (result.IsUnhandledException()) {
572 return Api::ErrorFromException(result); 564 return Api::ErrorFromException(result);
573 } 565 }
574 } else { 566 } else {
575 // This is a VM internal object. Call the C++ method of printing. 567 // This is a VM internal object. Call the C++ method of printing.
576 result = String::New(obj.ToCString()); 568 result = String::New(obj.ToCString());
577 } 569 }
578 return Api::NewLocalHandle(result); 570 return Api::NewLocalHandle(result);
579 } 571 }
580 572
581 573
582 DART_EXPORT Dart_Handle Dart_Null() { 574 DART_EXPORT Dart_Handle Dart_Null() {
583 return Api::Null(); 575 return Api::Null();
584 } 576 }
585 577
586 578
587 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { 579 DART_EXPORT bool Dart_IsNull(Dart_Handle object) {
588 Zone zone; // Setup a VM zone as we are creating some handles. 580 DARTSCOPE(Isolate::Current());
589 HandleScope scope; // Setup a VM handle scope.
590 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 581 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
591 return obj.IsNull(); 582 return obj.IsNull();
592 } 583 }
593 584
594 585
595 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 586 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
596 Zone zone; // Setup a VM zone as we are creating some handles. 587 DARTSCOPE(Isolate::Current());
597 HandleScope scope; // Setup a VM handle scope.
598 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 588 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
599 return obj.IsClosure(); 589 return obj.IsClosure();
600 } 590 }
601 591
602 592
603 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { 593 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) {
604 Zone zone; 594 DARTSCOPE(Isolate::Current());
605 HandleScope scope;
606 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 595 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
607 const Integer& smrck = Integer::Handle(obj.smrck()); 596 const Integer& smrck = Integer::Handle(obj.smrck());
608 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); 597 return smrck.IsNull() ? 0 : smrck.AsInt64Value();
609 } 598 }
610 599
611 600
612 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) { 601 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) {
613 Zone zone; 602 DARTSCOPE(Isolate::Current());
614 HandleScope scope;
615 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 603 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
616 const Integer& smrck = Integer::Handle(Integer::New(value)); 604 const Integer& smrck = Integer::Handle(Integer::New(value));
617 obj.set_smrck(smrck); 605 obj.set_smrck(smrck);
618 } 606 }
619 607
620 608
621 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, 609 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2,
622 bool* value) { 610 bool* value) {
623 Zone zone; // Setup a VM zone as we are creating some handles. 611 DARTSCOPE(Isolate::Current());
624 HandleScope scope; // Setup a VM handle scope.
625 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); 612 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1));
626 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); 613 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2));
627 const Instance& result = 614 const Instance& result =
628 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); 615 Instance::Handle(DartLibraryCalls::Equals(expected, actual));
629 if (result.IsBool()) { 616 if (result.IsBool()) {
630 Bool& b = Bool::Handle(); 617 Bool& b = Bool::Handle();
631 b ^= result.raw(); 618 b ^= result.raw();
632 *value = b.value(); 619 *value = b.value();
633 return Api::Success(); 620 return Api::Success();
634 } else if (result.IsUnhandledException()) { 621 } else if (result.IsUnhandledException()) {
635 return Api::ErrorFromException(result); 622 return Api::ErrorFromException(result);
636 } else { 623 } else {
637 return Api::Error("Expected boolean result from =="); 624 return Api::Error("Expected boolean result from ==");
638 } 625 }
639 } 626 }
640 627
641 628
642 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, 629 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2,
643 bool* value) { 630 bool* value) {
644 Zone zone; // Setup a VM zone as we are creating some handles. 631 DARTSCOPE(Isolate::Current());
645 HandleScope scope; // Setup a VM handle scope.
646 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); 632 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1));
647 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); 633 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2));
648 *value = (expected.raw() == actual.raw()); 634 *value = (expected.raw() == actual.raw());
649 return Api::Success(); 635 return Api::Success();
650 } 636 }
651 637
652 638
653 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { 639 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) {
654 Zone zone; // Setup a VM zone as we are creating some handles. 640 DARTSCOPE(Isolate::Current());
655 HandleScope scope; // Setup a VM handle scope.
656 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 641 const Object& param = Object::Handle(Api::UnwrapHandle(name));
657 if (param.IsNull() || !param.IsString()) { 642 if (param.IsNull() || !param.IsString()) {
658 return Api::Error("Invalid class name specified"); 643 return Api::Error("Invalid class name specified");
659 } 644 }
660 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 645 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library));
661 if (lib.IsNull()) { 646 if (lib.IsNull()) {
662 return Api::Error("Invalid parameter, Unknown library specified"); 647 return Api::Error("Invalid parameter, Unknown library specified");
663 } 648 }
664 String& cls_name = String::Handle(); 649 String& cls_name = String::Handle();
665 cls_name ^= param.raw(); 650 cls_name ^= param.raw();
666 const Class& cls = Class::Handle(lib.LookupClass(cls_name)); 651 const Class& cls = Class::Handle(lib.LookupClass(cls_name));
667 if (cls.IsNull()) { 652 if (cls.IsNull()) {
668 const String& lib_name = String::Handle(lib.name()); 653 const String& lib_name = String::Handle(lib.name());
669 return Api::Error("Class '%s' not found in library '%s'.", 654 return Api::Error("Class '%s' not found in library '%s'.",
670 cls_name.ToCString(), lib_name.ToCString()); 655 cls_name.ToCString(), lib_name.ToCString());
671 } 656 }
672 return Api::NewLocalHandle(cls); 657 return Api::NewLocalHandle(cls);
673 } 658 }
674 659
675 660
676 // TODO(iposva): This call actually implements IsInstanceOfClass. 661 // TODO(iposva): This call actually implements IsInstanceOfClass.
677 // Do we also need a real Dart_IsInstanceOf, which should take an instance 662 // Do we also need a real Dart_IsInstanceOf, which should take an instance
678 // rather than an object and a type rather than a class? 663 // rather than an object and a type rather than a class?
679 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, 664 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object,
680 Dart_Handle clazz, 665 Dart_Handle clazz,
681 bool* value) { 666 bool* value) {
682 Zone zone; // Setup a VM zone as we are creating some handles. 667 Isolate* isolate = Isolate::Current();
683 HandleScope scope; // Setup a VM handle scope. 668 DARTSCOPE(isolate);
684 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz)); 669 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz));
685 if (cls.IsNull()) { 670 if (cls.IsNull()) {
686 return Api::Error("instanceof check against null class"); 671 return Api::Error("instanceof check against null class");
687 } 672 }
688 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 673 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
689 Instance& instance = Instance::Handle(); 674 Instance& instance = Instance::Handle();
690 instance ^= obj.raw(); 675 instance ^= obj.raw();
691 // Finalize all classes. 676 // Finalize all classes.
692 const char* msg = CheckIsolateState(); 677 const char* msg = CheckIsolateState(isolate);
693 if (msg != NULL) { 678 if (msg != NULL) {
694 return Api::Error(msg); 679 return Api::Error(msg);
695 } 680 }
696 const Type& type = Type::Handle(Type::NewNonParameterizedType(cls)); 681 const Type& type = Type::Handle(Type::NewNonParameterizedType(cls));
697 *value = instance.Is(type); 682 *value = instance.Is(type);
698 return Api::Success(); 683 return Api::Success();
699 } 684 }
700 685
701 686
702 // TODO(iposva): The argument should be an instance. 687 // TODO(iposva): The argument should be an instance.
703 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { 688 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) {
704 Zone zone; // Setup a VM zone as we are creating some handles. 689 DARTSCOPE(Isolate::Current());
705 HandleScope scope; // Setup a VM handle scope.
706 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 690 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
707 return obj.IsNumber(); 691 return obj.IsNumber();
708 } 692 }
709 693
710 694
711 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { 695 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) {
712 Zone zone; // Setup a VM zone as we are creating some handles. 696 DARTSCOPE(Isolate::Current());
713 HandleScope scope; // Setup a VM handle scope.
714 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 697 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
715 return obj.IsInteger(); 698 return obj.IsInteger();
716 } 699 }
717 700
718 701
719 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { 702 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
720 Zone zone; // Setup a VM zone as we are creating some handles. 703 DARTSCOPE(Isolate::Current());
721 HandleScope scope; // Setup a VM handle scope.
722 const Integer& obj = Integer::Handle(Integer::New(value)); 704 const Integer& obj = Integer::Handle(Integer::New(value));
723 return Api::NewLocalHandle(obj); 705 return Api::NewLocalHandle(obj);
724 } 706 }
725 707
726 708
727 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 709 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
728 Zone zone; // Setup a VM zone as we are creating some handles. 710 DARTSCOPE(Isolate::Current());
729 HandleScope scope; // Setup a VM handle scope.
730 const String& str_obj = String::Handle(String::New(str)); 711 const String& str_obj = String::Handle(String::New(str));
731 const Integer& obj = Integer::Handle(Integer::New(str_obj)); 712 const Integer& obj = Integer::Handle(Integer::New(str_obj));
732 return Api::NewLocalHandle(obj); 713 return Api::NewLocalHandle(obj);
733 } 714 }
734 715
735 716
736 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) { 717 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) {
737 Zone zone; // Setup a VM zone as we are creating some handles. 718 DARTSCOPE(Isolate::Current());
738 HandleScope scope; // Setup a VM handle scope.
739 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 719 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
740 if (obj.IsSmi() || obj.IsMint()) { 720 if (obj.IsSmi() || obj.IsMint()) {
741 Integer& integer = Integer::Handle(); 721 Integer& integer = Integer::Handle();
742 integer ^= obj.raw(); 722 integer ^= obj.raw();
743 *value = integer.AsInt64Value(); 723 *value = integer.AsInt64Value();
744 return Api::Success(); 724 return Api::Success();
745 } 725 }
746 if (obj.IsBigint()) { 726 if (obj.IsBigint()) {
747 Bigint& bigint = Bigint::Handle(); 727 Bigint& bigint = Bigint::Handle();
748 bigint ^= obj.raw(); 728 bigint ^= obj.raw();
749 if (BigintOperations::FitsIntoInt64(bigint)) { 729 if (BigintOperations::FitsIntoInt64(bigint)) {
750 *value = BigintOperations::ToInt64(bigint); 730 *value = BigintOperations::ToInt64(bigint);
751 return Api::Success(); 731 return Api::Success();
752 } else { 732 } else {
753 return Api::Error("Integer too big to fit in int64_t"); 733 return Api::Error("Integer too big to fit in int64_t");
754 } 734 }
755 } 735 }
756 return Api::Error("Object is not a Integer"); 736 return Api::Error("Object is not a Integer");
757 } 737 }
758 738
759 739
760 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, 740 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer,
761 const char** value) { 741 const char** value) {
762 Zone zone; // Setup a VM zone as we are creating some handles. 742 DARTSCOPE(Isolate::Current());
763 HandleScope scope; // Setup a VM handle scope.
764 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 743 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
765 Bigint& bigint = Bigint::Handle(); 744 Bigint& bigint = Bigint::Handle();
766 if (obj.IsSmi() || obj.IsMint()) { 745 if (obj.IsSmi() || obj.IsMint()) {
767 Integer& integer = Integer::Handle(); 746 Integer& integer = Integer::Handle();
768 integer ^= obj.raw(); 747 integer ^= obj.raw();
769 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value()); 748 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value());
770 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate); 749 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
771 return Api::Success(); 750 return Api::Success();
772 } 751 }
773 if (obj.IsBigint()) { 752 if (obj.IsBigint()) {
774 bigint ^= obj.raw(); 753 bigint ^= obj.raw();
775 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate); 754 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
776 return Api::Success(); 755 return Api::Success();
777 } 756 }
778 return Api::Error("Object is not a Integer"); 757 return Api::Error("Object is not a Integer");
779 } 758 }
780 759
781 760
782 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, 761 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
783 bool* fits) { 762 bool* fits) {
784 Zone zone; // Setup a VM zone as we are creating some handles. 763 DARTSCOPE(Isolate::Current());
785 HandleScope scope; // Setup a VM handle scope.
786 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 764 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
787 if (obj.IsSmi() || obj.IsMint()) { 765 if (obj.IsSmi() || obj.IsMint()) {
788 *fits = true; 766 *fits = true;
789 return Api::Success(); 767 return Api::Success();
790 } else if (obj.IsBigint()) { 768 } else if (obj.IsBigint()) {
791 #if defined(DEBUG) 769 #if defined(DEBUG)
792 Bigint& bigint = Bigint::Handle(); 770 Bigint& bigint = Bigint::Handle();
793 bigint ^= obj.raw(); 771 bigint ^= obj.raw();
794 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); 772 ASSERT(!BigintOperations::FitsIntoInt64(bigint));
795 #endif 773 #endif
796 *fits = false; 774 *fits = false;
797 return Api::Success(); 775 return Api::Success();
798 } 776 }
799 return Api::Error("Object is not a Integer"); 777 return Api::Error("Object is not a Integer");
800 } 778 }
801 779
802 780
803 DART_EXPORT Dart_Handle Dart_True() { 781 DART_EXPORT Dart_Handle Dart_True() {
804 return Api::True(); 782 return Api::True();
805 } 783 }
806 784
807 785
808 DART_EXPORT Dart_Handle Dart_False() { 786 DART_EXPORT Dart_Handle Dart_False() {
809 return Api::False(); 787 return Api::False();
810 } 788 }
811 789
812 790
813 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { 791 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) {
814 Zone zone; // Setup a VM zone as we are creating some handles. 792 DARTSCOPE(Isolate::Current());
815 HandleScope scope; // Setup a VM handle scope.
816 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 793 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
817 return obj.IsBool(); 794 return obj.IsBool();
818 } 795 }
819 796
820 797
821 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { 798 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) {
822 return value ? Api::True() : Api::False(); 799 return value ? Api::True() : Api::False();
823 } 800 }
824 801
825 802
826 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, 803 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object,
827 bool* value) { 804 bool* value) {
828 Zone zone; // Setup a VM zone as we are creating some handles. 805 DARTSCOPE(Isolate::Current());
829 HandleScope scope; // Setup a VM handle scope.
830 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object)); 806 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object));
831 if (obj.IsBool()) { 807 if (obj.IsBool()) {
832 Bool& bool_obj = Bool::Handle(); 808 Bool& bool_obj = Bool::Handle();
833 bool_obj ^= obj.raw(); 809 bool_obj ^= obj.raw();
834 *value = bool_obj.value(); 810 *value = bool_obj.value();
835 return Api::Success(); 811 return Api::Success();
836 } 812 }
837 return Api::Error("Object is not a Boolean"); 813 return Api::Error("Object is not a Boolean");
838 } 814 }
839 815
840 816
841 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { 817 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) {
842 Zone zone; // Setup a VM zone as we are creating some handles. 818 DARTSCOPE(Isolate::Current());
843 HandleScope scope; // Setup a VM handle scope.
844 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 819 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
845 return obj.IsDouble(); 820 return obj.IsDouble();
846 } 821 }
847 822
848 823
849 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { 824 DART_EXPORT Dart_Handle Dart_NewDouble(double value) {
850 Zone zone; // Setup a VM zone as we are creating some handles. 825 DARTSCOPE(Isolate::Current());
851 HandleScope scope; // Setup a VM handle scope.
852 const Double& obj = Double::Handle(Double::New(value)); 826 const Double& obj = Double::Handle(Double::New(value));
853 return Api::NewLocalHandle(obj); 827 return Api::NewLocalHandle(obj);
854 } 828 }
855 829
856 830
857 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle integer, double* result) { 831 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle integer, double* result) {
858 Zone zone; // Setup a VM zone as we are creating some handles. 832 DARTSCOPE(Isolate::Current());
859 HandleScope scope; // Setup a VM handle scope.
860 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 833 const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
861 if (obj.IsDouble()) { 834 if (obj.IsDouble()) {
862 Double& double_obj = Double::Handle(); 835 Double& double_obj = Double::Handle();
863 double_obj ^= obj.raw(); 836 double_obj ^= obj.raw();
864 *result = double_obj.value(); 837 *result = double_obj.value();
865 return Api::Success(); 838 return Api::Success();
866 } 839 }
867 return Api::Error("Object is not a Double"); 840 return Api::Error("Object is not a Double");
868 } 841 }
869 842
870 843
871 DART_EXPORT bool Dart_IsString(Dart_Handle object) { 844 DART_EXPORT bool Dart_IsString(Dart_Handle object) {
872 Zone zone; // Setup a VM zone as we are creating some handles. 845 DARTSCOPE(Isolate::Current());
873 HandleScope scope; // Setup a VM handle scope.
874 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 846 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
875 return obj.IsString(); 847 return obj.IsString();
876 } 848 }
877 849
878 850
879 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { 851 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
880 Zone zone; // Setup a VM zone as we are creating some handles. 852 DARTSCOPE(Isolate::Current());
881 HandleScope scope; // Setup a VM handle scope.
882 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 853 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
883 if (obj.IsString()) { 854 if (obj.IsString()) {
884 String& string_obj = String::Handle(); 855 String& string_obj = String::Handle();
885 string_obj ^= obj.raw(); 856 string_obj ^= obj.raw();
886 *len = string_obj.Length(); 857 *len = string_obj.Length();
887 return Api::Success(); 858 return Api::Success();
888 } 859 }
889 return Api::Error("Object is not a String"); 860 return Api::Error("Object is not a String");
890 } 861 }
891 862
892 863
893 DART_EXPORT Dart_Handle Dart_NewString(const char* str) { 864 DART_EXPORT Dart_Handle Dart_NewString(const char* str) {
894 Zone zone; // Setup a VM zone as we are creating some handles. 865 DARTSCOPE(Isolate::Current());
895 HandleScope scope; // Setup a VM handle scope.
896 const String& obj = String::Handle(String::New(str)); 866 const String& obj = String::Handle(String::New(str));
897 return Api::NewLocalHandle(obj); 867 return Api::NewLocalHandle(obj);
898 } 868 }
899 869
900 870
901 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, 871 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints,
902 intptr_t length) { 872 intptr_t length) {
903 Zone zone; // Setup a VM zone as we are creating some handles. 873 DARTSCOPE(Isolate::Current());
904 HandleScope scope; // Setup a VM handle scope.
905 const String& obj = String::Handle(String::New(codepoints, length)); 874 const String& obj = String::Handle(String::New(codepoints, length));
906 return Api::NewLocalHandle(obj); 875 return Api::NewLocalHandle(obj);
907 } 876 }
908 877
909 878
910 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, 879 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints,
911 intptr_t length) { 880 intptr_t length) {
912 Zone zone; // Setup a VM zone as we are creating some handles. 881 DARTSCOPE(Isolate::Current());
913 HandleScope scope; // Setup a VM handle scope.
914 const String& obj = String::Handle(String::New(codepoints, length)); 882 const String& obj = String::Handle(String::New(codepoints, length));
915 return Api::NewLocalHandle(obj); 883 return Api::NewLocalHandle(obj);
916 } 884 }
917 885
918 886
919 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, 887 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
920 intptr_t length) { 888 intptr_t length) {
921 Zone zone; // Setup a VM zone as we are creating some handles. 889 DARTSCOPE(Isolate::Current());
922 HandleScope scope; // Setup a VM handle scope.
923 const String& obj = String::Handle(String::New(codepoints, length)); 890 const String& obj = String::Handle(String::New(codepoints, length));
924 return Api::NewLocalHandle(obj); 891 return Api::NewLocalHandle(obj);
925 } 892 }
926 893
927 894
928 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { 895 DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
929 Zone zone; // Setup a VM zone as we are creating some handles. 896 DARTSCOPE(Isolate::Current());
930 HandleScope scope; // Setup a VM handle scope.
931 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 897 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
932 return obj.IsOneByteString(); 898 return obj.IsOneByteString();
933 } 899 }
934 900
935 901
936 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { 902 DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
937 Zone zone; // Setup a VM zone as we are creating some handles. 903 DARTSCOPE(Isolate::Current());
938 HandleScope scope; // Setup a VM handle scope.
939 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 904 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
940 return obj.IsOneByteString() || obj.IsTwoByteString(); 905 return obj.IsOneByteString() || obj.IsTwoByteString();
941 } 906 }
942 907
943 908
944 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, 909 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
945 uint8_t* codepoints, 910 uint8_t* codepoints,
946 intptr_t* length) { 911 intptr_t* length) {
947 Zone zone; // Setup a VM zone as we are creating some handles. 912 DARTSCOPE(Isolate::Current());
948 HandleScope scope; // Setup a VM handle scope.
949 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 913 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
950 if (obj.IsOneByteString()) { 914 if (obj.IsOneByteString()) {
951 OneByteString& string_obj = OneByteString::Handle(); 915 OneByteString& string_obj = OneByteString::Handle();
952 string_obj ^= obj.raw(); 916 string_obj ^= obj.raw();
953 intptr_t str_len = string_obj.Length(); 917 intptr_t str_len = string_obj.Length();
954 intptr_t copy_len = (str_len > *length) ? *length : str_len; 918 intptr_t copy_len = (str_len > *length) ? *length : str_len;
955 for (intptr_t i = 0; i < copy_len; i++) { 919 for (intptr_t i = 0; i < copy_len; i++) {
956 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); 920 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
957 } 921 }
958 *length= copy_len; 922 *length= copy_len;
959 return Api::Success(); 923 return Api::Success();
960 } 924 }
961 return Api::Error(obj.IsString() 925 return Api::Error(obj.IsString()
962 ? "Object is not a String8" 926 ? "Object is not a String8"
963 : "Object is not a String"); 927 : "Object is not a String");
964 } 928 }
965 929
966 930
967 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, 931 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
968 uint16_t* codepoints, 932 uint16_t* codepoints,
969 intptr_t* length) { 933 intptr_t* length) {
970 Zone zone; // Setup a VM zone as we are creating some handles. 934 DARTSCOPE(Isolate::Current());
971 HandleScope scope; // Setup a VM handle scope.
972 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 935 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
973 if (obj.IsOneByteString() || obj.IsTwoByteString()) { 936 if (obj.IsOneByteString() || obj.IsTwoByteString()) {
974 String& string_obj = String::Handle(); 937 String& string_obj = String::Handle();
975 string_obj ^= obj.raw(); 938 string_obj ^= obj.raw();
976 intptr_t str_len = string_obj.Length(); 939 intptr_t str_len = string_obj.Length();
977 intptr_t copy_len = (str_len > *length) ? *length : str_len; 940 intptr_t copy_len = (str_len > *length) ? *length : str_len;
978 for (intptr_t i = 0; i < copy_len; i++) { 941 for (intptr_t i = 0; i < copy_len; i++) {
979 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); 942 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
980 } 943 }
981 *length = copy_len; 944 *length = copy_len;
982 return Api::Success(); 945 return Api::Success();
983 } 946 }
984 return Api::Error(obj.IsString() 947 return Api::Error(obj.IsString()
985 ? "Object is not a String16" 948 ? "Object is not a String16"
986 : "Object is not a String"); 949 : "Object is not a String");
987 } 950 }
988 951
989 952
990 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, 953 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str,
991 uint32_t* codepoints, 954 uint32_t* codepoints,
992 intptr_t* length) { 955 intptr_t* length) {
993 Zone zone; // Setup a VM zone as we are creating some handles. 956 DARTSCOPE(Isolate::Current());
994 HandleScope scope; // Setup a VM handle scope.
995 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 957 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
996 if (obj.IsString()) { 958 if (obj.IsString()) {
997 String& string_obj = String::Handle(); 959 String& string_obj = String::Handle();
998 string_obj ^= obj.raw(); 960 string_obj ^= obj.raw();
999 intptr_t str_len = string_obj.Length(); 961 intptr_t str_len = string_obj.Length();
1000 intptr_t copy_len = (str_len > *length) ? *length : str_len; 962 intptr_t copy_len = (str_len > *length) ? *length : str_len;
1001 for (intptr_t i = 0; i < copy_len; i++) { 963 for (intptr_t i = 0; i < copy_len; i++) {
1002 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i)); 964 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i));
1003 } 965 }
1004 *length = copy_len; 966 *length = copy_len;
1005 return Api::Success(); 967 return Api::Success();
1006 } 968 }
1007 return Api::Error("Object is not a String"); 969 return Api::Error("Object is not a String");
1008 } 970 }
1009 971
1010 972
1011 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, 973 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
1012 const char** result) { 974 const char** result) {
1013 Zone zone; // Setup a VM zone as we are creating some handles. 975 DARTSCOPE(Isolate::Current());
1014 HandleScope scope; // Setup a VM handle scope.
1015 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 976 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1016 if (obj.IsString()) { 977 if (obj.IsString()) {
1017 const char* string_value = obj.ToCString(); 978 const char* string_value = obj.ToCString();
1018 intptr_t string_length = strlen(string_value); 979 intptr_t string_length = strlen(string_value);
1019 char* res = reinterpret_cast<char*>(Api::Allocate(string_length + 1)); 980 char* res = reinterpret_cast<char*>(Api::Allocate(string_length + 1));
1020 if (res == NULL) { 981 if (res == NULL) {
1021 return Api::Error("Unable to allocate memory"); 982 return Api::Error("Unable to allocate memory");
1022 } 983 }
1023 strncpy(res, string_value, string_length + 1); 984 strncpy(res, string_value, string_length + 1);
1024 ASSERT(res[string_length] == '\0'); 985 ASSERT(res[string_length] == '\0');
1025 *result = res; 986 *result = res;
1026 return Api::Success(); 987 return Api::Success();
1027 } 988 }
1028 return Api::Error("Object is not a String"); 989 return Api::Error("Object is not a String");
1029 } 990 }
1030 991
1031 992
1032 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { 993 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) {
1033 if (obj.IsInstance()) { 994 if (obj.IsInstance()) {
1034 Instance& instance = Instance::Handle(); 995 Instance& instance = Instance::Handle();
1035 instance ^= obj.raw(); 996 instance ^= obj.raw();
1036 const Type& type = Type::Handle(isolate->object_store()->list_interface()); 997 const Type& type = Type::Handle(isolate->object_store()->list_interface());
1037 return instance.Is(type) ? instance.raw() : Instance::null(); 998 return instance.Is(type) ? instance.raw() : Instance::null();
1038 } 999 }
1039 return Instance::null(); 1000 return Instance::null();
1040 } 1001 }
1041 1002
1042 1003
1043 DART_EXPORT bool Dart_IsList(Dart_Handle object) { 1004 DART_EXPORT bool Dart_IsList(Dart_Handle object) {
1044 Zone zone; // Setup a VM zone as we are creating some handles. 1005 Isolate* isolate = Isolate::Current();
1045 HandleScope scope; // Setup a VM handle scope. 1006 DARTSCOPE(isolate);
1046 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1007 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1047 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1008 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1048 return (obj.IsArray() || 1009 return (obj.IsArray() ||
1049 (GetListInstance(Isolate::Current(), obj) != Instance::null())); 1010 (GetListInstance(isolate, obj) != Instance::null()));
1050 } 1011 }
1051 1012
1052 1013
1053 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { 1014 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) {
1054 Zone zone; // Setup a VM zone as we are creating some handles. 1015 DARTSCOPE(Isolate::Current());
1055 HandleScope scope; // Setup a VM handle scope.
1056 const Array& obj = Array::Handle(Array::New(length)); 1016 const Array& obj = Array::Handle(Array::New(length));
1057 return Api::NewLocalHandle(obj); 1017 return Api::NewLocalHandle(obj);
1058 } 1018 }
1059 1019
1060 1020
1061 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { 1021 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) {
1062 Zone zone; // Setup a VM zone as we are creating some handles. 1022 Isolate* isolate = Isolate::Current();
1063 HandleScope scope; // Setup a VM handle scope. 1023 DARTSCOPE(isolate);
1064 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1024 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1065 if (obj.IsArray()) { 1025 if (obj.IsArray()) {
1066 Array& array_obj = Array::Handle(); 1026 Array& array_obj = Array::Handle();
1067 array_obj ^= obj.raw(); 1027 array_obj ^= obj.raw();
1068 *len = array_obj.Length(); 1028 *len = array_obj.Length();
1069 return Api::Success(); 1029 return Api::Success();
1070 } 1030 }
1071 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1031 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1072 // Now check and handle a dart object that implements the List interface. 1032 // Now check and handle a dart object that implements the List interface.
1073 Isolate* isolate = Isolate::Current();
1074 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1033 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1075 if (!instance.IsNull()) { 1034 if (!instance.IsNull()) {
1076 String& name = String::Handle(String::New("length")); 1035 String& name = String::Handle(String::New("length"));
1077 name = Field::GetterName(name); 1036 name = Field::GetterName(name);
1078 const Function& function = Function::Handle( 1037 const Function& function = Function::Handle(
1079 Resolver::ResolveDynamic(instance, name, 1, 0)); 1038 Resolver::ResolveDynamic(instance, name, 1, 0));
1080 if (!function.IsNull()) { 1039 if (!function.IsNull()) {
1081 GrowableArray<const Object*> args(0); 1040 GrowableArray<const Object*> args(0);
1082 LongJump* base = isolate->long_jump_base(); 1041 LongJump* base = isolate->long_jump_base();
1083 LongJump jump; 1042 LongJump jump;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 SetupErrorResult(result); 1109 SetupErrorResult(result);
1151 isolate->set_long_jump_base(base); 1110 isolate->set_long_jump_base(base);
1152 return Object::null(); 1111 return Object::null();
1153 } 1112 }
1154 1113
1155 1114
1156 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, 1115 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list,
1157 intptr_t offset, 1116 intptr_t offset,
1158 uint8_t* native_array, 1117 uint8_t* native_array,
1159 intptr_t length) { 1118 intptr_t length) {
1160 Zone zone; // Setup a VM zone as we are creating some handles. 1119 Isolate* isolate = Isolate::Current();
1161 HandleScope scope; // Setup a VM handle scope. 1120 DARTSCOPE(isolate);
1162 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1121 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1163 if (obj.IsArray()) { 1122 if (obj.IsArray()) {
1164 Array& array_obj = Array::Handle(); 1123 Array& array_obj = Array::Handle();
1165 array_obj ^= obj.raw(); 1124 array_obj ^= obj.raw();
1166 if ((offset + length) <= array_obj.Length()) { 1125 if ((offset + length) <= array_obj.Length()) {
1167 Object& element = Object::Handle(); 1126 Object& element = Object::Handle();
1168 Integer& integer = Integer::Handle(); 1127 Integer& integer = Integer::Handle();
1169 for (int i = 0; i < length; i++) { 1128 for (int i = 0; i < length; i++) {
1170 element = array_obj.At(offset + i); 1129 element = array_obj.At(offset + i);
1171 integer ^= element.raw(); 1130 integer ^= element.raw();
1172 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); 1131 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff);
1173 ASSERT(integer.AsInt64Value() <= 0xff); 1132 ASSERT(integer.AsInt64Value() <= 0xff);
1174 // TODO(hpayer): value should always be smaller then 0xff. Add error 1133 // TODO(hpayer): value should always be smaller then 0xff. Add error
1175 // handling. 1134 // handling.
1176 } 1135 }
1177 return Api::Success(); 1136 return Api::Success();
1178 } 1137 }
1179 return Api::Error("Invalid length passed in to access array elements"); 1138 return Api::Error("Invalid length passed in to access array elements");
1180 } 1139 }
1181 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1140 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1182 // Now check and handle a dart object that implements the List interface. 1141 // Now check and handle a dart object that implements the List interface.
1183 Isolate* isolate = Isolate::Current();
1184 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1142 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1185 if (!instance.IsNull()) { 1143 if (!instance.IsNull()) {
1186 String& name = String::Handle(String::New("[]")); 1144 String& name = String::Handle(String::New("[]"));
1187 const Function& function = Function::Handle( 1145 const Function& function = Function::Handle(
1188 Resolver::ResolveDynamic(instance, name, 2, 0)); 1146 Resolver::ResolveDynamic(instance, name, 2, 0));
1189 if (!function.IsNull()) { 1147 if (!function.IsNull()) {
1190 Object& element = Object::Handle(); 1148 Object& element = Object::Handle();
1191 Integer& intobj = Integer::Handle(); 1149 Integer& intobj = Integer::Handle();
1192 Dart_Handle result; 1150 Dart_Handle result;
1193 for (int i = 0; i < length; i++) { 1151 for (int i = 0; i < length; i++) {
1194 intobj = Integer::New(offset + i); 1152 intobj = Integer::New(offset + i);
1195 element = GetListAt(isolate, instance, intobj, function, &result); 1153 element = GetListAt(isolate, instance, intobj, function, &result);
1196 if (Dart_IsError(result)) { 1154 if (Dart_IsError(result)) {
1197 return result; // Error condition. 1155 return result; // Error condition.
1198 } 1156 }
1199 intobj ^= element.raw(); 1157 intobj ^= element.raw();
1200 ASSERT(intobj.AsInt64Value() <= 0xff); 1158 ASSERT(intobj.AsInt64Value() <= 0xff);
1201 // TODO(hpayer): value should always be smaller then 0xff. Add error 1159 // TODO(hpayer): value should always be smaller then 0xff. Add error
1202 // handling. 1160 // handling.
1203 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); 1161 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff);
1204 } 1162 }
1205 return Api::Success(); 1163 return Api::Success();
1206 } 1164 }
1207 } 1165 }
1208 return Api::Error("Object does not implement the 'List' interface"); 1166 return Api::Error("Object does not implement the 'List' interface");
1209 } 1167 }
1210 1168
1211 1169
1212 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { 1170 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) {
1213 Zone zone; // Setup a VM zone as we are creating some handles. 1171 Isolate* isolate = Isolate::Current();
1214 HandleScope scope; // Setup a VM handle scope. 1172 DARTSCOPE(isolate);
1215 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1173 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1216 if (obj.IsArray()) { 1174 if (obj.IsArray()) {
1217 Array& array_obj = Array::Handle(); 1175 Array& array_obj = Array::Handle();
1218 array_obj ^= obj.raw(); 1176 array_obj ^= obj.raw();
1219 if ((index >= 0) && (index < array_obj.Length())) { 1177 if ((index >= 0) && (index < array_obj.Length())) {
1220 const Object& element = Object::Handle(array_obj.At(index)); 1178 const Object& element = Object::Handle(array_obj.At(index));
1221 return Api::NewLocalHandle(element); 1179 return Api::NewLocalHandle(element);
1222 } 1180 }
1223 return Api::Error("Invalid index passed in to access array element"); 1181 return Api::Error("Invalid index passed in to access array element");
1224 } 1182 }
1225 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1183 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1226 // Now check and handle a dart object that implements the List interface. 1184 // Now check and handle a dart object that implements the List interface.
1227 Isolate* isolate = Isolate::Current();
1228 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1185 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1229 if (!instance.IsNull()) { 1186 if (!instance.IsNull()) {
1230 String& name = String::Handle(String::New("[]")); 1187 String& name = String::Handle(String::New("[]"));
1231 const Function& function = Function::Handle( 1188 const Function& function = Function::Handle(
1232 Resolver::ResolveDynamic(instance, name, 2, 0)); 1189 Resolver::ResolveDynamic(instance, name, 2, 0));
1233 if (!function.IsNull()) { 1190 if (!function.IsNull()) {
1234 Object& element = Object::Handle(); 1191 Object& element = Object::Handle();
1235 Integer& indexobj = Integer::Handle(); 1192 Integer& indexobj = Integer::Handle();
1236 Dart_Handle result; 1193 Dart_Handle result;
1237 indexobj = Integer::New(index); 1194 indexobj = Integer::New(index);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 SetupErrorResult(result); 1233 SetupErrorResult(result);
1277 } 1234 }
1278 isolate->set_long_jump_base(base); 1235 isolate->set_long_jump_base(base);
1279 } 1236 }
1280 1237
1281 1238
1282 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, 1239 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list,
1283 intptr_t offset, 1240 intptr_t offset,
1284 uint8_t* native_array, 1241 uint8_t* native_array,
1285 intptr_t length) { 1242 intptr_t length) {
1286 Zone zone; 1243 Isolate* isolate = Isolate::Current();
1287 HandleScope scope; 1244 DARTSCOPE(isolate);
1288 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1245 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1289 if (obj.IsArray()) { 1246 if (obj.IsArray()) {
1290 Array& array_obj = Array::Handle(); 1247 Array& array_obj = Array::Handle();
1291 array_obj ^= obj.raw(); 1248 array_obj ^= obj.raw();
1292 Integer& integer = Integer::Handle(); 1249 Integer& integer = Integer::Handle();
1293 if ((offset + length) <= array_obj.Length()) { 1250 if ((offset + length) <= array_obj.Length()) {
1294 for (int i = 0; i < length; i++) { 1251 for (int i = 0; i < length; i++) {
1295 integer ^= Integer::New(native_array[i]); 1252 integer ^= Integer::New(native_array[i]);
1296 array_obj.SetAt(offset + i, integer); 1253 array_obj.SetAt(offset + i, integer);
1297 } 1254 }
1298 return Api::Success(); 1255 return Api::Success();
1299 } 1256 }
1300 return Api::Error("Invalid length passed in to set array elements"); 1257 return Api::Error("Invalid length passed in to set array elements");
1301 } 1258 }
1302 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1259 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1303 // Now check and handle a dart object that implements the List interface. 1260 // Now check and handle a dart object that implements the List interface.
1304 Isolate* isolate = Isolate::Current();
1305 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1261 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1306 if (!instance.IsNull()) { 1262 if (!instance.IsNull()) {
1307 String& name = String::Handle(String::New("[]=")); 1263 String& name = String::Handle(String::New("[]="));
1308 const Function& function = Function::Handle( 1264 const Function& function = Function::Handle(
1309 Resolver::ResolveDynamic(instance, name, 3, 0)); 1265 Resolver::ResolveDynamic(instance, name, 3, 0));
1310 if (!function.IsNull()) { 1266 if (!function.IsNull()) {
1311 Integer& indexobj = Integer::Handle(); 1267 Integer& indexobj = Integer::Handle();
1312 Integer& valueobj = Integer::Handle(); 1268 Integer& valueobj = Integer::Handle();
1313 Dart_Handle result; 1269 Dart_Handle result;
1314 for (int i = 0; i < length; i++) { 1270 for (int i = 0; i < length; i++) {
1315 indexobj = Integer::New(offset + i); 1271 indexobj = Integer::New(offset + i);
1316 valueobj ^= Integer::New(native_array[i]); 1272 valueobj ^= Integer::New(native_array[i]);
1317 SetListAt(isolate, instance, indexobj, valueobj, function, &result); 1273 SetListAt(isolate, instance, indexobj, valueobj, function, &result);
1318 if (Dart_IsError(result)) { 1274 if (Dart_IsError(result)) {
1319 return result; // Error condition. 1275 return result; // Error condition.
1320 } 1276 }
1321 } 1277 }
1322 return Api::Success(); 1278 return Api::Success();
1323 } 1279 }
1324 } 1280 }
1325 return Api::Error("Object does not implement the 'List' interface"); 1281 return Api::Error("Object does not implement the 'List' interface");
1326 } 1282 }
1327 1283
1328 1284
1329 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, 1285 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list,
1330 intptr_t index, 1286 intptr_t index,
1331 Dart_Handle value) { 1287 Dart_Handle value) {
1332 Zone zone; // Setup a VM zone as we are creating some handles. 1288 Isolate* isolate = Isolate::Current();
1333 HandleScope scope; // Setup a VM handle scope. 1289 DARTSCOPE(isolate);
1334 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1290 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1335 if (obj.IsArray()) { 1291 if (obj.IsArray()) {
1336 Array& array_obj = Array::Handle(); 1292 Array& array_obj = Array::Handle();
1337 array_obj ^= obj.raw(); 1293 array_obj ^= obj.raw();
1338 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 1294 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
1339 if ((index >= 0) && (index < array_obj.Length())) { 1295 if ((index >= 0) && (index < array_obj.Length())) {
1340 array_obj.SetAt(index, value_obj); 1296 array_obj.SetAt(index, value_obj);
1341 return Api::Success(); 1297 return Api::Success();
1342 } 1298 }
1343 return Api::Error("Invalid index passed in to set array element"); 1299 return Api::Error("Invalid index passed in to set array element");
1344 } 1300 }
1345 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1301 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1346 // Now check and handle a dart object that implements the List interface. 1302 // Now check and handle a dart object that implements the List interface.
1347 Isolate* isolate = Isolate::Current();
1348 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1303 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1349 if (!instance.IsNull()) { 1304 if (!instance.IsNull()) {
1350 String& name = String::Handle(String::New("[]=")); 1305 String& name = String::Handle(String::New("[]="));
1351 const Function& function = Function::Handle( 1306 const Function& function = Function::Handle(
1352 Resolver::ResolveDynamic(instance, name, 3, 0)); 1307 Resolver::ResolveDynamic(instance, name, 3, 0));
1353 if (!function.IsNull()) { 1308 if (!function.IsNull()) {
1354 Dart_Handle result; 1309 Dart_Handle result;
1355 const Integer& index_obj = Integer::Handle(Integer::New(index)); 1310 const Integer& index_obj = Integer::Handle(Integer::New(index));
1356 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 1311 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
1357 SetListAt(isolate, instance, index_obj, value_obj, function, &result); 1312 SetListAt(isolate, instance, index_obj, value_obj, function, &result);
1358 return result; 1313 return result;
1359 } 1314 }
1360 } 1315 }
1361 return Api::Error("Object does not implement the 'List' interface"); 1316 return Api::Error("Object does not implement the 'List' interface");
1362 } 1317 }
1363 1318
1364 1319
1365 // NOTE: Need to pass 'result' as a parameter here in order to avoid 1320 // NOTE: Need to pass 'result' as a parameter here in order to avoid
1366 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 1321 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
1367 // which shows up because of the use of setjmp. 1322 // which shows up because of the use of setjmp.
1368 static void InvokeStatic(const Function& function, 1323 static void InvokeStatic(Isolate* isolate,
1324 const Function& function,
1369 GrowableArray<const Object*>& args, 1325 GrowableArray<const Object*>& args,
1370 Dart_Handle* result) { 1326 Dart_Handle* result) {
1371 Isolate* isolate = Isolate::Current();
1372 ASSERT(isolate != NULL); 1327 ASSERT(isolate != NULL);
1373 LongJump* base = isolate->long_jump_base(); 1328 LongJump* base = isolate->long_jump_base();
1374 LongJump jump; 1329 LongJump jump;
1375 isolate->set_long_jump_base(&jump); 1330 isolate->set_long_jump_base(&jump);
1376 if (setjmp(*jump.Set()) == 0) { 1331 if (setjmp(*jump.Set()) == 0) {
1377 const Array& kNoArgumentNames = Array::Handle(); 1332 const Array& kNoArgumentNames = Array::Handle();
1378 const Instance& retval = Instance::Handle( 1333 const Instance& retval = Instance::Handle(
1379 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); 1334 DartEntry::InvokeStatic(function, args, kNoArgumentNames));
1380 if (retval.IsUnhandledException()) { 1335 if (retval.IsUnhandledException()) {
1381 *result = Api::ErrorFromException(retval); 1336 *result = Api::ErrorFromException(retval);
1382 } else { 1337 } else {
1383 *result = Api::NewLocalHandle(retval); 1338 *result = Api::NewLocalHandle(retval);
1384 } 1339 }
1385 } else { 1340 } else {
1386 SetupErrorResult(result); 1341 SetupErrorResult(result);
1387 } 1342 }
1388 isolate->set_long_jump_base(base); 1343 isolate->set_long_jump_base(base);
1389 } 1344 }
1390 1345
1391 1346
1392 // NOTE: Need to pass 'result' as a parameter here in order to avoid 1347 // NOTE: Need to pass 'result' as a parameter here in order to avoid
1393 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 1348 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
1394 // which shows up because of the use of setjmp. 1349 // which shows up because of the use of setjmp.
1395 static void InvokeDynamic(const Instance& receiver, 1350 static void InvokeDynamic(Isolate* isolate,
1351 const Instance& receiver,
1396 const Function& function, 1352 const Function& function,
1397 GrowableArray<const Object*>& args, 1353 GrowableArray<const Object*>& args,
1398 Dart_Handle* result) { 1354 Dart_Handle* result) {
1399 Isolate* isolate = Isolate::Current();
1400 ASSERT(isolate != NULL); 1355 ASSERT(isolate != NULL);
1401 LongJump* base = isolate->long_jump_base(); 1356 LongJump* base = isolate->long_jump_base();
1402 LongJump jump; 1357 LongJump jump;
1403 isolate->set_long_jump_base(&jump); 1358 isolate->set_long_jump_base(&jump);
1404 if (setjmp(*jump.Set()) == 0) { 1359 if (setjmp(*jump.Set()) == 0) {
1405 const Array& kNoArgumentNames = Array::Handle(); 1360 const Array& kNoArgumentNames = Array::Handle();
1406 const Instance& retval = Instance::Handle( 1361 const Instance& retval = Instance::Handle(
1407 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); 1362 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames));
1408 if (retval.IsUnhandledException()) { 1363 if (retval.IsUnhandledException()) {
1409 *result = Api::ErrorFromException(retval); 1364 *result = Api::ErrorFromException(retval);
1410 } else { 1365 } else {
1411 *result = Api::NewLocalHandle(retval); 1366 *result = Api::NewLocalHandle(retval);
1412 } 1367 }
1413 } else { 1368 } else {
1414 SetupErrorResult(result); 1369 SetupErrorResult(result);
1415 } 1370 }
1416 isolate->set_long_jump_base(base); 1371 isolate->set_long_jump_base(base);
1417 } 1372 }
1418 1373
1419 1374
1420 // NOTE: Need to pass 'result' as a parameter here in order to avoid 1375 // NOTE: Need to pass 'result' as a parameter here in order to avoid
1421 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 1376 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
1422 // which shows up because of the use of setjmp. 1377 // which shows up because of the use of setjmp.
1423 static void InvokeClosure(const Closure& closure, 1378 static void InvokeClosure(Isolate* isolate,
1379 const Closure& closure,
1424 GrowableArray<const Object*>& args, 1380 GrowableArray<const Object*>& args,
1425 Dart_Handle* result) { 1381 Dart_Handle* result) {
1426 Isolate* isolate = Isolate::Current();
1427 ASSERT(isolate != NULL); 1382 ASSERT(isolate != NULL);
1428 LongJump* base = isolate->long_jump_base(); 1383 LongJump* base = isolate->long_jump_base();
1429 LongJump jump; 1384 LongJump jump;
1430 isolate->set_long_jump_base(&jump); 1385 isolate->set_long_jump_base(&jump);
1431 if (setjmp(*jump.Set()) == 0) { 1386 if (setjmp(*jump.Set()) == 0) {
1432 const Array& kNoArgumentNames = Array::Handle(); 1387 const Array& kNoArgumentNames = Array::Handle();
1433 const Instance& retval = Instance::Handle( 1388 const Instance& retval = Instance::Handle(
1434 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); 1389 DartEntry::InvokeClosure(closure, args, kNoArgumentNames));
1435 if (retval.IsUnhandledException()) { 1390 if (retval.IsUnhandledException()) {
1436 *result = Api::ErrorFromException(retval); 1391 *result = Api::ErrorFromException(retval);
1437 } else { 1392 } else {
1438 *result = Api::NewLocalHandle(retval); 1393 *result = Api::NewLocalHandle(retval);
1439 } 1394 }
1440 } else { 1395 } else {
1441 SetupErrorResult(result); 1396 SetupErrorResult(result);
1442 } 1397 }
1443 isolate->set_long_jump_base(base); 1398 isolate->set_long_jump_base(base);
1444 } 1399 }
1445 1400
1446 1401
1447 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, 1402 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in,
1448 Dart_Handle class_name_in, 1403 Dart_Handle class_name_in,
1449 Dart_Handle function_name_in, 1404 Dart_Handle function_name_in,
1450 int number_of_arguments, 1405 int number_of_arguments,
1451 Dart_Handle* arguments) { 1406 Dart_Handle* arguments) {
1452 Zone zone; // Setup a VM zone as we are creating some handles. 1407 Isolate* isolate = Isolate::Current();
1453 HandleScope scope; // Setup a VM handle scope. 1408 DARTSCOPE(isolate);
1454 // Finalize all classes. 1409 // Finalize all classes.
1455 const char* msg = CheckIsolateState(); 1410 const char* msg = CheckIsolateState(isolate);
1456 if (msg != NULL) { 1411 if (msg != NULL) {
1457 return Api::Error(msg); 1412 return Api::Error(msg);
1458 } 1413 }
1459 1414
1460 // Now try to resolve and invoke the static function. 1415 // Now try to resolve and invoke the static function.
1461 const Library& library = 1416 const Library& library =
1462 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 1417 Library::CheckedHandle(Api::UnwrapHandle(library_in));
1463 if (library.IsNull()) { 1418 if (library.IsNull()) {
1464 return Api::Error("No library specified"); 1419 return Api::Error("No library specified");
1465 } 1420 }
(...skipping 26 matching lines...) Expand all
1492 class_name.ToCString(), function_name.ToCString()); 1447 class_name.ToCString(), function_name.ToCString());
1493 } 1448 }
1494 return Api::Error(msg); 1449 return Api::Error(msg);
1495 } 1450 }
1496 Dart_Handle retval; 1451 Dart_Handle retval;
1497 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1452 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1498 for (int i = 0; i < number_of_arguments; i++) { 1453 for (int i = 0; i < number_of_arguments; i++) {
1499 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1454 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1500 dart_arguments.Add(&arg); 1455 dart_arguments.Add(&arg);
1501 } 1456 }
1502 InvokeStatic(function, dart_arguments, &retval); 1457 InvokeStatic(isolate, function, dart_arguments, &retval);
1503 return retval; 1458 return retval;
1504 } 1459 }
1505 1460
1506 1461
1507 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, 1462 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object,
1508 Dart_Handle function_name, 1463 Dart_Handle function_name,
1509 int number_of_arguments, 1464 int number_of_arguments,
1510 Dart_Handle* arguments) { 1465 Dart_Handle* arguments) {
1511 Zone zone; // Setup a VM zone as we are creating some handles. 1466 Isolate* isolate = Isolate::Current();
1512 HandleScope scope; // Setup a VM handle scope. 1467 DARTSCOPE(isolate);
1513 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1468 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1514 // Let the resolver figure out the correct target for null receiver. 1469 // Let the resolver figure out the correct target for null receiver.
1515 // E.g., (null).toString() should execute correctly. 1470 // E.g., (null).toString() should execute correctly.
1516 if (!obj.IsNull() && !obj.IsInstance()) { 1471 if (!obj.IsNull() && !obj.IsInstance()) {
1517 return Api::Error( 1472 return Api::Error(
1518 "Invalid receiver (not instance) passed to invoke dynamic"); 1473 "Invalid receiver (not instance) passed to invoke dynamic");
1519 } 1474 }
1520 if (function_name == NULL) { 1475 if (function_name == NULL) {
1521 return Api::Error("Invalid function name specified"); 1476 return Api::Error("Invalid function name specified");
1522 } 1477 }
(...skipping 12 matching lines...) Expand all
1535 // TODO(5415268): Invoke noSuchMethod instead of failing. 1490 // TODO(5415268): Invoke noSuchMethod instead of failing.
1536 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); 1491 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString());
1537 return Api::Error("Unable to find instance function"); 1492 return Api::Error("Unable to find instance function");
1538 } 1493 }
1539 Dart_Handle retval; 1494 Dart_Handle retval;
1540 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1495 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1541 for (int i = 0; i < number_of_arguments; i++) { 1496 for (int i = 0; i < number_of_arguments; i++) {
1542 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1497 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1543 dart_arguments.Add(&arg); 1498 dart_arguments.Add(&arg);
1544 } 1499 }
1545 InvokeDynamic(receiver, function, dart_arguments, &retval); 1500 InvokeDynamic(isolate, receiver, function, dart_arguments, &retval);
1546 return retval; 1501 return retval;
1547 } 1502 }
1548 1503
1549 1504
1550 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 1505 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
1551 int number_of_arguments, 1506 int number_of_arguments,
1552 Dart_Handle* arguments) { 1507 Dart_Handle* arguments) {
1553 Zone zone; // Setup a VM zone as we are creating some handles. 1508 Isolate* isolate = Isolate::Current();
1554 HandleScope scope; // Setup a VM handle scope. 1509 DARTSCOPE(isolate);
1555 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); 1510 const Object& obj = Object::Handle(Api::UnwrapHandle(closure));
1556 if (obj.IsNull()) { 1511 if (obj.IsNull()) {
1557 return Api::Error("Null object passed in to invoke closure"); 1512 return Api::Error("Null object passed in to invoke closure");
1558 } 1513 }
1559 if (!obj.IsClosure()) { 1514 if (!obj.IsClosure()) {
1560 return Api::Error("Invalid closure passed to invoke closure"); 1515 return Api::Error("Invalid closure passed to invoke closure");
1561 } 1516 }
1562 ASSERT(ClassFinalizer::AllClassesFinalized()); 1517 ASSERT(ClassFinalizer::AllClassesFinalized());
1563 1518
1564 // Now try to invoke the closure. 1519 // Now try to invoke the closure.
1565 Closure& closure_obj = Closure::Handle(); 1520 Closure& closure_obj = Closure::Handle();
1566 closure_obj ^= obj.raw(); 1521 closure_obj ^= obj.raw();
1567 Dart_Handle retval; 1522 Dart_Handle retval;
1568 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1523 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1569 for (int i = 0; i < number_of_arguments; i++) { 1524 for (int i = 0; i < number_of_arguments; i++) {
1570 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1525 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1571 dart_arguments.Add(&arg); 1526 dart_arguments.Add(&arg);
1572 } 1527 }
1573 InvokeClosure(closure_obj, dart_arguments, &retval); 1528 InvokeClosure(isolate, closure_obj, dart_arguments, &retval);
1574 return retval; 1529 return retval;
1575 } 1530 }
1576 1531
1577 1532
1578 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, 1533 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
1579 int index) { 1534 int index) {
1580 Zone zone; // Setup a VM zone as we are creating some handles. 1535 DARTSCOPE(Isolate::Current());
1581 HandleScope scope; // Setup a VM handle scope.
1582 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 1536 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
1583 const Object& obj = Object::Handle(arguments->At(index)); 1537 const Object& obj = Object::Handle(arguments->At(index));
1584 return Api::NewLocalHandle(obj); 1538 return Api::NewLocalHandle(obj);
1585 } 1539 }
1586 1540
1587 1541
1588 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { 1542 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) {
1589 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 1543 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
1590 return arguments->Count(); 1544 return arguments->Count();
1591 } 1545 }
1592 1546
1593 1547
1594 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 1548 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
1595 Dart_Handle retval) { 1549 Dart_Handle retval) {
1596 Zone zone; // Setup a VM zone as we are creating some handles. 1550 DARTSCOPE(Isolate::Current());
1597 HandleScope scope; // Setup a VM handle scope.
1598 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 1551 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
1599 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval))); 1552 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval)));
1600 } 1553 }
1601 1554
1602 1555
1603 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { 1556 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
1604 Isolate* isolate = Isolate::Current(); 1557 Isolate* isolate = Isolate::Current();
1605 ASSERT(isolate != NULL); 1558 DARTSCOPE(isolate);
1606 Zone zone; // Setup a VM zone as we are creating some handles.
1607 HandleScope scope; // Setup a VM handle scope.
1608 if (isolate->top_exit_frame_info() == 0) { 1559 if (isolate->top_exit_frame_info() == 0) {
1609 // There are no dart frames on the stack so it would be illegal to 1560 // There are no dart frames on the stack so it would be illegal to
1610 // throw an exception here. 1561 // throw an exception here.
1611 return Api::Error("No Dart frames on stack, cannot throw exception"); 1562 return Api::Error("No Dart frames on stack, cannot throw exception");
1612 } 1563 }
1613 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); 1564 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
1614 // Unwind all the API scopes till the exit frame before throwing an 1565 // Unwind all the API scopes till the exit frame before throwing an
1615 // exception. 1566 // exception.
1616 ApiState* state = isolate->api_state(); 1567 ApiState* state = isolate->api_state();
1617 ASSERT(state != NULL); 1568 ASSERT(state != NULL);
1618 state->UnwindScopes(isolate->top_exit_frame_info()); 1569 state->UnwindScopes(isolate->top_exit_frame_info());
1619 Exceptions::Throw(excp); 1570 Exceptions::Throw(excp);
1620 return Api::Error("Exception was not thrown, internal error"); 1571 return Api::Error("Exception was not thrown, internal error");
1621 } 1572 }
1622 1573
1623 1574
1624 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, 1575 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
1625 Dart_Handle stacktrace) { 1576 Dart_Handle stacktrace) {
1626 Isolate* isolate = Isolate::Current(); 1577 Isolate* isolate = Isolate::Current();
1627 ASSERT(isolate != NULL); 1578 ASSERT(isolate != NULL);
1628 if (isolate->top_exit_frame_info() == 0) { 1579 if (isolate->top_exit_frame_info() == 0) {
1629 // There are no dart frames on the stack so it would be illegal to 1580 // There are no dart frames on the stack so it would be illegal to
1630 // throw an exception here. 1581 // throw an exception here.
1631 return Api::Error("No Dart frames on stack, cannot throw exception"); 1582 return Api::Error("No Dart frames on stack, cannot throw exception");
1632 } 1583 }
1633 Zone zone; // Setup a VM zone as we are creating some handles. 1584 DARTSCOPE(isolate);
1634 HandleScope scope; // Setup a VM handle scope.
1635 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); 1585 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
1636 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace)); 1586 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace));
1637 // Unwind all the API scopes till the exit frame before throwing an 1587 // Unwind all the API scopes till the exit frame before throwing an
1638 // exception. 1588 // exception.
1639 ApiState* state = isolate->api_state(); 1589 ApiState* state = isolate->api_state();
1640 ASSERT(state != NULL); 1590 ASSERT(state != NULL);
1641 state->UnwindScopes(isolate->top_exit_frame_info()); 1591 state->UnwindScopes(isolate->top_exit_frame_info());
1642 Exceptions::ReThrow(excp, stk); 1592 Exceptions::ReThrow(excp, stk);
1643 return Api::Error("Exception was not re thrown, internal error"); 1593 return Api::Error("Exception was not re thrown, internal error");
1644 } 1594 }
(...skipping 17 matching lines...) Expand all
1662 ApiState* state = isolate->api_state(); 1612 ApiState* state = isolate->api_state();
1663 ASSERT(state != NULL); 1613 ASSERT(state != NULL);
1664 ApiLocalScope* scope = state->top_scope(); 1614 ApiLocalScope* scope = state->top_scope();
1665 ASSERT(scope != NULL); 1615 ASSERT(scope != NULL);
1666 state->set_top_scope(scope->previous()); // Reset top scope to previous. 1616 state->set_top_scope(scope->previous()); // Reset top scope to previous.
1667 delete scope; // Free up the old scope which we have just exited. 1617 delete scope; // Free up the old scope which we have just exited.
1668 } 1618 }
1669 1619
1670 1620
1671 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { 1621 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
1672 Zone zone; // Setup a VM zone as we are creating some handles.
1673 HandleScope scope; // Setup a VM handle scope.
1674 Isolate* isolate = Isolate::Current(); 1622 Isolate* isolate = Isolate::Current();
1675 ASSERT(isolate != NULL); 1623 DARTSCOPE(isolate);
1676 ApiState* state = isolate->api_state(); 1624 ApiState* state = isolate->api_state();
1677 ASSERT(state != NULL); 1625 ASSERT(state != NULL);
1678 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object)); 1626 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object));
1679 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); 1627 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
1680 new_ref->set_raw(old_ref); 1628 new_ref->set_raw(old_ref);
1681 return reinterpret_cast<Dart_Handle>(new_ref); 1629 return reinterpret_cast<Dart_Handle>(new_ref);
1682 } 1630 }
1683 1631
1684 1632
1685 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object) { 1633 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 return Api::NewLocalHandle(function); 1734 return Api::NewLocalHandle(function);
1787 } 1735 }
1788 cls = cls.SuperClass(); 1736 cls = cls.SuperClass();
1789 } 1737 }
1790 return Api::Error("Unable to find field in the class"); 1738 return Api::Error("Unable to find field in the class");
1791 } 1739 }
1792 1740
1793 1741
1794 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, 1742 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls,
1795 Dart_Handle name) { 1743 Dart_Handle name) {
1796 Zone zone; // Setup a VM zone as we are creating some handles. 1744 Isolate* isolate = Isolate::Current();
1797 HandleScope scope; // Setup a VM handle scope. 1745 DARTSCOPE(isolate);
1798 Dart_Handle result = LookupStaticField(cls, name, kGetter); 1746 Dart_Handle result = LookupStaticField(cls, name, kGetter);
1799 if (::Dart_IsError(result)) { 1747 if (::Dart_IsError(result)) {
1800 return result; 1748 return result;
1801 } 1749 }
1802 Object& retval = Object::Handle(); 1750 Object& retval = Object::Handle();
1803 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); 1751 const Object& obj = Object::Handle(Api::UnwrapHandle(result));
1804 if (obj.IsField()) { 1752 if (obj.IsField()) {
1805 Field& fld = Field::Handle(); 1753 Field& fld = Field::Handle();
1806 fld ^= obj.raw(); 1754 fld ^= obj.raw();
1807 retval = fld.value(); 1755 retval = fld.value();
1808 return Api::NewLocalHandle(retval); 1756 return Api::NewLocalHandle(retval);
1809 } else { 1757 } else {
1810 Function& func = Function::Handle(); 1758 Function& func = Function::Handle();
1811 func ^= obj.raw(); 1759 func ^= obj.raw();
1812 GrowableArray<const Object*> args; 1760 GrowableArray<const Object*> args;
1813 InvokeStatic(func, args, &result); 1761 InvokeStatic(isolate, func, args, &result);
1814 return result; 1762 return result;
1815 } 1763 }
1816 } 1764 }
1817 1765
1818 1766
1819 // TODO(iposva): The value parameter should be documented as being an instance. 1767 // TODO(iposva): The value parameter should be documented as being an instance.
1820 // TODO(turnidge): Is this skipping the setter? 1768 // TODO(turnidge): Is this skipping the setter?
1821 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, 1769 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls,
1822 Dart_Handle name, 1770 Dart_Handle name,
1823 Dart_Handle value) { 1771 Dart_Handle value) {
1824 Zone zone; // Setup a VM zone as we are creating some handles. 1772 DARTSCOPE(Isolate::Current());
1825 HandleScope scope; // Setup a VM handle scope.
1826 Dart_Handle result = LookupStaticField(cls, name, kSetter); 1773 Dart_Handle result = LookupStaticField(cls, name, kSetter);
1827 if (::Dart_IsError(result)) { 1774 if (::Dart_IsError(result)) {
1828 return result; 1775 return result;
1829 } 1776 }
1830 Field& fld = Field::Handle(); 1777 Field& fld = Field::Handle();
1831 fld ^= Api::UnwrapHandle(result); 1778 fld ^= Api::UnwrapHandle(result);
1832 if (fld.is_final()) { 1779 if (fld.is_final()) {
1833 return Api::Error("Specified field is a static final field in the class"); 1780 return Api::Error("Specified field is a static final field in the class");
1834 } 1781 }
1835 const Object& val = Object::Handle(Api::UnwrapHandle(value)); 1782 const Object& val = Object::Handle(Api::UnwrapHandle(value));
1836 Instance& instance = Instance::Handle(); 1783 Instance& instance = Instance::Handle();
1837 instance ^= val.raw(); 1784 instance ^= val.raw();
1838 fld.set_value(instance); 1785 fld.set_value(instance);
1839 return Api::NewLocalHandle(val); 1786 return Api::NewLocalHandle(val);
1840 } 1787 }
1841 1788
1842 1789
1843 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, 1790 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj,
1844 Dart_Handle name) { 1791 Dart_Handle name) {
1845 Zone zone; // Setup a VM zone as we are creating some handles. 1792 Isolate* isolate = Isolate::Current();
1846 HandleScope scope; // Setup a VM handle scope. 1793 DARTSCOPE(isolate);
1847 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1794 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1848 if (param.IsNull() || !param.IsInstance()) { 1795 if (param.IsNull() || !param.IsInstance()) {
1849 return Api::Error("Invalid object passed in to access instance field"); 1796 return Api::Error("Invalid object passed in to access instance field");
1850 } 1797 }
1851 Instance& object = Instance::Handle(); 1798 Instance& object = Instance::Handle();
1852 object ^= param.raw(); 1799 object ^= param.raw();
1853 Dart_Handle result = LookupInstanceField(object, name, kGetter); 1800 Dart_Handle result = LookupInstanceField(object, name, kGetter);
1854 if (::Dart_IsError(result)) { 1801 if (::Dart_IsError(result)) {
1855 return result; 1802 return result;
1856 } 1803 }
1857 Function& func = Function::Handle(); 1804 Function& func = Function::Handle();
1858 func ^= Api::UnwrapHandle(result); 1805 func ^= Api::UnwrapHandle(result);
1859 GrowableArray<const Object*> arguments; 1806 GrowableArray<const Object*> arguments;
1860 InvokeDynamic(object, func, arguments, &result); 1807 InvokeDynamic(isolate, object, func, arguments, &result);
1861 return result; 1808 return result;
1862 } 1809 }
1863 1810
1864 1811
1865 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, 1812 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj,
1866 Dart_Handle name, 1813 Dart_Handle name,
1867 Dart_Handle value) { 1814 Dart_Handle value) {
1868 Zone zone; // Setup a VM zone as we are creating some handles. 1815 Isolate* isolate = Isolate::Current();
1869 HandleScope scope; // Setup a VM handle scope. 1816 DARTSCOPE(isolate);
1870 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1817 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1871 if (param.IsNull() || !param.IsInstance()) { 1818 if (param.IsNull() || !param.IsInstance()) {
1872 return Api::Error("Invalid object passed in to access instance field"); 1819 return Api::Error("Invalid object passed in to access instance field");
1873 } 1820 }
1874 Instance& object = Instance::Handle(); 1821 Instance& object = Instance::Handle();
1875 object ^= param.raw(); 1822 object ^= param.raw();
1876 Dart_Handle result = LookupInstanceField(object, name, kSetter); 1823 Dart_Handle result = LookupInstanceField(object, name, kSetter);
1877 if (::Dart_IsError(result)) { 1824 if (::Dart_IsError(result)) {
1878 return result; 1825 return result;
1879 } 1826 }
1880 Function& func = Function::Handle(); 1827 Function& func = Function::Handle();
1881 func ^= Api::UnwrapHandle(result); 1828 func ^= Api::UnwrapHandle(result);
1882 GrowableArray<const Object*> arguments(1); 1829 GrowableArray<const Object*> arguments(1);
1883 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); 1830 const Object& arg = Object::Handle(Api::UnwrapHandle(value));
1884 arguments.Add(&arg); 1831 arguments.Add(&arg);
1885 InvokeDynamic(object, func, arguments, &result); 1832 InvokeDynamic(isolate, object, func, arguments, &result);
1886 return result; 1833 return result;
1887 } 1834 }
1888 1835
1889 1836
1890 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, 1837 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library,
1891 Dart_Handle name, 1838 Dart_Handle name,
1892 int field_count) { 1839 int field_count) {
1893 Zone zone; // Setup a VM zone as we are creating some handles. 1840 Isolate* isolate = Isolate::Current();
1894 HandleScope scope; // Setup a VM handle scope. 1841 DARTSCOPE(isolate);
1895 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 1842 const Object& param = Object::Handle(Api::UnwrapHandle(name));
1896 if (param.IsNull() || !param.IsString() || field_count <= 0) { 1843 if (param.IsNull() || !param.IsString() || field_count <= 0) {
1897 return Api::Error( 1844 return Api::Error(
1898 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); 1845 "Invalid arguments passed to Dart_CreateNativeWrapperClass");
1899 } 1846 }
1900 String& cls_name = String::Handle(); 1847 String& cls_name = String::Handle();
1901 cls_name ^= param.raw(); 1848 cls_name ^= param.raw();
1902 cls_name = String::NewSymbol(cls_name); 1849 cls_name = String::NewSymbol(cls_name);
1903 Library& lib = Library::Handle(); 1850 Library& lib = Library::Handle();
1904 lib ^= Api::UnwrapHandle(library); 1851 lib ^= Api::UnwrapHandle(library);
1905 if (lib.IsNull()) { 1852 if (lib.IsNull()) {
1906 return Api::Error( 1853 return Api::Error(
1907 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); 1854 "Invalid arguments passed to Dart_CreateNativeWrapperClass");
1908 } 1855 }
1909 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib, 1856 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib,
1910 cls_name, 1857 cls_name,
1911 field_count)); 1858 field_count));
1912 if (cls.IsNull()) { 1859 if (cls.IsNull()) {
1913 return Api::Error( 1860 return Api::Error(
1914 "Unable to create native wrapper class : already exists"); 1861 "Unable to create native wrapper class : already exists");
1915 } 1862 }
1916 return Api::NewLocalHandle(cls); 1863 return Api::NewLocalHandle(cls);
1917 } 1864 }
1918 1865
1919 1866
1920 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, 1867 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj,
1921 int index, 1868 int index,
1922 intptr_t* value) { 1869 intptr_t* value) {
1923 Zone zone; // Setup a VM zone as we are creating some handles. 1870 DARTSCOPE(Isolate::Current());
1924 HandleScope scope; // Setup a VM handle scope.
1925 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1871 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1926 if (param.IsNull() || !param.IsInstance()) { 1872 if (param.IsNull() || !param.IsInstance()) {
1927 return Api::Error( 1873 return Api::Error(
1928 "Invalid object passed in to access native instance field"); 1874 "Invalid object passed in to access native instance field");
1929 } 1875 }
1930 Instance& object = Instance::Handle(); 1876 Instance& object = Instance::Handle();
1931 object ^= param.raw(); 1877 object ^= param.raw();
1932 if (!object.IsValidNativeIndex(index)) { 1878 if (!object.IsValidNativeIndex(index)) {
1933 return Api::Error( 1879 return Api::Error(
1934 "Invalid index passed in to access native instance field"); 1880 "Invalid index passed in to access native instance field");
1935 } 1881 }
1936 *value = object.GetNativeField(index); 1882 *value = object.GetNativeField(index);
1937 return Api::Success(); 1883 return Api::Success();
1938 } 1884 }
1939 1885
1940 1886
1941 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, 1887 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj,
1942 int index, 1888 int index,
1943 intptr_t value) { 1889 intptr_t value) {
1944 Zone zone; // Setup a VM zone as we are creating some handles. 1890 DARTSCOPE(Isolate::Current());
1945 HandleScope scope; // Setup a VM handle scope.
1946 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1891 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
1947 if (param.IsNull() || !param.IsInstance()) { 1892 if (param.IsNull() || !param.IsInstance()) {
1948 return Api::Error("Invalid object passed in to set native instance field"); 1893 return Api::Error("Invalid object passed in to set native instance field");
1949 } 1894 }
1950 Instance& object = Instance::Handle(); 1895 Instance& object = Instance::Handle();
1951 object ^= param.raw(); 1896 object ^= param.raw();
1952 if (!object.IsValidNativeIndex(index)) { 1897 if (!object.IsValidNativeIndex(index)) {
1953 return Api::Error("Invalid index passed in to set native instance field"); 1898 return Api::Error("Invalid index passed in to set native instance field");
1954 } 1899 }
1955 object.SetNativeField(index, value); 1900 object.SetNativeField(index, value);
1956 return Api::Success(); 1901 return Api::Success();
1957 } 1902 }
1958 1903
1959 1904
1960 static uint8_t* ApiAllocator(uint8_t* ptr, 1905 static uint8_t* ApiAllocator(uint8_t* ptr,
1961 intptr_t old_size, 1906 intptr_t old_size,
1962 intptr_t new_size) { 1907 intptr_t new_size) {
1963 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr), 1908 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr),
1964 old_size, 1909 old_size,
1965 new_size); 1910 new_size);
1966 return reinterpret_cast<uint8_t*>(new_ptr); 1911 return reinterpret_cast<uint8_t*>(new_ptr);
1967 } 1912 }
1968 1913
1969 1914
1970 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snapshot_buffer, 1915 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snapshot_buffer,
1971 intptr_t* snapshot_size) { 1916 intptr_t* snapshot_size) {
1972 Zone zone; // Setup a VM zone as we are creating some handles. 1917 Isolate* isolate = Isolate::Current();
1973 HandleScope scope; // Setup a VM handle scope. 1918 DARTSCOPE(isolate);
1974 if (snapshot_buffer == NULL || snapshot_size == NULL) { 1919 if (snapshot_buffer == NULL || snapshot_size == NULL) {
1975 return Api::Error("Invalid input parameters to Dart_CreateSnapshot"); 1920 return Api::Error("Invalid input parameters to Dart_CreateSnapshot");
1976 } 1921 }
1977 const char* msg = CheckIsolateState(); 1922 const char* msg = CheckIsolateState(isolate);
1978 if (msg != NULL) { 1923 if (msg != NULL) {
1979 return Api::Error(msg); 1924 return Api::Error(msg);
1980 } 1925 }
1981 // Since this is only a snapshot the root library should not be set. 1926 // Since this is only a snapshot the root library should not be set.
1982 Isolate* isolate = Isolate::Current();
1983 isolate->object_store()->set_root_library(Library::Handle()); 1927 isolate->object_store()->set_root_library(Library::Handle());
1984 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator); 1928 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator);
1985 writer.WriteFullSnapshot(); 1929 writer.WriteFullSnapshot();
1986 *snapshot_size = writer.Size(); 1930 *snapshot_size = writer.Size();
1987 return Api::Success(); 1931 return Api::Success();
1988 } 1932 }
1989 1933
1990 1934
1991 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 1935 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
1992 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 1936 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
1993 return reinterpret_cast<uint8_t*>(new_ptr); 1937 return reinterpret_cast<uint8_t*>(new_ptr);
1994 } 1938 }
1995 1939
1996 1940
1997 DART_EXPORT bool Dart_PostIntArray(Dart_Port port, 1941 DART_EXPORT bool Dart_PostIntArray(Dart_Port port,
1998 intptr_t len, 1942 intptr_t len,
1999 intptr_t* data) { 1943 intptr_t* data) {
2000 uint8_t* buffer = NULL; 1944 uint8_t* buffer = NULL;
2001 MessageWriter writer(&buffer, &allocator); 1945 MessageWriter writer(&buffer, &allocator);
2002 1946
2003 writer.WriteMessage(len, data); 1947 writer.WriteMessage(len, data);
2004 1948
2005 // Post the message at the given port. 1949 // Post the message at the given port.
2006 return PortMap::PostMessage(port, kNoReplyPort, buffer); 1950 return PortMap::PostMessage(port, kNoReplyPort, buffer);
2007 } 1951 }
2008 1952
2009 1953
2010 DART_EXPORT bool Dart_Post(Dart_Port port, Dart_Handle handle) { 1954 DART_EXPORT bool Dart_Post(Dart_Port port, Dart_Handle handle) {
2011 Zone zone; // Setup a VM zone as we are creating some handles. 1955 DARTSCOPE(Isolate::Current());
2012 HandleScope scope; // Setup a VM handle scope.
2013 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); 1956 const Object& object = Object::Handle(Api::UnwrapHandle(handle));
2014 uint8_t* data = NULL; 1957 uint8_t* data = NULL;
2015 SnapshotWriter writer(false, &data, &allocator); 1958 SnapshotWriter writer(false, &data, &allocator);
2016 writer.WriteObject(object.raw()); 1959 writer.WriteObject(object.raw());
2017 writer.FinalizeBuffer(); 1960 writer.FinalizeBuffer();
2018 return PortMap::PostMessage(port, kNoReplyPort, data); 1961 return PortMap::PostMessage(port, kNoReplyPort, data);
2019 } 1962 }
2020 1963
2021 1964
2022 DART_EXPORT void Dart_InitPprofSupport() { 1965 DART_EXPORT void Dart_InitPprofSupport() {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 Isolate* isolate = Isolate::Current(); 2046 Isolate* isolate = Isolate::Current();
2104 ASSERT(isolate != NULL); 2047 ASSERT(isolate != NULL);
2105 ApiState* state = isolate->api_state(); 2048 ApiState* state = isolate->api_state();
2106 ASSERT(state != NULL); 2049 ASSERT(state != NULL);
2107 PersistentHandle* true_handle = state->True(); 2050 PersistentHandle* true_handle = state->True();
2108 return reinterpret_cast<Dart_Handle>(true_handle); 2051 return reinterpret_cast<Dart_Handle>(true_handle);
2109 } 2052 }
2110 2053
2111 2054
2112 Dart_Handle Api::Error(const char* format, ...) { 2055 Dart_Handle Api::Error(const char* format, ...) {
2113 Zone zone; // Setup a VM zone as we are creating some handles. 2056 DARTSCOPE(Isolate::Current());
2114 HandleScope scope; // Setup a VM handle scope.
2115 2057
2116 va_list args; 2058 va_list args;
2117 va_start(args, format); 2059 va_start(args, format);
2118 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 2060 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
2119 va_end(args); 2061 va_end(args);
2120 2062
2121 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); 2063 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
2122 va_list args2; 2064 va_list args2;
2123 va_start(args2, format); 2065 va_start(args2, format);
2124 OS::VSNPrint(buffer, (len + 1), format, args2); 2066 OS::VSNPrint(buffer, (len + 1), format, args2);
2125 va_end(args2); 2067 va_end(args2);
2126 2068
2127 const String& message = String::Handle(String::New(buffer)); 2069 const String& message = String::Handle(String::New(buffer));
2128 const Object& obj = Object::Handle(ApiError::New(message)); 2070 const Object& obj = Object::Handle(ApiError::New(message));
2129 return Api::NewLocalHandle(obj); 2071 return Api::NewLocalHandle(obj);
2130 } 2072 }
2131 2073
2132 2074
2133 Dart_Handle Api::ErrorFromException(const Object& obj) { 2075 Dart_Handle Api::ErrorFromException(const Object& obj) {
2134 Zone zone; // Setup a VM zone as we are creating some handles. 2076 DARTSCOPE(Isolate::Current());
2135 HandleScope scope; // Setup a VM handle scope.
2136 2077
2137 ASSERT(obj.IsUnhandledException()); 2078 ASSERT(obj.IsUnhandledException());
2138 if (obj.IsUnhandledException()) { 2079 if (obj.IsUnhandledException()) {
2139 UnhandledException& uhe = UnhandledException::Handle(); 2080 UnhandledException& uhe = UnhandledException::Handle();
2140 uhe ^= obj.raw(); 2081 uhe ^= obj.raw();
2141 const Object& error = Object::Handle(ApiError::New(uhe)); 2082 const Object& error = Object::Handle(ApiError::New(uhe));
2142 return Api::NewLocalHandle(error); 2083 return Api::NewLocalHandle(error);
2143 } else { 2084 } else {
2144 return Api::Error("Internal error: expected obj.IsUnhandledException()."); 2085 return Api::Error("Internal error: expected obj.IsUnhandledException().");
2145 } 2086 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 ASSERT(isolate != NULL); 2133 ASSERT(isolate != NULL);
2193 ApiState* state = isolate->api_state(); 2134 ApiState* state = isolate->api_state();
2194 ASSERT(state != NULL); 2135 ASSERT(state != NULL);
2195 ApiLocalScope* scope = state->top_scope(); 2136 ApiLocalScope* scope = state->top_scope();
2196 ASSERT(scope != NULL); 2137 ASSERT(scope != NULL);
2197 return scope->zone().Reallocate(ptr, old_size, new_size); 2138 return scope->zone().Reallocate(ptr, old_size, new_size);
2198 } 2139 }
2199 2140
2200 2141
2201 } // namespace dart 2142 } // 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