Skip to content

Commit

Permalink
add the proper validation of arguments to some methods from web stand…
Browse files Browse the repository at this point in the history
…ards
  • Loading branch information
zloirock committed Jan 29, 2022
1 parent be8a033 commit 100c539
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Added the proper validation of arguments to some methods from web standards
- Added Rhino 1.7.14 compat data
- Added Deno 1.19 compat data mapping
- Added Opera Android 66 and 67 compat data mapping
Expand Down
7 changes: 5 additions & 2 deletions packages/core-js/internals/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var fails = require('../internals/fails');
var html = require('../internals/html');
var arraySlice = require('../internals/array-slice');
var createElement = require('../internals/document-create-element');
var validateArgumentsLength = require('../internals/validate-arguments-length');
var IS_IOS = require('../internals/engine-is-ios');
var IS_NODE = require('../internals/engine-is-node');

Expand Down Expand Up @@ -52,10 +53,12 @@ var post = function (id) {

// Node.js 0.9+ & IE10+ has setImmediate, otherwise:
if (!set || !clear) {
set = function setImmediate(fn) {
set = function setImmediate(handler) {
validateArgumentsLength(arguments.length, 1);
var fn = isCallable(handler) ? handler : Function(handler);
var args = arraySlice(arguments, 1);
queue[++counter] = function () {
apply(isCallable(fn) ? fn : Function(fn), undefined, args);
apply(fn, undefined, args);
};
defer(counter);
return counter;
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/modules/web.queue-microtask.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var $ = require('../internals/export');
var global = require('../internals/global');
var microtask = require('../internals/microtask');
var aCallable = require('../internals/a-callable');
var validateArgumentsLength = require('../internals/validate-arguments-length');
var IS_NODE = require('../internals/engine-is-node');

var process = global.process;
Expand All @@ -9,6 +11,8 @@ var process = global.process;
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask
$({ global: true, enumerable: true, noTargetGet: true }, {
queueMicrotask: function queueMicrotask(fn) {
validateArgumentsLength(arguments.length, 1);
aCallable(fn);
var domain = IS_NODE && process.domain;
microtask(domain ? domain.bind(fn) : fn);
}
Expand Down
8 changes: 5 additions & 3 deletions packages/core-js/modules/web.timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ var apply = require('../internals/function-apply');
var isCallable = require('../internals/is-callable');
var userAgent = require('../internals/engine-user-agent');
var arraySlice = require('../internals/array-slice');
var validateArgumentsLength = require('../internals/validate-arguments-length');

var MSIE = /MSIE .\./.test(userAgent); // <- dirty ie9- check
var Function = global.Function;

var wrap = function (scheduler) {
return function (handler, timeout /* , ...arguments */) {
var boundArgs = arguments.length > 2;
var boundArgs = validateArgumentsLength(arguments.length, 1) > 2;
var fn = isCallable(handler) ? handler : Function(handler);
var args = boundArgs ? arraySlice(arguments, 2) : undefined;
return scheduler(boundArgs ? function () {
apply(isCallable(handler) ? handler : Function(handler), this, args);
} : handler, timeout);
apply(fn, this, args);
} : fn, timeout);
};
};

Expand Down
3 changes: 2 additions & 1 deletion packages/core-js/modules/web.url.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var codeAt = require('../internals/string-multibyte').codeAt;
var toASCII = require('../internals/string-punycode-to-ascii');
var $toString = require('../internals/to-string');
var setToStringTag = require('../internals/set-to-string-tag');
var validateArgumentsLength = require('../internals/validate-arguments-length');
var URLSearchParamsModule = require('../modules/web.url-search-params');
var InternalStateModule = require('../internals/internal-state');

Expand Down Expand Up @@ -939,7 +940,7 @@ URLState.prototype = {
// https://url.spec.whatwg.org/#url-class
var URLConstructor = function URL(url /* , base */) {
var that = anInstance(this, URLPrototype);
var base = arguments.length > 1 ? arguments[1] : undefined;
var base = validateArgumentsLength(arguments.length, 1) > 1 ? arguments[1] : undefined;
var state = setInternalState(that, new URLState(url, false, base));
if (!DESCRIPTORS) {
that.href = state.serialize();
Expand Down

0 comments on commit 100c539

Please sign in to comment.