diff --git a/engine/core/html/parser/HTMLScriptRunner.cpp b/engine/core/html/parser/HTMLScriptRunner.cpp
index e0bab6300db..2cdb3846d35 100644
--- a/engine/core/html/parser/HTMLScriptRunner.cpp
+++ b/engine/core/html/parser/HTMLScriptRunner.cpp
@@ -115,8 +115,11 @@ void HTMLScriptRunner::executeLibrary(RefPtr module,
// or script failures, etc.
Microtask::performCheckpoint();
- if (LocalFrame* frame = contextFrame(m_element.get()))
- frame->dart().ExecuteLibraryInModule(module.get(), library->dart_value());
+ if (LocalFrame* frame = contextFrame(m_element.get())) {
+ frame->dart().ExecuteLibraryInModule(module.get(),
+ library->dart_value(),
+ m_element.get());
+ }
advanceTo(StateCompleted);
// We may be deleted at this point.
diff --git a/engine/core/script/dart_controller.cc b/engine/core/script/dart_controller.cc
index 8d17fbc3b7d..ecbcad02b91 100644
--- a/engine/core/script/dart_controller.cc
+++ b/engine/core/script/dart_controller.cc
@@ -16,6 +16,7 @@
#include "sky/engine/core/app/Module.h"
#include "sky/engine/core/dom/Element.h"
#include "sky/engine/core/frame/LocalFrame.h"
+#include "sky/engine/core/html/HTMLScriptElement.h"
#include "sky/engine/core/html/imports/HTMLImport.h"
#include "sky/engine/core/html/imports/HTMLImportChild.h"
#include "sky/engine/core/loader/FrameLoaderClient.h"
@@ -29,6 +30,7 @@
#include "sky/engine/tonic/dart_gc_controller.h"
#include "sky/engine/tonic/dart_isolate_scope.h"
#include "sky/engine/tonic/dart_state.h"
+#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/text/TextPosition.h"
namespace blink {
@@ -122,7 +124,8 @@ void DartController::LoadScriptInModule(
}
void DartController::ExecuteLibraryInModule(AbstractModule* module,
- Dart_Handle library) {
+ Dart_Handle library,
+ HTMLScriptElement* script) {
ASSERT(library);
DCHECK(Dart_CurrentIsolate() == dart_state()->isolate());
DartApiScope dart_api_scope;
@@ -130,16 +133,23 @@ void DartController::ExecuteLibraryInModule(AbstractModule* module,
// Don't continue if we failed to load the module.
if (LogIfError(Dart_FinalizeLoading(true)))
return;
- const char* name = module->isApplication() ? "main" : "init";
+ const char* name = module->isApplication() ? "main" : "_init";
// main() is required, but init() is not:
// TODO(rmacnak): Dart_LookupFunction won't find re-exports, etc.
Dart_Handle entry = Dart_LookupFunction(library, ToDart(name));
- if (!Dart_IsFunction(entry) && !module->isApplication())
+ if (module->isApplication()) {
+ LogIfError(Dart_Invoke(library, ToDart(name), 0, nullptr));
+ return;
+ }
+
+ if (!Dart_IsFunction(entry))
return;
- Dart_Handle result = Dart_Invoke(library, ToDart(name), 0, nullptr);
- LogIfError(result);
+ Dart_Handle args[] = {
+ ToDart(script),
+ };
+ LogIfError(Dart_Invoke(library, ToDart(name), arraysize(args), args));
}
static void UnhandledExceptionCallback(Dart_Handle error) {
diff --git a/engine/core/script/dart_controller.h b/engine/core/script/dart_controller.h
index 1fdd4089507..2266a8d7c87 100644
--- a/engine/core/script/dart_controller.h
+++ b/engine/core/script/dart_controller.h
@@ -16,8 +16,9 @@ namespace blink {
class AbstractModule;
class BuiltinSky;
class DOMDartState;
-class Document;
class DartValue;
+class Document;
+class HTMLScriptElement;
class DartController {
public:
@@ -33,7 +34,9 @@ class DartController {
const String& source,
const TextPosition& textPosition,
const LoadFinishedCallback& load_finished_callback);
- void ExecuteLibraryInModule(AbstractModule* module, Dart_Handle library);
+ void ExecuteLibraryInModule(AbstractModule* module,
+ Dart_Handle library,
+ HTMLScriptElement* script);
void ClearForClose();
void CreateIsolateFor(Document* document);
diff --git a/examples/example-element/example-element.sky b/examples/example-element/example-element.sky
new file mode 100644
index 00000000000..097d4f54e2c
--- /dev/null
+++ b/examples/example-element/example-element.sky
@@ -0,0 +1,25 @@
+
+
+
+
+
+ Hi
+
+
+
diff --git a/examples/example-element/index.sky b/examples/example-element/index.sky
new file mode 100644
index 00000000000..f895fbefd4f
--- /dev/null
+++ b/examples/example-element/index.sky
@@ -0,0 +1,16 @@
+
+
+
+
+
+
diff --git a/framework/sky-element.sky b/framework/sky-element.sky
new file mode 100644
index 00000000000..38d757a8f5a
--- /dev/null
+++ b/framework/sky-element.sky
@@ -0,0 +1,85 @@
+
+
diff --git a/tests/modules/resources/multiple-scripts-child.sky b/tests/modules/resources/multiple-scripts-child.sky
index dd3e5eaac81..c46aeb6327e 100644
--- a/tests/modules/resources/multiple-scripts-child.sky
+++ b/tests/modules/resources/multiple-scripts-child.sky
@@ -2,7 +2,7 @@
diff --git a/tests/resources/dump-as-markup.sky b/tests/resources/dump-as-markup.sky
index 03513106c0b..ce00be56c62 100644
--- a/tests/resources/dump-as-markup.sky
+++ b/tests/resources/dump-as-markup.sky
@@ -3,7 +3,7 @@
import "dart:sky";
import "dart:sky.internals" as internals;
-void init() {
+void _init(_) {
window.addEventListener('load', (_) {
internals.notifyTestComplete(DomSerializer.serializeNode(document));
});
diff --git a/tests/resources/dump-as-render-tree.sky b/tests/resources/dump-as-render-tree.sky
index 0ea5f039978..74e07f06359 100644
--- a/tests/resources/dump-as-render-tree.sky
+++ b/tests/resources/dump-as-render-tree.sky
@@ -2,7 +2,7 @@
import "dart:sky" as sky;
import "dart:sky.internals" as internals;
-void init() {
+void _init(_) {
sky.window.addEventListener('load', (_) =>
internals.notifyTestComplete(internals.renderTreeAsText()));
}
diff --git a/tests/resources/dump-as-text.sky b/tests/resources/dump-as-text.sky
index 4effcb5aca1..2e948fbcd72 100644
--- a/tests/resources/dump-as-text.sky
+++ b/tests/resources/dump-as-text.sky
@@ -6,7 +6,7 @@ void handleLoadEvent(event) {
internals.notifyTestComplete(internals.contentAsText());
}
-void init() {
+void _init(_) {
sky.window.addEventListener('load', handleLoadEvent);
}