Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/validation/worker-options-load-policy-701-81-227.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Worker options and script-load policy (#701, #81, #227)

## Implemented boundary

Dedicated workers now convert the first `WorkerOptions` dictionary members for
`type`, `credentials`, and `name`. The defaults are `classic`, `same-origin`,
and the empty string. Invalid worker types, invalid credential modes, and
non-dictionary option values throw `TypeError` before a worker slot is
reserved.

The selected credential mode is retained by the worker realm and applied to
the entry script, classic `importScripts()` loads, static module dependencies,
and dynamic module imports. Classic entry and dependency loads remain
same-origin. Module dependency loads use CORS and require an admitted HTTP
response to carry a matching `Access-Control-Allow-Origin`; credentialed
cross-origin loads additionally require
`Access-Control-Allow-Credentials: true`. Wildcard origins are rejected with
`include` credentials.

The resource request carries the creator origin, final request base, script
destination, fetch mode, and credential mode to the existing host loader.
Unsuccessful HTTP status, a cross-origin classic redirect, or a missing CORS
admission fails closed. A successful redirect becomes the worker location and
the base for relative classic or module dependencies.

## Failure and lifecycle contract

Worker construction stays asynchronous after synchronous URL and option
conversion. Each worker captures a generation before its thread starts.
Termination, worker-side `close()`, navigation, and engine teardown advance
that generation and clear queued messages. Resource completion and worker
wakeups check the captured generation before publishing cookies, compiling a
script, dispatching an error, or running queued work.

A startup network, status, redirect, CORS, syntax, or module-resolution failure
uses one terminal transition. That transition publishes at most one bounded
error to the owning realm, clears queued messages, marks the worker stopped,
and makes its live execution slot reusable. Later completion or exception
paths cannot publish a second terminal error.

The existing limits remain unchanged: at most 64 live dedicated workers, 256
retained stopped wrappers, 256 messages and 16 MiB in either queue, and 16
bounded error strings per worker.

## Deferred acceptance

Per the implementation-first policy for #701, no build, native suite, browser
comparison, WPT run, package run, cross-platform CI, throughput, or heap/RSS
measurement was executed for this change. Those gates remain acceptance work
under #81 and #227. MessagePort reachability remains owned by #288, and general
nested-document navigation and security remain owned by #267.

The host resource API exposes the final response rather than each intermediate
redirect response. It receives the worker fetch mode, origin, and credentials
and therefore remains responsible for enforcing every redirect hop; the worker
runtime independently validates the returned final URL and response. A future
resource-contract revision would be needed for engine-side, per-hop CORS audit.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
v8::Global<v8::Module> module;
};
std::vector<module_entry> module_map;
bool worker_script_fetch_policy_active{false};
std::string worker_script_fetch_origin;
uint32_t worker_script_fetch_credentials{
WEBSCENE_FETCH_CREDENTIALS_SAME_ORIGIN};

std::string module_url(v8::Local<v8::Module> module) {
for (auto& entry : module_map)
Expand Down Expand Up @@ -56,18 +60,36 @@
if (entry.url == url && entry.realm.Get(isolate) == realm)
return entry.module.Get(isolate);
std::string source, resolved;
const resource_request_context request_context{
WEBSCENE_RESOURCE_INITIATOR_SUBRESOURCE,
current_security_origin(),
base.empty() ? current_base_address() : base,
WEBSCENE_FETCH_MODE_CORS,
WEBSCENE_REQUEST_DESTINATION_SCRIPT,
"GET", {}, {}, WEBSCENE_FETCH_CREDENTIALS_SAME_ORIGIN, {}};
if (!load_text_resource(
url, {}, WEBSCENE_RESOURCE_SCRIPT, source, resolved,
nullptr, request_context)) {
std::string load_error;
const auto loaded = worker_script_fetch_policy_active
? load_worker_script_resource(
url,
base.empty() ? current_base_address() : base,
WEBSCENE_FETCH_MODE_CORS,
source,
resolved,
load_error)
: load_text_resource(
url,
{},
WEBSCENE_RESOURCE_SCRIPT,
source,
resolved,
nullptr,
resource_request_context{
WEBSCENE_RESOURCE_INITIATOR_SUBRESOURCE,
current_security_origin(),
base.empty() ? current_base_address() : base,
WEBSCENE_FETCH_MODE_CORS,
WEBSCENE_REQUEST_DESTINATION_SCRIPT,
"GET",
{},
{},
WEBSCENE_FETCH_CREDENTIALS_SAME_ORIGIN,
{}});
if (!loaded) {
isolate->ThrowException(v8::Exception::TypeError(js_dom_string(isolate,
"Unable to load module: " + url)));
load_error.empty() ? "Unable to load module: " + url : load_error)));
return {};
}
return compile_module(realm, source, resolved);
Expand Down
Loading
Loading