| 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 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 Debugger* debugger = isolate->debugger(); | 25 Debugger* debugger = isolate->debugger(); |
| 26 if (!FLAG_support_debugger || !debugger) { | 26 if (!FLAG_support_debugger || !debugger) { |
| 27 return when.raw(); | 27 return when.raw(); |
| 28 } | 28 } |
| 29 if (when.value()) { | 29 if (when.value()) { |
| 30 debugger->PauseDeveloper(msg); | 30 debugger->PauseDeveloper(msg); |
| 31 } | 31 } |
| 32 return when.raw(); | 32 return when.raw(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 | |
| 36 DEFINE_NATIVE_ENTRY(Developer_inspect, 1) { | 35 DEFINE_NATIVE_ENTRY(Developer_inspect, 1) { |
| 37 GET_NATIVE_ARGUMENT(Instance, inspectee, arguments->NativeArgAt(0)); | 36 GET_NATIVE_ARGUMENT(Instance, inspectee, arguments->NativeArgAt(0)); |
| 38 #ifndef PRODUCT | 37 #ifndef PRODUCT |
| 39 if (FLAG_support_service) { | 38 if (FLAG_support_service) { |
| 40 Service::SendInspectEvent(isolate, inspectee); | 39 Service::SendInspectEvent(isolate, inspectee); |
| 41 } | 40 } |
| 42 #endif // !PRODUCT | 41 #endif // !PRODUCT |
| 43 return inspectee.raw(); | 42 return inspectee.raw(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 | |
| 47 DEFINE_NATIVE_ENTRY(Developer_log, 8) { | 45 DEFINE_NATIVE_ENTRY(Developer_log, 8) { |
| 48 #if defined(PRODUCT) | 46 #if defined(PRODUCT) |
| 49 return Object::null(); | 47 return Object::null(); |
| 50 #else | 48 #else |
| 51 if (!FLAG_support_service) { | 49 if (!FLAG_support_service) { |
| 52 return Object::null(); | 50 return Object::null(); |
| 53 } | 51 } |
| 54 GET_NON_NULL_NATIVE_ARGUMENT(String, message, arguments->NativeArgAt(0)); | 52 GET_NON_NULL_NATIVE_ARGUMENT(String, message, arguments->NativeArgAt(0)); |
| 55 GET_NON_NULL_NATIVE_ARGUMENT(Integer, timestamp, arguments->NativeArgAt(1)); | 53 GET_NON_NULL_NATIVE_ARGUMENT(Integer, timestamp, arguments->NativeArgAt(1)); |
| 56 GET_NON_NULL_NATIVE_ARGUMENT(Integer, sequence, arguments->NativeArgAt(2)); | 54 GET_NON_NULL_NATIVE_ARGUMENT(Integer, sequence, arguments->NativeArgAt(2)); |
| 57 GET_NON_NULL_NATIVE_ARGUMENT(Smi, level, arguments->NativeArgAt(3)); | 55 GET_NON_NULL_NATIVE_ARGUMENT(Smi, level, arguments->NativeArgAt(3)); |
| 58 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4)); | 56 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4)); |
| 59 GET_NATIVE_ARGUMENT(Instance, dart_zone, arguments->NativeArgAt(5)); | 57 GET_NATIVE_ARGUMENT(Instance, dart_zone, arguments->NativeArgAt(5)); |
| 60 GET_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(6)); | 58 GET_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(6)); |
| 61 GET_NATIVE_ARGUMENT(Instance, stack_trace, arguments->NativeArgAt(7)); | 59 GET_NATIVE_ARGUMENT(Instance, stack_trace, arguments->NativeArgAt(7)); |
| 62 Service::SendLogEvent(isolate, sequence.AsInt64Value(), | 60 Service::SendLogEvent(isolate, sequence.AsInt64Value(), |
| 63 timestamp.AsInt64Value(), level.Value(), name, message, | 61 timestamp.AsInt64Value(), level.Value(), name, message, |
| 64 dart_zone, error, stack_trace); | 62 dart_zone, error, stack_trace); |
| 65 return Object::null(); | 63 return Object::null(); |
| 66 #endif // PRODUCT | 64 #endif // PRODUCT |
| 67 } | 65 } |
| 68 | 66 |
| 69 | |
| 70 DEFINE_NATIVE_ENTRY(Developer_postEvent, 2) { | 67 DEFINE_NATIVE_ENTRY(Developer_postEvent, 2) { |
| 71 #if defined(PRODUCT) | 68 #if defined(PRODUCT) |
| 72 return Object::null(); | 69 return Object::null(); |
| 73 #else | 70 #else |
| 74 if (!FLAG_support_service) { | 71 if (!FLAG_support_service) { |
| 75 return Object::null(); | 72 return Object::null(); |
| 76 } | 73 } |
| 77 GET_NON_NULL_NATIVE_ARGUMENT(String, event_kind, arguments->NativeArgAt(0)); | 74 GET_NON_NULL_NATIVE_ARGUMENT(String, event_kind, arguments->NativeArgAt(0)); |
| 78 GET_NON_NULL_NATIVE_ARGUMENT(String, event_data, arguments->NativeArgAt(1)); | 75 GET_NON_NULL_NATIVE_ARGUMENT(String, event_data, arguments->NativeArgAt(1)); |
| 79 Service::SendExtensionEvent(isolate, event_kind, event_data); | 76 Service::SendExtensionEvent(isolate, event_kind, event_data); |
| 80 return Object::null(); | 77 return Object::null(); |
| 81 #endif // PRODUCT | 78 #endif // PRODUCT |
| 82 } | 79 } |
| 83 | 80 |
| 84 | |
| 85 DEFINE_NATIVE_ENTRY(Developer_lookupExtension, 1) { | 81 DEFINE_NATIVE_ENTRY(Developer_lookupExtension, 1) { |
| 86 #if defined(PRODUCT) | 82 #if defined(PRODUCT) |
| 87 return Object::null(); | 83 return Object::null(); |
| 88 #else | 84 #else |
| 89 if (!FLAG_support_service) { | 85 if (!FLAG_support_service) { |
| 90 return Object::null(); | 86 return Object::null(); |
| 91 } | 87 } |
| 92 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); | 88 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 93 return isolate->LookupServiceExtensionHandler(name); | 89 return isolate->LookupServiceExtensionHandler(name); |
| 94 #endif // PRODUCT | 90 #endif // PRODUCT |
| 95 } | 91 } |
| 96 | 92 |
| 97 | |
| 98 DEFINE_NATIVE_ENTRY(Developer_registerExtension, 2) { | 93 DEFINE_NATIVE_ENTRY(Developer_registerExtension, 2) { |
| 99 #if defined(PRODUCT) | 94 #if defined(PRODUCT) |
| 100 return Object::null(); | 95 return Object::null(); |
| 101 #else | 96 #else |
| 102 if (!FLAG_support_service) { | 97 if (!FLAG_support_service) { |
| 103 return Object::null(); | 98 return Object::null(); |
| 104 } | 99 } |
| 105 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); | 100 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 106 GET_NON_NULL_NATIVE_ARGUMENT(Instance, handler, arguments->NativeArgAt(1)); | 101 GET_NON_NULL_NATIVE_ARGUMENT(Instance, handler, arguments->NativeArgAt(1)); |
| 107 // We don't allow service extensions to be registered for the | 102 // We don't allow service extensions to be registered for the |
| 108 // service isolate. This can happen, for example, because the | 103 // service isolate. This can happen, for example, because the |
| 109 // service isolate uses dart:io. If we decide that we want to start | 104 // service isolate uses dart:io. If we decide that we want to start |
| 110 // supporting this in the future, it will take some work. | 105 // supporting this in the future, it will take some work. |
| 111 if (!ServiceIsolate::IsServiceIsolateDescendant(isolate)) { | 106 if (!ServiceIsolate::IsServiceIsolateDescendant(isolate)) { |
| 112 isolate->RegisterServiceExtensionHandler(name, handler); | 107 isolate->RegisterServiceExtensionHandler(name, handler); |
| 113 } | 108 } |
| 114 return Object::null(); | 109 return Object::null(); |
| 115 #endif // PRODUCT | 110 #endif // PRODUCT |
| 116 } | 111 } |
| 117 | 112 |
| 118 DEFINE_NATIVE_ENTRY(Developer_getServiceMajorVersion, 0) { | 113 DEFINE_NATIVE_ENTRY(Developer_getServiceMajorVersion, 0) { |
| 119 #if defined(PRODUCT) | 114 #if defined(PRODUCT) |
| 120 return Smi::New(0); | 115 return Smi::New(0); |
| 121 #else | 116 #else |
| 122 return Smi::New(SERVICE_PROTOCOL_MAJOR_VERSION); | 117 return Smi::New(SERVICE_PROTOCOL_MAJOR_VERSION); |
| 123 #endif | 118 #endif |
| 124 } | 119 } |
| 125 | 120 |
| 126 | |
| 127 DEFINE_NATIVE_ENTRY(Developer_getServiceMinorVersion, 0) { | 121 DEFINE_NATIVE_ENTRY(Developer_getServiceMinorVersion, 0) { |
| 128 #if defined(PRODUCT) | 122 #if defined(PRODUCT) |
| 129 return Smi::New(0); | 123 return Smi::New(0); |
| 130 #else | 124 #else |
| 131 return Smi::New(SERVICE_PROTOCOL_MINOR_VERSION); | 125 return Smi::New(SERVICE_PROTOCOL_MINOR_VERSION); |
| 132 #endif | 126 #endif |
| 133 } | 127 } |
| 134 | 128 |
| 135 | |
| 136 static void SendNull(const SendPort& port) { | 129 static void SendNull(const SendPort& port) { |
| 137 const Dart_Port destination_port_id = port.Id(); | 130 const Dart_Port destination_port_id = port.Id(); |
| 138 PortMap::PostMessage(new Message(destination_port_id, Object::null(), | 131 PortMap::PostMessage(new Message(destination_port_id, Object::null(), |
| 139 Message::kNormalPriority)); | 132 Message::kNormalPriority)); |
| 140 } | 133 } |
| 141 | 134 |
| 142 | |
| 143 DEFINE_NATIVE_ENTRY(Developer_getServerInfo, 1) { | 135 DEFINE_NATIVE_ENTRY(Developer_getServerInfo, 1) { |
| 144 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 136 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
| 145 #if defined(PRODUCT) | 137 #if defined(PRODUCT) |
| 146 SendNull(port); | 138 SendNull(port); |
| 147 return Object::null(); | 139 return Object::null(); |
| 148 #else | 140 #else |
| 149 if (!ServiceIsolate::IsRunning()) { | 141 if (!ServiceIsolate::IsRunning()) { |
| 150 SendNull(port); | 142 SendNull(port); |
| 151 } else { | 143 } else { |
| 152 ServiceIsolate::RequestServerInfo(port); | 144 ServiceIsolate::RequestServerInfo(port); |
| 153 } | 145 } |
| 154 return Object::null(); | 146 return Object::null(); |
| 155 #endif | 147 #endif |
| 156 } | 148 } |
| 157 | 149 |
| 158 | |
| 159 DEFINE_NATIVE_ENTRY(Developer_webServerControl, 2) { | 150 DEFINE_NATIVE_ENTRY(Developer_webServerControl, 2) { |
| 160 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 151 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
| 161 #if defined(PRODUCT) | 152 #if defined(PRODUCT) |
| 162 SendNull(port); | 153 SendNull(port); |
| 163 return Object::null(); | 154 return Object::null(); |
| 164 #else | 155 #else |
| 165 GET_NON_NULL_NATIVE_ARGUMENT(Bool, enabled, arguments->NativeArgAt(1)); | 156 GET_NON_NULL_NATIVE_ARGUMENT(Bool, enabled, arguments->NativeArgAt(1)); |
| 166 if (!ServiceIsolate::IsRunning()) { | 157 if (!ServiceIsolate::IsRunning()) { |
| 167 SendNull(port); | 158 SendNull(port); |
| 168 } else { | 159 } else { |
| 169 ServiceIsolate::ControlWebServer(port, enabled.value()); | 160 ServiceIsolate::ControlWebServer(port, enabled.value()); |
| 170 } | 161 } |
| 171 return Object::null(); | 162 return Object::null(); |
| 172 #endif | 163 #endif |
| 173 } | 164 } |
| 174 | 165 |
| 175 | |
| 176 DEFINE_NATIVE_ENTRY(Developer_getIsolateIDFromSendPort, 1) { | 166 DEFINE_NATIVE_ENTRY(Developer_getIsolateIDFromSendPort, 1) { |
| 177 #if defined(PRODUCT) | 167 #if defined(PRODUCT) |
| 178 return Object::null(); | 168 return Object::null(); |
| 179 #else | 169 #else |
| 180 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 170 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
| 181 int64_t port_id = port.Id(); | 171 int64_t port_id = port.Id(); |
| 182 return String::NewFormatted(ISOLATE_SERVICE_ID_FORMAT_STRING, port_id); | 172 return String::NewFormatted(ISOLATE_SERVICE_ID_FORMAT_STRING, port_id); |
| 183 #endif | 173 #endif |
| 184 } | 174 } |
| 185 | 175 |
| 186 | |
| 187 } // namespace dart | 176 } // namespace dart |
| OLD | NEW |