Intrinsic
Abstract
JavaScript is a dynamic and embeddable language that conforms to the ECMAScript
specification. All objects and their prototypes in JavaScript are mutable unless
they have been frozen. This can affect the safety of the executable code at
runtime.
The specification assumes that the source code is executed in a secure runtime
where all implementations are consistent. Third-party libraries can modify
references to objects in the global scope, built-in object prototypes, their
properties and methods. This leads to inconsistency between implementations.
The inconsistency can be resolved by copying references to all built-in objects,
their prototypes, properties and methods before importing the source code.
Access to these references must be encapsulated.
Install
npm i --save @dwcore/intrinsic
Usage
``
javascript
// CJS
const $ = require('@dwcore/intrinsic');
// ESM
import $ from '@dwcore/intrinsic';
const uncurryThis = $('%uncurryThis%');
const ObjectToString = uncurryThis($('Object.prototype.toString'));
ObjectToString(Reflect); // => '[object Object]'
$('@@iterator') === Symbol.iterator; // true
$('Array.prototype[@@iterator]') === Array.prototype[Symbol.iterator]; // true
const TypedArray = Reflect.getPrototypeOf(Uint8Array);
$('get %TypedArray%.prototype.length') === Reflect.getOwnPropertyDescriptor(
TypedArray.prototype,
'length'
).get; // true
``