dommy 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dommy/backend.rb +16 -15
- data/lib/dommy/blob.rb +17 -0
- data/lib/dommy/bridge/values.rb +29 -2
- data/lib/dommy/bridge/wire_tags.rb +8 -4
- data/lib/dommy/browser.rb +324 -49
- data/lib/dommy/character_data.rb +20 -27
- data/lib/dommy/class_list.rb +24 -9
- data/lib/dommy/cookie_jar.rb +408 -0
- data/lib/dommy/cookie_store.rb +104 -49
- data/lib/dommy/css.rb +34 -8
- data/lib/dommy/custom_elements.rb +362 -114
- data/lib/dommy/data_transfer.rb +22 -2
- data/lib/dommy/document.rb +1071 -200
- data/lib/dommy/dom_exception.rb +6 -0
- data/lib/dommy/dom_parser.rb +46 -14
- data/lib/dommy/dom_string_list.rb +36 -0
- data/lib/dommy/element.rb +217 -102
- data/lib/dommy/element_internals.rb +215 -0
- data/lib/dommy/encodings.rb +10 -0
- data/lib/dommy/event.rb +378 -122
- data/lib/dommy/event_source.rb +4 -30
- data/lib/dommy/file_reader.rb +5 -29
- data/lib/dommy/form_data.rb +40 -6
- data/lib/dommy/form_entry_list.rb +106 -137
- data/lib/dommy/fragment.rb +11 -10
- data/lib/dommy/history.rb +247 -90
- data/lib/dommy/html_canvas_element.rb +15 -35
- data/lib/dommy/html_collection.rb +49 -30
- data/lib/dommy/html_elements/base.rb +111 -69
- data/lib/dommy/html_elements/embedded.rb +349 -105
- data/lib/dommy/html_elements/forms/form.rb +407 -368
- data/lib/dommy/html_elements/forms/input.rb +333 -174
- data/lib/dommy/html_elements/forms/select.rb +90 -74
- data/lib/dommy/html_elements/interactive.rb +274 -64
- data/lib/dommy/html_elements/media.rb +71 -30
- data/lib/dommy/html_elements/metadata.rb +215 -71
- data/lib/dommy/html_elements/miscellaneous.rb +58 -14
- data/lib/dommy/html_elements/tables.rb +7 -9
- data/lib/dommy/html_elements.rb +23 -1
- data/lib/dommy/hyperlink_utils.rb +15 -4
- data/lib/dommy/interaction/drag_and_drop.rb +187 -0
- data/lib/dommy/interaction/event_synthesis.rb +182 -24
- data/lib/dommy/interaction/field_interactor.rb +17 -5
- data/lib/dommy/interaction/form_submission.rb +10 -4
- data/lib/dommy/interaction/key_sender.rb +101 -16
- data/lib/dommy/interaction.rb +1 -0
- data/lib/dommy/internal/accessibility_tree.rb +15 -3
- data/lib/dommy/internal/accessible_description.rb +1 -1
- data/lib/dommy/internal/accessible_name.rb +10 -17
- data/lib/dommy/internal/aria_role.rb +1 -1
- data/lib/dommy/internal/autofill.rb +2 -2
- data/lib/dommy/internal/backend_prefilter.rb +1 -5
- data/lib/dommy/internal/ce_reactions.rb +285 -0
- data/lib/dommy/internal/ce_reactions_table.rb +296 -0
- data/lib/dommy/internal/child_list.rb +7 -43
- data/lib/dommy/internal/child_navigable.rb +155 -0
- data/lib/dommy/internal/child_node.rb +44 -41
- data/lib/dommy/internal/close_watcher_manager.rb +238 -0
- data/lib/dommy/internal/complex_match.rb +3 -1
- data/lib/dommy/internal/constraint_validation.rb +130 -0
- data/lib/dommy/internal/css/ancestor_filter.rb +107 -0
- data/lib/dommy/internal/css/cascade.rb +7 -7
- data/lib/dommy/internal/css/cascaded_declarations.rb +4 -1
- data/lib/dommy/internal/css/computed_style_builder.rb +9 -3
- data/lib/dommy/internal/css/custom_properties.rb +41 -29
- data/lib/dommy/internal/css/parser.rb +0 -22
- data/lib/dommy/internal/css/renderability.rb +6 -0
- data/lib/dommy/internal/css/rule_index.rb +149 -98
- data/lib/dommy/internal/css/rule_index_inputs.rb +135 -0
- data/lib/dommy/internal/css/selector_dependencies.rb +8 -2
- data/lib/dommy/internal/css/style_cache.rb +7 -4
- data/lib/dommy/internal/css/ua_stylesheet.rb +34 -0
- data/lib/dommy/internal/declarative_shadow_roots.rb +182 -0
- data/lib/dommy/internal/document_generations.rb +55 -2
- data/lib/dommy/internal/document_interaction_state.rb +293 -9
- data/lib/dommy/internal/dom_matching.rb +2 -2
- data/lib/dommy/internal/element_aria.rb +25 -19
- data/lib/dommy/internal/element_popover.rb +226 -25
- data/lib/dommy/internal/element_shadow.rb +97 -26
- data/lib/dommy/internal/element_state.rb +98 -5
- data/lib/dommy/internal/element_top_layer.rb +15 -1
- data/lib/dommy/internal/enumerated_keyword_sets.rb +40 -0
- data/lib/dommy/internal/event_handler_tables.rb +241 -0
- data/lib/dommy/internal/event_handlers.rb +149 -0
- data/lib/dommy/internal/exception_report.rb +1 -1
- data/lib/dommy/internal/focusability.rb +267 -0
- data/lib/dommy/internal/form_associated_custom_elements.rb +127 -0
- data/lib/dommy/internal/html_or_svg_or_mathml_element.rb +34 -23
- data/lib/dommy/internal/html_serialization.rb +292 -0
- data/lib/dommy/internal/idl_reflection.rb +202 -0
- data/lib/dommy/internal/idl_reflection_table.rb +589 -0
- data/lib/dommy/internal/infra.rb +9 -0
- data/lib/dommy/internal/input_type.rb +76 -18
- data/lib/dommy/internal/insertion_point.rb +27 -3
- data/lib/dommy/internal/js_number.rb +60 -0
- data/lib/dommy/internal/light_dismiss.rb +178 -0
- data/lib/dommy/internal/mime_type.rb +8 -0
- data/lib/dommy/internal/mutation_coordinator.rb +94 -62
- data/lib/dommy/internal/node_adopter.rb +52 -4
- data/lib/dommy/internal/node_factory.rb +111 -7
- data/lib/dommy/internal/node_identity.rb +1 -1
- data/lib/dommy/internal/node_traversal.rb +22 -4
- data/lib/dommy/internal/node_wrapper_cache.rb +6 -38
- data/lib/dommy/internal/observer_options.rb +24 -14
- data/lib/dommy/internal/origin.rb +86 -0
- data/lib/dommy/internal/parent_node.rb +10 -8
- data/lib/dommy/internal/popover_invoker_element.rb +67 -0
- data/lib/dommy/internal/popover_stack.rb +120 -0
- data/lib/dommy/internal/post_insertion_steps.rb +140 -71
- data/lib/dommy/internal/reflected_attributes.rb +128 -18
- data/lib/dommy/internal/rendered_text/collector.rb +1 -5
- data/lib/dommy/internal/rendered_text/fragment.rb +6 -2
- data/lib/dommy/internal/selector_arguments.rb +2 -1
- data/lib/dommy/internal/selector_match.rb +1 -1
- data/lib/dommy/internal/selector_matcher.rb +11 -6
- data/lib/dommy/internal/selector_parser.rb +14 -1
- data/lib/dommy/internal/sequential_focus_navigation.rb +210 -0
- data/lib/dommy/internal/shadow_root_registry.rb +7 -0
- data/lib/dommy/internal/template_content_registry.rb +7 -1
- data/lib/dommy/internal/text_selection.rb +185 -32
- data/lib/dommy/internal/toggle_events.rb +6 -4
- data/lib/dommy/internal/unsafe_html.rb +107 -0
- data/lib/dommy/internal/url_parser.rb +84 -8
- data/lib/dommy/internal/user_activation.rb +192 -0
- data/lib/dommy/internal/web_idl.rb +149 -16
- data/lib/dommy/internal/window_constructors.rb +26 -6
- data/lib/dommy/internal/xml_serialization.rb +3 -3
- data/lib/dommy/js/constructor_resolver.rb +18 -0
- data/lib/dommy/js/custom_element_bridge.rb +57 -82
- data/lib/dommy/js/dom_interfaces.rb +50 -15
- data/lib/dommy/js/host_bridge.rb +189 -40
- data/lib/dommy/js/host_runtime.js +1897 -415
- data/lib/dommy/js/marshaller.rb +13 -4
- data/lib/dommy/js/module_loader.rb +37 -6
- data/lib/dommy/js/module_preload.rb +107 -29
- data/lib/dommy/js/script_boot.rb +197 -115
- data/lib/dommy/js/serialized_record.rb +32 -0
- data/lib/dommy/js/webidl_event_handlers.js +45 -0
- data/lib/dommy/js/webidl_members.js +196 -0
- data/lib/dommy/js/webidl_signatures.js +2055 -0
- data/lib/dommy/js/webidl_tables.js +47 -100
- data/lib/dommy/js/window_wiring.rb +9 -5
- data/lib/dommy/location.rb +129 -76
- data/lib/dommy/media_query_list.rb +4 -13
- data/lib/dommy/message_channel.rb +137 -64
- data/lib/dommy/mutation_observer.rb +2 -0
- data/lib/dommy/navigation.rb +59 -9
- data/lib/dommy/navigator.rb +131 -5
- data/lib/dommy/node.rb +19 -11
- data/lib/dommy/notification.rb +9 -1
- data/lib/dommy/promise.rb +8 -0
- data/lib/dommy/range.rb +5 -34
- data/lib/dommy/resources.rb +38 -3
- data/lib/dommy/scheduler.rb +176 -48
- data/lib/dommy/shadow_root.rb +117 -19
- data/lib/dommy/storage.rb +135 -25
- data/lib/dommy/structured_data.rb +45 -0
- data/lib/dommy/style_declaration.rb +16 -0
- data/lib/dommy/text_codec.rb +2 -14
- data/lib/dommy/tree_walker.rb +10 -18
- data/lib/dommy/url.rb +11 -4
- data/lib/dommy/validity_state.rb +109 -107
- data/lib/dommy/version.rb +1 -1
- data/lib/dommy/web_socket.rb +5 -28
- data/lib/dommy/window.rb +811 -99
- data/lib/dommy/worker.rb +4 -28
- data/lib/dommy/xml_http_request.rb +32 -45
- data/lib/dommy.rb +35 -1
- metadata +35 -4
- data/lib/dommy/internal/cookie_jar.rb +0 -29
data/lib/dommy/js/script_boot.rb
CHANGED
|
@@ -34,21 +34,32 @@ module Dommy
|
|
|
34
34
|
ScriptBooter.new(runtime, document, resources: resources, on_error: on_error, on_script: on_script).run
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
runtime.execute("__rbHost.wireInlineHandlers();")
|
|
37
|
+
# Activate the event handler content attributes the parser left on the
|
|
38
|
+
# document's elements (it runs no attribute change steps). Safe to
|
|
39
|
+
# replay: an attribute is activated once, and one whose handler was
|
|
40
|
+
# since set by script is left alone. Compilation itself is lazy (the
|
|
41
|
+
# handler's first read or event) and lives in host_runtime.js.
|
|
42
|
+
def wire_inline_handlers(_runtime = nil, document: nil, on_error: nil)
|
|
43
|
+
document&.__internal_activate_parsed_event_handlers__
|
|
45
44
|
rescue StandardError => e
|
|
46
45
|
on_error&.call(e)
|
|
47
46
|
end
|
|
48
47
|
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
48
|
+
# The module loader the document's boot installed, so a module script
|
|
49
|
+
# inserted later resolves its imports through the same import map and
|
|
50
|
+
# module map.
|
|
51
|
+
MODULE_LOADERS = ObjectSpace::WeakMap.new
|
|
52
|
+
|
|
53
|
+
def register_module_loader(document, loader)
|
|
54
|
+
MODULE_LOADERS[document] = loader
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def module_loader_for(document) = MODULE_LOADERS[document]
|
|
58
|
+
|
|
59
|
+
# Fetch + execute a single script that was dynamically inserted into an
|
|
60
|
+
# already-booted document (webpack/Vite on-demand chunk loading, or a
|
|
61
|
+
# `<script type=module>`), then fire its load / error event so the
|
|
62
|
+
# loader's promise settles.
|
|
52
63
|
def run_external_script(runtime, document, element, src, resources: nil, on_error: nil)
|
|
53
64
|
ScriptBooter.new(runtime, document, resources: resources, on_error: on_error).run_inserted_external(element, src)
|
|
54
65
|
end
|
|
@@ -70,26 +81,75 @@ module Dommy
|
|
|
70
81
|
@runtime.set_document_ready_state("loading")
|
|
71
82
|
@loader = install_module_loader
|
|
72
83
|
wire_inline_event_handlers
|
|
73
|
-
|
|
84
|
+
# The parser inserted the document's iframes: each gets its child
|
|
85
|
+
# navigable (a srcless one fires `load` now; one with a `src` starts
|
|
86
|
+
# navigating in a task, which comes before this document's `load`).
|
|
87
|
+
@document.__internal_process_parsed_iframes__ if @document.respond_to?(:__internal_process_parsed_iframes__)
|
|
88
|
+
# The parser's scripts, those in declarative shadow trees included.
|
|
89
|
+
scripts = @document.respond_to?(:__internal_parser_scripts__) ? @document.__internal_parser_scripts__ : @document.scripts.to_a
|
|
74
90
|
# Pass 1: parser-blocking classic scripts, in document order.
|
|
75
91
|
scripts.each { |element| run_one(element) unless deferred?(element) }
|
|
76
|
-
|
|
92
|
+
the_end(scripts)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# HTML §13.2.7 "The end": the document becomes "interactive", the
|
|
96
|
+
# deferred scripts (modules + classic `defer`) run in document order, and
|
|
97
|
+
# then DOMContentLoaded and — once nothing delays it — `load` fire from
|
|
98
|
+
# tasks of their own. Work the page queued before them (a timer, a
|
|
99
|
+
# history traversal, a frame's navigation) therefore runs first, as in a
|
|
100
|
+
# browser. Those tasks are run here, before boot returns, so a host that
|
|
101
|
+
# booted the page finds it loaded; a later timer stays pending.
|
|
102
|
+
def the_end(scripts)
|
|
103
|
+
# A runtime that only records the lifecycle (it left the document as
|
|
104
|
+
# it was) is replayed the transitions through the port, as before.
|
|
105
|
+
return replay_the_end(scripts) unless @document.__internal_ready_state__ == "loading"
|
|
106
|
+
|
|
107
|
+
@document.__internal_update_readiness__("interactive")
|
|
108
|
+
@runtime.drain_microtasks
|
|
109
|
+
scripts.each { |element| run_one(element) if deferred?(element) }
|
|
110
|
+
# The modules the page fetched, for the next page to read without a
|
|
111
|
+
# request, and as bytecode.
|
|
112
|
+
ModulePreload.register(@runtime, @loader.served)
|
|
113
|
+
scheduler = microtask_scheduler
|
|
114
|
+
unless scheduler
|
|
115
|
+
@document.__internal_fire_dom_content_loaded__
|
|
116
|
+
@document.__internal_finish_loading__
|
|
117
|
+
return
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
scheduler.set_timeout(proc { @document.__internal_fire_dom_content_loaded__ }, 0)
|
|
121
|
+
queue_load_task(scheduler)
|
|
122
|
+
scheduler.run_tasks_until { @document.__internal_completely_loaded__? }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def replay_the_end(scripts)
|
|
77
126
|
scripts.each { |element| run_one(element) if deferred?(element) }
|
|
78
|
-
# The modules the page fetched, for the next page of its origin to read
|
|
79
|
-
# as bytecode.
|
|
80
127
|
ModulePreload.register(@runtime, @loader.served)
|
|
81
128
|
@runtime.set_document_ready_state("interactive")
|
|
82
129
|
@runtime.set_document_ready_state("complete")
|
|
83
130
|
end
|
|
84
131
|
|
|
132
|
+
# The load task, queued once nothing delays the load event: while a
|
|
133
|
+
# child navigable is still navigating, wait behind its task.
|
|
134
|
+
def queue_load_task(scheduler)
|
|
135
|
+
scheduler.set_timeout(proc do
|
|
136
|
+
if @document.__internal_load_delayed__?
|
|
137
|
+
queue_load_task(scheduler)
|
|
138
|
+
else
|
|
139
|
+
@document.__internal_finish_loading__
|
|
140
|
+
end
|
|
141
|
+
end, 0)
|
|
142
|
+
end
|
|
143
|
+
|
|
85
144
|
def wire_inline_event_handlers
|
|
86
|
-
ScriptBoot.wire_inline_handlers(@runtime, on_error: @on_error)
|
|
145
|
+
ScriptBoot.wire_inline_handlers(@runtime, document: @document, on_error: @on_error)
|
|
87
146
|
end
|
|
88
147
|
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
148
|
+
# Run a script that was not parser-inserted once its turn comes: an
|
|
149
|
+
# external classic script (its fetch, then execution, then `load` — or
|
|
150
|
+
# `error` when the fetch failed), or a module script, inline or external.
|
|
151
|
+
# The element was already prepared by the post-connection steps, which
|
|
152
|
+
# kept what to run on it; `src` is the URL they resolved.
|
|
93
153
|
#
|
|
94
154
|
# `error` means the FETCH failed — that is the only thing the element's
|
|
95
155
|
# event reports. A script that downloaded fine and then threw still fires
|
|
@@ -98,21 +158,13 @@ module Dommy
|
|
|
98
158
|
# that the network failed, so it retries or gives up on a chunk that is
|
|
99
159
|
# sitting right there.
|
|
100
160
|
def run_inserted_external(element, src)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
begin
|
|
106
|
-
with_current_script(element) { @runtime.load_script_cached(response.body, cache_key: url) }
|
|
107
|
-
rescue StandardError => e
|
|
108
|
-
report_exception(e)
|
|
161
|
+
prepared = element.__internal_prepared_script__ if element.respond_to?(:__internal_prepared_script__)
|
|
162
|
+
if prepared&.type == :module
|
|
163
|
+
@loader = ScriptBoot.module_loader_for(@document) || install_module_loader
|
|
164
|
+
return run_module(element, prepared)
|
|
109
165
|
end
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
# The fetch itself blew up (a resources adapter raising, not a page
|
|
113
|
-
# exception): nothing loaded, so the element reports a failure.
|
|
114
|
-
report_exception(e)
|
|
115
|
-
dispatch_script_event(element, "error")
|
|
166
|
+
|
|
167
|
+
run_classic_external(element, src)
|
|
116
168
|
end
|
|
117
169
|
|
|
118
170
|
private
|
|
@@ -163,27 +215,20 @@ module Dommy
|
|
|
163
215
|
@runtime.rebuild_error(error)
|
|
164
216
|
end
|
|
165
217
|
|
|
166
|
-
# Fire the script's load/error event
|
|
167
|
-
#
|
|
168
|
-
# (
|
|
169
|
-
#
|
|
170
|
-
#
|
|
171
|
-
#
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
fire = proc do
|
|
181
|
-
element.dispatch_event(Dommy::Event.new(type))
|
|
182
|
-
rescue StandardError => e
|
|
183
|
-
@on_error&.call(e)
|
|
184
|
-
end
|
|
185
|
-
scheduler = microtask_scheduler
|
|
186
|
-
scheduler ? scheduler.queue_microtask(fire) : fire.call
|
|
218
|
+
# Fire the script's `load` / `error` event — a trusted event, fired
|
|
219
|
+
# synchronously as "execute the script element" does once the script ran
|
|
220
|
+
# (or failed to load). A dynamically inserted script is already run from
|
|
221
|
+
# a later microtask or task, so `head.appendChild(s); s.onload = …` has
|
|
222
|
+
# attached its handler by now. A listener that throws is reported by the
|
|
223
|
+
# dispatch itself; what the rescue covers is the dispatch failing outright.
|
|
224
|
+
def fire_script_event(element, type)
|
|
225
|
+
return nil unless element.respond_to?(:__internal_fire_event__)
|
|
226
|
+
|
|
227
|
+
element.__internal_fire_event__(type)
|
|
228
|
+
nil
|
|
229
|
+
rescue StandardError => e
|
|
230
|
+
@on_error&.call(e)
|
|
231
|
+
nil
|
|
187
232
|
end
|
|
188
233
|
|
|
189
234
|
# Whether the element runs in the deferred pass rather than at its parse
|
|
@@ -194,10 +239,10 @@ module Dommy
|
|
|
194
239
|
def deferred?(element)
|
|
195
240
|
return false if element.async
|
|
196
241
|
|
|
197
|
-
|
|
242
|
+
type = element.__internal_script_type__
|
|
243
|
+
type == :module || (type == :classic && external?(element) && element.defer)
|
|
198
244
|
end
|
|
199
245
|
|
|
200
|
-
def module_script?(element) = element.type.to_s.strip.downcase == "module"
|
|
201
246
|
# "If el has a src attribute" — the CONTENT attribute, not the IDL one. The
|
|
202
247
|
# IDL `src` is a URL reflection, so `src=""` reads back as the document's
|
|
203
248
|
# own address rather than as the empty string, and an empty src is the one
|
|
@@ -210,41 +255,92 @@ module Dommy
|
|
|
210
255
|
# modules can be seeded under a document URL.
|
|
211
256
|
def install_module_loader
|
|
212
257
|
loader = ModuleLoader.new(@resources, parse_import_map, base_url: document_base,
|
|
213
|
-
preloaded: ModulePreload.preloaded(@runtime)
|
|
258
|
+
preloaded: ModulePreload.preloaded(@runtime),
|
|
259
|
+
kept: ModulePreload.method(:source))
|
|
214
260
|
# The engine requires a Proc specifically.
|
|
215
261
|
@runtime.module_loader = ->(specifier, importer) { loader.call(specifier, importer) }
|
|
262
|
+
ScriptBoot.register_module_loader(@document, loader)
|
|
216
263
|
loader
|
|
217
264
|
end
|
|
218
265
|
|
|
219
266
|
def parse_import_map
|
|
220
|
-
el = @document.scripts.find { |s| s.
|
|
267
|
+
el = @document.scripts.find { |s| s.__internal_script_type__ == :importmap }
|
|
221
268
|
ImportMap.parse(el ? el.text : "")
|
|
222
269
|
end
|
|
223
270
|
|
|
224
|
-
#
|
|
225
|
-
#
|
|
226
|
-
#
|
|
227
|
-
#
|
|
271
|
+
# Prepare one parser-inserted <script> element and execute what it
|
|
272
|
+
# prepared to, notifying `on_script` (element, error) when a classic or
|
|
273
|
+
# module script ran — success with nil, failure with the raised error
|
|
274
|
+
# (alongside the report at the window). A script that prepared to nothing
|
|
275
|
+
# (empty, an unknown type, `nomodule`, already started) is not reported.
|
|
228
276
|
def run_one(element)
|
|
229
|
-
|
|
277
|
+
prepared = element.__internal_prepare_script__
|
|
278
|
+
return unless prepared && %i[classic module].include?(prepared.type)
|
|
279
|
+
|
|
280
|
+
error =
|
|
281
|
+
if prepared.type == :module
|
|
282
|
+
run_module(element, prepared)
|
|
283
|
+
elsif prepared.external
|
|
284
|
+
run_classic_external(element, prepared.url)
|
|
285
|
+
else
|
|
286
|
+
execute_classic(element) { @runtime.load_script(prepared.source) }
|
|
287
|
+
end
|
|
288
|
+
@on_script&.call(element, error)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
# HTML "execute the script element" for a classic script: currentScript
|
|
292
|
+
# is the element while it runs, and back to its old value afterwards; a
|
|
293
|
+
# throw is reported at the window from inside that window (the report is
|
|
294
|
+
# part of running the script), then a microtask checkpoint runs before
|
|
295
|
+
# the next script, as "clean up after running script" does. Returns the
|
|
296
|
+
# error, if any.
|
|
297
|
+
def execute_classic(element)
|
|
298
|
+
error = nil
|
|
299
|
+
@document.__internal_with_current_script__(element) do
|
|
300
|
+
yield
|
|
301
|
+
rescue StandardError => e
|
|
302
|
+
error = e
|
|
303
|
+
report_exception(e)
|
|
304
|
+
checkpoint
|
|
305
|
+
end
|
|
306
|
+
error
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# A microtask checkpoint, for the paths where the engine did not run one
|
|
310
|
+
# (a throwing script unwinds past its own).
|
|
311
|
+
def checkpoint
|
|
312
|
+
@runtime.drain_microtasks
|
|
230
313
|
rescue StandardError => e
|
|
231
|
-
|
|
232
|
-
@on_script&.call(element, e)
|
|
314
|
+
@on_error&.call(e)
|
|
233
315
|
end
|
|
234
316
|
|
|
235
|
-
#
|
|
236
|
-
#
|
|
237
|
-
def
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
317
|
+
# Fetch an external classic script, run it, then fire `load` at the
|
|
318
|
+
# element; a failed fetch fires `error` instead and runs nothing.
|
|
319
|
+
def run_classic_external(element, url)
|
|
320
|
+
body = fetch(url)
|
|
321
|
+
return fire_script_event(element, "error") unless body
|
|
322
|
+
|
|
323
|
+
# Cache the compiled bytecode by URL: vendored bundles re-parse on
|
|
324
|
+
# every fresh VM otherwise.
|
|
325
|
+
error = execute_classic(element) { @runtime.load_script_cached(body, cache_key: url) }
|
|
326
|
+
fire_script_event(element, "load")
|
|
327
|
+
error
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
# The body of a successful fetch of `url`, or nil. A resources adapter
|
|
331
|
+
# that raises is a failed fetch too (reported to the host, not the page).
|
|
332
|
+
def fetch(url)
|
|
333
|
+
# A `data:` URL is fetched by its scheme, not over the network.
|
|
334
|
+
if (decoded = Dommy::DataUri.parse(url))
|
|
335
|
+
return decoded[:body]
|
|
246
336
|
end
|
|
247
|
-
|
|
337
|
+
return nil unless @resources && url
|
|
338
|
+
|
|
339
|
+
response = @resources.get(url)
|
|
340
|
+
response.body if response&.success?
|
|
341
|
+
rescue StandardError => e
|
|
342
|
+
@on_error&.call(e)
|
|
343
|
+
nil
|
|
248
344
|
end
|
|
249
345
|
|
|
250
346
|
# An ES module script. `currentScript` is null for modules (spec), so it
|
|
@@ -253,19 +349,34 @@ module Dommy
|
|
|
253
349
|
# `import.meta.url`: the engine derives import.meta.url from the module's
|
|
254
350
|
# unique cache key, which carries a `#dommy-inline-N` fragment for a
|
|
255
351
|
# second inline module, so we set `import.meta.url` (writable) to the
|
|
256
|
-
# clean page URL up front. An external module loads by its own URL
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
352
|
+
# clean page URL up front. An external module loads by its own URL, and
|
|
353
|
+
# fires `load` after it ran — or `error`, running nothing, when its own
|
|
354
|
+
# fetch failed. Returns the error the evaluation raised, if any.
|
|
355
|
+
def run_module(element, prepared)
|
|
356
|
+
if prepared.external
|
|
357
|
+
url = prepared.url
|
|
358
|
+
return fire_script_event(element, "error") unless @loader.prefetch(url)
|
|
359
|
+
|
|
360
|
+
error = evaluate_module { @runtime.load_module_url(url) }
|
|
361
|
+
fire_script_event(element, "load")
|
|
362
|
+
error
|
|
363
|
+
else
|
|
260
364
|
base = inline_base
|
|
261
365
|
# No newline, so the original body's line numbers are preserved.
|
|
262
|
-
body = "import.meta.url = #{base.to_json}; #{
|
|
263
|
-
@runtime.load_module_url(@loader.seed_inline(base, body))
|
|
264
|
-
elsif (url = resolve_url(value))
|
|
265
|
-
@runtime.load_module_url(url)
|
|
366
|
+
body = "import.meta.url = #{base.to_json}; #{prepared.source}"
|
|
367
|
+
evaluate_module { @runtime.load_module_url(@loader.seed_inline(base, body)) }
|
|
266
368
|
end
|
|
267
369
|
end
|
|
268
370
|
|
|
371
|
+
def evaluate_module
|
|
372
|
+
yield
|
|
373
|
+
nil
|
|
374
|
+
rescue StandardError => e
|
|
375
|
+
report_exception(e)
|
|
376
|
+
checkpoint
|
|
377
|
+
e
|
|
378
|
+
end
|
|
379
|
+
|
|
269
380
|
# The page URL an inline module is identified by (its import.meta.url and
|
|
270
381
|
# the base for its relative imports).
|
|
271
382
|
def inline_base
|
|
@@ -273,28 +384,6 @@ module Dommy
|
|
|
273
384
|
base.empty? ? "about:blank" : base
|
|
274
385
|
end
|
|
275
386
|
|
|
276
|
-
def run_external(element, src)
|
|
277
|
-
return unless @resources
|
|
278
|
-
|
|
279
|
-
url = resolve_url(src)
|
|
280
|
-
return unless url
|
|
281
|
-
|
|
282
|
-
response = @resources.get(url)
|
|
283
|
-
return unless response&.success?
|
|
284
|
-
|
|
285
|
-
# Cache the compiled bytecode by URL: vendored bundles re-parse on
|
|
286
|
-
# every fresh VM otherwise.
|
|
287
|
-
with_current_script(element) { @runtime.load_script_cached(response.body, cache_key: url) }
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
# Resolve a script's `src` against the document's base URL, which is the
|
|
291
|
-
# realm's own location (correct for frames too).
|
|
292
|
-
def resolve_url(src)
|
|
293
|
-
::URI.join(document_base, src).to_s
|
|
294
|
-
rescue ::URI::InvalidURIError
|
|
295
|
-
nil
|
|
296
|
-
end
|
|
297
|
-
|
|
298
387
|
# The document's effective base URL string: its `<base>`-derived base
|
|
299
388
|
# URI, falling back to the realm's own location. Empty string when
|
|
300
389
|
# neither is set (callers decide their own fallback).
|
|
@@ -303,13 +392,6 @@ module Dommy
|
|
|
303
392
|
base = @document.url if base.to_s.empty?
|
|
304
393
|
base.to_s
|
|
305
394
|
end
|
|
306
|
-
|
|
307
|
-
def with_current_script(element)
|
|
308
|
-
@document.__internal_set_current_script__(element)
|
|
309
|
-
yield
|
|
310
|
-
ensure
|
|
311
|
-
@document.__internal_set_current_script__(nil)
|
|
312
|
-
end
|
|
313
395
|
end
|
|
314
396
|
end
|
|
315
397
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dommy
|
|
4
|
+
module Js
|
|
5
|
+
# A message the JS realm serialized (host_runtime.js
|
|
6
|
+
# structuredSerializeWithTransfer), referenced by its id there. The record
|
|
7
|
+
# itself — cycles, BigInts, lone surrogates, a transferred ArrayBuffer — only
|
|
8
|
+
# makes sense in the realm, so deserializing asks the realm to do it.
|
|
9
|
+
class SerializedRecord < Dommy::SerializedValue
|
|
10
|
+
attr_reader :id
|
|
11
|
+
|
|
12
|
+
def initialize(bridge, id)
|
|
13
|
+
super()
|
|
14
|
+
@bridge = bridge
|
|
15
|
+
@id = id
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def deserialize_with_transfer
|
|
19
|
+
result = @bridge.deserialize_record(@id)
|
|
20
|
+
raise DOMException::DataCloneError, result["error"].to_s if result.key?("error")
|
|
21
|
+
|
|
22
|
+
[result["value"], Array(result["ports"])]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Forget the record JS-side, once nothing will deserialize it again.
|
|
26
|
+
def release
|
|
27
|
+
@bridge.release_record(@id)
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// GENERATED by script/build_event_handlers.rb from
|
|
2
|
+
// test/fixtures/webidl/interfaces.json (web-platform-tests 863077959ca8c1a7ceecfbe2534b75d2527b9013).
|
|
3
|
+
// Do not edit by hand: re-run the script (`rake webidl:event_handlers`).
|
|
4
|
+
//
|
|
5
|
+
// The event handler IDL attributes (HTML §8.1.8.1: attributes of type
|
|
6
|
+
// EventHandler, OnErrorEventHandler or OnBeforeUnloadEventHandler) each
|
|
7
|
+
// interface declares itself, its mixins' included. A name is an event
|
|
8
|
+
// handler on an object when an interface in its chain declares it, which
|
|
9
|
+
// is what host_runtime.js looks up (eventHandlersOf).
|
|
10
|
+
globalThis.__rbIdlEventHandlers = {
|
|
11
|
+
"AbortSignal": ["onabort"],
|
|
12
|
+
"AudioTrackList": ["onaddtrack","onchange","onremovetrack"],
|
|
13
|
+
"BroadcastChannel": ["onmessage","onmessageerror"],
|
|
14
|
+
"CloseWatcher": ["oncancel","onclose"],
|
|
15
|
+
"DedicatedWorkerGlobalScope": ["onmessage","onmessageerror"],
|
|
16
|
+
"Document": ["onabort","onanimationcancel","onanimationend","onanimationiteration","onanimationstart","onauxclick","onbeforeinput","onbeforematch","onbeforetoggle","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncommand","oncontextlost","oncontextmenu","oncontextrestored","oncopy","oncuechange","oncut","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","onfullscreenchange","onfullscreenerror","ongotpointercapture","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onlostpointercapture","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onpaste","onpause","onplay","onplaying","onpointercancel","onpointerdown","onpointerenter","onpointerleave","onpointermove","onpointerout","onpointerover","onpointerrawupdate","onpointerup","onprogress","onratechange","onreadystatechange","onreset","onresize","onscroll","onscrollend","onsecuritypolicyviolation","onseeked","onseeking","onselect","onselectionchange","onselectstart","onslotchange","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","ontransitioncancel","ontransitionend","ontransitionrun","ontransitionstart","onvisibilitychange","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel"],
|
|
17
|
+
"Element": ["onfullscreenchange","onfullscreenerror"],
|
|
18
|
+
"EventSource": ["onerror","onmessage","onopen"],
|
|
19
|
+
"FileReader": ["onabort","onerror","onload","onloadend","onloadstart","onprogress"],
|
|
20
|
+
"HTMLBodyElement": ["onafterprint","onbeforeprint","onbeforeunload","onhashchange","onlanguagechange","onmessage","onmessageerror","onoffline","ononline","onpagehide","onpagereveal","onpageshow","onpageswap","onpopstate","onrejectionhandled","onstorage","onunhandledrejection","onunload"],
|
|
21
|
+
"HTMLElement": ["onabort","onanimationcancel","onanimationend","onanimationiteration","onanimationstart","onauxclick","onbeforeinput","onbeforematch","onbeforetoggle","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncommand","oncontextlost","oncontextmenu","oncontextrestored","oncopy","oncuechange","oncut","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","ongotpointercapture","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onlostpointercapture","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onpaste","onpause","onplay","onplaying","onpointercancel","onpointerdown","onpointerenter","onpointerleave","onpointermove","onpointerout","onpointerover","onpointerrawupdate","onpointerup","onprogress","onratechange","onreset","onresize","onscroll","onscrollend","onsecuritypolicyviolation","onseeked","onseeking","onselect","onselectionchange","onselectstart","onslotchange","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","ontransitioncancel","ontransitionend","ontransitionrun","ontransitionstart","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel"],
|
|
22
|
+
"HTMLFrameSetElement": ["onafterprint","onbeforeprint","onbeforeunload","onhashchange","onlanguagechange","onmessage","onmessageerror","onoffline","ononline","onpagehide","onpagereveal","onpageshow","onpageswap","onpopstate","onrejectionhandled","onstorage","onunhandledrejection","onunload"],
|
|
23
|
+
"MathMLElement": ["onabort","onanimationcancel","onanimationend","onanimationiteration","onanimationstart","onauxclick","onbeforeinput","onbeforematch","onbeforetoggle","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncommand","oncontextlost","oncontextmenu","oncontextrestored","oncopy","oncuechange","oncut","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","ongotpointercapture","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onlostpointercapture","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onpaste","onpause","onplay","onplaying","onpointercancel","onpointerdown","onpointerenter","onpointerleave","onpointermove","onpointerout","onpointerover","onpointerrawupdate","onpointerup","onprogress","onratechange","onreset","onresize","onscroll","onscrollend","onsecuritypolicyviolation","onseeked","onseeking","onselect","onselectionchange","onselectstart","onslotchange","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","ontransitioncancel","ontransitionend","ontransitionrun","ontransitionstart","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel"],
|
|
24
|
+
"MediaQueryList": ["onchange"],
|
|
25
|
+
"MessagePort": ["onclose","onmessage","onmessageerror"],
|
|
26
|
+
"Navigation": ["oncurrententrychange","onnavigate","onnavigateerror","onnavigatesuccess"],
|
|
27
|
+
"NavigationHistoryEntry": ["ondispose"],
|
|
28
|
+
"Notification": ["onclick","onclose","onerror","onshow"],
|
|
29
|
+
"OffscreenCanvas": ["oncontextlost","oncontextrestored"],
|
|
30
|
+
"SVGElement": ["onabort","onanimationcancel","onanimationend","onanimationiteration","onanimationstart","onauxclick","onbeforeinput","onbeforematch","onbeforetoggle","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncommand","oncontextlost","oncontextmenu","oncontextrestored","oncopy","oncuechange","oncut","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","ongotpointercapture","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onlostpointercapture","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onpaste","onpause","onplay","onplaying","onpointercancel","onpointerdown","onpointerenter","onpointerleave","onpointermove","onpointerout","onpointerover","onpointerrawupdate","onpointerup","onprogress","onratechange","onreset","onresize","onscroll","onscrollend","onsecuritypolicyviolation","onseeked","onseeking","onselect","onselectionchange","onselectstart","onslotchange","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","ontransitioncancel","ontransitionend","ontransitionrun","ontransitionstart","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel"],
|
|
31
|
+
"ShadowRoot": ["onslotchange"],
|
|
32
|
+
"SharedWorker": ["onerror"],
|
|
33
|
+
"SharedWorkerGlobalScope": ["onconnect"],
|
|
34
|
+
"TextTrack": ["oncuechange"],
|
|
35
|
+
"TextTrackCue": ["onenter","onexit"],
|
|
36
|
+
"TextTrackList": ["onaddtrack","onchange","onremovetrack"],
|
|
37
|
+
"VideoTrackList": ["onaddtrack","onchange","onremovetrack"],
|
|
38
|
+
"VisualViewport": ["onresize","onscroll","onscrollend"],
|
|
39
|
+
"WebSocket": ["onclose","onerror","onmessage","onopen"],
|
|
40
|
+
"Window": ["onabort","onafterprint","onanimationcancel","onanimationend","onanimationiteration","onanimationstart","onauxclick","onbeforeinput","onbeforematch","onbeforeprint","onbeforetoggle","onbeforeunload","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncommand","oncontextlost","oncontextmenu","oncontextrestored","oncopy","oncuechange","oncut","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","ongotpointercapture","onhashchange","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onlanguagechange","onload","onloadeddata","onloadedmetadata","onloadstart","onlostpointercapture","onmessage","onmessageerror","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onoffline","ononline","onpagehide","onpagereveal","onpageshow","onpageswap","onpaste","onpause","onplay","onplaying","onpointercancel","onpointerdown","onpointerenter","onpointerleave","onpointermove","onpointerout","onpointerover","onpointerrawupdate","onpointerup","onpopstate","onprogress","onratechange","onrejectionhandled","onreset","onresize","onscroll","onscrollend","onsecuritypolicyviolation","onseeked","onseeking","onselect","onselectionchange","onselectstart","onslotchange","onstalled","onstorage","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","ontransitioncancel","ontransitionend","ontransitionrun","ontransitionstart","onunhandledrejection","onunload","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel"],
|
|
41
|
+
"Worker": ["onerror","onmessage","onmessageerror"],
|
|
42
|
+
"WorkerGlobalScope": ["onerror","onlanguagechange","onoffline","ononline","onrejectionhandled","onunhandledrejection"],
|
|
43
|
+
"XMLHttpRequest": ["onreadystatechange"],
|
|
44
|
+
"XMLHttpRequestEventTarget": ["onabort","onerror","onload","onloadend","onloadstart","onprogress","ontimeout"]
|
|
45
|
+
};
|