| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 #include "vm/dart_api_impl.h" | 6 #include "vm/dart_api_impl.h" |
| 7 #include "vm/datastream.h" | 7 #include "vm/datastream.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/flags.h" |
| 9 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| 10 #include "vm/message.h" | 11 #include "vm/message.h" |
| 11 #include "vm/native_entry.h" | 12 #include "vm/native_entry.h" |
| 12 #include "vm/object.h" | 13 #include "vm/object.h" |
| 13 #include "vm/port.h" | 14 #include "vm/port.h" |
| 14 #include "vm/service_isolate.h" | 15 #include "vm/service_isolate.h" |
| 15 #include "vm/symbols.h" | 16 #include "vm/symbols.h" |
| 16 | 17 |
| 17 namespace dart { | 18 namespace dart { |
| 18 | 19 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // TODO(turnidge): Throw an exception when the return value is false? | 97 // TODO(turnidge): Throw an exception when the return value is false? |
| 97 bool result = PortMap::PostMessage( | 98 bool result = PortMap::PostMessage( |
| 98 new Message(sp.Id(), data, writer.BytesWritten(), | 99 new Message(sp.Id(), data, writer.BytesWritten(), |
| 99 Message::kOOBPriority)); | 100 Message::kOOBPriority)); |
| 100 return Bool::Get(result).raw(); | 101 return Bool::Get(result).raw(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 | 104 |
| 104 DEFINE_NATIVE_ENTRY(VMService_SendRootServiceMessage, 1) { | 105 DEFINE_NATIVE_ENTRY(VMService_SendRootServiceMessage, 1) { |
| 105 GET_NON_NULL_NATIVE_ARGUMENT(Array, message, arguments->NativeArgAt(0)); | 106 GET_NON_NULL_NATIVE_ARGUMENT(Array, message, arguments->NativeArgAt(0)); |
| 106 Service::HandleRootMessage(message); | 107 if (FLAG_support_service) { |
| 108 Service::HandleRootMessage(message); |
| 109 } |
| 107 return Object::null(); | 110 return Object::null(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 | 113 |
| 111 DEFINE_NATIVE_ENTRY(VMService_OnStart, 0) { | 114 DEFINE_NATIVE_ENTRY(VMService_OnStart, 0) { |
| 112 if (FLAG_trace_service) { | 115 if (FLAG_trace_service) { |
| 113 OS::Print("vm-service: Booting dart:vmservice library.\n"); | 116 OS::Print("vm-service: Booting dart:vmservice library.\n"); |
| 114 } | 117 } |
| 115 // Boot the dart:vmservice library. | 118 // Boot the dart:vmservice library. |
| 116 ServiceIsolate::BootVmServiceLibrary(); | 119 ServiceIsolate::BootVmServiceLibrary(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 140 ServiceIsolate::SetServerAddress(NULL); | 143 ServiceIsolate::SetServerAddress(NULL); |
| 141 } else { | 144 } else { |
| 142 ServiceIsolate::SetServerAddress(address.ToCString()); | 145 ServiceIsolate::SetServerAddress(address.ToCString()); |
| 143 } | 146 } |
| 144 return Object::null(); | 147 return Object::null(); |
| 145 } | 148 } |
| 146 | 149 |
| 147 | 150 |
| 148 DEFINE_NATIVE_ENTRY(VMService_ListenStream, 1) { | 151 DEFINE_NATIVE_ENTRY(VMService_ListenStream, 1) { |
| 149 GET_NON_NULL_NATIVE_ARGUMENT(String, stream_id, arguments->NativeArgAt(0)); | 152 GET_NON_NULL_NATIVE_ARGUMENT(String, stream_id, arguments->NativeArgAt(0)); |
| 150 bool result = Service::ListenStream(stream_id.ToCString()); | 153 bool result = false; |
| 154 if (FLAG_support_service) { |
| 155 result = Service::ListenStream(stream_id.ToCString()); |
| 156 } |
| 151 return Bool::Get(result).raw(); | 157 return Bool::Get(result).raw(); |
| 152 } | 158 } |
| 153 | 159 |
| 154 | 160 |
| 155 DEFINE_NATIVE_ENTRY(VMService_CancelStream, 1) { | 161 DEFINE_NATIVE_ENTRY(VMService_CancelStream, 1) { |
| 156 GET_NON_NULL_NATIVE_ARGUMENT(String, stream_id, arguments->NativeArgAt(0)); | 162 GET_NON_NULL_NATIVE_ARGUMENT(String, stream_id, arguments->NativeArgAt(0)); |
| 157 Service::CancelStream(stream_id.ToCString()); | 163 if (FLAG_support_service) { |
| 164 Service::CancelStream(stream_id.ToCString()); |
| 165 } |
| 158 return Object::null(); | 166 return Object::null(); |
| 159 } | 167 } |
| 160 | 168 |
| 161 | 169 |
| 162 DEFINE_NATIVE_ENTRY(VMService_RequestAssets, 0) { | 170 DEFINE_NATIVE_ENTRY(VMService_RequestAssets, 0) { |
| 171 if (!FLAG_support_service) { |
| 172 return Object::null(); |
| 173 } |
| 163 return Service::RequestAssets(); | 174 return Service::RequestAssets(); |
| 164 } | 175 } |
| 165 | 176 |
| 166 | 177 |
| 178 #ifndef PRODUCT |
| 167 // TODO(25041): When reading, this class copies out the filenames and contents | 179 // TODO(25041): When reading, this class copies out the filenames and contents |
| 168 // into new buffers. It does this because the lifetime of |bytes| is uncertain. | 180 // into new buffers. It does this because the lifetime of |bytes| is uncertain. |
| 169 // If |bytes| is pinned in memory, then we could instead load up | 181 // If |bytes| is pinned in memory, then we could instead load up |
| 170 // |filenames_| and |contents_| with pointers into |bytes| without making | 182 // |filenames_| and |contents_| with pointers into |bytes| without making |
| 171 // copies. | 183 // copies. |
| 172 class TarArchive { | 184 class TarArchive { |
| 173 public: | 185 public: |
| 174 TarArchive(uint8_t* bytes, intptr_t bytes_length) | 186 TarArchive(uint8_t* bytes, intptr_t bytes_length) |
| 175 : rs_(bytes, bytes_length) {} | 187 : rs_(bytes, bytes_length) {} |
| 176 | 188 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 delete[] data; | 356 delete[] data; |
| 345 } | 357 } |
| 346 | 358 |
| 347 | 359 |
| 348 static void FilenameFinalizer(void* peer) { | 360 static void FilenameFinalizer(void* peer) { |
| 349 char* filename = reinterpret_cast<char*>(peer); | 361 char* filename = reinterpret_cast<char*>(peer); |
| 350 delete[] filename; | 362 delete[] filename; |
| 351 } | 363 } |
| 352 | 364 |
| 353 | 365 |
| 366 #endif |
| 367 |
| 368 |
| 354 DEFINE_NATIVE_ENTRY(VMService_DecodeAssets, 1) { | 369 DEFINE_NATIVE_ENTRY(VMService_DecodeAssets, 1) { |
| 370 #ifndef PRODUCT |
| 355 GET_NON_NULL_NATIVE_ARGUMENT(TypedData, data, arguments->NativeArgAt(0)); | 371 GET_NON_NULL_NATIVE_ARGUMENT(TypedData, data, arguments->NativeArgAt(0)); |
| 356 TransitionVMToNative transition(thread); | 372 TransitionVMToNative transition(thread); |
| 357 Api::Scope scope(thread); | 373 Api::Scope scope(thread); |
| 358 | 374 |
| 359 Dart_Handle data_handle = Api::NewHandle(thread, data.raw()); | 375 Dart_Handle data_handle = Api::NewHandle(thread, data.raw()); |
| 360 | 376 |
| 361 Dart_TypedData_Type typ; | 377 Dart_TypedData_Type typ; |
| 362 void* bytes; | 378 void* bytes; |
| 363 intptr_t length; | 379 intptr_t length; |
| 364 Dart_Handle err = Dart_TypedDataAcquireData( | 380 Dart_Handle err = Dart_TypedDataAcquireData( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 dart_contents, contents, contents_length, ContentsFinalizer); | 412 dart_contents, contents, contents_length, ContentsFinalizer); |
| 397 | 413 |
| 398 result_list.SetAt(idx, Api::UnwrapStringHandle( | 414 result_list.SetAt(idx, Api::UnwrapStringHandle( |
| 399 thread->zone(), dart_filename)); | 415 thread->zone(), dart_filename)); |
| 400 result_list.SetAt(idx + 1, Api::UnwrapExternalTypedDataHandle( | 416 result_list.SetAt(idx + 1, Api::UnwrapExternalTypedDataHandle( |
| 401 thread->zone(), dart_contents)); | 417 thread->zone(), dart_contents)); |
| 402 idx += 2; | 418 idx += 2; |
| 403 } | 419 } |
| 404 | 420 |
| 405 return result_list.raw(); | 421 return result_list.raw(); |
| 422 #else |
| 423 return Object::null(); |
| 424 #endif |
| 406 } | 425 } |
| 407 | 426 |
| 408 } // namespace dart | 427 } // namespace dart |
| OLD | NEW |