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" |
11 #include "vm/exceptions.h" | 11 #include "vm/exceptions.h" |
12 #include "vm/lockers.h" | 12 #include "vm/lockers.h" |
13 #include "vm/longjump.h" | 13 #include "vm/longjump.h" |
14 #include "vm/message_handler.h" | 14 #include "vm/message_handler.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
17 #include "vm/port.h" | 17 #include "vm/port.h" |
18 #include "vm/resolver.h" | 18 #include "vm/resolver.h" |
19 #include "vm/service.h" | |
19 #include "vm/snapshot.h" | 20 #include "vm/snapshot.h" |
20 #include "vm/symbols.h" | 21 #include "vm/symbols.h" |
21 #include "vm/unicode.h" | 22 #include "vm/unicode.h" |
22 | 23 |
23 namespace dart { | 24 namespace dart { |
24 | 25 |
25 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 26 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
26 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 27 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
27 return reinterpret_cast<uint8_t*>(new_ptr); | 28 return reinterpret_cast<uint8_t*>(new_ptr); |
28 } | 29 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 return Smi::New(hash); | 96 return Smi::New(hash); |
96 } | 97 } |
97 | 98 |
98 | 99 |
99 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) { | 100 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) { |
100 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 101 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
101 // TODO(iposva): Allow for arbitrary messages to be sent. | 102 // TODO(iposva): Allow for arbitrary messages to be sent. |
102 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); | 103 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); |
103 | 104 |
104 uint8_t* data = NULL; | 105 uint8_t* data = NULL; |
105 bool can_send_any_object = (isolate->origin_id() == port.origin_id()); | 106 |
107 Dart_Port destination_port_id = port.Id(); | |
108 | |
109 // The service isolate needs to send typed data objects. | |
110 bool sender_is_service = Service::IsServiceIsolate(isolate); | |
111 bool destination_is_service = Service::IsServicePort(destination_port_id); | |
siva
2015/01/22 22:39:31
I thought the service protocol is based on JSON.
I
Cutch
2015/01/26 18:59:30
Done.
| |
112 | |
113 bool can_send_any_object = (isolate->origin_id() == port.origin_id()) || | |
114 sender_is_service || | |
115 destination_is_service; | |
116 | |
106 MessageWriter writer(&data, &allocator, can_send_any_object); | 117 MessageWriter writer(&data, &allocator, can_send_any_object); |
107 writer.WriteMessage(obj); | 118 writer.WriteMessage(obj); |
108 | 119 |
109 // TODO(turnidge): Throw an exception when the return value is false? | 120 // TODO(turnidge): Throw an exception when the return value is false? |
110 PortMap::PostMessage(new Message(port.Id(), | 121 PortMap::PostMessage(new Message(destination_port_id, |
111 data, writer.BytesWritten(), | 122 data, writer.BytesWritten(), |
112 Message::kNormalPriority)); | 123 Message::kNormalPriority)); |
113 return Object::null(); | 124 return Object::null(); |
114 } | 125 } |
115 | 126 |
116 | 127 |
117 static void ThrowIsolateSpawnException(const String& message) { | 128 static void ThrowIsolateSpawnException(const String& message) { |
118 const Array& args = Array::Handle(Array::New(1)); | 129 const Array& args = Array::Handle(Array::New(1)); |
119 args.SetAt(0, message); | 130 args.SetAt(0, message); |
120 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args); | 131 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 MessageWriter writer(&data, &allocator, false); | 310 MessageWriter writer(&data, &allocator, false); |
300 writer.WriteMessage(msg); | 311 writer.WriteMessage(msg); |
301 | 312 |
302 PortMap::PostMessage(new Message(port.Id(), | 313 PortMap::PostMessage(new Message(port.Id(), |
303 data, writer.BytesWritten(), | 314 data, writer.BytesWritten(), |
304 Message::kOOBPriority)); | 315 Message::kOOBPriority)); |
305 return Object::null(); | 316 return Object::null(); |
306 } | 317 } |
307 | 318 |
308 } // namespace dart | 319 } // namespace dart |
OLD | NEW |