forked from aosabook/500lines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostmessage.als
More file actions
33 lines (29 loc) · 886 Bytes
/
Copy pathpostmessage.als
File metadata and controls
33 lines (29 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* postmessage.als
* A model of the HTML5 PostMessage mechanism intended for cross-domain
* communication between scripts
*/
module postMessage
open origin
open script
// Browser API function for cross-document messaging
// used to send a message from one script to another
sig PostMessage extends BrowserOp {
message: Resource,
targetOrigin: Origin
}{
noDocumentChange[start, end]
}
sig ReceiveMessage extends EventHandler {
data: Resource,
srcOrigin: Origin
}{
causedBy in PostMessage
-- "ReceiveMessage" event is sent to the script with the correct context
origin[to.context.src] = causedBy.targetOrigin
-- messages match
data = causedBy.@message
-- the origin of the sender script is provided as "srcOrigin" param
srcOrigin = origin[[email protected]]
}
run { some m: ReceiveMessage | m.srcOrigin != m.causedBy.targetOrigin }