Skip to content

Commit

Permalink
use null instead of undefined as an empty placeholder in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Aug 15, 2024
1 parent 9cc1d63 commit 5b69af0
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions packages/core-js/internals/collection-strong.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = {
setInternalState(that, {
type: CONSTRUCTOR_NAME,
index: create(null),
first: undefined,
last: undefined,
first: null,
last: null,
size: 0
});
if (!DESCRIPTORS) that.size = 0;
Expand All @@ -49,7 +49,7 @@ module.exports = {
key: key,
value: value,
previous: previous = state.last,
next: undefined,
next: null,
removed: false
};
if (!state.first) state.first = entry;
Expand Down Expand Up @@ -83,10 +83,10 @@ module.exports = {
var entry = state.first;
while (entry) {
entry.removed = true;
if (entry.previous) entry.previous = entry.previous.next = undefined;
if (entry.previous) entry.previous = entry.previous.next = null;
entry = entry.next;
}
state.first = state.last = undefined;
state.first = state.last = null;
state.index = create(null);
if (DESCRIPTORS) state.size = 0;
else that.size = 0;
Expand Down Expand Up @@ -178,7 +178,7 @@ module.exports = {
target: iterated,
state: getInternalCollectionState(iterated),
kind: kind,
last: undefined
last: null
});
}, function () {
var state = getInternalIteratorState(this);
Expand All @@ -189,7 +189,7 @@ module.exports = {
// get next entry
if (!state.target || !(state.last = entry = entry ? entry.next : state.state.first)) {
// or finish the iteration
state.target = undefined;
state.target = null;
return createIterResultObject(undefined, true);
}
// return step by kind
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/internals/collection-weak.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
setInternalState(that, {
type: CONSTRUCTOR_NAME,
id: id++,
frozen: undefined
frozen: null
});
if (!isNullOrUndefined(iterable)) iterate(iterable, that[ADDER], { that: that, AS_ENTRIES: IS_MAP });
});
Expand Down Expand Up @@ -110,7 +110,7 @@ module.exports = {
if (isObject(key)) {
var data = getWeakData(key);
if (data === true) return uncaughtFrozenStore(state).get(key);
return data ? data[state.id] : undefined;
if (data) return data[state.id];
}
},
// `WeakMap.prototype.set(key, value)` method
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.array.iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = defineIterator(Array, 'Array', function (iterated, kind) {
var target = state.target;
var index = state.index++;
if (!target || index >= target.length) {
state.target = undefined;
state.target = null;
return createIterResultObject(undefined, true);
}
switch (state.kind) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.promise.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ if (FORCED_PROMISE_CONSTRUCTOR) {
reactions: new Queue(),
rejection: false,
state: PENDING,
value: undefined
value: null
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ defineBuiltIns(AsyncDisposableStackPrototype, {
var loop = function () {
if (i) {
var disposeMethod = stack[--i];
stack[i] = undefined;
stack[i] = null;
try {
Promise.resolve(disposeMethod()).then(loop, handleError);
} catch (error) {
handleError(error);
}
} else {
internalState.stack = undefined;
internalState.stack = null;
thrown ? reject(suppressed) : resolve(undefined);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defineBuiltIns(DisposableStackPrototype, {
var suppressed;
while (i) {
var disposeMethod = stack[--i];
stack[i] = undefined;
stack[i] = null;
try {
disposeMethod();
} catch (errorResult) {
Expand All @@ -68,7 +68,7 @@ defineBuiltIns(DisposableStackPrototype, {
}
}
}
internalState.stack = undefined;
internalState.stack = null;
if (thrown) throw suppressed;
},
use: function use(value) {
Expand Down
10 changes: 5 additions & 5 deletions packages/core-js/modules/esnext.observable.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ var getSubscriptionObserverInternalState = getterFor(SUBSCRIPTION_OBSERVER);

var SubscriptionState = function (observer) {
this.observer = anObject(observer);
this.cleanup = undefined;
this.subscriptionObserver = undefined;
this.cleanup = null;
this.subscriptionObserver = null;
};

SubscriptionState.prototype = {
type: SUBSCRIPTION,
clean: function () {
var cleanup = this.cleanup;
if (cleanup) {
this.cleanup = undefined;
this.cleanup = null;
try {
cleanup();
} catch (error) {
Expand All @@ -53,10 +53,10 @@ SubscriptionState.prototype = {
var subscriptionObserver = this.subscriptionObserver;
subscription.closed = true;
if (subscriptionObserver) subscriptionObserver.closed = true;
} this.observer = undefined;
} this.observer = null;
},
isClosed: function () {
return this.observer === undefined;
return this.observer === null;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params
var target = state.target;
var index = state.index++;
if (!target || index >= target.length) {
state.target = undefined;
state.target = null;
return createIterResultObject(undefined, true);
}
var entry = target[index];
Expand Down

0 comments on commit 5b69af0

Please sign in to comment.