| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sky/engine/config.h" | |
| 6 #include "sky/engine/bindings2/dart_master.h" | |
| 7 | |
| 8 #include "base/logging.h" | |
| 9 | |
| 10 namespace mojo { | |
| 11 namespace dart { | |
| 12 | |
| 13 extern const uint8_t* snapshot_buffer; | |
| 14 } | |
| 15 } | |
| 16 | |
| 17 namespace blink { | |
| 18 | |
| 19 static Dart_Isolate IsolateCreateCallback(const char* script_uri, | |
| 20 const char* main, | |
| 21 const char* package_root, | |
| 22 void* callback_data, | |
| 23 char** error) { | |
| 24 // LOG(INFO) << "IsolateCreateCallback"; | |
| 25 return nullptr; | |
| 26 } | |
| 27 | |
| 28 static void UnhandledExceptionCallback(Dart_Handle error) { | |
| 29 // LOG(INFO) << "UnhandledExceptionCallback"; | |
| 30 } | |
| 31 | |
| 32 static void IsolateShutdownCallback(void* callback_data) { | |
| 33 // LOG(INFO) << "IsolateShutdownCallback"; | |
| 34 } | |
| 35 | |
| 36 static Dart_Isolate ServiceIsolateCreateCallback(void* callback_data, | |
| 37 char** error) { | |
| 38 // LOG(INFO) << "ServiceIsolateCreateCallback"; | |
| 39 return nullptr; | |
| 40 } | |
| 41 | |
| 42 void DartMaster::InitVM() { | |
| 43 bool result = Dart_SetVMFlags(0, NULL); | |
| 44 | |
| 45 result = Dart_Initialize(IsolateCreateCallback, | |
| 46 nullptr, // Isolate interrupt callback. | |
| 47 UnhandledExceptionCallback, IsolateShutdownCallback, | |
| 48 // File IO callbacks. | |
| 49 nullptr, nullptr, nullptr, nullptr, nullptr, | |
| 50 ServiceIsolateCreateCallback); | |
| 51 | |
| 52 char* error; | |
| 53 Dart_Isolate isolate = Dart_CreateIsolate( | |
| 54 "bogus:uri", "main", mojo::dart::snapshot_buffer, nullptr, &error); | |
| 55 | |
| 56 CHECK(isolate); | |
| 57 | |
| 58 Dart_EnterScope(); | |
| 59 | |
| 60 Dart_Handle library = Dart_LoadLibrary( | |
| 61 Dart_NewStringFromCString("foo:bar"), | |
| 62 Dart_NewStringFromCString("main() { int foo = 2; foo++; return foo; }"), | |
| 63 0, 0); | |
| 64 | |
| 65 Dart_FinalizeLoading(true); | |
| 66 | |
| 67 if (Dart_IsError(library)) { | |
| 68 LOG(INFO) << Dart_GetError(library); | |
| 69 abort(); | |
| 70 } | |
| 71 | |
| 72 Dart_Handle invoke_result = | |
| 73 Dart_Invoke(library, Dart_NewStringFromCString("main"), 0, nullptr); | |
| 74 if (Dart_IsError(invoke_result)) { | |
| 75 LOG(INFO) << Dart_GetError(invoke_result); | |
| 76 abort(); | |
| 77 } | |
| 78 | |
| 79 CHECK(Dart_IsInteger(invoke_result)); | |
| 80 Dart_Handle str = Dart_ToString(invoke_result); | |
| 81 const char* xyz = "invalid"; | |
| 82 Dart_StringToCString(str, &xyz); | |
| 83 LOG(INFO) << xyz; | |
| 84 } | |
| 85 } | |
| OLD | NEW |