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

Side by Side Diff: lib/isolate.cc

Issue 10874072: Use the return value of vm native methods to set the return value, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart.h" 8 #include "vm/dart.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 123
124 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { 124 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) {
125 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); 125 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull());
126 intptr_t port_id = 126 intptr_t port_id =
127 PortMap::CreatePort(arguments->isolate()->message_handler()); 127 PortMap::CreatePort(arguments->isolate()->message_handler());
128 const Object& port = Object::Handle(ReceivePortCreate(port_id)); 128 const Object& port = Object::Handle(ReceivePortCreate(port_id));
129 if (port.IsError()) { 129 if (port.IsError()) {
130 Exceptions::PropagateError(Error::Cast(port)); 130 Exceptions::PropagateError(Error::Cast(port));
131 } 131 }
132 arguments->SetReturn(port); 132 return port.raw();
133 } 133 }
134 134
135 135
136 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { 136 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) {
137 GET_NATIVE_ARGUMENT(Smi, id, arguments->At(0)); 137 GET_NATIVE_ARGUMENT(Smi, id, arguments->At(0));
138 PortMap::ClosePort(id.Value()); 138 PortMap::ClosePort(id.Value());
139 return Object::null();
139 } 140 }
140 141
141 142
142 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { 143 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) {
143 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->At(0)); 144 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->At(0));
144 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->At(1)); 145 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->At(1));
145 // TODO(iposva): Allow for arbitrary messages to be sent. 146 // TODO(iposva): Allow for arbitrary messages to be sent.
146 GET_NATIVE_ARGUMENT(Instance, obj, arguments->At(2)); 147 GET_NATIVE_ARGUMENT(Instance, obj, arguments->At(2));
147 uint8_t* data = SerializeObject(obj); 148 uint8_t* data = SerializeObject(obj);
148 149
149 // TODO(turnidge): Throw an exception when the return value is false? 150 // TODO(turnidge): Throw an exception when the return value is false?
150 PortMap::PostMessage(new Message( 151 PortMap::PostMessage(new Message(
151 send_id.Value(), reply_id.Value(), data, Message::kNormalPriority)); 152 send_id.Value(), reply_id.Value(), data, Message::kNormalPriority));
153 return Object::null();
152 } 154 }
153 155
154 156
155 static void ThrowIllegalArgException(const String& message) { 157 static void ThrowIllegalArgException(const String& message) {
156 GrowableArray<const Object*> args(1); 158 GrowableArray<const Object*> args(1);
157 args.Add(&message); 159 args.Add(&message);
158 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 160 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
159 } 161 }
160 162
161 163
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 result = DartEntry::InvokeStatic(func, args, kNoArgNames); 366 result = DartEntry::InvokeStatic(func, args, kNoArgNames);
365 if (result.IsError()) { 367 if (result.IsError()) {
366 StoreError(isolate, result); 368 StoreError(isolate, result);
367 return false; 369 return false;
368 } 370 }
369 } 371 }
370 return true; 372 return true;
371 } 373 }
372 374
373 375
374 static void Spawn(NativeArguments* arguments, SpawnState* state) { 376 static RawObject* Spawn(NativeArguments* arguments, SpawnState* state) {
375 // Create a new isolate. 377 // Create a new isolate.
376 char* error = NULL; 378 char* error = NULL;
377 if (!CreateIsolate(state, &error)) { 379 if (!CreateIsolate(state, &error)) {
378 delete state; 380 delete state;
379 const String& msg = String::Handle(String::New(error)); 381 const String& msg = String::Handle(String::New(error));
380 free(error); 382 free(error);
381 ThrowIsolateSpawnException(msg); 383 ThrowIsolateSpawnException(msg);
382 } 384 }
383 385
384 // Try to create a SendPort for the new isolate. 386 // Try to create a SendPort for the new isolate.
385 const Object& port = Object::Handle( 387 const Object& port = Object::Handle(
386 DartLibraryCalls::NewSendPort(state->isolate()->main_port())); 388 DartLibraryCalls::NewSendPort(state->isolate()->main_port()));
387 if (port.IsError()) { 389 if (port.IsError()) {
388 state->Cleanup(); 390 state->Cleanup();
389 delete state; 391 delete state;
390 Exceptions::PropagateError(Error::Cast(port)); 392 Exceptions::PropagateError(Error::Cast(port));
391 } 393 }
392 394
393 // Start the new isolate. 395 // Start the new isolate.
394 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); 396 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state));
395 state->isolate()->message_handler()->Run( 397 state->isolate()->message_handler()->Run(
396 Dart::thread_pool(), RunIsolate, ShutdownIsolate, 398 Dart::thread_pool(), RunIsolate, ShutdownIsolate,
397 reinterpret_cast<uword>(state->isolate())); 399 reinterpret_cast<uword>(state->isolate()));
398 400
399 arguments->SetReturn(port); 401 return port.raw();
400 } 402 }
401 403
402 404
403 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 1) { 405 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 1) {
404 GET_NATIVE_ARGUMENT(Closure, closure, arguments->At(0)); 406 GET_NATIVE_ARGUMENT(Closure, closure, arguments->At(0));
405 const Function& func = Function::Handle(closure.function()); 407 const Function& func = Function::Handle(closure.function());
406 const Class& cls = Class::Handle(func.Owner()); 408 const Class& cls = Class::Handle(func.Owner());
407 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { 409 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) {
408 const String& msg = String::Handle(String::New( 410 const String& msg = String::Handle(String::New(
409 "spawnFunction expects to be passed a closure to a top-level static " 411 "spawnFunction expects to be passed a closure to a top-level static "
410 "function")); 412 "function"));
411 ThrowIllegalArgException(msg); 413 ThrowIllegalArgException(msg);
412 } 414 }
413 415
414 #if defined(DEBUG) 416 #if defined(DEBUG)
415 const Context& ctx = Context::Handle(closure.context()); 417 const Context& ctx = Context::Handle(closure.context());
416 ASSERT(ctx.num_variables() == 0); 418 ASSERT(ctx.num_variables() == 0);
417 #endif 419 #endif
418 420
419 Spawn(arguments, new SpawnState(func)); 421 return Spawn(arguments, new SpawnState(func));
420 } 422 }
421 423
422 424
423 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) { 425 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) {
424 GET_NATIVE_ARGUMENT(String, uri, arguments->At(0)); 426 GET_NATIVE_ARGUMENT(String, uri, arguments->At(0));
425 427
426 // Canonicalize the uri with respect to the current isolate. 428 // Canonicalize the uri with respect to the current isolate.
427 char* error = NULL; 429 char* error = NULL;
428 char* canonical_uri = NULL; 430 char* canonical_uri = NULL;
429 const Library& root_lib = 431 const Library& root_lib =
430 Library::Handle(arguments->isolate()->object_store()->root_library()); 432 Library::Handle(arguments->isolate()->object_store()->root_library());
431 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, 433 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri,
432 &canonical_uri, &error)) { 434 &canonical_uri, &error)) {
433 const String& msg = String::Handle(String::New(error)); 435 const String& msg = String::Handle(String::New(error));
434 free(error); 436 free(error);
435 ThrowIsolateSpawnException(msg); 437 ThrowIsolateSpawnException(msg);
436 } 438 }
437 439
438 Spawn(arguments, new SpawnState(canonical_uri)); 440 return Spawn(arguments, new SpawnState(canonical_uri));
439 } 441 }
440 442
441 443
442 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { 444 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) {
443 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); 445 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port()));
444 if (port.IsError()) { 446 if (port.IsError()) {
445 Exceptions::PropagateError(Error::Cast(port)); 447 Exceptions::PropagateError(Error::Cast(port));
446 } 448 }
447 arguments->SetReturn(port); 449 return port.raw();
448 } 450 }
449 451
450 } // namespace dart 452 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698