forked from aosabook/500lines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonp.als
More file actions
39 lines (33 loc) · 995 Bytes
/
Copy pathjsonp.als
File metadata and controls
39 lines (33 loc) · 995 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
34
35
36
37
38
39
/**
* jsonp.als
* A model of the JSONP mechanism for cross-domain communication from a
* script and a server
*/
module jsonp
open script
abstract sig Callback {} // identifier of a callback function
// Request sent as a result of <script> tag
sig JsonpRequest in BrowserHttpRequest { padding: Callback }{
response in JsonpResponse
}
// A JsonpResponse is a piece of Javascript
sig JsonpResponse in Resource {
cb: Callback,
payload: Resource
}{
payload != this
}
fact { all r: JsonpResponse | some req: JsonpRequest | req.response = r }
// Callback function called when the JSONP request completes
sig ExecCallback extends EventHandler {
cb: Callback,
payload: Resource
}{
causedBy in JsonpRequest
to.context = causedBy.(BrowserHttpRequest <: doc)
let resp = causedBy.response |
cb = resp.@cb and
-- result of JSONP request is passed on as an argument to the callback
payload = resp.@payload
}
run { some cb: ExecCallback | some cb.payload }