inspect-js / is-descriptor Goto Github PK
View Code? Open in Web Editor NEWReturns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
License: MIT License
Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
License: MIT License
Hello, I may have found a problem with the is-data-descriptor and is-accessor-descriptor checkings.
A data property descriptor is one that includes any fields named either [[Value]] or [[Writable]]. An accessor property descriptor is one that includes any fields named either [[Get]] or [[Set]]. Any property descriptor may have fields named [[Enumerable]] and [[Configurable]]. A Property Descriptor value may not be both a data property descriptor and an accessor property descriptor; however, it may be neither.
-- The Property Descriptor and Property Identifier Specification Types
This one works fine:
// object: { test: 'value' }
var descriptor = {
value: 'value',
writable: true,
enumerable: true,
configurable: true
};
isDataDescriptor(descriptor ); // true - right
isAccessor(descriptor ); // false - right
But, if we do this:
/*
object: {
get test() {
// Return something
},
set test(value) {
// Do something
}
}
*/
var descriptor = {
get: [Function: test],
set: [Function: test],
enumerable: true,
configurable: true
};
isDataDescriptor(descriptor); // true - wrong
isAccessor(descriptor); // true - right
Which is wrong, because it doesn't have neither the [[value]] or [[writable]] attributes.
This one { get: [Function: test], set: undefined, enumerable: true, configurable: true }
is not even considered a descriptor either. But, as an accessor descriptor it can have either [[get]] or [[set]] and should return false only if doesn't have any, as you can read here:
When the abstract operation IsAccessorDescriptor is called with property descriptor Desc, the following steps are taken:
- If Desc is undefined, then return false.
- If both Desc.[[Get]] and Desc.[[Set]] are absent, then return false.
- Return true.
Due to CVE-2019-20149, a new version of kind-of has been released.
This package still uses 6.0.2.
The dependencies should be updated to 6.0.3, the latest version with the fix.
npm still reports 1.0.2 as the most current version
is_descriptor
return false for valid descriptors
https://www.ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type
const descs = [
{value: 1},
{writable: true},
{configurable: true},
{get: () => 3},
]
for (const desc of descs) {
console.group(desc);
console.log('is_descriptor = ', is_descriptor(desc));
console.log('defineProperty = %o', Reflect.defineProperty({}, "foo", desc));
console.groupEnd();
}
Hi,
in our company we are using 0.1.6 and I can see that version on npmjs. However, for some reason the 0.1.6 to has not been set in git. In fact when I look at the commits for 1.0.0 I can see that the version jumped directly from 0.1.5 to 1.0.0. How come there appears to be some mismatch? This is causing an issue in our licensing department. Is it possible to add that tag retrospectively?
Any help on this would be greatly appreciated.
Thanks!
Michael
Hey,
I am actually trying to use karma-server-side module with karma, and i am running into some issue with the 'is-descriptor' dependency importing kind-of. I am not sure if this is a bug or an issue with my configuration, but any help would be greatly appreciated.
here is the failure output.
Cannot find module 'kind-of'.
Simple.test.js:8902:88
[email protected]:8902:90
[email protected]:8899:51
[email protected]:8670:32
[email protected]:8588:13
[email protected]:8559:20
[email protected]:8524:14
[email protected]:8466:18
[email protected]:8390:26
Simple.test.js:56:20
here is a reduced version of the setup i am using.
tools/
webpack.shared.config.js
src/
Simple.test.js
package.json
karma.conf.json
package.json
{
"description": "",
"scripts": {
"test": "karma start karma.conf.js --single-run",
"test:debug": "karma start karma.conf.js --browsers=Chrome --single-run=false"
},
"keywords": [],
"devDependencies": {
"autoprefixer": "^6.3.7",
"babel-core": "^6.10.4",
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"chai": "^3.5.0",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.2.0",
"karma-phantomjs-launcher": "^1.0.1",
"karma-server-side": "^1.5.0",
"karma-webpack": "^1.7.0",
"mocha": "^3.1.2",
"postcss-loader": "^0.11.1",
"precss": "^1.4.0",
"webpack": "^1.13.1"
},
"dependencies": {
"babel-runtime": "^6.11.6"
}
}
karma.conf.json
// Karma configuration
const path = require('path');
const webpackConfig = require('./tools/webpack.shared.config');
const extend = require('extend');
module.exports = (config) => {
config.set({
basePath: 'src',
frameworks: ['mocha', 'server-side'],
files: [
'**/Simple.test.js',
],
exclude: [],
preprocessors: {
'**/*.test.js': ['webpack'],
},
reporters: ['mocha'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: 1,
webpack: webpackConfig,
});
};
webpack.shared.config.js
const path = require('path');
const webpack = require('webpack');
const plugins = [];
if (process.env.NODE_ENV) {
plugins.push(new webpack.optimize.UglifyJsPlugin());
}
module.exports = {
resolve: {
extensions: ['', '.js', '.jsx', '.json'],
},
module: {
loaders: [{
test: /\.js?$/,
exclude: /node_modules/,
loaders: [
'babel-loader?cacheDirectory&presets[]=es2015&plugins[]=transform-runtime',
],
}],
},
plugins,
};
Simple.test.js
/* eslint-env mocha */
import { assert } from 'chai';
const server = require('karma-server-side');
describe('Test send request', () => {
it('karma-server-side test', (done) => {
const server = require('karma-server-side');
server.run(() => {
return 'success';
}).then((result) => {
assert.equal(result, 'success');
done();
});
});
});
the workflow i am running is just to run the following commands
'npm install'
'npm test'
additionally i do see these warnings:
WARNING in .//is-descriptor/utils.js/is-descriptor/utils.js 7:34-41
Critical dependencies:
7:34-41 require function is used in a way in which dependencies cannot be statically extracted
@ ./
WARNING in ./~/is-descriptor/package.json
Module parse failed: /Users/mhenley/git/scrd/milestest/node_modules/is-descriptor/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)
Any ideas? could this be a bug? or am i just doing something wrong?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.