ses 0.15.4 → 0.15.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/NEWS.md +10 -0
- package/SECURITY.md +1 -1
- package/dist/lockdown.cjs +1506 -1378
- package/dist/lockdown.mjs +1506 -1378
- package/dist/lockdown.umd.js +1506 -1378
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +1506 -1378
- package/dist/ses.mjs +1506 -1378
- package/dist/ses.umd.js +1506 -1378
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +122 -39
- package/package.json +8 -8
- package/src/commons.js +6 -0
- package/src/environment-options.js +2 -2
- package/src/error/tame-console.js +5 -1
- package/src/lockdown-shim.js +7 -1
- package/src/make-hardener.js +68 -1
package/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals, vars-on-top, no-var */
|
|
1
2
|
|
|
2
3
|
// It's academically tempting to define a hardened type, but TypeScript doesn't
|
|
3
4
|
// strike a good balance in distinguishing "readonly" in the sense that you
|
|
@@ -31,8 +32,8 @@ export interface LockdownOptions {
|
|
|
31
32
|
|
|
32
33
|
export type Lockdown = (options?: LockdownOptions) => void;
|
|
33
34
|
|
|
34
|
-
export type __LiveExportsMap__ = Record<string, [string, boolean]
|
|
35
|
-
export type __FixedExportsMap__ = Record<string, [string]
|
|
35
|
+
export type __LiveExportsMap__ = Record<string, [string, boolean]>;
|
|
36
|
+
export type __FixedExportsMap__ = Record<string, [string]>;
|
|
36
37
|
|
|
37
38
|
export interface PrecompiledStaticModuleInterface {
|
|
38
39
|
imports: Array<string>;
|
|
@@ -46,33 +47,46 @@ export interface PrecompiledStaticModuleInterface {
|
|
|
46
47
|
export interface ThirdPartyStaticModuleInterface {
|
|
47
48
|
imports: Array<string>;
|
|
48
49
|
exports: Array<string>;
|
|
49
|
-
execute(
|
|
50
|
+
execute(
|
|
51
|
+
proxiedExports: Object,
|
|
52
|
+
compartment: Compartment,
|
|
53
|
+
resolvedImports: Record<string, string>,
|
|
54
|
+
): void;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
export type FinalStaticModuleType =
|
|
57
|
+
export type FinalStaticModuleType =
|
|
58
|
+
| PrecompiledStaticModuleInterface
|
|
59
|
+
| ThirdPartyStaticModuleInterface;
|
|
53
60
|
|
|
54
61
|
export interface RedirectStaticModuleInterface {
|
|
55
|
-
record: FinalStaticModuleType
|
|
56
|
-
specifier: string
|
|
62
|
+
record: FinalStaticModuleType;
|
|
63
|
+
specifier: string;
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
export type StaticModuleType =
|
|
66
|
+
export type StaticModuleType =
|
|
67
|
+
| RedirectStaticModuleInterface
|
|
68
|
+
| FinalStaticModuleType;
|
|
60
69
|
|
|
61
|
-
export type ModuleExportsNamespace = Record<string, any
|
|
70
|
+
export type ModuleExportsNamespace = Record<string, any>;
|
|
62
71
|
|
|
63
72
|
export type Transform = (source: string) => string;
|
|
64
|
-
export type ResolveHook = (
|
|
73
|
+
export type ResolveHook = (
|
|
74
|
+
importSpecifier: string,
|
|
75
|
+
referrerSpecifier: string,
|
|
76
|
+
) => string;
|
|
65
77
|
export type ModuleMap = Record<string, string | ModuleExportsNamespace>;
|
|
66
|
-
export type ModuleMapHook = (
|
|
78
|
+
export type ModuleMapHook = (
|
|
79
|
+
moduleSpecifier: string,
|
|
80
|
+
) => string | ModuleExportsNamespace | void;
|
|
67
81
|
export type ImportHook = (moduleSpecifier: string) => Promise<StaticModuleType>;
|
|
68
82
|
|
|
69
83
|
export interface CompartmentOptions {
|
|
70
84
|
name?: string;
|
|
71
85
|
transforms?: Array<Transform>;
|
|
72
86
|
globalLexicals?: Record<string, any>;
|
|
73
|
-
moduleMapHook?: ModuleMapHook
|
|
74
|
-
importHook?: ImportHook
|
|
75
|
-
resolveHook?: ResolveHook
|
|
87
|
+
moduleMapHook?: ModuleMapHook;
|
|
88
|
+
importHook?: ImportHook;
|
|
89
|
+
resolveHook?: ResolveHook;
|
|
76
90
|
__shimTransforms__?: Array<Transform>;
|
|
77
91
|
}
|
|
78
92
|
|
|
@@ -85,21 +99,53 @@ export interface EvaluateOptions {
|
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
// The DetailsToken is an empty object literal.
|
|
88
|
-
export type DetailsToken = Record<any, never
|
|
89
|
-
export type Details = string | DetailsToken
|
|
102
|
+
export type DetailsToken = Record<any, never>;
|
|
103
|
+
export type Details = string | DetailsToken;
|
|
90
104
|
|
|
91
105
|
export interface AssertMakeErrorOptions {
|
|
92
|
-
errorName?: string
|
|
106
|
+
errorName?: string;
|
|
93
107
|
}
|
|
94
108
|
|
|
95
|
-
type AssertTypeofBigint = (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
type
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
type AssertTypeofBigint = (
|
|
110
|
+
specimen: any,
|
|
111
|
+
typeName: 'bigint',
|
|
112
|
+
details?: Details,
|
|
113
|
+
) => asserts specimen is bigint;
|
|
114
|
+
type AssertTypeofBoolean = (
|
|
115
|
+
specimen: any,
|
|
116
|
+
typeName: 'boolean',
|
|
117
|
+
details?: Details,
|
|
118
|
+
) => asserts specimen is boolean;
|
|
119
|
+
type AssertTypeofFunction = (
|
|
120
|
+
specimen: any,
|
|
121
|
+
typeName: 'function',
|
|
122
|
+
details?: Details,
|
|
123
|
+
) => asserts specimen is Function;
|
|
124
|
+
type AssertTypeofNumber = (
|
|
125
|
+
specimen: any,
|
|
126
|
+
typeName: 'number',
|
|
127
|
+
details?: Details,
|
|
128
|
+
) => asserts specimen is number;
|
|
129
|
+
type AssertTypeofObject = (
|
|
130
|
+
specimen: any,
|
|
131
|
+
typeName: 'object',
|
|
132
|
+
details?: Details,
|
|
133
|
+
) => asserts specimen is Record<any, any> | null;
|
|
134
|
+
type AssertTypeofString = (
|
|
135
|
+
specimen: any,
|
|
136
|
+
typeName: 'string',
|
|
137
|
+
details?: Details,
|
|
138
|
+
) => asserts specimen is string;
|
|
139
|
+
type AssertTypeofSymbol = (
|
|
140
|
+
specimen: any,
|
|
141
|
+
typeName: 'symbol',
|
|
142
|
+
details?: Details,
|
|
143
|
+
) => asserts specimen is symbol;
|
|
144
|
+
type AssertTypeofUndefined = (
|
|
145
|
+
specimen: any,
|
|
146
|
+
typeName: 'undefined',
|
|
147
|
+
details?: Details,
|
|
148
|
+
) => asserts specimen is undefined;
|
|
103
149
|
|
|
104
150
|
export type AssertTypeof = AssertTypeofBigint &
|
|
105
151
|
AssertTypeofBoolean &
|
|
@@ -110,24 +156,50 @@ export type AssertTypeof = AssertTypeofBigint &
|
|
|
110
156
|
AssertTypeofSymbol &
|
|
111
157
|
AssertTypeofUndefined;
|
|
112
158
|
|
|
113
|
-
export type Raise = (reason: Error) => void;
|
|
114
|
-
export type MakeAssert = (raise?: Raise, unredacted?: boolean) => Assert;
|
|
115
|
-
|
|
116
159
|
interface ToStringable {
|
|
117
|
-
toString(): string
|
|
160
|
+
toString(): string;
|
|
118
161
|
}
|
|
119
162
|
|
|
163
|
+
export type Raise = (reason: Error) => void;
|
|
164
|
+
// Behold: recursion.
|
|
165
|
+
// eslint-disable-next-line no-use-before-define
|
|
166
|
+
export type MakeAssert = (raise?: Raise, unredacted?: boolean) => Assert;
|
|
167
|
+
|
|
120
168
|
export interface Assert {
|
|
121
|
-
(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
169
|
+
(
|
|
170
|
+
value: any,
|
|
171
|
+
details?: Details,
|
|
172
|
+
errorConstructor?: ErrorConstructor,
|
|
173
|
+
): asserts value;
|
|
174
|
+
typeof: AssertTypeof;
|
|
175
|
+
error(
|
|
176
|
+
details?: Details,
|
|
177
|
+
errorConstructor?: ErrorConstructor,
|
|
178
|
+
options?: AssertMakeErrorOptions,
|
|
179
|
+
): Error;
|
|
180
|
+
fail(details?: Details, errorConstructor?: ErrorConstructor): never;
|
|
181
|
+
equal(
|
|
182
|
+
left: any,
|
|
183
|
+
right: any,
|
|
184
|
+
details?: Details,
|
|
185
|
+
errorConstructor?: ErrorConstructor,
|
|
186
|
+
): void;
|
|
126
187
|
string(specimen: any, details?: Details): asserts specimen is string;
|
|
127
188
|
note(error: Error, details: Details): void;
|
|
128
|
-
details(
|
|
129
|
-
|
|
130
|
-
|
|
189
|
+
details(
|
|
190
|
+
template: TemplateStringsArray | string[],
|
|
191
|
+
...args: any
|
|
192
|
+
): DetailsToken;
|
|
193
|
+
quote(payload: any, spaces?: string | number): ToStringable;
|
|
194
|
+
makeAssert: MakeAssert;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface CompartmentEvaluateOptions {
|
|
198
|
+
sloppyGlobalsMode?: boolean;
|
|
199
|
+
__moduleShimLexicals__?: Object;
|
|
200
|
+
__evadeHtmlCommentTest__?: boolean;
|
|
201
|
+
__evadeImportExpressionTest__?: boolean;
|
|
202
|
+
__rejectSomeDirectEvalExpressions__?: boolean;
|
|
131
203
|
}
|
|
132
204
|
|
|
133
205
|
declare global {
|
|
@@ -142,13 +214,24 @@ declare global {
|
|
|
142
214
|
* code in a context bound to a new global creates a new compartment.
|
|
143
215
|
*/
|
|
144
216
|
export class Compartment {
|
|
145
|
-
constructor(
|
|
217
|
+
constructor(
|
|
218
|
+
globals?: Object,
|
|
219
|
+
moduleMap?: ModuleMap,
|
|
220
|
+
options?: CompartmentOptions,
|
|
221
|
+
);
|
|
222
|
+
|
|
146
223
|
get globalThis(): Record<string, any>;
|
|
224
|
+
|
|
147
225
|
get name(): string;
|
|
148
|
-
|
|
149
|
-
|
|
226
|
+
|
|
227
|
+
evaluate(code: string, options?: CompartmentEvaluateOptions): any;
|
|
228
|
+
|
|
229
|
+
import(specifier: string): Promise<{ namespace: ModuleExportsNamespace }>;
|
|
230
|
+
|
|
150
231
|
load(specifier: string): Promise<void>;
|
|
232
|
+
|
|
151
233
|
importNow(specifier: string): ModuleExportsNamespace;
|
|
234
|
+
|
|
152
235
|
module(specifier: string): ModuleExportsNamespace;
|
|
153
236
|
}
|
|
154
237
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.8",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"lint": "yarn lint:types && yarn lint:js",
|
|
53
53
|
"lint-fix": "eslint --fix .",
|
|
54
54
|
"lint:js": "eslint .",
|
|
55
|
-
"lint:types": "tsc
|
|
55
|
+
"lint:types": "tsc -p jsconfig.json",
|
|
56
56
|
"prepublish": "yarn run clean && yarn build",
|
|
57
57
|
"qt": "ava",
|
|
58
58
|
"test": "yarn build && ava",
|
|
59
59
|
"test:platform-compatability": "node test/package/test.cjs"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@endo/compartment-mapper": "^0.6.
|
|
63
|
-
"@endo/eslint-config": "^0.3
|
|
64
|
-
"@endo/static-module-record": "^0.6.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
62
|
+
"@endo/compartment-mapper": "^0.6.6",
|
|
63
|
+
"@endo/eslint-config": "^0.4.3",
|
|
64
|
+
"@endo/static-module-record": "^0.6.13",
|
|
65
|
+
"@endo/test262-runner": "^0.1.19",
|
|
66
66
|
"ava": "^3.12.1",
|
|
67
67
|
"babel-eslint": "^10.0.3",
|
|
68
68
|
"c8": "^7.7.3",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"prettier": "^1.19.1",
|
|
76
76
|
"sinon": "8.0.4",
|
|
77
77
|
"terser": "^4.8.0",
|
|
78
|
-
"typescript": "
|
|
78
|
+
"typescript": "~4.5.5"
|
|
79
79
|
},
|
|
80
80
|
"files": [
|
|
81
81
|
"LICENSE*",
|
|
@@ -178,5 +178,5 @@
|
|
|
178
178
|
],
|
|
179
179
|
"timeout": "2m"
|
|
180
180
|
},
|
|
181
|
-
"gitHead": "
|
|
181
|
+
"gitHead": "9d2f88ab47f546bc59b6b6e7340482209b3cee56"
|
|
182
182
|
}
|
package/src/commons.js
CHANGED
|
@@ -62,6 +62,7 @@ export const {
|
|
|
62
62
|
keys,
|
|
63
63
|
prototype: objectPrototype,
|
|
64
64
|
seal,
|
|
65
|
+
preventExtensions,
|
|
65
66
|
setPrototypeOf,
|
|
66
67
|
values,
|
|
67
68
|
} = Object;
|
|
@@ -73,6 +74,8 @@ export const {
|
|
|
73
74
|
matchAll: matchAllSymbol,
|
|
74
75
|
} = Symbol;
|
|
75
76
|
|
|
77
|
+
export const { isInteger } = Number;
|
|
78
|
+
|
|
76
79
|
export const { stringify: stringifyJson } = JSON;
|
|
77
80
|
|
|
78
81
|
// At time of this writing, we still support Node 10 which doesn't have
|
|
@@ -137,6 +140,8 @@ export const { prototype: weaksetPrototype } = WeakSet;
|
|
|
137
140
|
export const { prototype: functionPrototype } = Function;
|
|
138
141
|
export const { prototype: promisePrototype } = Promise;
|
|
139
142
|
|
|
143
|
+
export const typedArrayPrototype = getPrototypeOf(Uint8Array.prototype);
|
|
144
|
+
|
|
140
145
|
/**
|
|
141
146
|
* uncurryThis()
|
|
142
147
|
* This form of uncurry uses Reflect.apply()
|
|
@@ -174,6 +179,7 @@ export const mapHas = uncurryThis(mapPrototype.has);
|
|
|
174
179
|
export const iterateMap = uncurryThis(mapPrototype[iteratorSymbol]);
|
|
175
180
|
//
|
|
176
181
|
export const setAdd = uncurryThis(setPrototype.add);
|
|
182
|
+
export const setDelete = uncurryThis(setPrototype.delete);
|
|
177
183
|
export const setForEach = uncurryThis(setPrototype.forEach);
|
|
178
184
|
export const setHas = uncurryThis(setPrototype.has);
|
|
179
185
|
export const iterateSet = uncurryThis(setPrototype[iteratorSymbol]);
|
|
@@ -40,8 +40,8 @@ const { details: X, quote: q } = assert;
|
|
|
40
40
|
* global `process` object holding an `env` object,
|
|
41
41
|
* optionally holding a property named for the `optionName` whose value is the
|
|
42
42
|
* configuration setting of that option. For example, for the optionName
|
|
43
|
-
* `
|
|
44
|
-
* `globalThis.process.env.
|
|
43
|
+
* `FOO_BAR` it would look in
|
|
44
|
+
* `globalThis.process.env.FOO_BAR`.
|
|
45
45
|
*
|
|
46
46
|
* If setting is either absent or `undefined`, that indicates that
|
|
47
47
|
* this configuration option should have its default behavior, whatever that is.
|
|
@@ -71,7 +71,11 @@ export const tameConsole = (
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// Browser
|
|
74
|
-
if (
|
|
74
|
+
if (
|
|
75
|
+
errorTrapping !== 'none' &&
|
|
76
|
+
globalThis.window !== undefined &&
|
|
77
|
+
globalThis.window.addEventListener !== undefined
|
|
78
|
+
) {
|
|
75
79
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
76
80
|
globalThis.window.addEventListener('error', event => {
|
|
77
81
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
package/src/lockdown-shim.js
CHANGED
|
@@ -229,11 +229,14 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
229
229
|
const seemsToBeLockedDown = () => {
|
|
230
230
|
return (
|
|
231
231
|
globalThis.Function.prototype.constructor !== globalThis.Function &&
|
|
232
|
+
// @ts-ignore harden is absent on globalThis type def.
|
|
232
233
|
typeof globalThis.harden === 'function' &&
|
|
234
|
+
// @ts-ignore lockdown is absent on globalThis type def.
|
|
233
235
|
typeof globalThis.lockdown === 'function' &&
|
|
234
236
|
globalThis.Date.prototype.constructor !== globalThis.Date &&
|
|
235
237
|
typeof globalThis.Date.now === 'function' &&
|
|
236
|
-
// @ts-ignore
|
|
238
|
+
// @ts-ignore does not recognize that Date constructor is a special
|
|
239
|
+
// Function.
|
|
237
240
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
238
241
|
is(globalThis.Date.prototype.constructor.now(), NaN)
|
|
239
242
|
);
|
|
@@ -289,12 +292,14 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
289
292
|
);
|
|
290
293
|
globalThis.console = /** @type {Console} */ (consoleRecord.console);
|
|
291
294
|
|
|
295
|
+
// @ts-ignore assert is absent on globalThis type def.
|
|
292
296
|
if (errorTaming === 'unsafe' && globalThis.assert === assert) {
|
|
293
297
|
// If errorTaming is 'unsafe' we replace the global assert with
|
|
294
298
|
// one whose `details` template literal tag does not redact
|
|
295
299
|
// unmarked substitution values. IOW, it blabs information that
|
|
296
300
|
// was supposed to be secret from callers, as an aid to debugging
|
|
297
301
|
// at a further cost in safety.
|
|
302
|
+
// @ts-ignore assert is absent on globalThis type def.
|
|
298
303
|
globalThis.assert = makeAssert(undefined, true);
|
|
299
304
|
}
|
|
300
305
|
|
|
@@ -359,6 +364,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
359
364
|
// that is portable between JS and SES), the existence of harden in global
|
|
360
365
|
// scope signals whether such code should attempt to use harden in the
|
|
361
366
|
// defense of its own API.
|
|
367
|
+
// @ts-ignore harden not yet recognized on globalThis.
|
|
362
368
|
globalThis.harden = harden;
|
|
363
369
|
|
|
364
370
|
// Returning `true` indicates that this is a JS to SES transition.
|
package/src/make-hardener.js
CHANGED
|
@@ -27,26 +27,88 @@ import {
|
|
|
27
27
|
TypeError,
|
|
28
28
|
WeakMap,
|
|
29
29
|
WeakSet,
|
|
30
|
+
apply,
|
|
30
31
|
arrayForEach,
|
|
32
|
+
defineProperty,
|
|
31
33
|
freeze,
|
|
34
|
+
getOwnPropertyDescriptor,
|
|
32
35
|
getOwnPropertyDescriptors,
|
|
33
36
|
getPrototypeOf,
|
|
37
|
+
isInteger,
|
|
34
38
|
isObject,
|
|
35
39
|
objectHasOwnProperty,
|
|
36
40
|
ownKeys,
|
|
41
|
+
preventExtensions,
|
|
37
42
|
setAdd,
|
|
38
43
|
setForEach,
|
|
39
44
|
setHas,
|
|
45
|
+
toStringTagSymbol,
|
|
46
|
+
typedArrayPrototype,
|
|
40
47
|
weakmapGet,
|
|
41
48
|
weakmapSet,
|
|
42
49
|
weaksetAdd,
|
|
43
50
|
weaksetHas,
|
|
44
51
|
} from './commons.js';
|
|
52
|
+
import { assert } from './error/assert.js';
|
|
45
53
|
|
|
46
54
|
/**
|
|
47
55
|
* @typedef {import('../index.js').Harden} Harden
|
|
48
56
|
*/
|
|
49
57
|
|
|
58
|
+
// Obtain the string tag accessor of of TypedArray so we can indirectly use the
|
|
59
|
+
// TypedArray brand check it employs.
|
|
60
|
+
const typedArrayToStringTag = getOwnPropertyDescriptor(
|
|
61
|
+
typedArrayPrototype,
|
|
62
|
+
toStringTagSymbol,
|
|
63
|
+
);
|
|
64
|
+
assert(typedArrayToStringTag);
|
|
65
|
+
const getTypedArrayToStringTag = typedArrayToStringTag.get;
|
|
66
|
+
assert(getTypedArrayToStringTag);
|
|
67
|
+
|
|
68
|
+
// Exported for tests.
|
|
69
|
+
/** @param {unknown} object */
|
|
70
|
+
export const isTypedArray = object => {
|
|
71
|
+
// The object must pass a brand check or toStringTag will return undefined.
|
|
72
|
+
const tag = apply(getTypedArrayToStringTag, object, []);
|
|
73
|
+
return tag !== undefined;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @template T
|
|
78
|
+
* @param {ArrayLike<T>} array
|
|
79
|
+
*/
|
|
80
|
+
const freezeTypedArray = array => {
|
|
81
|
+
const descs = getOwnPropertyDescriptors(array);
|
|
82
|
+
|
|
83
|
+
preventExtensions(array);
|
|
84
|
+
|
|
85
|
+
// Downgrade writable expandos to readonly, even if non-configurable.
|
|
86
|
+
arrayForEach(ownKeys(descs), (/** @type {string | symbol} */ name) => {
|
|
87
|
+
const desc = descs[/** @type {string} */ (name)];
|
|
88
|
+
// The numbered properties are writable and non-configurable,
|
|
89
|
+
// and cannot be made non-writable by defineProperty.
|
|
90
|
+
// This is a strange behavior intrinsic to TypedArrays, but no more harmful
|
|
91
|
+
// than the mutability of properties of a hardened Map or Set,
|
|
92
|
+
// so we carve out this exceptional behavior.
|
|
93
|
+
//
|
|
94
|
+
// TypedArrays are integer-indexed exotic objects, so indexed properties
|
|
95
|
+
// outside the range of 0 to the typed array's length are disallowed.
|
|
96
|
+
// Assignment to these indexes silently fails and defining an indexed
|
|
97
|
+
// property throws an error.
|
|
98
|
+
// So, we only need to make non-index properties non-writable and
|
|
99
|
+
// non-configurable.
|
|
100
|
+
// https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects
|
|
101
|
+
const number = +String(name);
|
|
102
|
+
if (!isInteger(number)) {
|
|
103
|
+
defineProperty(array, name, {
|
|
104
|
+
...desc,
|
|
105
|
+
writable: false,
|
|
106
|
+
configurable: false,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
50
112
|
/**
|
|
51
113
|
* Create a `harden` function.
|
|
52
114
|
*
|
|
@@ -101,7 +163,12 @@ export const makeHardener = () => {
|
|
|
101
163
|
// Object are verified before being enqueued,
|
|
102
164
|
// therefore this is a valid candidate.
|
|
103
165
|
// Throws if this fails (strict mode).
|
|
104
|
-
|
|
166
|
+
// Also throws if the object is an ArrayBuffer or any TypedArray.
|
|
167
|
+
if (isTypedArray(obj)) {
|
|
168
|
+
freezeTypedArray(obj);
|
|
169
|
+
} else {
|
|
170
|
+
freeze(obj);
|
|
171
|
+
}
|
|
105
172
|
|
|
106
173
|
// we rely upon certain commitments of Object.freeze and proxies here
|
|
107
174
|
|