Web Workers API support in Opera Presto 2.7
- W3C reference:
- W3C Web Workers API
- Opera article
- Web Workers rise up!
Opera Presto offers support for Web Workers, an API for running scripts
in the background independently of any user interface scripts. This allows for long-running scripts that are not interrupted
by scripts that respond to clicks or other user interactions, and allows long tasks to be executed without yielding to keep
the page responsive. See this demo
Infrastructure
► Workers
There are two kinds of workers; dedicated workers, and shared workers.
- Dedicated workers
- Once created, they are linked to their creator. Message ports can be used to communicate from a dedicated worker to multiple other browsing contexts or workers.
- Shared workers
- Are named, and once created, any script running in the same origin can obtain a reference to that worker and communicate with it.
► Global scope
The global scope is the "inside" of a worker.
Interface support
► WorkerGlobalScope abstract interface
|
Interface
|
Attributes
|
Description
|
Support
|
WorkerGlobalScope
|
self
|
- This attribute must return the
WorkerGlobalScope object itself.
|
Yes
|
location
|
- This attribute must return the
WorkerLocation object created for the WorkerGlobalScope object
when the worker was created.
- It represents the absolute URL of the script that was used to initialize the worker, after any redirects.
|
Yes
|
|
Method
|
Attributes
|
Description
|
Support
|
initErrorEvent()
|
message
|
This attribute represents the error message.
|
Yes
|
filename
|
This attribute represents the absolute URL of the script in which the error originally occurred.
|
Yes
|
lineno
|
This attribute represents the line number where the error occurred in the script.
|
Yes
|
|
Event handler
|
Event handler event type
|
Support
|
onerror
|
error
|
Yes
|
► DedicatedWorkerGlobalScope interface
|
Interface
|
Method
|
Description
|
Support
|
DedicatedWorkerGlobalScope
|
postMessage()
|
This method must act as if, when invoked, it immediately invoked the method of the same
name on the port, with the same arguments,
and returned the same return value.
|
Yes
|
|
Event handler
|
Event handler event type
|
Support
|
onmessage
|
message
|
Yes
|
► SharedWorkerGlobalScope interface
|
Interface
|
Attribute
|
Description
|
Support
|
SharedWorkerGlobalScope
|
name
|
- This attribute must return the value it was assigned when the
SharedWorkerGlobalScope object was created by the "run a worker" algorithm.
- Its value represents the name that can be used to obtain a reference to the worker using the
SharedWorker constructor.
|
Yes
|
|
Event handler
|
Event handler event type
|
Support
|
onconnect
|
connect
|
Yes
|
► AbstractWorker abstract interface
|
Event handler
|
Event handler event type
|
Support
|
onerror
|
error
|
Yes
|
► Worker interface
|
Interface
|
Methods
|
Description
|
Support
|
Worker
|
terminate()
|
This method, when invoked, must cause the "terminate a worker" algorithm to be run on the worker with the object that is associated.
|
Yes
|
postMessage()
|
This method on Worker objects must act as if, when invoked, it immediately invoked the method of the same name on the port, with the same arguments, and returned the same return value.
|
Yes
|
|
Event handler
|
Event handler event type
|
Support
|
onmessage
|
message
|
Yes
|
► SharedWorker interface
|
Interface
|
Attribute
|
Description
|
Support
|
SharedWorker
|
port
|
- This attribute must return the value it was assigned by the object's constructor.
- It represents the
MessagePort for communicating with the shared worker.
|
Yes
|
APIs available to workers
► WorkerUtils interface
|
Interface
|
Attribute
|
Description
|
Support
|
WorkerUtils
|
WorkerNavigator |
This attribute represents the identity and state of the user agent (the client). |
Yes |
navigator |
Ths attribute returns an instance of the WorkerNavigator interface. |
Yes |