Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: sky/engine/core/script/dart_controller.cc

Issue 950493003: Add a basic sky-element custom element (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/config.h" 5 #include "sky/engine/config.h"
6 #include "sky/engine/core/script/dart_controller.h" 6 #include "sky/engine/core/script/dart_controller.h"
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "dart/runtime/include/dart_mirrors_api.h" 11 #include "dart/runtime/include/dart_mirrors_api.h"
12 #include "sky/engine/bindings/builtin.h" 12 #include "sky/engine/bindings/builtin.h"
13 #include "sky/engine/bindings/builtin_natives.h" 13 #include "sky/engine/bindings/builtin_natives.h"
14 #include "sky/engine/bindings/builtin_sky.h" 14 #include "sky/engine/bindings/builtin_sky.h"
15 #include "sky/engine/core/app/AbstractModule.h" 15 #include "sky/engine/core/app/AbstractModule.h"
16 #include "sky/engine/core/app/Module.h" 16 #include "sky/engine/core/app/Module.h"
17 #include "sky/engine/core/dom/Element.h" 17 #include "sky/engine/core/dom/Element.h"
18 #include "sky/engine/core/frame/LocalFrame.h" 18 #include "sky/engine/core/frame/LocalFrame.h"
19 #include "sky/engine/core/html/HTMLScriptElement.h"
19 #include "sky/engine/core/html/imports/HTMLImport.h" 20 #include "sky/engine/core/html/imports/HTMLImport.h"
20 #include "sky/engine/core/html/imports/HTMLImportChild.h" 21 #include "sky/engine/core/html/imports/HTMLImportChild.h"
21 #include "sky/engine/core/loader/FrameLoaderClient.h" 22 #include "sky/engine/core/loader/FrameLoaderClient.h"
22 #include "sky/engine/core/script/dart_dependency_catcher.h" 23 #include "sky/engine/core/script/dart_dependency_catcher.h"
23 #include "sky/engine/core/script/dart_loader.h" 24 #include "sky/engine/core/script/dart_loader.h"
24 #include "sky/engine/core/script/dom_dart_state.h" 25 #include "sky/engine/core/script/dom_dart_state.h"
25 #include "sky/engine/public/platform/Platform.h" 26 #include "sky/engine/public/platform/Platform.h"
26 #include "sky/engine/tonic/dart_api_scope.h" 27 #include "sky/engine/tonic/dart_api_scope.h"
27 #include "sky/engine/tonic/dart_class_library.h" 28 #include "sky/engine/tonic/dart_class_library.h"
28 #include "sky/engine/tonic/dart_error.h" 29 #include "sky/engine/tonic/dart_error.h"
29 #include "sky/engine/tonic/dart_gc_controller.h" 30 #include "sky/engine/tonic/dart_gc_controller.h"
30 #include "sky/engine/tonic/dart_isolate_scope.h" 31 #include "sky/engine/tonic/dart_isolate_scope.h"
31 #include "sky/engine/tonic/dart_state.h" 32 #include "sky/engine/tonic/dart_state.h"
33 #include "sky/engine/tonic/dart_wrappable.h"
32 #include "sky/engine/wtf/text/TextPosition.h" 34 #include "sky/engine/wtf/text/TextPosition.h"
33 35
34 namespace blink { 36 namespace blink {
35 37
36 #if ENABLE(ASSERT) 38 #if ENABLE(ASSERT)
37 static const char* kCheckedModeArgs[] = { 39 static const char* kCheckedModeArgs[] = {
38 "--enable_asserts", 40 "--enable_asserts",
39 "--enable_type_checks", 41 "--enable_type_checks",
40 "--error_on_bad_type", 42 "--error_on_bad_type",
41 "--error_on_bad_override", 43 "--error_on_bad_override",
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 module->AddLibrary(library, position); 117 module->AddLibrary(library, position);
116 118
117 // TODO(eseidel): Better if the library/module retained its dependencies and 119 // TODO(eseidel): Better if the library/module retained its dependencies and
118 // dependency waiting could be separate from library creation. 120 // dependency waiting could be separate from library creation.
119 dart_state()->loader().WaitForDependencies( 121 dart_state()->loader().WaitForDependencies(
120 dependency_catcher.dependencies(), 122 dependency_catcher.dependencies(),
121 base::Bind(finished_callback, module, library)); 123 base::Bind(finished_callback, module, library));
122 } 124 }
123 125
124 void DartController::ExecuteLibraryInModule(AbstractModule* module, 126 void DartController::ExecuteLibraryInModule(AbstractModule* module,
125 Dart_Handle library) { 127 Dart_Handle library,
128 HTMLScriptElement* script) {
126 ASSERT(library); 129 ASSERT(library);
127 DCHECK(Dart_CurrentIsolate() == dart_state()->isolate()); 130 DCHECK(Dart_CurrentIsolate() == dart_state()->isolate());
128 DartApiScope dart_api_scope; 131 DartApiScope dart_api_scope;
129 132
130 // Don't continue if we failed to load the module. 133 // Don't continue if we failed to load the module.
131 if (LogIfError(Dart_FinalizeLoading(true))) 134 if (LogIfError(Dart_FinalizeLoading(true)))
132 return; 135 return;
133 const char* name = module->isApplication() ? "main" : "init"; 136 const char* name = module->isApplication() ? "main" : "_init";
134 137
135 // main() is required, but init() is not: 138 // main() is required, but init() is not:
136 // TODO(rmacnak): Dart_LookupFunction won't find re-exports, etc. 139 // TODO(rmacnak): Dart_LookupFunction won't find re-exports, etc.
137 Dart_Handle entry = Dart_LookupFunction(library, ToDart(name)); 140 Dart_Handle entry = Dart_LookupFunction(library, ToDart(name));
138 if (!Dart_IsFunction(entry) && !module->isApplication()) 141 if (module->isApplication()) {
142 LogIfError(Dart_Invoke(library, ToDart(name), 0, nullptr));
143 return;
144 }
145
146 if (!Dart_IsFunction(entry))
139 return; 147 return;
140 148
141 Dart_Handle result = Dart_Invoke(library, ToDart(name), 0, nullptr); 149 Dart_Handle args[] = {
142 LogIfError(result); 150 ToDart(script),
151 };
152 LogIfError(Dart_Invoke(library, ToDart(name), arraysize(args), args));
143 } 153 }
144 154
145 static void UnhandledExceptionCallback(Dart_Handle error) { 155 static void UnhandledExceptionCallback(Dart_Handle error) {
146 DCHECK(!Dart_IsError(error)); 156 DCHECK(!Dart_IsError(error));
147 LOG(ERROR) << Dart_GetError(error); 157 LOG(ERROR) << Dart_GetError(error);
148 } 158 }
149 159
150 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, 160 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
151 Dart_Handle library, 161 Dart_Handle library,
152 Dart_Handle url) { 162 Dart_Handle url) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 299
290 CHECK(Dart_SetVMFlags(argc, argv)); 300 CHECK(Dart_SetVMFlags(argc, argv));
291 CHECK(Dart_Initialize(IsolateCreateCallback, 301 CHECK(Dart_Initialize(IsolateCreateCallback,
292 nullptr, // Isolate interrupt callback. 302 nullptr, // Isolate interrupt callback.
293 UnhandledExceptionCallback, IsolateShutdownCallback, 303 UnhandledExceptionCallback, IsolateShutdownCallback,
294 // File IO callbacks. 304 // File IO callbacks.
295 nullptr, nullptr, nullptr, nullptr, nullptr)); 305 nullptr, nullptr, nullptr, nullptr, nullptr));
296 } 306 }
297 307
298 } // namespace blink 308 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698