Permalink
Cannot retrieve contributors at this time
40 lines (34 sloc)
1.12 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/es-abstract/2023/IsConstructor.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var GetIntrinsic = require('../GetIntrinsic.js'); | |
var $construct = GetIntrinsic('%Reflect.construct%', true); | |
var DefinePropertyOrThrow = require('./DefinePropertyOrThrow'); | |
try { | |
DefinePropertyOrThrow({}, '', { '[[Get]]': function () {} }); | |
} catch (e) { | |
// Accessor properties aren't supported | |
DefinePropertyOrThrow = null; | |
} | |
// https://262.ecma-international.org/6.0/#sec-isconstructor | |
if (DefinePropertyOrThrow && $construct) { | |
var isConstructorMarker = {}; | |
var badArrayLike = {}; | |
DefinePropertyOrThrow(badArrayLike, 'length', { | |
'[[Get]]': function () { | |
throw isConstructorMarker; | |
}, | |
'[[Enumerable]]': true | |
}); | |
module.exports = function IsConstructor(argument) { | |
try { | |
// `Reflect.construct` invokes `IsConstructor(target)` before `Get(args, 'length')`: | |
$construct(argument, badArrayLike); | |
} catch (err) { | |
return err === isConstructorMarker; | |
} | |
}; | |
} else { | |
module.exports = function IsConstructor(argument) { | |
// unfortunately there's no way to truly check this without try/catch `new argument` in old environments | |
return typeof argument === 'function' && !!argument.prototype; | |
}; | |
} |