mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 21:24:26 +08:00
This is need to be able to move to flat config which I am handling in a separate CL. The overrides are there as these packages got update today, so we need to way, but they were last touched 3 years ago, so reviewing their changes upstream as well. Bug: none Change-Id: I61534f881fd4e747c716b42b773f8f7f3e9bc761 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6063618 Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org> Reviewed-by: Danil Somsikov <dsv@chromium.org>
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
var hasOwn = require('hasown');
|
|
|
|
var $TypeError = require('es-errors/type');
|
|
|
|
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 (hasOwn(Obj, 'enumerable')) {
|
|
desc['[[Enumerable]]'] = ToBoolean(Obj.enumerable);
|
|
}
|
|
if (hasOwn(Obj, 'configurable')) {
|
|
desc['[[Configurable]]'] = ToBoolean(Obj.configurable);
|
|
}
|
|
if (hasOwn(Obj, 'value')) {
|
|
desc['[[Value]]'] = Obj.value;
|
|
}
|
|
if (hasOwn(Obj, 'writable')) {
|
|
desc['[[Writable]]'] = ToBoolean(Obj.writable);
|
|
}
|
|
if (hasOwn(Obj, 'get')) {
|
|
var getter = Obj.get;
|
|
if (typeof getter !== 'undefined' && !IsCallable(getter)) {
|
|
throw new $TypeError('getter must be a function');
|
|
}
|
|
desc['[[Get]]'] = getter;
|
|
}
|
|
if (hasOwn(Obj, 'set')) {
|
|
var setter = Obj.set;
|
|
if (typeof setter !== 'undefined' && !IsCallable(setter)) {
|
|
throw new $TypeError('setter must be a function');
|
|
}
|
|
desc['[[Set]]'] = setter;
|
|
}
|
|
|
|
if ((hasOwn(desc, '[[Get]]') || hasOwn(desc, '[[Set]]')) && (hasOwn(desc, '[[Value]]') || hasOwn(desc, '[[Writable]]'))) {
|
|
throw new $TypeError('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute');
|
|
}
|
|
return desc;
|
|
};
|