| 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 "include/dart_native_api.h" | 5 #include "include/dart_native_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 int32_t hash = (hi ^ lo) & kSmiMax; | 99 int32_t hash = (hi ^ lo) & kSmiMax; |
| 100 return Smi::New(hash); | 100 return Smi::New(hash); |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) { | 104 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) { |
| 105 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 105 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
| 106 // TODO(iposva): Allow for arbitrary messages to be sent. | 106 // TODO(iposva): Allow for arbitrary messages to be sent. |
| 107 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); | 107 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); |
| 108 | 108 |
| 109 uint8_t* data = NULL; | |
| 110 | |
| 111 const Dart_Port destination_port_id = port.Id(); | 109 const Dart_Port destination_port_id = port.Id(); |
| 112 const bool can_send_any_object = isolate->origin_id() == port.origin_id(); | 110 const bool can_send_any_object = isolate->origin_id() == port.origin_id(); |
| 113 | 111 |
| 114 MessageWriter writer(&data, &allocator, can_send_any_object); | 112 if (obj.IsSmi() || obj.InVMHeap()) { |
| 115 writer.WriteMessage(obj); | 113 PortMap::PostMessage(new Message(destination_port_id, |
| 114 reinterpret_cast<uint8_t*>(obj.raw()), 0, |
| 115 Message::kNormalPriority)); |
| 116 } else { |
| 117 uint8_t* data = NULL; |
| 118 MessageWriter writer(&data, &allocator, can_send_any_object); |
| 119 writer.WriteMessage(obj); |
| 116 | 120 |
| 117 // TODO(turnidge): Throw an exception when the return value is false? | 121 // TODO(turnidge): Throw an exception when the return value is false? |
| 118 PortMap::PostMessage(new Message(destination_port_id, | 122 PortMap::PostMessage(new Message(destination_port_id, |
| 119 data, writer.BytesWritten(), | 123 data, writer.BytesWritten(), |
| 120 Message::kNormalPriority)); | 124 Message::kNormalPriority)); |
| 125 } |
| 121 return Object::null(); | 126 return Object::null(); |
| 122 } | 127 } |
| 123 | 128 |
| 124 | 129 |
| 125 static void ThrowIsolateSpawnException(const String& message) { | 130 static void ThrowIsolateSpawnException(const String& message) { |
| 126 const Array& args = Array::Handle(Array::New(1)); | 131 const Array& args = Array::Handle(Array::New(1)); |
| 127 args.SetAt(0, message); | 132 args.SetAt(0, message); |
| 128 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args); | 133 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args); |
| 129 } | 134 } |
| 130 | 135 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 MessageWriter writer(&data, &allocator, false); | 424 MessageWriter writer(&data, &allocator, false); |
| 420 writer.WriteMessage(msg); | 425 writer.WriteMessage(msg); |
| 421 | 426 |
| 422 PortMap::PostMessage(new Message(port.Id(), | 427 PortMap::PostMessage(new Message(port.Id(), |
| 423 data, writer.BytesWritten(), | 428 data, writer.BytesWritten(), |
| 424 Message::kOOBPriority)); | 429 Message::kOOBPriority)); |
| 425 return Object::null(); | 430 return Object::null(); |
| 426 } | 431 } |
| 427 | 432 |
| 428 } // namespace dart | 433 } // namespace dart |
| OLD | NEW |