| 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 12 matching lines...) Expand all  Loading... | 
| 23 #include "vm/symbols.h" | 23 #include "vm/symbols.h" | 
| 24 #include "vm/unicode.h" | 24 #include "vm/unicode.h" | 
| 25 | 25 | 
| 26 namespace dart { | 26 namespace dart { | 
| 27 | 27 | 
| 28 DEFINE_FLAG(bool, | 28 DEFINE_FLAG(bool, | 
| 29             i_like_slow_isolate_spawn, | 29             i_like_slow_isolate_spawn, | 
| 30             false, | 30             false, | 
| 31             "Block the parent thread when loading spawned isolates."); | 31             "Block the parent thread when loading spawned isolates."); | 
| 32 | 32 | 
| 33 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 33 static uint8_t* malloc_allocator(uint8_t* ptr, | 
|  | 34                                  intptr_t old_size, | 
|  | 35                                  intptr_t new_size) { | 
| 34   void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 36   void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 
| 35   return reinterpret_cast<uint8_t*>(new_ptr); | 37   return reinterpret_cast<uint8_t*>(new_ptr); | 
| 36 } | 38 } | 
| 37 | 39 | 
|  | 40 static void malloc_deallocator(uint8_t* ptr) { | 
|  | 41   free(reinterpret_cast<void*>(ptr)); | 
|  | 42 } | 
|  | 43 | 
| 38 | 44 | 
| 39 DEFINE_NATIVE_ENTRY(CapabilityImpl_factory, 1) { | 45 DEFINE_NATIVE_ENTRY(CapabilityImpl_factory, 1) { | 
| 40   ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 46   ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 
| 41   uint64_t id = isolate->random()->NextUInt64(); | 47   uint64_t id = isolate->random()->NextUInt64(); | 
| 42   return Capability::New(id); | 48   return Capability::New(id); | 
| 43 } | 49 } | 
| 44 | 50 | 
| 45 | 51 | 
| 46 DEFINE_NATIVE_ENTRY(CapabilityImpl_equals, 2) { | 52 DEFINE_NATIVE_ENTRY(CapabilityImpl_equals, 2) { | 
| 47   GET_NON_NULL_NATIVE_ARGUMENT(Capability, recv, arguments->NativeArgAt(0)); | 53   GET_NON_NULL_NATIVE_ARGUMENT(Capability, recv, arguments->NativeArgAt(0)); | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 109   GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); | 115   GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); | 
| 110 | 116 | 
| 111   const Dart_Port destination_port_id = port.Id(); | 117   const Dart_Port destination_port_id = port.Id(); | 
| 112   const bool can_send_any_object = isolate->origin_id() == port.origin_id(); | 118   const bool can_send_any_object = isolate->origin_id() == port.origin_id(); | 
| 113 | 119 | 
| 114   if (ApiObjectConverter::CanConvert(obj.raw())) { | 120   if (ApiObjectConverter::CanConvert(obj.raw())) { | 
| 115     PortMap::PostMessage( | 121     PortMap::PostMessage( | 
| 116         new Message(destination_port_id, obj.raw(), Message::kNormalPriority)); | 122         new Message(destination_port_id, obj.raw(), Message::kNormalPriority)); | 
| 117   } else { | 123   } else { | 
| 118     uint8_t* data = NULL; | 124     uint8_t* data = NULL; | 
| 119     MessageWriter writer(&data, &allocator, can_send_any_object); | 125     MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, | 
|  | 126                          can_send_any_object); | 
| 120     writer.WriteMessage(obj); | 127     writer.WriteMessage(obj); | 
| 121 | 128 | 
| 122     // TODO(turnidge): Throw an exception when the return value is false? | 129     // TODO(turnidge): Throw an exception when the return value is false? | 
| 123     PortMap::PostMessage(new Message(destination_port_id, data, | 130     PortMap::PostMessage(new Message(destination_port_id, data, | 
| 124                                      writer.BytesWritten(), | 131                                      writer.BytesWritten(), | 
| 125                                      Message::kNormalPriority)); | 132                                      Message::kNormalPriority)); | 
| 126   } | 133   } | 
| 127   return Object::null(); | 134   return Object::null(); | 
| 128 } | 135 } | 
| 129 | 136 | 
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 417 | 424 | 
| 418 | 425 | 
| 419 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) { | 426 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) { | 
| 420   GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 427   GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 
| 421   GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1)); | 428   GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1)); | 
| 422 | 429 | 
| 423   // Make sure to route this request to the isolate library OOB mesage handler. | 430   // Make sure to route this request to the isolate library OOB mesage handler. | 
| 424   msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg))); | 431   msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg))); | 
| 425 | 432 | 
| 426   uint8_t* data = NULL; | 433   uint8_t* data = NULL; | 
| 427   MessageWriter writer(&data, &allocator, false); | 434   MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false); | 
| 428   writer.WriteMessage(msg); | 435   writer.WriteMessage(msg); | 
| 429 | 436 | 
| 430   PortMap::PostMessage(new Message(port.Id(), data, writer.BytesWritten(), | 437   PortMap::PostMessage(new Message(port.Id(), data, writer.BytesWritten(), | 
| 431                                    Message::kOOBPriority)); | 438                                    Message::kOOBPriority)); | 
| 432   return Object::null(); | 439   return Object::null(); | 
| 433 } | 440 } | 
| 434 | 441 | 
| 435 }  // namespace dart | 442 }  // namespace dart | 
| OLD | NEW | 
|---|