Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
502e14b
add headers impl
Ethan-Arrowood Jun 10, 2021
b0f9a75
update headers and begin porting tests
Ethan-Arrowood Jun 10, 2021
499c1c6
add in progress test script
Ethan-Arrowood Jun 15, 2021
357ba5d
complete test migration
Ethan-Arrowood Jun 21, 2021
b34a484
add docs
Ethan-Arrowood Jun 21, 2021
f8f2059
fix ordering
Ethan-Arrowood Jun 21, 2021
b585716
lint fixes
Ethan-Arrowood Jun 21, 2021
865d422
Update doc/api/fetch.md
Ethan-Arrowood Jun 21, 2021
c96bf21
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
e7413b1
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
4d96cf4
Update test/parallel/test-headers.js
Ethan-Arrowood Jun 21, 2021
6b726a9
Update test/parallel/test-headers.js
Ethan-Arrowood Jun 21, 2021
c735d9e
use entries for iterator
Ethan-Arrowood Jun 21, 2021
173ccef
lint md
Ethan-Arrowood Jun 21, 2021
d856bd4
fix lint again
Ethan-Arrowood Jun 21, 2021
bed131e
add missing character
Ethan-Arrowood Jun 21, 2021
a87342f
Update doc/api/fetch.md
Ethan-Arrowood Jun 21, 2021
71c1aa2
Update doc/api/fetch.md
Ethan-Arrowood Jun 21, 2021
d5e3df3
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
c8d156a
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
8fdd64c
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
d66e313
fix lint and tests
Ethan-Arrowood Jun 21, 2021
1d042f0
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
0a58d93
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
a85b1c0
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jul 22, 2021
58da701
incorporate review and fix failing test
Ethan-Arrowood Jul 22, 2021
92b9519
export api
Ethan-Arrowood Jul 22, 2021
ce73c08
Merge branch 'master' into feature/fetch-headers
Ethan-Arrowood Jul 22, 2021
6f212c0
add inspect and docs
Ethan-Arrowood Jul 22, 2021
6f06698
Update lib/fetch.js
Ethan-Arrowood Jul 26, 2021
ae223ca
Update lib/fetch.js
Ethan-Arrowood Jul 26, 2021
1ef66a0
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jul 26, 2021
a9a7b4d
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jul 26, 2021
3b902a1
incorporate review changes
Ethan-Arrowood Jul 26, 2021
1568b7c
Merge branch 'master' into feature/fetch-headers
Ethan-Arrowood Jul 26, 2021
cd38842
lint fixes
Ethan-Arrowood Jul 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
incorporate review changes
  • Loading branch information
