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