Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse realm for Request/Response #3142

Merged
merged 1 commit into from
Apr 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
isValidHTTPToken,
sameOrigin,
normalizeMethod,
EnvironmentSettingsObject,
environmentSettingsObject,
normalizeMethodRecord
} = require('./util')
const {
Expand Down Expand Up @@ -54,8 +54,8 @@ class Request {
init = webidl.converters.RequestInit(init)

// https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
// Note: Slow initialization of object literals with getters.
this[kRealm] = new EnvironmentSettingsObject()
this[kRealm] = environmentSettingsObject

// 1. Let request be null.
let request = null

Expand Down
10 changes: 2 additions & 8 deletions lib/web/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
serializeJavascriptValueToJSONString,
isErrorLike,
isomorphicEncode,
EnvironmentSettingsObject
environmentSettingsObject: relevantRealm
} = require('./util')
const {
redirectStatusSet,
Expand All @@ -33,8 +33,6 @@ const textEncoder = new TextEncoder('utf-8')
class Response {
// Creates network error Response.
static error () {
const relevantRealm = new EnvironmentSettingsObject()

// The static error() method steps are to return the result of creating a
// Response object, given a new network error, "immutable", and this’s
// relevant Realm.
Expand All @@ -61,7 +59,6 @@ class Response {

// 3. Let responseObject be the result of creating a Response object, given a new response,
// "response", and this’s relevant Realm.
const relevantRealm = new EnvironmentSettingsObject()
const responseObject = fromInnerResponse(makeResponse({}), 'response', relevantRealm)

// 4. Perform initialize a response given responseObject, init, and (body, "application/json").
Expand All @@ -73,8 +70,6 @@ class Response {

// Creates a redirect Response that redirects to url with status status.
static redirect (url, status = 302) {
const relevantRealm = new EnvironmentSettingsObject()

webidl.argumentLengthCheck(arguments, 1, { header: 'Response.redirect' })

url = webidl.converters.USVString(url)
Expand Down Expand Up @@ -125,8 +120,7 @@ class Response {

init = webidl.converters.ResponseInit(init)

// TODO
this[kRealm] = new EnvironmentSettingsObject()
this[kRealm] = relevantRealm

// 1. Set this’s response to a new response.
this[kState] = makeResponse({})
Expand Down
8 changes: 6 additions & 2 deletions lib/web/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,9 @@ function utf8DecodeBytes (buffer) {
}

class EnvironmentSettingsObjectBase {
baseUrl = getGlobalOrigin()
get baseUrl () {
return getGlobalOrigin()
}

get origin () {
return this.baseUrl?.origin
Expand All @@ -1583,6 +1585,8 @@ class EnvironmentSettingsObject {
settingsObject = new EnvironmentSettingsObjectBase()
}

const environmentSettingsObject = new EnvironmentSettingsObject()

module.exports = {
isAborted,
isCancelled,
Expand Down Expand Up @@ -1635,5 +1639,5 @@ module.exports = {
extractMimeType,
getDecodeSplit,
utf8DecodeBytes,
EnvironmentSettingsObject
environmentSettingsObject
}