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 24 matching lines...) Expand all Loading... | |
35 intptr_t port_id_; | 35 intptr_t port_id_; |
36 }; | 36 }; |
37 | 37 |
38 | 38 |
39 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 39 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
40 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 40 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
41 return reinterpret_cast<uint8_t*>(new_ptr); | 41 return reinterpret_cast<uint8_t*>(new_ptr); |
42 } | 42 } |
43 | 43 |
44 | 44 |
45 static uint8_t* SerializeObject(const Instance& obj) { | |
46 uint8_t* result = NULL; | |
47 SnapshotWriter writer(Snapshot::kMessage, &result, &allocator); | |
48 writer.WriteObject(obj.raw()); | |
49 writer.FinalizeBuffer(); | |
50 return result; | |
51 } | |
52 | |
53 | |
54 static void StoreError(Isolate* isolate, const Object& obj) { | 45 static void StoreError(Isolate* isolate, const Object& obj) { |
55 ASSERT(obj.IsError()); | 46 ASSERT(obj.IsError()); |
56 Error& error = Error::Handle(); | 47 Error& error = Error::Handle(); |
57 error ^= obj.raw(); | 48 error ^= obj.raw(); |
58 isolate->object_store()->set_sticky_error(error); | 49 isolate->object_store()->set_sticky_error(error); |
59 } | 50 } |
60 | 51 |
61 | 52 |
62 // TODO(turnidge): Move to DartLibraryCalls. | 53 // TODO(turnidge): Move to DartLibraryCalls. |
63 RawObject* ReceivePortCreate(intptr_t port_id) { | 54 RawObject* ReceivePortCreate(intptr_t port_id) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 GET_NATIVE_ARGUMENT(Smi, id, arguments->At(0)); | 128 GET_NATIVE_ARGUMENT(Smi, id, arguments->At(0)); |
138 PortMap::ClosePort(id.Value()); | 129 PortMap::ClosePort(id.Value()); |
139 } | 130 } |
140 | 131 |
141 | 132 |
142 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { | 133 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { |
143 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->At(0)); | 134 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->At(0)); |
144 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->At(1)); | 135 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->At(1)); |
145 // TODO(iposva): Allow for arbitrary messages to be sent. | 136 // TODO(iposva): Allow for arbitrary messages to be sent. |
146 GET_NATIVE_ARGUMENT(Instance, obj, arguments->At(2)); | 137 GET_NATIVE_ARGUMENT(Instance, obj, arguments->At(2)); |
147 uint8_t* data = SerializeObject(obj); | 138 |
139 uint8_t* data = NULL; | |
140 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); | |
141 writer.WriteObject(obj.raw()); | |
142 intptr_t data_len = writer.FinalizeBuffer(); | |
siva
2012/08/22 23:30:39
As discussed offline we could probably get rid of
turnidge
2012/08/23 18:37:57
Done.
| |
148 | 143 |
149 // TODO(turnidge): Throw an exception when the return value is false? | 144 // TODO(turnidge): Throw an exception when the return value is false? |
150 PortMap::PostMessage(new Message( | 145 PortMap::PostMessage(new Message( |
151 send_id.Value(), reply_id.Value(), data, Message::kNormalPriority)); | 146 send_id.Value(), reply_id.Value(), data, data_len, |
147 Message::kNormalPriority)); | |
152 } | 148 } |
153 | 149 |
154 | 150 |
155 static void ThrowIllegalArgException(const String& message) { | 151 static void ThrowIllegalArgException(const String& message) { |
156 GrowableArray<const Object*> args(1); | 152 GrowableArray<const Object*> args(1); |
157 args.Add(&message); | 153 args.Add(&message); |
158 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 154 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
159 } | 155 } |
160 | 156 |
161 | 157 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 | 437 |
442 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { | 438 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { |
443 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); | 439 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); |
444 if (port.IsError()) { | 440 if (port.IsError()) { |
445 Exceptions::PropagateError(Error::Cast(port)); | 441 Exceptions::PropagateError(Error::Cast(port)); |
446 } | 442 } |
447 arguments->SetReturn(port); | 443 arguments->SetReturn(port); |
448 } | 444 } |
449 | 445 |
450 } // namespace dart | 446 } // namespace dart |
OLD | NEW |