Permalink
Cannot retrieve contributors at this time
52 lines (44 sloc)
1.42 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/2022/ToPropertyDescriptor.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 has = require('has'); | |
var GetIntrinsic = require('get-intrinsic'); | |
var $TypeError = GetIntrinsic('%TypeError%'); | |
var Type = require('./Type'); | |
var ToBoolean = require('./ToBoolean'); | |
var IsCallable = require('./IsCallable'); | |
// https://262.ecma-international.org/5.1/#sec-8.10.5 | |
module.exports = function ToPropertyDescriptor(Obj) { | |
if (Type(Obj) !== 'Object') { | |
throw new $TypeError('ToPropertyDescriptor requires an object'); | |
} | |
var desc = {}; | |
if (has(Obj, 'enumerable')) { | |
desc['[[Enumerable]]'] = ToBoolean(Obj.enumerable); | |
} | |
if (has(Obj, 'configurable')) { | |
desc['[[Configurable]]'] = ToBoolean(Obj.configurable); | |
} | |
if (has(Obj, 'value')) { | |
desc['[[Value]]'] = Obj.value; | |
} | |
if (has(Obj, 'writable')) { | |
desc['[[Writable]]'] = ToBoolean(Obj.writable); | |
} | |
if (has(Obj, 'get')) { | |
var getter = Obj.get; | |
if (typeof getter !== 'undefined' && !IsCallable(getter)) { | |
throw new $TypeError('getter must be a function'); | |
} | |
desc['[[Get]]'] = getter; | |
} | |
if (has(Obj, 'set')) { | |
var setter = Obj.set; | |
if (typeof setter !== 'undefined' && !IsCallable(setter)) { | |
throw new $TypeError('setter must be a function'); | |
} | |
desc['[[Set]]'] = setter; | |
} | |
if ((has(desc, '[[Get]]') || has(desc, '[[Set]]')) && (has(desc, '[[Value]]') || has(desc, '[[Writable]]'))) { | |
throw new $TypeError('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute'); | |
} | |
return desc; | |
}; |