This repository was archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathruntime.js
More file actions
117 lines (113 loc) · 3.43 KB
/
runtime.js
File metadata and controls
117 lines (113 loc) · 3.43 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const { Request, Response, fetch, Headers, freezeHeaders, bindCfProperty } = require('./runtime/fetch')
const { URL, URLSearchParams } = require('./runtime/url')
const { ReadableStream, WritableStream, TransformStream } = require('./runtime/stream')
const { FetchEvent } = require('./runtime/fetch-event')
const { crypto } = require('./runtime/crypto')
const { TextDecoder, TextEncoder } = require('./runtime/text-encoder')
const { atob, btoa } = require('./runtime/base64')
class Context {
constructor (addEventListener, cacheFactory, bindings = {}) {
this.setTimeout = setTimeout
this.clearTimeout = clearTimeout
this.setInterval = setInterval
this.clearInterval = clearInterval
this.addEventListener = addEventListener
this.fetch = fetch
this.Request = Request
this.Response = Response
this.Headers = Headers
this.URL = URL
this.URLSearchParams = URLSearchParams
this.ReadableStream = ReadableStream
this.WritableStream = WritableStream
this.TransformStream = TransformStream
this.FetchEvent = FetchEvent
this.caches = cacheFactory
this.crypto = crypto
this.TextDecoder = TextDecoder
this.TextEncoder = TextEncoder
this.atob = atob
this.btoa = btoa
// These are necessary to use "instanceof" within a vm accross different realms
if (!bindings.VM_DEFAULT_REALM) {
this.Array = Array
this.ArrayBuffer = ArrayBuffer
this.Atomics = Atomics
this.BigInt = BigInt
this.BigInt64Array = BigInt64Array
this.BigUint64Array = BigUint64Array
this.Boolean = Boolean
this.DataView = DataView
this.Date = Date
this.Error = Error
this.EvalError = EvalError
this.Float32Array = Float32Array
this.Float64Array = Float64Array
this.Function = Function
this.Int8Array = Int8Array
this.Int16Array = Int16Array
this.Int32Array = Int32Array
this.Intl = Intl
this.JSON = JSON
this.Map = Map
this.Math = Math
this.NaN = NaN
this.Number = Number
this.Object = Object
this.Promise = Promise
this.Proxy = Proxy
this.RangeError = RangeError
this.ReferenceError = ReferenceError
this.Reflect = Reflect
this.RegExp = RegExp
this.Set = Set
this.SharedArrayBuffer = SharedArrayBuffer
this.String = String
this.Symbol = Symbol
this.SyntaxError = SyntaxError
this.TypeError = TypeError
this.URIError = URIError
this.Uint8Array = Uint8Array
this.Uint8ClampedArray = Uint8ClampedArray
this.Uint16Array = Uint16Array
this.Uint32Array = Uint32Array
this.WeakMap = WeakMap
this.WebAssembly = WebAssembly
this.console = console
this.constructor = constructor
this.decodeURI = decodeURI
this.decodeURIComponent = decodeURIComponent
this.encodeURI = encodeURI
this.encodeURIComponent = encodeURIComponent
this.escape = escape
this.globalThis = this
this.isFinite = isFinite
this.isNaN = isNaN
this.parseFloat = parseFloat
this.parseInt = parseInt
this.self = this
this.undefined = undefined
this.unescape = unescape
}
Object.assign(this, bindings)
}
}
module.exports = {
Context,
fetch,
FetchEvent,
freezeHeaders,
bindCfProperty,
Headers,
Request,
Response,
ReadableStream,
WritableStream,
TransformStream,
URL,
URLSearchParams,
TextDecoder,
TextEncoder,
atob,
btoa,
}