Ethan-Arrowood committed Jul 26, 2021
commit 3b902a1db23e41953b75ea7e4d64cf0719096de2
36 changes: 17 additions & 19 deletions lib/internal/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
ArrayIsArray,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
FunctionPrototypeCall,
MathFloor,
ObjectDefineProperties,
ObjectEntries,
Expand All @@ -25,13 +26,15 @@ const {

const { validateObject } = require('internal/validators');
const { isBoxedPrimitive } = require('internal/util/types');
const {
customInspectSymbol,
kEnumerableProperty,
} = require('internal/util')

const { validateHeaderName, validateHeaderValue } = require('_http_outgoing');

const { Buffer } = require('buffer');

const { inspect } = require('internal/util/inspect');

const kHeadersList = Symbol('headers list');

/**
Expand Down Expand Up @@ -132,12 +135,6 @@ function fill(headers, object) {

class Headers {
constructor(init = {}) {
// Fail silently on primitives
const typeofInit = typeof init;
if (typeofInit === 'number' ||
typeofInit === 'string' ||
typeofInit === 'boolean' ||
typeofInit === 'function') return;
validateObject(init, 'init', { allowArray: true });
this[kHeadersList] = [];
fill(this, init);
Expand Down Expand Up @@ -256,7 +253,8 @@ class Headers {
}

for (let index = 0; index < this[kHeadersList].length; index += 2) {
callback.call(
FunctionPrototypeCall(
callback,
thisArg,
this[kHeadersList][index + 1],
this[kHeadersList][index],
Expand All @@ -265,23 +263,23 @@ class Headers {
}
}
Comment thread
Ethan-Arrowood marked this conversation as resolved.

[inspect.custom] () {
[customInspectSymbol] () {
return this[kHeadersList]
}
}

Comment thread
Ethan-Arrowood marked this conversation as resolved.
Headers.prototype[SymbolIterator] = Headers.prototype.entries;

ObjectDefineProperties(Headers.prototype, {
append: { enumerable: true },
delete: { enumerable: true },
get: { enumerable: true },
has: { enumerable: true },
set: { enumerable: true },
keys: { enumerable: true },
values: { enumerable: true },
entries: { enumerable: true },
forEach: { enumerable: true },
append: kEnumerableProperty,
delete: kEnumerableProperty,
get: kEnumerableProperty,
has: kEnumerableProperty,
set: kEnumerableProperty,
keys: kEnumerableProperty,
values: kEnumerableProperty,
entries: kEnumerableProperty,
forEach: kEnumerableProperty,
});

module.exports = {
Expand Down
6 changes: 5 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ const lazyDOMException = hideStackFrames((message, name) => {
return new DOMException(message, name);
});

const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;

module.exports = {
assertCrypto,
cachedResult,
Expand Down Expand Up @@ -483,5 +486,6 @@ module.exports = {
// Used by the buffer module to capture an internal reference to the
// default isEncoding implementation, just in case userland overrides it.
kIsEncodingSymbol: Symbol('kIsEncodingSymbol'),
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol')
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol'),
kEnumerableProperty,
};
6 changes: 2 additions & 4 deletions lib/internal/webstreams/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ const {
newReadableWritablePairFromDuplex,
} = require('internal/webstreams/adapters');

const {
customInspect,
kEnumerableProperty,
} = require('internal/webstreams/util');
const { customInspect } = require('internal/webstreams/util');

const {
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

let zlib;
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/webstreams/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const {
TransformStream,
} = require('internal/webstreams/transformstream');

const {
customInspect,
kEnumerableProperty,
} = require('internal/webstreams/util');
const { customInspect } = require('internal/webstreams/util');

const { kEnumerableProperty } = require('internal/util');

const {
codes: {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/webstreams/queuingstrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const {

const {
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
customInspect,
isBrandCheck,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
Expand Down Expand Up @@ -103,7 +104,6 @@ const {
nonOpStart,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/webstreams/transformstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
Expand All @@ -45,7 +46,6 @@ const {
nonOpFlush,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
4 changes: 0 additions & 4 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ function lazyTransfer() {
return transfer;
}

const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;

module.exports = {
ArrayBufferViewGetBuffer,
ArrayBufferViewGetByteLength,
Expand Down Expand Up @@ -237,5 +234,4 @@ module.exports = {
nonOpWrite,
kType,
kState,
kEnumerableProperty,
};
2 changes: 1 addition & 1 deletion lib/internal/webstreams/writablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
Expand Down Expand Up @@ -64,7 +65,6 @@ const {
nonOpWrite,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
24 changes: 2 additions & 22 deletions test/parallel/test-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const assert = require('assert');
// Flags: --expose-internals

const {
Headers,
binarySearch,
kHeadersList,
binarySearch
Headers,
} = require('internal/fetch/headers');

{
Expand Down Expand Up @@ -82,26 +82,6 @@ const {
assert.strictEqual(headers[kHeadersList].length, 4);
}

{
// Init fails silently when initialized with BoxedPrimitives
[
new Number(),
new Boolean(),
new String(),
].forEach((arg) => new Headers(arg));
}

{
// Init fails silently if function or primitive is passed
[
new Function(),
function() {},
1,
'test',
true,
].forEach((arg) => new Headers(arg));
}

{
// append
const headers = new Headers();
Expand Down