OLD | NEW |
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 static char* GetRootScriptUri(Isolate* isolate) { | 106 static char* GetRootScriptUri(Isolate* isolate) { |
107 const Library& library = | 107 const Library& library = |
108 Library::Handle(isolate->object_store()->root_library()); | 108 Library::Handle(isolate->object_store()->root_library()); |
109 ASSERT(!library.IsNull()); | 109 ASSERT(!library.IsNull()); |
110 const String& script_name = String::Handle(library.url()); | 110 const String& script_name = String::Handle(library.url()); |
111 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); | 111 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { | 115 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { |
116 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); | 116 ASSERT(AbstractTypeArguments::CheckedHandle( |
| 117 arguments->NativeArgAt(0)).IsNull()); |
117 intptr_t port_id = | 118 intptr_t port_id = |
118 PortMap::CreatePort(arguments->isolate()->message_handler()); | 119 PortMap::CreatePort(arguments->isolate()->message_handler()); |
119 const Object& port = Object::Handle(ReceivePortCreate(port_id)); | 120 const Object& port = Object::Handle(ReceivePortCreate(port_id)); |
120 if (port.IsError()) { | 121 if (port.IsError()) { |
121 Exceptions::PropagateError(Error::Cast(port)); | 122 Exceptions::PropagateError(Error::Cast(port)); |
122 } | 123 } |
123 return port.raw(); | 124 return port.raw(); |
124 } | 125 } |
125 | 126 |
126 | 127 |
127 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { | 128 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { |
128 GET_NATIVE_ARGUMENT(Smi, id, arguments->At(0)); | 129 GET_NATIVE_ARGUMENT(Smi, id, arguments->NativeArgAt(0)); |
129 PortMap::ClosePort(id.Value()); | 130 PortMap::ClosePort(id.Value()); |
130 return Object::null(); | 131 return Object::null(); |
131 } | 132 } |
132 | 133 |
133 | 134 |
134 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { | 135 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { |
135 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->At(0)); | 136 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->NativeArgAt(0)); |
136 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->At(1)); | 137 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->NativeArgAt(1)); |
137 // TODO(iposva): Allow for arbitrary messages to be sent. | 138 // TODO(iposva): Allow for arbitrary messages to be sent. |
138 GET_NATIVE_ARGUMENT(Instance, obj, arguments->At(2)); | 139 GET_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(2)); |
139 | 140 |
140 uint8_t* data = NULL; | 141 uint8_t* data = NULL; |
141 MessageWriter writer(&data, &allocator); | 142 MessageWriter writer(&data, &allocator); |
142 writer.WriteMessage(obj); | 143 writer.WriteMessage(obj); |
143 | 144 |
144 // TODO(turnidge): Throw an exception when the return value is false? | 145 // TODO(turnidge): Throw an exception when the return value is false? |
145 PortMap::PostMessage(new Message(send_id.Value(), reply_id.Value(), | 146 PortMap::PostMessage(new Message(send_id.Value(), reply_id.Value(), |
146 data, writer.BytesWritten(), | 147 data, writer.BytesWritten(), |
147 Message::kNormalPriority)); | 148 Message::kNormalPriority)); |
148 return Object::null(); | 149 return Object::null(); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); | 392 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); |
392 state->isolate()->message_handler()->Run( | 393 state->isolate()->message_handler()->Run( |
393 Dart::thread_pool(), RunIsolate, ShutdownIsolate, | 394 Dart::thread_pool(), RunIsolate, ShutdownIsolate, |
394 reinterpret_cast<uword>(state->isolate())); | 395 reinterpret_cast<uword>(state->isolate())); |
395 | 396 |
396 return port.raw(); | 397 return port.raw(); |
397 } | 398 } |
398 | 399 |
399 | 400 |
400 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 1) { | 401 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 1) { |
401 GET_NATIVE_ARGUMENT(Instance, closure, arguments->At(0)); | 402 GET_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
402 bool throw_exception = false; | 403 bool throw_exception = false; |
403 Function& func = Function::Handle(); | 404 Function& func = Function::Handle(); |
404 if (closure.IsClosure()) { | 405 if (closure.IsClosure()) { |
405 func ^= Closure::function(closure); | 406 func ^= Closure::function(closure); |
406 const Class& cls = Class::Handle(func.Owner()); | 407 const Class& cls = Class::Handle(func.Owner()); |
407 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { | 408 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { |
408 throw_exception = true; | 409 throw_exception = true; |
409 } | 410 } |
410 } else { | 411 } else { |
411 throw_exception = true; | 412 throw_exception = true; |
412 } | 413 } |
413 if (throw_exception) { | 414 if (throw_exception) { |
414 const String& msg = String::Handle(String::New( | 415 const String& msg = String::Handle(String::New( |
415 "spawnFunction expects to be passed a closure to a top-level static " | 416 "spawnFunction expects to be passed a closure to a top-level static " |
416 "function")); | 417 "function")); |
417 ThrowIllegalArgException(msg); | 418 ThrowIllegalArgException(msg); |
418 } | 419 } |
419 | 420 |
420 #if defined(DEBUG) | 421 #if defined(DEBUG) |
421 const Context& ctx = Context::Handle(Closure::context(closure)); | 422 const Context& ctx = Context::Handle(Closure::context(closure)); |
422 ASSERT(ctx.num_variables() == 0); | 423 ASSERT(ctx.num_variables() == 0); |
423 #endif | 424 #endif |
424 | 425 |
425 return Spawn(arguments, new SpawnState(func)); | 426 return Spawn(arguments, new SpawnState(func)); |
426 } | 427 } |
427 | 428 |
428 | 429 |
429 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) { | 430 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) { |
430 GET_NATIVE_ARGUMENT(String, uri, arguments->At(0)); | 431 GET_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); |
431 | 432 |
432 // Canonicalize the uri with respect to the current isolate. | 433 // Canonicalize the uri with respect to the current isolate. |
433 char* error = NULL; | 434 char* error = NULL; |
434 char* canonical_uri = NULL; | 435 char* canonical_uri = NULL; |
435 const Library& root_lib = | 436 const Library& root_lib = |
436 Library::Handle(arguments->isolate()->object_store()->root_library()); | 437 Library::Handle(arguments->isolate()->object_store()->root_library()); |
437 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, | 438 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, |
438 &canonical_uri, &error)) { | 439 &canonical_uri, &error)) { |
439 const String& msg = String::Handle(String::New(error)); | 440 const String& msg = String::Handle(String::New(error)); |
440 free(error); | 441 free(error); |
441 ThrowIsolateSpawnException(msg); | 442 ThrowIsolateSpawnException(msg); |
442 } | 443 } |
443 | 444 |
444 return Spawn(arguments, new SpawnState(canonical_uri)); | 445 return Spawn(arguments, new SpawnState(canonical_uri)); |
445 } | 446 } |
446 | 447 |
447 | 448 |
448 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { | 449 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { |
449 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); | 450 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); |
450 if (port.IsError()) { | 451 if (port.IsError()) { |
451 Exceptions::PropagateError(Error::Cast(port)); | 452 Exceptions::PropagateError(Error::Cast(port)); |
452 } | 453 } |
453 return port.raw(); | 454 return port.raw(); |
454 } | 455 } |
455 | 456 |
456 } // namespace dart | 457 } // namespace dart |
OLD | NEW |