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

fix(fetch): re-add support for node v16.8.0+ #1534

Merged
merged 4 commits into from Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .github/workflows/nodejs.yml
Expand Up @@ -17,6 +17,9 @@ jobs:
post-test-steps: |
- name: Coverage Report
uses: codecov/codecov-action@v2
include: |
- runs-on: ubuntu-latest
node-version: 16.5
automerge:
if: >
github.event_name == 'pull_request' &&
Expand Down
8 changes: 7 additions & 1 deletion lib/fetch/util.js
Expand Up @@ -431,6 +431,11 @@ function makeIterator (iterator, name) {
return Object.setPrototypeOf({}, i)
}

/**
* Fetch supports node >= 16.5.0, but Object.hasOwn was added in v16.9.0.
*/
const hasOwn = Object.hasOwn || ((dict, key) => Object.prototype.hasOwnProperty.call(dict, key))

module.exports = {
isAborted,
isCancelled,
Expand Down Expand Up @@ -463,5 +468,6 @@ module.exports = {
serializeJavascriptValueToJSONString,
makeIterator,
isValidHeaderName,
isValidHeaderValue
isValidHeaderValue,
hasOwn
}
7 changes: 4 additions & 3 deletions lib/fetch/webidl.js
@@ -1,6 +1,7 @@
'use strict'

const { toUSVString, types } = require('util')
const { types } = require('util')
const { hasOwn, toUSVString } = require('./util')

const webidl = {}
webidl.converters = {}
Expand Down Expand Up @@ -315,7 +316,7 @@ webidl.dictionaryConverter = function (converters) {
const { key, defaultValue, required, converter } = options

if (required === true) {
if (!Object.hasOwn(dictionary, key)) {
if (!hasOwn(dictionary, key)) {
webidl.errors.exception({
header: 'Dictionary',
message: `Missing required key "${key}".`
Expand All @@ -324,7 +325,7 @@ webidl.dictionaryConverter = function (converters) {
}

let value = dictionary[key]
const hasDefault = Object.hasOwn(options, 'defaultValue')
const hasDefault = hasOwn(options, 'defaultValue')

// Only use defaultValue if value is undefined and
// a defaultValue options was provided.
Expand Down