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

Side by Side Diff: runtime/lib/isolate.cc

Issue 1499853004: Adds a special case for sending an int over a port with the native API. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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 "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"
11 #include "vm/dart_api_message.h"
11 #include "vm/dart_entry.h" 12 #include "vm/dart_entry.h"
12 #include "vm/exceptions.h" 13 #include "vm/exceptions.h"
13 #include "vm/lockers.h" 14 #include "vm/lockers.h"
14 #include "vm/longjump.h" 15 #include "vm/longjump.h"
15 #include "vm/message_handler.h" 16 #include "vm/message_handler.h"
16 #include "vm/object.h" 17 #include "vm/object.h"
17 #include "vm/object_store.h" 18 #include "vm/object_store.h"
18 #include "vm/port.h" 19 #include "vm/port.h"
19 #include "vm/resolver.h" 20 #include "vm/resolver.h"
20 #include "vm/service.h" 21 #include "vm/service.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 int32_t hash = (hi ^ lo) & kSmiMax; 100 int32_t hash = (hi ^ lo) & kSmiMax;
100 return Smi::New(hash); 101 return Smi::New(hash);
101 } 102 }
102 103
103 104
104 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) { 105 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) {
105 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); 106 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
106 // TODO(iposva): Allow for arbitrary messages to be sent. 107 // TODO(iposva): Allow for arbitrary messages to be sent.
107 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); 108 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1));
108 109
109 uint8_t* data = NULL;
110
111 const Dart_Port destination_port_id = port.Id(); 110 const Dart_Port destination_port_id = port.Id();
112 const bool can_send_any_object = isolate->origin_id() == port.origin_id(); 111 const bool can_send_any_object = isolate->origin_id() == port.origin_id();
113 112
114 MessageWriter writer(&data, &allocator, can_send_any_object); 113 if (ApiObjectConverter::CanConvert(obj.raw())) {
115 writer.WriteMessage(obj); 114 PortMap::PostMessage(new Message(destination_port_id,
115 reinterpret_cast<uint8_t*>(obj.raw()), 0,
116 Message::kNormalPriority));
117 } else {
118 uint8_t* data = NULL;
119 MessageWriter writer(&data, &allocator, can_send_any_object);
120 writer.WriteMessage(obj);
116 121
117 // TODO(turnidge): Throw an exception when the return value is false? 122 // TODO(turnidge): Throw an exception when the return value is false?
118 PortMap::PostMessage(new Message(destination_port_id, 123 PortMap::PostMessage(new Message(destination_port_id,
119 data, writer.BytesWritten(), 124 data, writer.BytesWritten(),
120 Message::kNormalPriority)); 125 Message::kNormalPriority));
126 }
121 return Object::null(); 127 return Object::null();
122 } 128 }
123 129
124 130
125 static void ThrowIsolateSpawnException(const String& message) { 131 static void ThrowIsolateSpawnException(const String& message) {
126 const Array& args = Array::Handle(Array::New(1)); 132 const Array& args = Array::Handle(Array::New(1));
127 args.SetAt(0, message); 133 args.SetAt(0, message);
128 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args); 134 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args);
129 } 135 }
130 136
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 MessageWriter writer(&data, &allocator, false); 425 MessageWriter writer(&data, &allocator, false);
420 writer.WriteMessage(msg); 426 writer.WriteMessage(msg);
421 427
422 PortMap::PostMessage(new Message(port.Id(), 428 PortMap::PostMessage(new Message(port.Id(),
423 data, writer.BytesWritten(), 429 data, writer.BytesWritten(),
424 Message::kOOBPriority)); 430 Message::kOOBPriority));
425 return Object::null(); 431 return Object::null();
426 } 432 }
427 433
428 } // namespace dart 434 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698