| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/engine/bindings/builtin_natives.h" | 5 #include "sky/engine/bindings/builtin_natives.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "dart/runtime/include/dart_api.h" | 15 #include "dart/runtime/include/dart_api.h" |
| 16 #include "sky/engine/bindings/builtin.h" | 16 #include "sky/engine/bindings/builtin.h" |
| 17 #include "sky/engine/core/dom/Microtask.h" | 17 #include "sky/engine/core/dom/Microtask.h" |
| 18 #include "sky/engine/core/script/dom_dart_state.h" | 18 #include "sky/engine/core/script/dom_dart_state.h" |
| 19 #include "sky/engine/tonic/dart_api_scope.h" | 19 #include "sky/engine/tonic/dart_api_scope.h" |
| 20 #include "sky/engine/tonic/dart_builtin.h" | 20 #include "sky/engine/tonic/dart_builtin.h" |
| 21 #include "sky/engine/tonic/dart_error.h" | 21 #include "sky/engine/tonic/dart_error.h" |
| 22 #include "sky/engine/tonic/dart_invoke.h" | 22 #include "sky/engine/tonic/dart_invoke.h" |
| 23 #include "sky/engine/tonic/dart_isolate_scope.h" | 23 #include "sky/engine/tonic/dart_isolate_scope.h" |
| 24 #include "sky/engine/tonic/dart_state.h" | 24 #include "sky/engine/tonic/dart_state.h" |
| 25 #include "sky/engine/tonic/dart_timer_heap.h" | 25 #include "sky/engine/tonic/dart_timer_heap.h" |
| 26 #include "sky/engine/tonic/dart_value.h" | 26 #include "sky/engine/tonic/dart_value.h" |
| 27 #include "sky/engine/wtf/text/WTFString.h" | 27 #include "sky/engine/wtf/text/WTFString.h" |
| 28 | 28 |
| 29 #if defined(OS_ANDROID) |
| 30 #include <android/log.h> |
| 31 #endif |
| 32 |
| 29 namespace blink { | 33 namespace blink { |
| 30 | 34 |
| 31 #define REGISTER_FUNCTION(name, count) \ | 35 #define REGISTER_FUNCTION(name, count) \ |
| 32 { "" #name, name, count }, | 36 { "" #name, name, count }, |
| 33 #define DECLARE_FUNCTION(name, count) \ | 37 #define DECLARE_FUNCTION(name, count) \ |
| 34 extern void name(Dart_NativeArguments args); | 38 extern void name(Dart_NativeArguments args); |
| 35 | 39 |
| 36 // Lists the native functions implementing basic functionality in | 40 // Lists the native functions implementing basic functionality in |
| 37 // the Mojo embedder dart, such as printing, and file I/O. | 41 // the Mojo embedder dart, such as printing, and file I/O. |
| 38 #define BUILTIN_NATIVE_LIST(V) \ | 42 #define BUILTIN_NATIVE_LIST(V) \ |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Implementation of native functions which are used for some | 156 // Implementation of native functions which are used for some |
| 153 // test/debug functionality in standalone dart mode. | 157 // test/debug functionality in standalone dart mode. |
| 154 void Logger_PrintString(Dart_NativeArguments args) { | 158 void Logger_PrintString(Dart_NativeArguments args) { |
| 155 intptr_t length = 0; | 159 intptr_t length = 0; |
| 156 uint8_t* chars = nullptr; | 160 uint8_t* chars = nullptr; |
| 157 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 161 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
| 158 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); | 162 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); |
| 159 if (Dart_IsError(result)) { | 163 if (Dart_IsError(result)) { |
| 160 Dart_PropagateError(result); | 164 Dart_PropagateError(result); |
| 161 } else { | 165 } else { |
| 162 | 166 // Uses fwrite to support printing NUL bytes. |
| 163 String message(chars, length); | 167 fwrite(chars, 1, length, stdout); |
| 164 // TODO(dart): Hook up to developer console (if/when that's a thing). | 168 fputs("\n", stdout); |
| 165 #if OS(ANDROID) || OS(IOS) | 169 #if defined(OS_ANDROID) |
| 166 LOG(INFO) << "CONSOLE: " << message.utf8().data(); | 170 // In addition to writing to the stdout, write to the logcat so that the |
| 167 #else | 171 // message is discoverable when running on an unrooted device. |
| 168 printf("CONSOLE: %s\n", message.utf8().data()); | 172 __android_log_print(ANDROID_LOG_INFO, "sky", "%.*s", length, chars); |
| 169 fflush(stdout); | |
| 170 #endif | 173 #endif |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 static void ExecuteMicrotask(base::WeakPtr<DartState> dart_state, | 177 static void ExecuteMicrotask(base::WeakPtr<DartState> dart_state, |
| 175 RefPtr<DartValue> callback) { | 178 RefPtr<DartValue> callback) { |
| 176 if (!dart_state) | 179 if (!dart_state) |
| 177 return; | 180 return; |
| 178 DartIsolateScope scope(dart_state->isolate()); | 181 DartIsolateScope scope(dart_state->isolate()); |
| 179 DartApiScope api_scope; | 182 DartApiScope api_scope; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 void Timer_cancel(Dart_NativeArguments args) { | 222 void Timer_cancel(Dart_NativeArguments args) { |
| 220 int64_t timer_id = 0; | 223 int64_t timer_id = 0; |
| 221 DART_CHECK_VALID(Dart_GetNativeIntegerArgument(args, 0, &timer_id)); | 224 DART_CHECK_VALID(Dart_GetNativeIntegerArgument(args, 0, &timer_id)); |
| 222 | 225 |
| 223 DartState* state = DartState::Current(); | 226 DartState* state = DartState::Current(); |
| 224 CHECK(state); | 227 CHECK(state); |
| 225 state->timer_heap().Remove(timer_id); | 228 state->timer_heap().Remove(timer_id); |
| 226 } | 229 } |
| 227 | 230 |
| 228 } // namespace blink | 231 } // namespace blink |
| OLD | NEW |