Index: Source/WebCore/bindings/dart/DartNativeUtilities.cpp |
diff --git a/Source/WebCore/bindings/dart/DartNativeUtilities.cpp b/Source/WebCore/bindings/dart/DartNativeUtilities.cpp |
index a4b567fd0a2bf02dc6ba8ba94fc698a330cf12cb..d365063c24978b60bd1fcc50bcfd27f0a1c12473 100644 |
--- a/Source/WebCore/bindings/dart/DartNativeUtilities.cpp |
+++ b/Source/WebCore/bindings/dart/DartNativeUtilities.cpp |
@@ -36,7 +36,9 @@ |
#include "DartDOMWrapper.h" |
#include "DartDocument.h" |
#include "DartUtilities.h" |
+#include "Frame.h" |
#include "RuntimeEnabledFeatures.h" |
+#include "V8Converter.h" |
#include "npruntime_impl.h" |
#include <bindings/npruntime.h> |
@@ -90,6 +92,34 @@ fail: |
ASSERT_NOT_REACHED(); |
} |
+/** |
+ * Gadget for testing. |
+ * |
+ * With DART_FORWARDING_PRINT environment variable set, it invokes dartPrint |
+ * JavaScript function on global object to communicate to Dart test framework. |
+ */ |
+static void forwardingPrint(Dart_NativeArguments args) |
+{ |
+ v8::HandleScope v8Scope; |
+ ScriptExecutionContext* scriptExecutionContext = DartUtilities::scriptExecutionContext(); |
+ ASSERT(scriptExecutionContext); |
+ |
+ DartController* dartController = DartController::retrieve(scriptExecutionContext); |
+ if (!dartController) |
+ return; |
+ |
+ v8::Handle<v8::Context> v8Context = dartController->frame()->script()->mainWorldContext(); |
+ v8::Context::Scope scope(v8Context); |
+ v8::TryCatch tryCatch; |
+ |
+ v8::Handle<v8::Value> function = v8Context->Global()->Get(v8::String::New("dartPrint")); |
+ if (function.IsEmpty() || !function->IsFunction()) |
+ return; |
+ |
+ v8::Handle<v8::Value> message = V8Converter::stringToV8(Dart_GetNativeArgument(args, 0)); |
+ function.As<v8::Function>()->Call(v8Context->Global(), 1, &message); |
+} |
+ |
static void getNewIsolateId(Dart_NativeArguments args) |
{ |
DartApiScope dartApiScope; |
@@ -276,6 +306,8 @@ Dart_NativeFunction domResolver(Dart_Handle name, int argumentCount) |
return topLevelWindow; |
if (argumentCount == 1 && str == "Utils_print") |
return print; |
+ if (argumentCount == 1 && str == "Utils_forwardingPrint") |
+ return forwardingPrint; |
if (argumentCount == 1 && str == "Utils_spawnDomFunction") |
return spawnDomFunction; |
if (argumentCount == 0 && str == "Utils_getNewIsolateId") |