@lwrjs/client-modules 0.5.8 → 0.5.9

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.
@@ -113,9 +113,13 @@ const {
113
113
  } = Object;
114
114
  const {
115
115
  ownKeys: ReflectOwnKeys$2,
116
- setPrototypeOf: ReflectSetPrototypeOf
116
+ setPrototypeOf: ReflectSetPrototypeOf$2
117
117
  } = Reflect;
118
118
 
119
+ function isObject(value) {
120
+ return typeof value === 'object' && value !== null;
121
+ }
122
+
119
123
  function isObjectLike(value) {
120
124
  return typeof value === 'function' || typeof value === 'object' && value !== null;
121
125
  }
@@ -142,7 +146,7 @@ function toSafeDescriptorMap(descriptorMap) {
142
146
  const props = ReflectOwnKeys$2(descriptorMap);
143
147
 
144
148
  for (let i = 0, len = props.length; i < len; i += 1) {
145
- ReflectSetPrototypeOf(descriptorMap[props[i]], null);
149
+ ReflectSetPrototypeOf$2(descriptorMap[props[i]], null);
146
150
  }
147
151
 
148
152
  return descriptorMap;
@@ -153,7 +157,7 @@ const {
153
157
  __lookupGetter__: ObjectProto__lookupGetter__$1,
154
158
  // eslint-disable-next-line @typescript-eslint/naming-convention
155
159
  __lookupSetter__: ObjectProto__lookupSetter__,
156
- hasOwnProperty: ObjectProtoHasOwnProperty$2
160
+ hasOwnProperty: ObjectProtoHasOwnProperty$1
157
161
  } = Object.prototype;
158
162
  const {
159
163
  assign: ObjectAssign$3,
@@ -172,11 +176,11 @@ const {
172
176
  } = Object;
173
177
 
174
178
  function ObjectHasOwnProperty(obj, key) {
175
- return obj !== null && obj !== undefined && ReflectApply$3(ObjectProtoHasOwnProperty$2, obj, [key]);
179
+ return obj !== null && obj !== undefined && ReflectApply$3(ObjectProtoHasOwnProperty$1, obj, [key]);
176
180
  }
177
181
 
178
182
  function ObjectLookupOwnGetter$1(obj, key) {
179
- if (obj === null || obj === undefined || !ReflectApply$3(ObjectProtoHasOwnProperty$2, obj, [key])) {
183
+ if (obj === null || obj === undefined || !ReflectApply$3(ObjectProtoHasOwnProperty$1, obj, [key])) {
180
184
  return undefined;
181
185
  }
182
186
 
@@ -184,7 +188,7 @@ function ObjectLookupOwnGetter$1(obj, key) {
184
188
  }
185
189
 
186
190
  function ObjectLookupOwnSetter(obj, key) {
187
- if (obj === null || obj === undefined || !ReflectApply$3(ObjectProtoHasOwnProperty$2, obj, [key])) {
191
+ if (obj === null || obj === undefined || !ReflectApply$3(ObjectProtoHasOwnProperty$1, obj, [key])) {
188
192
  return undefined;
189
193
  }
190
194
 
@@ -192,7 +196,7 @@ function ObjectLookupOwnSetter(obj, key) {
192
196
  }
193
197
 
194
198
  function ObjectLookupOwnValue(obj, key) {
195
- if (obj === null || obj === undefined || !ReflectApply$3(ObjectProtoHasOwnProperty$2, obj, [key])) {
199
+ if (obj === null || obj === undefined || !ReflectApply$3(ObjectProtoHasOwnProperty$1, obj, [key])) {
196
200
  return undefined;
197
201
  }
198
202
 
@@ -245,6 +249,11 @@ const {
245
249
  } = Function.prototype;
246
250
 
247
251
  const FunctionBind = (func, thisArg) => ReflectApply$3(FunctionProtoBind, func, [thisArg]);
252
+
253
+ const {
254
+ parse: JSONParse,
255
+ stringify: JSONStringify
256
+ } = JSON;
248
257
  const {
249
258
  for: SymbolFor,
250
259
  iterator: SymbolIterator
@@ -469,7 +478,7 @@ function WeakMapGet(weakMap, key) {
469
478
  function WeakMapSet(weakMap, key, value) {
470
479
  return ReflectApply$3(WeakMapProtoSet$1, weakMap, [key, value]);
471
480
  }
472
- /*! version: 0.14.13 */
481
+ /*! version: 0.14.15 */
473
482
 
474
483
  /*!
475
484
  * Copyright (C) 2019 salesforce.com, inc.
@@ -751,6 +760,10 @@ function isSharedElement(element) {
751
760
  return element === DocumentHeadGetter(doc) || element === DocumentBodyGetter(doc);
752
761
  }
753
762
 
763
+ function JSONClone(value) {
764
+ return JSONParse(JSONStringify(value));
765
+ }
766
+
754
767
  const BlobProtoSizeGetter = ObjectLookupOwnGetter$1(Blob.prototype, 'size');
755
768
  const {
756
769
  slice: BlobProtoSlice
@@ -774,7 +787,9 @@ function BlobTypeGetter(blob) {
774
787
  return StringToLowerCase(ReflectApply$3(BlobProtoTypeGetter, blob, emptyArray$1));
775
788
  }
776
789
 
777
- const CookieStoreProto = typeof CookieStore === 'undefined' ? undefined : CookieStore.prototype; // This has to be done 1-by-1 because putting a a full file ignore in this file will result in
790
+ const CookieStoreProto = typeof CookieStore === 'undefined' ? undefined :
791
+ /* istanbul ignore next: only available in secure context */
792
+ CookieStore.prototype; // This has to be done 1-by-1 because putting a a full file ignore in this file will result in
778
793
  // dist/index.js containing the directive and subsequently being ignored.
779
794
  // istanbul ignore next
780
795
 
@@ -864,10 +879,14 @@ function HTMLElementDatasetGetter(el) {
864
879
 
865
880
  const HTMLElementInnerTextSetter = HTMLElementProtoInnerTextSetter ? function HTMLElementInnerTextSetter(el, text) {
866
881
  ReflectApply$3(HTMLElementProtoInnerTextSetter, el, [text]);
867
- } : function HTMLElementInnerTextSetter(_el, _text) {};
882
+ } :
883
+ /* istanbul ignore next: safely ignorable fallback */
884
+ function HTMLElementInnerTextSetter(_el, _text) {};
868
885
  const HTMLElementOuterTextSetter = HTMLElementProtoOuterTextSetter ? function HTMLElementOuterTextSetter(el, text) {
869
886
  ReflectApply$3(HTMLElementProtoOuterTextSetter, el, [text]);
870
- } : function HTMLElementOuterTextSetter(_el, _text) {};
887
+ } :
888
+ /* istanbul ignore next: safely ignorable fallback */
889
+ function HTMLElementOuterTextSetter(_el, _text) {};
871
890
 
872
891
  function HTMLElementStyleGetter$1(el) {
873
892
  return ReflectApply$3(HTMLElementProtoStyleGetter$1, el, emptyArray$1);
@@ -922,7 +941,9 @@ function HTMLObjectElementContentDocumentGetter(objectEl) {
922
941
 
923
942
  const HTMLObjectElementContentWindowGetter = HTMLObjectElementProtoContentWindowGetter ? function HTMLObjectElementContentWindowGetter(objectEl) {
924
943
  return ReflectApply$3(HTMLObjectElementProtoContentWindowGetter, objectEl, emptyArray$1);
925
- } : function HTMLObjectElementContentWindowGetter(_objectEl) {
944
+ } :
945
+ /* istanbul ignore next: safely ignorable fallback */
946
+ function HTMLObjectElementContentWindowGetter(_objectEl) {
926
947
  return null;
927
948
  };
928
949
  const {
@@ -987,8 +1008,8 @@ const {
987
1008
  createObjectURL: URLCreateObjectURL,
988
1009
  revokeObjectURL: URLRevokeObjectURL
989
1010
  } = URL;
990
- const ALLOW_LIST_PATCHED = ['opener', 'parent'];
991
- const ALLOW_LIST_RAW = ['close', 'closed', 'focus', 'postMessage'];
1011
+ const ALLOW_LIST_PATCHED = ['opener', 'parent', 'postMessage'];
1012
+ const ALLOW_LIST_RAW = ['close', 'closed', 'focus'];
992
1013
  const DEFAULT_OVERWRITTEN_VALUE = {};
993
1014
  const {
994
1015
  clearInterval: WindowStaticClearInterval
@@ -996,8 +1017,30 @@ const {
996
1017
  const WindowStaticLengthGetter = ObjectLookupOwnGetter$1(window, 'length');
997
1018
  const WindowStaticOpenerGetter = ObjectLookupOwnGetter$1(window, 'opener');
998
1019
  const WindowStaticParentGetter = ObjectLookupOwnGetter$1(window, 'parent');
1020
+ const WindowStaticPostMessageValue = ObjectLookupOwnValue(window, 'postMessage');
999
1021
  const WindowStaticSelfGetter = ObjectLookupOwnGetter$1(window, 'self');
1000
- const patchedWindowMap = new WeakMapCtor(); // istanbul ignore next
1022
+ const patchedWindowMap = new WeakMapCtor(); // NOTE: Currently, only used for "postMessage" to unwrap plain objects and primitives.
1023
+ // This is a temporary fix that would remove classes, functions, callbacks, etc.
1024
+
1025
+ function patchedWindowPostMessageValue() {
1026
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1027
+ args[_key5] = arguments[_key5];
1028
+ }
1029
+
1030
+ const message = args.length ? args[0] : undefined;
1031
+
1032
+ if (isObject(message)) {
1033
+ try {
1034
+ args[0] = JSONClone(message);
1035
+ } catch (_unused) {
1036
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
1037
+ throw new DOMException('The object could not be cloned.');
1038
+ }
1039
+ }
1040
+
1041
+ return ReflectApply$3(WindowStaticPostMessageValue, this, args);
1042
+ } // istanbul ignore next
1043
+
1001
1044
 
1002
1045
  function createPatchedWindow(rawWindow) {
1003
1046
  const patchedWindow = {};
@@ -1048,7 +1091,8 @@ function createPatchedWindow(rawWindow) {
1048
1091
  ReflectSetPrototypeOf$1(originalDescriptor, null);
1049
1092
  const {
1050
1093
  get: originalDescriptorGetter,
1051
- set: originalDescriptorSetter
1094
+ set: originalDescriptorSetter,
1095
+ value: originalDescriptorValue
1052
1096
  } = originalDescriptor;
1053
1097
  let overwrittenValue = DEFAULT_OVERWRITTEN_VALUE;
1054
1098
 
@@ -1068,6 +1112,16 @@ function createPatchedWindow(rawWindow) {
1068
1112
  };
1069
1113
  }
1070
1114
 
1115
+ if (key === 'postMessage' && typeof originalDescriptorValue === 'function') {
1116
+ originalDescriptor.value = function postMessage() {
1117
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1118
+ args[_key6] = arguments[_key6];
1119
+ }
1120
+
1121
+ return ReflectApply$3(patchedWindowPostMessageValue, rawWindow, args);
1122
+ };
1123
+ }
1124
+
1071
1125
  ReflectDefineProperty(patchedWindow, key, originalDescriptor);
1072
1126
  }
1073
1127
  }
@@ -1120,7 +1174,7 @@ function isWindow(value) {
1120
1174
  // https://html.spec.whatwg.org/multipage/window-object.html#dom-self
1121
1175
  WindowSelfGetter(value);
1122
1176
  return true; // eslint-disable-next-line no-empty
1123
- } catch (_unused) {}
1177
+ } catch (_unused2) {}
1124
1178
 
1125
1179
  return false;
1126
1180
  }
@@ -1146,8 +1200,8 @@ function WindowSelfGetter(win) {
1146
1200
  }
1147
1201
 
1148
1202
  function WindowSetInterval(win) {
1149
- for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
1150
- args[_key5 - 1] = arguments[_key5];
1203
+ for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
1204
+ args[_key7 - 1] = arguments[_key7];
1151
1205
  }
1152
1206
 
1153
1207
  return ReflectApply$3(WindowStaticSetInterval, win, args);
@@ -1193,7 +1247,7 @@ function XhrStatusGetter(xhr) {
1193
1247
  function XhrWithCredentialsSetter(xhr, bool) {
1194
1248
  ReflectApply$3(XhrProtoWithCredentialsSetter, xhr, [bool]);
1195
1249
  }
1196
- /*! version: 0.14.13 */
1250
+ /*! version: 0.14.15 */
1197
1251
 
1198
1252
  /*!
1199
1253
  * Copyright (C) 2019 salesforce.com, inc.
@@ -1232,7 +1286,7 @@ function sanitizeURLForElement(url) {
1232
1286
  function sanitizeURLString(urlString) {
1233
1287
  return urlString === '' ? urlString : StringReplace(urlString, REMOVE_URL_CHARS_REGEXP, '');
1234
1288
  }
1235
- /*! version: 0.14.13 */
1289
+ /*! version: 0.14.15 */
1236
1290
 
1237
1291
  /*! @license DOMPurify | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.2.2/LICENSE */
1238
1292
 
@@ -2800,7 +2854,7 @@ function sanitizeSvgTextReturnDOM(dirty) {
2800
2854
  const sanitizer = svgSanitizer();
2801
2855
  return sanitizer.sanitize(dirty);
2802
2856
  }
2803
- /*! version: 0.14.13 */
2857
+ /*! version: 0.14.15 */
2804
2858
 
2805
2859
  /*!
2806
2860
  * Copyright (C) 2019 salesforce.com, inc.
@@ -3183,6 +3237,8 @@ function prefixCookieName(detailsOrName, key) {
3183
3237
 
3184
3238
  return detailsOrName;
3185
3239
  }
3240
+ /* istanbul ignore next: only available in secure context */
3241
+
3186
3242
 
3187
3243
  function factoryPatchedDeleteValue(globalObject, options) {
3188
3244
  const {
@@ -3219,6 +3275,8 @@ function factoryPatchedDeleteValue(globalObject, options) {
3219
3275
 
3220
3276
  return [originalDeleteValue, deleteValue];
3221
3277
  }
3278
+ /* istanbul ignore next: only available in secure context */
3279
+
3222
3280
 
3223
3281
  function factoryPatchedGetValue(globalObject, options) {
3224
3282
  const {
@@ -3255,6 +3313,8 @@ function factoryPatchedGetValue(globalObject, options) {
3255
3313
 
3256
3314
  return [originalGetValue, get];
3257
3315
  }
3316
+ /* istanbul ignore next: only available in secure context */
3317
+
3258
3318
 
3259
3319
  function factoryPatchedGetAllValue(globalObject, options) {
3260
3320
  const {
@@ -3306,6 +3366,8 @@ function factoryPatchedGetAllValue(globalObject, options) {
3306
3366
 
3307
3367
  return [originalGetAllValue, getAll];
3308
3368
  }
3369
+ /* istanbul ignore next: only available in secure context */
3370
+
3309
3371
 
3310
3372
  function factoryPatchedSetValue(globalObject, options) {
3311
3373
  const {
@@ -5238,6 +5300,20 @@ function factoryPatchedParent(globalObject) {
5238
5300
  return [originalParentGetter, parent];
5239
5301
  }
5240
5302
 
5303
+ function factoryPatchedPostMessage(globalObject) {
5304
+ const originalPostMessageValue = ObjectLookupOwnValue(globalObject, 'postMessage');
5305
+
5306
+ function postMessage() {
5307
+ for (var _len12 = arguments.length, args = new Array(_len12), _key13 = 0; _key13 < _len12; _key13++) {
5308
+ args[_key13] = arguments[_key13];
5309
+ }
5310
+
5311
+ return ReflectApply$3(patchedWindowPostMessageValue, this, args);
5312
+ }
5313
+
5314
+ return [originalPostMessageValue, postMessage];
5315
+ }
5316
+
5241
5317
  function patchedSetIntervalValue(globalObject, options) {
5242
5318
  const {
5243
5319
  evaluator,
@@ -5248,8 +5324,8 @@ function patchedSetIntervalValue(globalObject, options) {
5248
5324
  } = globalObject;
5249
5325
 
5250
5326
  function setInterval() {
5251
- for (var _len12 = arguments.length, args = new Array(_len12), _key13 = 0; _key13 < _len12; _key13++) {
5252
- args[_key13] = arguments[_key13];
5327
+ for (var _len13 = arguments.length, args = new Array(_len13), _key14 = 0; _key14 < _len13; _key14++) {
5328
+ args[_key14] = arguments[_key14];
5253
5329
  }
5254
5330
 
5255
5331
  if (args.length) {
@@ -5281,8 +5357,8 @@ function patchedSetTimeoutValue(globalObject, options) {
5281
5357
  } = globalObject;
5282
5358
 
5283
5359
  let setTimeout = function setTimeout() {
5284
- for (var _len13 = arguments.length, args = new Array(_len13), _key14 = 0; _key14 < _len13; _key14++) {
5285
- args[_key14] = arguments[_key14];
5360
+ for (var _len14 = arguments.length, args = new Array(_len14), _key15 = 0; _key15 < _len14; _key15++) {
5361
+ args[_key15] = arguments[_key15];
5286
5362
  }
5287
5363
 
5288
5364
  if (args.length) {
@@ -5383,7 +5459,7 @@ patchedConstructor$1, factoryPatchedPrototype, // Storage
5383
5459
  storagePropertyLength, storageGetItemValue, storageSetItemValue, storageKeyValue, storageRemoveItemValue, storageClearValue, storage, // SVGUseElement
5384
5460
  patchedSVGUseElementHrefAttributeSetter, patchedSVGUseElementXlinkHrefAttributeSetter, // URL
5385
5461
  patchedCreateObjectURL, // Window
5386
- patchedFetchValue, factoryPatchedFrames, factoryPatchedLength, patchedOpenValue$1, factoryPatchedOpener, factoryPatchedParent, // Worker
5462
+ patchedFetchValue, factoryPatchedFrames, factoryPatchedLength, patchedOpenValue$1, factoryPatchedOpener, factoryPatchedParent, factoryPatchedPostMessage, // Worker
5387
5463
  patchedConstructor, patchedPrototype, // XHR
5388
5464
  patchedOpenValue];
5389
5465
  const fundamentalKeyedDistortionFactories = [// Aura
@@ -5436,8 +5512,8 @@ function makeBlockedPropertyDistortionFactories(globalObject) {
5436
5512
 
5437
5513
  const instrumentDistortionForSandbox = (sandboxKey, value, errorBeacon) => function instrumentedDistortionWrapper() {
5438
5514
  try {
5439
- for (var _len14 = arguments.length, args = new Array(_len14), _key15 = 0; _key15 < _len14; _key15++) {
5440
- args[_key15] = arguments[_key15];
5515
+ for (var _len15 = arguments.length, args = new Array(_len15), _key16 = 0; _key16 < _len15; _key16++) {
5516
+ args[_key16] = arguments[_key16];
5441
5517
  }
5442
5518
 
5443
5519
  return ReflectApply$3(value, this, args);
@@ -5511,7 +5587,7 @@ function createExternalDistortionEntries(globalObject, key, evaluator, config) {
5511
5587
  ReflectApply$3(ArrayProtoPush, entries, makeElementDistortionsForSandboxKey(key));
5512
5588
  return entries;
5513
5589
  } // @TODO: [Issue #373] Abstract common code in sandbox and distortion packages
5514
- /*! version: 0.14.13 */
5590
+ /*! version: 0.14.15 */
5515
5591
 
5516
5592
  /*!
5517
5593
  * Copyright (C) 2021 salesforce.com, inc.
@@ -5634,8 +5710,11 @@ class DefaultInstrumentation {
5634
5710
 
5635
5711
 
5636
5712
  const defaultInstrumentation = new DefaultInstrumentation();
5637
- /*! version: 0.14.13 */
5713
+ /*! version: 0.14.15 */
5638
5714
 
5715
+ /*!
5716
+ * Copyright (C) 2019 salesforce.com, inc.
5717
+ */
5639
5718
  /**
5640
5719
  * This file contains an exportable (portable) function `init` used to initialize
5641
5720
  * one side of a membrane on any realm. The only prerequisite is the ability to evaluate
@@ -5656,1347 +5735,1644 @@ const defaultInstrumentation = new DefaultInstrumentation();
5656
5735
  * the foreign operation operates, it is always the first argument of the foreign
5657
5736
  * callable for proxies, and the other side can use it via `getSelectedTarget`.
5658
5737
  */
5659
- // eslint-disable-next-line no-shadow
5738
+
5739
+ const {
5740
+ setPrototypeOf: ReflectSetPrototypeOf
5741
+ } = Reflect; // eslint-disable-next-line no-shadow
5742
+
5660
5743
  var SupportFlagsEnum;
5744
+
5661
5745
  (function (SupportFlagsEnum) {
5662
- SupportFlagsEnum[SupportFlagsEnum["None"] = 0] = "None";
5663
- SupportFlagsEnum[SupportFlagsEnum["MagicMarker"] = 1] = "MagicMarker";
5746
+ SupportFlagsEnum[SupportFlagsEnum["None"] = 0] = "None";
5747
+ SupportFlagsEnum[SupportFlagsEnum["MagicMarker"] = 1] = "MagicMarker";
5664
5748
  })(SupportFlagsEnum || (SupportFlagsEnum = {}));
5665
- // istanbul ignore next
5749
+
5750
+ ReflectSetPrototypeOf(SupportFlagsEnum, null); // istanbul ignore next
5751
+
5666
5752
  function createMembraneMarshall() {
5667
- // eslint-disable-next-line no-shadow
5668
- let MarshallSupportFlagsField;
5669
- (function (MarshallSupportFlagsField) {
5670
- MarshallSupportFlagsField[MarshallSupportFlagsField["None"] = 0] = "None";
5671
- MarshallSupportFlagsField[MarshallSupportFlagsField["MagicMarker"] = 1] = "MagicMarker";
5672
- })(MarshallSupportFlagsField || (MarshallSupportFlagsField = {}));
5673
- // eslint-disable-next-line no-shadow
5674
- let TargetIntegrityTraits;
5675
- (function (TargetIntegrityTraits) {
5676
- TargetIntegrityTraits[TargetIntegrityTraits["None"] = 0] = "None";
5677
- TargetIntegrityTraits[TargetIntegrityTraits["IsNotExtensible"] = 1] = "IsNotExtensible";
5678
- TargetIntegrityTraits[TargetIntegrityTraits["IsSealed"] = 2] = "IsSealed";
5679
- TargetIntegrityTraits[TargetIntegrityTraits["IsFrozen"] = 4] = "IsFrozen";
5680
- TargetIntegrityTraits[TargetIntegrityTraits["Revoked"] = 16] = "Revoked";
5681
- })(TargetIntegrityTraits || (TargetIntegrityTraits = {}));
5682
- // eslint-disable-next-line no-shadow
5683
- let TargetTraits;
5684
- (function (TargetTraits) {
5685
- TargetTraits[TargetTraits["None"] = 0] = "None";
5686
- TargetTraits[TargetTraits["IsArray"] = 1] = "IsArray";
5687
- TargetTraits[TargetTraits["IsFunction"] = 2] = "IsFunction";
5688
- TargetTraits[TargetTraits["IsObject"] = 4] = "IsObject";
5689
- TargetTraits[TargetTraits["IsArrowFunction"] = 8] = "IsArrowFunction";
5690
- TargetTraits[TargetTraits["Revoked"] = 16] = "Revoked";
5691
- })(TargetTraits || (TargetTraits = {}));
5692
- const { eval: cachedLocalEval } = globalThis;
5693
- const ArrayCtor = Array;
5694
- const { isArray: isArrayOrNotOrThrowForRevoked } = Array;
5695
- const { defineProperties: ObjectDefineProperties, freeze: ObjectFreeze, isFrozen: ObjectIsFrozen, isSealed: ObjectIsSealed, seal: ObjectSeal, } = Object;
5696
- const { hasOwnProperty: ObjectProtoHasOwnProperty, toString: ObjectProtoToString } = Object.prototype;
5697
- const { revocable: ProxyRevocable } = Proxy;
5698
- const { defineProperty: ReflectDefineProperty, getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor, setPrototypeOf: ReflectSetPrototypeOf, apply: ReflectApply, construct: ReflectConstruct, deleteProperty: ReflectDeleteProperty, get: ReflectGet, set: ReflectSet, has: ReflectHas, getPrototypeOf: ReflectGetPrototypeOf, isExtensible: ReflectIsExtensible, ownKeys: ReflectOwnKeys, preventExtensions: ReflectPreventExtensions, } = Reflect;
5699
- const { slice: StringProtoSlice } = String.prototype;
5700
- const TypeErrorCtor = TypeError;
5701
- const { get: WeakMapProtoGet, set: WeakMapProtoSet } = WeakMap.prototype;
5702
- const LOCKER_LIVE_MARKER_SYMBOL = Symbol.for('@@lockerLiveValue');
5703
- const LOCKER_MAGIC_MARKER_SYMBOL = Symbol.for('@@lockerMagicValue');
5704
- const { toStringTag: TO_STRING_TAG_SYMBOL } = Symbol;
5705
- const UNDEFINED_SYMBOL = Symbol.for('@@membraneUndefinedValue');
5706
- return function createHooksCallback(color, trapMutations, supportFlags = SupportFlagsEnum.None, foreignCallableHooksCallback, options) {
5707
- const { distortionCallback = (o) => o, instrumentation } = options || {
5708
- __proto__: null,
5709
- };
5710
- const proxyTargetToPointerMap = new WeakMap();
5711
- const SUPPORT_MAGIC_MARKER = !!(supportFlags & MarshallSupportFlagsField.MagicMarker);
5712
- const INBOUND_INSTRUMENTATION_LABEL = `to:${color}`;
5713
- const OUTBOUND_INSTRUMENTATION_LABEL = `from:${color}`;
5714
- let foreignCallablePushTarget;
5715
- let foreignCallableApply;
5716
- let foreignCallableConstruct;
5717
- let foreignCallableDefineProperty;
5718
- let foreignCallableDeleteProperty;
5719
- let foreignCallableGetOwnPropertyDescriptor;
5720
- let foreignCallableGetPrototypeOf;
5721
- let foreignCallableIsExtensible;
5722
- let foreignCallableOwnKeys;
5723
- let foreignCallablePreventExtensions;
5724
- let foreignCallableSet;
5725
- let foreignCallableSetPrototypeOf;
5726
- let foreignCallableGetTargetIntegrityTraits;
5727
- let foreignCallableGetUnbrandedTag;
5728
- let foreignCallableHasOwnProperty;
5729
- let selectedTarget;
5730
- if (ReflectApply(ObjectProtoHasOwnProperty, Error, ['stackTraceLimit']) &&
5731
- typeof Error.stackTraceLimit === 'number') {
5732
- // The default stack trace limit is 10.
5733
- // Increasing to 20 as a baby step.
5734
- Error.stackTraceLimit *= 2;
5753
+ const {
5754
+ eval: cachedLocalEval
5755
+ } = globalThis;
5756
+ const ArrayCtor = Array;
5757
+ const {
5758
+ isArray: isArrayOrNotOrThrowForRevoked
5759
+ } = Array;
5760
+ const {
5761
+ defineProperties: ObjectDefineProperties,
5762
+ freeze: ObjectFreeze,
5763
+ isFrozen: ObjectIsFrozen,
5764
+ isSealed: ObjectIsSealed,
5765
+ seal: ObjectSeal
5766
+ } = Object;
5767
+ const {
5768
+ hasOwnProperty: ObjectProtoHasOwnProperty,
5769
+ toString: ObjectProtoToString
5770
+ } = Object.prototype;
5771
+ const {
5772
+ revocable: ProxyRevocable
5773
+ } = Proxy;
5774
+ const {
5775
+ apply: ReflectApply,
5776
+ construct: ReflectConstruct,
5777
+ defineProperty: ReflectDefineProperty,
5778
+ deleteProperty: ReflectDeleteProperty,
5779
+ get: ReflectGet,
5780
+ getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
5781
+ getPrototypeOf: ReflectGetPrototypeOf,
5782
+ has: ReflectHas,
5783
+ isExtensible: ReflectIsExtensible,
5784
+ ownKeys: ReflectOwnKeys,
5785
+ preventExtensions: ReflectPreventExtensions,
5786
+ set: ReflectSet,
5787
+ // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
5788
+ setPrototypeOf: ReflectSetPrototypeOf
5789
+ } = Reflect;
5790
+ const {
5791
+ slice: StringProtoSlice
5792
+ } = String.prototype;
5793
+ const TypeErrorCtor = TypeError;
5794
+ const {
5795
+ get: WeakMapProtoGet,
5796
+ set: WeakMapProtoSet
5797
+ } = WeakMap.prototype;
5798
+ const LOCKER_LIVE_MARKER_SYMBOL = Symbol.for('@@lockerLiveValue');
5799
+ const LOCKER_MAGIC_MARKER_SYMBOL = Symbol.for('@@lockerMagicValue');
5800
+ const {
5801
+ toStringTag: TO_STRING_TAG_SYMBOL
5802
+ } = Symbol;
5803
+ const UNDEFINED_SYMBOL = Symbol.for('@@membraneUndefinedValue'); // eslint-disable-next-line no-shadow
5804
+
5805
+ let MarshallSupportFlagsField;
5806
+
5807
+ (function (MarshallSupportFlagsField) {
5808
+ MarshallSupportFlagsField[MarshallSupportFlagsField["None"] = 0] = "None";
5809
+ MarshallSupportFlagsField[MarshallSupportFlagsField["MagicMarker"] = 1] = "MagicMarker";
5810
+ })(MarshallSupportFlagsField || (MarshallSupportFlagsField = {}));
5811
+
5812
+ ReflectSetPrototypeOf(MarshallSupportFlagsField, null); // eslint-disable-next-line no-shadow
5813
+
5814
+ let TargetIntegrityTraits;
5815
+
5816
+ (function (TargetIntegrityTraits) {
5817
+ TargetIntegrityTraits[TargetIntegrityTraits["None"] = 0] = "None";
5818
+ TargetIntegrityTraits[TargetIntegrityTraits["IsNotExtensible"] = 1] = "IsNotExtensible";
5819
+ TargetIntegrityTraits[TargetIntegrityTraits["IsSealed"] = 2] = "IsSealed";
5820
+ TargetIntegrityTraits[TargetIntegrityTraits["IsFrozen"] = 4] = "IsFrozen";
5821
+ TargetIntegrityTraits[TargetIntegrityTraits["Revoked"] = 16] = "Revoked";
5822
+ })(TargetIntegrityTraits || (TargetIntegrityTraits = {}));
5823
+
5824
+ ReflectSetPrototypeOf(TargetIntegrityTraits, null); // eslint-disable-next-line no-shadow
5825
+
5826
+ let TargetTraits;
5827
+
5828
+ (function (TargetTraits) {
5829
+ TargetTraits[TargetTraits["None"] = 0] = "None";
5830
+ TargetTraits[TargetTraits["IsArray"] = 1] = "IsArray";
5831
+ TargetTraits[TargetTraits["IsFunction"] = 2] = "IsFunction";
5832
+ TargetTraits[TargetTraits["IsObject"] = 4] = "IsObject";
5833
+ TargetTraits[TargetTraits["IsArrowFunction"] = 8] = "IsArrowFunction";
5834
+ TargetTraits[TargetTraits["Revoked"] = 16] = "Revoked";
5835
+ })(TargetTraits || (TargetTraits = {}));
5836
+
5837
+ ReflectSetPrototypeOf(TargetTraits, null);
5838
+ return function createHooksCallback(color, trapMutations) {
5839
+ let supportFlags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SupportFlagsEnum.None;
5840
+ let foreignCallableHooksCallback = arguments.length > 3 ? arguments[3] : undefined;
5841
+ let options = arguments.length > 4 ? arguments[4] : undefined;
5842
+ const {
5843
+ distortionCallback = o => o,
5844
+ instrumentation
5845
+ } = options || {
5846
+ __proto__: null
5847
+ };
5848
+ const proxyTargetToPointerMap = new WeakMap();
5849
+ const INBOUND_INSTRUMENTATION_LABEL = `to:${color}`;
5850
+ const OUTBOUND_INSTRUMENTATION_LABEL = `from:${color}`;
5851
+ const SUPPORT_MAGIC_MARKER = !!(supportFlags & MarshallSupportFlagsField.MagicMarker);
5852
+ let foreignCallablePushTarget;
5853
+ let foreignCallableApply;
5854
+ let foreignCallableConstruct;
5855
+ let foreignCallableDefineProperty;
5856
+ let foreignCallableDeleteProperty;
5857
+ let foreignCallableGetOwnPropertyDescriptor;
5858
+ let foreignCallableGetPrototypeOf;
5859
+ let foreignCallableIsExtensible;
5860
+ let foreignCallableOwnKeys;
5861
+ let foreignCallablePreventExtensions;
5862
+ let foreignCallableSet;
5863
+ let foreignCallableSetPrototypeOf;
5864
+ let foreignCallableGetTargetIntegrityTraits;
5865
+ let foreignCallableGetUnbrandedTag;
5866
+ let foreignCallableHasOwnProperty;
5867
+ let selectedTarget;
5868
+
5869
+ function copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer) {
5870
+ let keys = [];
5871
+ foreignCallableOwnKeys(foreignTargetPointer, function () {
5872
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5873
+ args[_key] = arguments[_key];
5735
5874
  }
5736
- function copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer) {
5737
- let keys = [];
5738
- foreignCallableOwnKeys(foreignTargetPointer, (...args) => {
5739
- keys = args;
5740
- });
5741
- const descriptors = {};
5742
- let safeDesc;
5743
- const callbackWithDescriptor = (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
5744
- safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
5745
- };
5746
- for (let i = 0, len = keys.length; i < len; i += 1) {
5747
- const key = keys[i];
5748
- foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, callbackWithDescriptor);
5749
- descriptors[key] = safeDesc;
5750
- }
5751
- // Use `ObjectDefineProperties` instead of individual
5752
- // `ReflectDefineProperty` calls for better performance.
5753
- ObjectDefineProperties(shadowTarget, descriptors);
5875
+
5876
+ keys = args;
5877
+ });
5878
+ const descriptors = {};
5879
+ let safeDesc;
5880
+
5881
+ const callbackWithDescriptor = (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
5882
+ safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
5883
+ };
5884
+
5885
+ for (let i = 0, len = keys.length; i < len; i += 1) {
5886
+ const key = keys[i];
5887
+ foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, callbackWithDescriptor);
5888
+
5889
+ if (safeDesc) {
5890
+ descriptors[key] = safeDesc;
5754
5891
  }
5755
- // metadata is the transferable descriptor definition
5756
- function createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer) {
5892
+ } // Use `ObjectDefineProperties` instead of individual
5893
+ // `ReflectDefineProperty` calls for better performance.
5894
+
5895
+
5896
+ ObjectDefineProperties(shadowTarget, descriptors);
5897
+ } // metadata is the transferable descriptor definition
5898
+
5899
+
5900
+ function createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer) {
5901
+ // @ts-ignore: TS doesn't like __proto__ on property descriptors.
5902
+ const safeDesc = {
5903
+ __proto__: null
5904
+ };
5905
+
5906
+ if (configurable !== UNDEFINED_SYMBOL) {
5907
+ safeDesc.configurable = !!configurable;
5908
+ }
5909
+
5910
+ if (enumerable !== UNDEFINED_SYMBOL) {
5911
+ safeDesc.enumerable = !!enumerable;
5912
+ }
5913
+
5914
+ if (writable !== UNDEFINED_SYMBOL) {
5915
+ safeDesc.writable = !!writable;
5916
+ }
5917
+
5918
+ if (getPointer !== UNDEFINED_SYMBOL) {
5919
+ safeDesc.get = getLocalValue(getPointer);
5920
+ }
5921
+
5922
+ if (setPointer !== UNDEFINED_SYMBOL) {
5923
+ safeDesc.set = getLocalValue(setPointer);
5924
+ }
5925
+
5926
+ if (valuePointer !== UNDEFINED_SYMBOL) {
5927
+ safeDesc.value = getLocalValue(valuePointer);
5928
+ }
5929
+
5930
+ return safeDesc;
5931
+ }
5932
+
5933
+ function createPointer(originalTarget) {
5934
+ // assert: originalTarget is a ProxyTarget
5935
+ const pointer = () => {
5936
+ // assert: selectedTarget is undefined
5937
+ selectedTarget = originalTarget;
5938
+ };
5939
+
5940
+ {
5941
+ // In case debugging is needed, the following lines can help:
5942
+ pointer['[[OriginalTarget]]'] = originalTarget;
5943
+ pointer['[[Color]]'] = color;
5944
+ }
5945
+ return pointer;
5946
+ }
5947
+
5948
+ function createShadowTarget(targetTraits, targetFunctionName) {
5949
+ let shadowTarget;
5950
+
5951
+ if (targetTraits & TargetTraits.IsFunction) {
5952
+ // This shadow target is never invoked. It's needed to avoid
5953
+ // proxy trap invariants. Because it's not invoked the code does
5954
+ // not need to be instrumented for code coverage.
5955
+ //
5956
+ // istanbul ignore next
5957
+ shadowTarget = // eslint-disable-next-line func-names
5958
+ targetTraits & TargetTraits.IsArrowFunction ? () => {} : function () {};
5959
+ {
5960
+ // This is only really needed for debugging,
5961
+ // it helps to identify the proxy by name
5962
+ ReflectDefineProperty(shadowTarget, 'name', {
5757
5963
  // @ts-ignore: TS doesn't like __proto__ on property descriptors.
5758
- const safeDesc = { __proto__: null };
5759
- if (configurable !== UNDEFINED_SYMBOL) {
5760
- safeDesc.configurable = !!configurable;
5761
- }
5762
- if (enumerable !== UNDEFINED_SYMBOL) {
5763
- safeDesc.enumerable = !!enumerable;
5764
- }
5765
- if (writable !== UNDEFINED_SYMBOL) {
5766
- safeDesc.writable = !!writable;
5767
- }
5768
- if (getPointer !== UNDEFINED_SYMBOL) {
5769
- safeDesc.get = getLocalValue(getPointer);
5770
- }
5771
- if (setPointer !== UNDEFINED_SYMBOL) {
5772
- safeDesc.set = getLocalValue(setPointer);
5773
- }
5774
- if (valuePointer !== UNDEFINED_SYMBOL) {
5775
- safeDesc.value = getLocalValue(valuePointer);
5776
- }
5777
- return safeDesc;
5964
+ __proto__: null,
5965
+ configurable: true,
5966
+ enumerable: false,
5967
+ value: targetFunctionName,
5968
+ writable: false
5969
+ });
5778
5970
  }
5779
- function createPointer(originalTarget) {
5780
- // assert: originalTarget is a ProxyTarget
5781
- const pointer = () => {
5782
- // assert: selectedTarget is undefined
5783
- selectedTarget = originalTarget;
5784
- };
5785
- {
5786
- // In case debugging is needed, the following lines can help:
5787
- pointer['[[OriginalTarget]]'] = originalTarget;
5788
- pointer['[[Color]]'] = color;
5789
- }
5790
- return pointer;
5971
+ } else {
5972
+ // target is array or object
5973
+ shadowTarget = targetTraits & TargetTraits.IsArray ? [] : {};
5974
+ }
5975
+
5976
+ return shadowTarget;
5977
+ } // this is needed even when using ShadowRealm, because the errors are not going
5978
+ // to cross the callable boundary in a try/catch, instead, they need to be ported
5979
+ // via the membrane artifacts.
5980
+
5981
+
5982
+ function foreignErrorControl(foreignFn) {
5983
+ return function foreignErrorControlFn() {
5984
+ try {
5985
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
5986
+ args[_key2] = arguments[_key2];
5987
+ }
5988
+
5989
+ return ReflectApply(foreignFn, this, args);
5990
+ } catch (e) {
5991
+ const pushedError = getSelectedTarget();
5992
+
5993
+ if (pushedError) {
5994
+ throw pushedError;
5995
+ }
5996
+
5997
+ throw new TypeErrorCtor(e === null || e === void 0 ? void 0 : e.message);
5791
5998
  }
5792
- function createShadowTarget(targetTraits, targetFunctionName) {
5793
- let shadowTarget;
5794
- if (targetTraits & TargetTraits.IsFunction) {
5795
- // This shadow target is never invoked. It's needed to avoid
5796
- // proxy trap invariants. Because it's not invoked the code does
5797
- // not need to be instrumented for code coverage.
5798
- //
5799
- // istanbul ignore next
5800
- shadowTarget =
5801
- // eslint-disable-next-line func-names
5802
- targetTraits & TargetTraits.IsArrowFunction ? () => { } : function () { };
5803
- {
5804
- // This is only really needed for debugging,
5805
- // it helps to identify the proxy by name
5806
- ReflectDefineProperty(shadowTarget, 'name', {
5807
- // @ts-ignore: TS doesn't like __proto__ on property descriptors.
5808
- __proto__: null,
5809
- configurable: true,
5810
- enumerable: false,
5811
- value: targetFunctionName,
5812
- writable: false,
5813
- });
5814
- }
5815
- }
5816
- else {
5817
- // target is array or object
5818
- shadowTarget = targetTraits & TargetTraits.IsArray ? [] : {};
5819
- }
5820
- return shadowTarget;
5999
+ };
6000
+ }
6001
+
6002
+ function getDescriptorMeta(unsafePartialDesc) {
6003
+ const safePartialDesc = toSafeDescriptor(unsafePartialDesc);
6004
+ const {
6005
+ configurable,
6006
+ enumerable,
6007
+ writable,
6008
+ value,
6009
+ get,
6010
+ set
6011
+ } = safePartialDesc;
6012
+ return ['configurable' in safePartialDesc ? !!configurable : UNDEFINED_SYMBOL, 'enumerable' in safePartialDesc ? !!enumerable : UNDEFINED_SYMBOL, 'writable' in safePartialDesc ? !!writable : UNDEFINED_SYMBOL, 'value' in safePartialDesc ? getTransferableValue(value) : UNDEFINED_SYMBOL, 'get' in safePartialDesc ? getTransferableValue(get) : UNDEFINED_SYMBOL, 'set' in safePartialDesc ? getTransferableValue(set) : UNDEFINED_SYMBOL];
6013
+ }
6014
+
6015
+ function getDistortedValue(target) {
6016
+ let distortedTarget;
6017
+
6018
+ try {
6019
+ distortedTarget = distortionCallback(target);
6020
+ return distortedTarget;
6021
+ } finally {
6022
+ // if a distortion entry is found, it must be a valid proxy target
6023
+ if (distortedTarget !== target && typeof distortedTarget !== typeof target) {
6024
+ // eslint-disable-next-line no-unsafe-finally
6025
+ throw new TypeErrorCtor(`Invalid distortion ${target}.`);
5821
6026
  }
5822
- // this is needed even when using ShadowRealm, because the errors are not going
5823
- // to cross the callable boundary in a try/catch, instead, they need to be ported
5824
- // via the membrane artifacts.
5825
- function foreignErrorControl(foreignFn) {
5826
- return function foreignErrorControlFn(...args) {
5827
- try {
5828
- return ReflectApply(foreignFn, this, args);
5829
- }
5830
- catch (e) {
5831
- const pushedError = getSelectedTarget();
5832
- if (pushedError) {
5833
- throw pushedError;
5834
- }
5835
- throw new TypeErrorCtor(e?.message);
5836
- }
5837
- };
6027
+ }
6028
+ }
6029
+
6030
+ function getInheritedPropertyDescriptor(foreignTargetPointer, key) {
6031
+ // Avoiding calling the has trap for any proto chain operation,
6032
+ // instead we implement the regular logic here in this trap.
6033
+ let currentObject = liveGetPrototypeOf(foreignTargetPointer);
6034
+
6035
+ while (currentObject) {
6036
+ const unsafeParentDesc = ReflectGetOwnPropertyDescriptor(currentObject, key);
6037
+
6038
+ if (unsafeParentDesc) {
6039
+ return toSafeDescriptor(unsafeParentDesc);
5838
6040
  }
5839
- function getDescriptorMeta(unsafePartialDesc) {
5840
- const safePartialDesc = toSafeDescriptor(unsafePartialDesc);
5841
- const { configurable, enumerable, writable, value, get, set } = safePartialDesc;
5842
- return [
5843
- 'configurable' in safePartialDesc ? !!configurable : UNDEFINED_SYMBOL,
5844
- 'enumerable' in safePartialDesc ? !!enumerable : UNDEFINED_SYMBOL,
5845
- 'writable' in safePartialDesc ? !!writable : UNDEFINED_SYMBOL,
5846
- 'value' in safePartialDesc ? getTransferableValue(value) : UNDEFINED_SYMBOL,
5847
- 'get' in safePartialDesc ? getTransferableValue(get) : UNDEFINED_SYMBOL,
5848
- 'set' in safePartialDesc ? getTransferableValue(set) : UNDEFINED_SYMBOL,
5849
- ];
6041
+
6042
+ currentObject = ReflectGetPrototypeOf(currentObject);
6043
+ }
6044
+
6045
+ return undefined;
6046
+ }
6047
+
6048
+ function getLocalValue(pointerOrPrimitive) {
6049
+ if (typeof pointerOrPrimitive === 'function') {
6050
+ pointerOrPrimitive();
6051
+ return getSelectedTarget();
6052
+ }
6053
+
6054
+ return pointerOrPrimitive;
6055
+ }
6056
+
6057
+ function getSelectedTarget() {
6058
+ // assert: selectedTarget is a ProxyTarget
6059
+ const result = selectedTarget;
6060
+ selectedTarget = undefined;
6061
+ return result;
6062
+ }
6063
+
6064
+ function getTargetTraits(target) {
6065
+ let targetTraits = TargetTraits.None;
6066
+
6067
+ if (typeof target === 'function') {
6068
+ targetTraits |= TargetTraits.IsFunction; // detecting arrow function vs function
6069
+
6070
+ try {
6071
+ targetTraits |= +!('prototype' in target) && TargetTraits.IsArrowFunction;
6072
+ } catch (_unused) {// target is either a revoked proxy, or a proxy that
6073
+ // throws on the `has` trap, in which case going with
6074
+ // a strict mode function seems appropriate.
5850
6075
  }
5851
- function getDistortedValue(target) {
5852
- let distortedTarget;
5853
- try {
5854
- distortedTarget = distortionCallback(target);
5855
- return distortedTarget;
5856
- }
5857
- finally {
5858
- // if a distortion entry is found, it must be a valid proxy target
5859
- if (distortedTarget !== target && typeof distortedTarget !== typeof target) {
5860
- // eslint-disable-next-line no-unsafe-finally
5861
- throw new TypeErrorCtor(`Invalid distortion ${target}.`);
5862
- }
5863
- }
6076
+ } else {
6077
+ let targetIsArray = false;
6078
+
6079
+ try {
6080
+ // try/catch in case Array.isArray throws when target
6081
+ // is a revoked proxy
6082
+ targetIsArray = isArrayOrNotOrThrowForRevoked(target);
6083
+ } catch (_unused2) {
6084
+ // TODO: this might be problematic, because functions
6085
+ // and arrow functions should also be subject to this,
6086
+ // but it seems that we can still create a proxy of
6087
+ // a revoke, and wait until the user-land code actually
6088
+ // access something out of it to throw the proper error.
6089
+ // target is a revoked proxy, so the type doesn't matter
6090
+ // much from this point on
6091
+ targetTraits |= TargetTraits.Revoked;
5864
6092
  }
5865
- function getInheritedPropertyDescriptor(foreignTargetPointer, key) {
5866
- // Avoiding calling the has trap for any proto chain operation,
5867
- // instead we implement the regular logic here in this trap.
5868
- let currentObject = liveGetPrototypeOf(foreignTargetPointer);
5869
- while (currentObject) {
5870
- const unsafeParentDesc = ReflectGetOwnPropertyDescriptor(currentObject, key);
5871
- if (unsafeParentDesc) {
5872
- return toSafeDescriptor(unsafeParentDesc);
5873
- }
5874
- currentObject = ReflectGetPrototypeOf(currentObject);
5875
- }
5876
- return undefined;
6093
+
6094
+ targetTraits |= +targetIsArray && TargetTraits.IsArray;
6095
+ targetTraits |= +!targetIsArray && TargetTraits.IsObject;
6096
+ }
6097
+
6098
+ return targetTraits;
6099
+ }
6100
+
6101
+ function getTargetIntegrityTraits(target) {
6102
+ let targetIntegrityTraits = TargetIntegrityTraits.None;
6103
+
6104
+ try {
6105
+ // a revoked proxy will break the membrane when reading the meta
6106
+ if (ObjectIsFrozen(target)) {
6107
+ targetIntegrityTraits |= TargetIntegrityTraits.IsSealed & TargetIntegrityTraits.IsFrozen & TargetIntegrityTraits.IsNotExtensible;
6108
+ } else if (ObjectIsSealed(target)) {
6109
+ targetIntegrityTraits |= TargetIntegrityTraits.IsSealed;
6110
+ } else if (!ReflectIsExtensible(target)) {
6111
+ targetIntegrityTraits |= TargetIntegrityTraits.IsNotExtensible;
6112
+ } // if the target was revoked or become revoked during the extraction
6113
+ // of the metadata, we mark it as broken in the catch.
6114
+
6115
+
6116
+ isArrayOrNotOrThrowForRevoked(target);
6117
+ } catch (_unused3) {
6118
+ // intentionally swallowing the error because this method is just
6119
+ // extracting the metadata in a way that it should always succeed
6120
+ // except for the cases in which the target is a proxy that is
6121
+ // either revoked or has some logic that is incompatible with the
6122
+ // membrane, in which case we will just create the proxy for the
6123
+ // membrane but revoke it right after to prevent any leakage.
6124
+ targetIntegrityTraits |= TargetIntegrityTraits.Revoked;
6125
+ }
6126
+
6127
+ return targetIntegrityTraits;
6128
+ }
6129
+
6130
+ function getTransferablePointer(originalTarget) {
6131
+ let proxyPointer = ReflectApply(WeakMapProtoGet, proxyTargetToPointerMap, [originalTarget]);
6132
+
6133
+ if (proxyPointer) {
6134
+ return proxyPointer;
6135
+ }
6136
+
6137
+ const distortedTarget = getDistortedValue(originalTarget); // the closure works as the implicit WeakMap
6138
+
6139
+ const targetPointer = createPointer(distortedTarget);
6140
+ const targetTraits = getTargetTraits(distortedTarget);
6141
+ let targetFunctionName;
6142
+
6143
+ if (typeof originalTarget === 'function') {
6144
+ try {
6145
+ // a revoked proxy will throw when reading the function name
6146
+ const unsafeDesc = ReflectGetOwnPropertyDescriptor(originalTarget, 'name');
6147
+
6148
+ if (unsafeDesc) {
6149
+ const safeDesc = toSafeDescriptor(unsafeDesc);
6150
+ targetFunctionName = safeDesc.value;
6151
+ }
6152
+ } catch (_unused4) {// intentionally swallowing the error because this method is just extracting
6153
+ // the function in a way that it should always succeed except for the cases
6154
+ // in which the provider is a proxy that is either revoked or has some logic
6155
+ // to prevent reading the name property descriptor.
5877
6156
  }
5878
- function getLocalValue(pointerOrPrimitive) {
5879
- if (typeof pointerOrPrimitive === 'function') {
5880
- pointerOrPrimitive();
5881
- return getSelectedTarget();
6157
+ }
6158
+
6159
+ proxyPointer = foreignCallablePushTarget(targetPointer, targetTraits, targetFunctionName); // the WeakMap is populated with the original target rather then the distorted one
6160
+ // while the pointer always uses the distorted one.
6161
+ // TODO: this mechanism poses another issue, which is that the return value of
6162
+ // getSelectedTarget() can never be used to call across the membrane because that
6163
+ // will cause a wrapping around the potential distorted value instead of the original
6164
+ // value. This is not fatal, but implies that for every distorted value where will
6165
+ // two proxies that are not ===, which is weird. Guaranteeing this is not easy because
6166
+ // it means auditing the code.
6167
+
6168
+ ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [originalTarget, proxyPointer]);
6169
+ return proxyPointer;
6170
+ }
6171
+
6172
+ function getTransferableValue(value) {
6173
+ // Internationally ignoring the case of (typeof document.all === 'undefined')
6174
+ // because in the reserve membrane, you never get one of those exotic objects.
6175
+ if (typeof value === 'undefined') {
6176
+ return undefined;
6177
+ } // TODO: What other ways to optimize this method?
6178
+
6179
+
6180
+ if (value === null || typeof value !== 'function' && typeof value !== 'object') {
6181
+ return value;
6182
+ }
6183
+
6184
+ return getTransferablePointer(value);
6185
+ } // This wrapping mechanism provides the means to add instrumentation
6186
+ // to the callable functions used to coordinate work between the sides
6187
+ // of the membrane.
6188
+ // TODO: do we need to pass more info into instrumentation hooks?
6189
+ // prettier-ignore
6190
+
6191
+
6192
+ function instrumentCallableWrapper(fn, activityName, crossingDirection) {
6193
+ if (instrumentation) {
6194
+ return function instrumentedFn() {
6195
+ const activity = instrumentation.startActivity(activityName, {
6196
+ crossingDirection
6197
+ });
6198
+
6199
+ try {
6200
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
6201
+ args[_key3] = arguments[_key3];
5882
6202
  }
5883
- return pointerOrPrimitive;
6203
+
6204
+ return ReflectApply(fn, this, args);
6205
+ } catch (e) {
6206
+ activity.error(e);
6207
+ throw e;
6208
+ } finally {
6209
+ activity.stop();
6210
+ }
6211
+ };
6212
+ }
6213
+
6214
+ return fn;
6215
+ }
6216
+ /**
6217
+ * An object is marked as a "live" object when it has a
6218
+ * LOCKER_LIVE_MARKER_SYMBOL property. Live objects have their
6219
+ * defineProperty, deleteProperty, preventExtensions, set, and
6220
+ * setPrototypeOf proxy traps as "live" variations meaning that when
6221
+ * mutation occurs instead of maintaining a separate object graph of
6222
+ * changes the mutations are performed directly on the foreign target.
6223
+ *
6224
+ */
6225
+
6226
+
6227
+ function isForeignTargetMarkedLive(foreignTargetPointer) {
6228
+ return foreignCallableHasOwnProperty(foreignTargetPointer, LOCKER_LIVE_MARKER_SYMBOL);
6229
+ }
6230
+ /**
6231
+ * An object is marked as a "magic" object when it has a
6232
+ * LOCKER_MAGIC_MARKER_SYMBOL property. These objects have magical side
6233
+ * effects when setting properties, which would be broken by a Define
6234
+ * Property operation. For example, the `style` object of an HTMLElement
6235
+ * in Safari <= 14. This marker is a signal to the membrane that it must
6236
+ * use a Set operation, instead of a Define Property operation.
6237
+ *
6238
+ */
6239
+
6240
+
6241
+ function isMarkedMagic(object) {
6242
+ return SUPPORT_MAGIC_MARKER && ReflectApply(ObjectProtoHasOwnProperty, object, [LOCKER_MAGIC_MARKER_SYMBOL]);
6243
+ }
6244
+
6245
+ function liveDefineProperty(foreignTargetPointer, shadowTarget, key, unsafePartialDesc) {
6246
+ const descMeta = getDescriptorMeta(unsafePartialDesc);
6247
+ const result = foreignCallableDefineProperty(foreignTargetPointer, key, descMeta[0], // configurable
6248
+ descMeta[1], // enumerable
6249
+ descMeta[2], // writable
6250
+ descMeta[3], // valuePointer
6251
+ descMeta[4], // getPointer
6252
+ descMeta[5] // setPointer
6253
+ );
6254
+
6255
+ if (result) {
6256
+ // Intentionally testing against false since it could be
6257
+ // undefined as well
6258
+ if (descMeta[0]
6259
+ /* configurable */
6260
+ === false) {
6261
+ foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6262
+ ReflectDefineProperty(shadowTarget, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
6263
+ });
5884
6264
  }
5885
- function getSelectedTarget() {
5886
- // assert: selectedTarget is a ProxyTarget
5887
- const r = selectedTarget;
5888
- selectedTarget = undefined;
5889
- return r;
6265
+ }
6266
+
6267
+ return result;
6268
+ }
6269
+
6270
+ function liveDeleteProperty(foreignTargetPointer, _shadowTarget, key) {
6271
+ return foreignCallableDeleteProperty(foreignTargetPointer, key);
6272
+ }
6273
+
6274
+ function liveGet(foreignTargetPointer, shadowTarget, key, receiver) {
6275
+ const safeDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) || getInheritedPropertyDescriptor(foreignTargetPointer, key);
6276
+
6277
+ if (safeDesc) {
6278
+ const {
6279
+ get: getter,
6280
+ value: localValue
6281
+ } = safeDesc;
6282
+
6283
+ if (getter) {
6284
+ // Even though the getter function exists, we can't use
6285
+ // `ReflectGet` because there might be a distortion for
6286
+ // that getter function, in which case we must resolve
6287
+ // the local getter and call it instead.
6288
+ return ReflectApply(getter, receiver, []);
5890
6289
  }
5891
- function getTargetTraits(target) {
5892
- let targetTraits = TargetTraits.None;
5893
- if (typeof target === 'function') {
5894
- targetTraits |= TargetTraits.IsFunction;
5895
- // detecting arrow function vs function
5896
- try {
5897
- targetTraits |= +!('prototype' in target) && TargetTraits.IsArrowFunction;
5898
- }
5899
- catch {
5900
- // target is either a revoked proxy, or a proxy that
5901
- // throws on the `has` trap, in which case going with
5902
- // a strict mode function seems appropriate.
5903
- }
5904
- }
5905
- else {
5906
- let targetIsArray = false;
5907
- try {
5908
- // try/catch in case Array.isArray throws when target
5909
- // is a revoked proxy
5910
- targetIsArray = isArrayOrNotOrThrowForRevoked(target);
5911
- }
5912
- catch {
5913
- // TODO: this might be problematic, because functions
5914
- // and arrow functions should also be subject to this,
5915
- // but it seems that we can still create a proxy of
5916
- // a revoke, and wait until the user-land code actually
5917
- // access something out of it to throw the proper error.
5918
- // target is a revoked proxy, so the type doesn't matter
5919
- // much from this point on
5920
- targetTraits |= TargetTraits.Revoked;
5921
- }
5922
- targetTraits |= +targetIsArray && TargetTraits.IsArray;
5923
- targetTraits |= +!targetIsArray && TargetTraits.IsObject;
5924
- }
5925
- return targetTraits;
6290
+
6291
+ return localValue;
6292
+ }
6293
+
6294
+ if (key === TO_STRING_TAG_SYMBOL) {
6295
+ return foreignCallableGetUnbrandedTag(foreignTargetPointer);
6296
+ }
6297
+
6298
+ return undefined;
6299
+ }
6300
+
6301
+ function liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) {
6302
+ let safeDesc;
6303
+ foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6304
+ safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
6305
+
6306
+ if (safeDesc.configurable === false) {
6307
+ // updating the descriptor to non-configurable on the shadow
6308
+ ReflectDefineProperty(shadowTarget, key, safeDesc);
5926
6309
  }
5927
- function getTargetIntegrityTraits(target) {
5928
- let targetIntegrityTraits = TargetIntegrityTraits.None;
5929
- try {
5930
- // a revoked proxy will break the membrane when reading the meta
5931
- if (ObjectIsFrozen(target)) {
5932
- targetIntegrityTraits |=
5933
- TargetIntegrityTraits.IsSealed &
5934
- TargetIntegrityTraits.IsFrozen &
5935
- TargetIntegrityTraits.IsNotExtensible;
5936
- }
5937
- else if (ObjectIsSealed(target)) {
5938
- targetIntegrityTraits |= TargetIntegrityTraits.IsSealed;
5939
- }
5940
- else if (!ReflectIsExtensible(target)) {
5941
- targetIntegrityTraits |= TargetIntegrityTraits.IsNotExtensible;
5942
- }
5943
- // if the target was revoked or become revoked during the extraction
5944
- // of the metadata, we mark it as broken in the catch.
5945
- isArrayOrNotOrThrowForRevoked(target);
5946
- }
5947
- catch {
5948
- // intentionally swallowing the error because this method is just
5949
- // extracting the metadata in a way that it should always succeed
5950
- // except for the cases in which the target is a proxy that is
5951
- // either revoked or has some logic that is incompatible with the
5952
- // membrane, in which case we will just create the proxy for the
5953
- // membrane but revoke it right after to prevent any leakage.
5954
- targetIntegrityTraits |= TargetIntegrityTraits.Revoked;
5955
- }
5956
- return targetIntegrityTraits;
6310
+ });
6311
+ return safeDesc;
6312
+ }
6313
+
6314
+ function liveGetPrototypeOf(foreignTargetPointer) {
6315
+ return getLocalValue(foreignCallableGetPrototypeOf(foreignTargetPointer));
6316
+ }
6317
+
6318
+ function liveHas(foreignTargetPointer, key) {
6319
+ if (foreignCallableHasOwnProperty(foreignTargetPointer, key)) {
6320
+ return true;
6321
+ } // Avoiding calling the has trap for any proto chain operation,
6322
+ // instead we implement the regular logic here in this trap.
6323
+
6324
+
6325
+ let currentObject = liveGetPrototypeOf(foreignTargetPointer);
6326
+
6327
+ while (currentObject) {
6328
+ if (ReflectApply(ObjectProtoHasOwnProperty, currentObject, [key])) {
6329
+ return true;
5957
6330
  }
5958
- function getTransferablePointer(originalTarget) {
5959
- let proxyPointer = ReflectApply(WeakMapProtoGet, proxyTargetToPointerMap, [
5960
- originalTarget,
5961
- ]);
5962
- if (proxyPointer) {
5963
- return proxyPointer;
5964
- }
5965
- const distortedTarget = getDistortedValue(originalTarget);
5966
- // the closure works as the implicit WeakMap
5967
- const targetPointer = createPointer(distortedTarget);
5968
- const targetTraits = getTargetTraits(distortedTarget);
5969
- let targetFunctionName;
5970
- if (typeof originalTarget === 'function') {
5971
- try {
5972
- // a revoked proxy will throw when reading the function name
5973
- const unsafeDesc = ReflectGetOwnPropertyDescriptor(originalTarget, 'name');
5974
- if (unsafeDesc) {
5975
- const safeDesc = toSafeDescriptor(unsafeDesc);
5976
- targetFunctionName = safeDesc.value;
5977
- }
5978
- }
5979
- catch {
5980
- // intentionally swallowing the error because this method is just extracting
5981
- // the function in a way that it should always succeed except for the cases
5982
- // in which the provider is a proxy that is either revoked or has some logic
5983
- // to prevent reading the name property descriptor.
5984
- }
5985
- }
5986
- proxyPointer = foreignCallablePushTarget(targetPointer, targetTraits, targetFunctionName);
5987
- // the WeakMap is populated with the original target rather then the distorted one
5988
- // while the pointer always uses the distorted one.
5989
- // TODO: this mechanism poses another issue, which is that the return value of
5990
- // getSelectedTarget() can never be used to call across the membrane because that
5991
- // will cause a wrapping around the potential distorted value instead of the original
5992
- // value. This is not fatal, but implies that for every distorted value where will
5993
- // two proxies that are not ===, which is weird. Guaranteeing this is not easy because
5994
- // it means auditing the code.
5995
- ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [originalTarget, proxyPointer]);
5996
- return proxyPointer;
6331
+
6332
+ currentObject = ReflectGetPrototypeOf(currentObject);
6333
+ }
6334
+
6335
+ return false;
6336
+ }
6337
+
6338
+ function liveIsExtensible(foreignTargetPointer, shadowTarget) {
6339
+ // check if already locked
6340
+ if (ReflectIsExtensible(shadowTarget)) {
6341
+ if (foreignCallableIsExtensible(foreignTargetPointer)) {
6342
+ return true;
5997
6343
  }
5998
- function getTransferableValue(value) {
5999
- // internationally ignoring the case of (typeof document.all === 'undefined') because
6000
- // in the reserve membrane, you never get one of those exotic objects
6001
- if (typeof value === 'undefined') {
6002
- return undefined;
6003
- }
6004
- // TODO: what other ways to optimize this method?
6005
- if (value === null || (typeof value !== 'function' && typeof value !== 'object')) {
6006
- return value;
6007
- }
6008
- return getTransferablePointer(value);
6009
- }
6010
- // This wrapping mechanism provides the means to add instrumentation
6011
- // to the callable functions used to coordinate work between the sides
6012
- // of the membrane.
6013
- // TODO: do we need to pass more info into instrumentation hooks?
6014
- // prettier-ignore
6015
- function instrumentCallableWrapper(fn, activityName, crossingDirection) {
6016
- if (instrumentation) {
6017
- return function instrumentedFn(...args) {
6018
- const activity = instrumentation.startActivity(activityName, {
6019
- crossingDirection
6020
- });
6021
- try {
6022
- return ReflectApply(fn, this, args);
6023
- }
6024
- catch (e) {
6025
- activity.error(e);
6026
- throw e;
6027
- }
6028
- finally {
6029
- activity.stop();
6030
- }
6031
- };
6032
- }
6033
- return fn;
6034
- }
6035
- /**
6036
- * An object is marked as a "live" object when it has a
6037
- * LOCKER_LIVE_MARKER_SYMBOL property. Live objects have their
6038
- * defineProperty, deleteProperty, preventExtensions, set, and
6039
- * setPrototypeOf proxy traps as "live" variations meaning that when
6040
- * mutation occurs instead of maintaining a separate object graph of
6041
- * changes the mutations are performed directly on the foreign target.
6042
- *
6043
- */
6044
- function isForeignTargetMarkedLive(foreignTargetPointer) {
6045
- return foreignCallableHasOwnProperty(foreignTargetPointer, LOCKER_LIVE_MARKER_SYMBOL);
6046
- }
6047
- /**
6048
- * An object is marked as a "magic" object when it has a
6049
- * LOCKER_MAGIC_MARKER_SYMBOL property. These objects have magical side
6050
- * effects when setting properties, which would be broken by a Define
6051
- * Property operation. For example, the `style` object of an HTMLElement
6052
- * in Safari <= 14. This marker is a signal to the membrane that it must
6053
- * use a Set operation, instead of a Define Property operation.
6054
- *
6055
- */
6056
- function isMarkedMagic(object) {
6057
- return (SUPPORT_MAGIC_MARKER &&
6058
- ReflectApply(ObjectProtoHasOwnProperty, object, [LOCKER_MAGIC_MARKER_SYMBOL]));
6059
- }
6060
- function liveDefineProperty(foreignTargetPointer, shadowTarget, key, unsafePartialDesc) {
6061
- const descMeta = getDescriptorMeta(unsafePartialDesc);
6062
- const result = foreignCallableDefineProperty(foreignTargetPointer, key, descMeta[0], // configurable
6063
- descMeta[1], // enumerable
6064
- descMeta[2], // writable
6065
- descMeta[3], // valuePointer
6066
- descMeta[4], // getPointer
6067
- descMeta[5] // setPointer
6068
- );
6069
- if (result) {
6070
- // Intentionally testing against false since it could be
6071
- // undefined as well
6072
- if (descMeta[0] /* configurable */ === false) {
6073
- foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6074
- ReflectDefineProperty(shadowTarget, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
6075
- });
6076
- }
6077
- }
6078
- return result;
6079
- }
6080
- function liveDeleteProperty(foreignTargetPointer, _shadowTarget, key) {
6081
- return foreignCallableDeleteProperty(foreignTargetPointer, key);
6344
+
6345
+ lockShadowTarget(shadowTarget, foreignTargetPointer);
6346
+ }
6347
+
6348
+ return false;
6349
+ }
6350
+
6351
+ function liveOwnKeys(foreignTargetPointer) {
6352
+ let keys;
6353
+ foreignCallableOwnKeys(foreignTargetPointer, function () {
6354
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
6355
+ args[_key4] = arguments[_key4];
6082
6356
  }
6083
- function liveGet(foreignTargetPointer, shadowTarget, key, receiver) {
6084
- const safeDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) ||
6085
- getInheritedPropertyDescriptor(foreignTargetPointer, key);
6086
- if (safeDesc) {
6087
- const { get: getter, value: localValue } = safeDesc;
6088
- if (getter) {
6089
- // Even though the getter function exists, we can't use
6090
- // `ReflectGet` because there might be a distortion for
6091
- // that getter function, in which case we must resolve
6092
- // the local getter and call it instead.
6093
- return ReflectApply(getter, receiver, []);
6094
- }
6095
- return localValue;
6096
- }
6097
- if (key === TO_STRING_TAG_SYMBOL) {
6098
- return foreignCallableGetUnbrandedTag(foreignTargetPointer);
6099
- }
6100
- return undefined;
6357
+
6358
+ keys = args;
6359
+ }); // @ts-ignore: Prevent used before assignment error.
6360
+
6361
+ return keys || [];
6362
+ }
6363
+
6364
+ function livePreventExtensions(foreignTargetPointer, shadowTarget) {
6365
+ if (ReflectIsExtensible(shadowTarget)) {
6366
+ if (!foreignCallablePreventExtensions(foreignTargetPointer)) {
6367
+ // if the target is a proxy manually created, it might
6368
+ // reject the preventExtension call, in which case we
6369
+ // should not attempt to lock down the shadow target.
6370
+ if (!foreignCallableIsExtensible(foreignTargetPointer)) {
6371
+ lockShadowTarget(shadowTarget, foreignTargetPointer);
6372
+ }
6373
+
6374
+ return false;
6101
6375
  }
6102
- function liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) {
6103
- let safeDesc;
6104
- foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6105
- safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
6106
- if (safeDesc.configurable === false) {
6107
- // updating the descriptor to non-configurable on the shadow
6108
- ReflectDefineProperty(shadowTarget, key, safeDesc);
6109
- }
6110
- });
6111
- return safeDesc;
6376
+
6377
+ lockShadowTarget(shadowTarget, foreignTargetPointer);
6378
+ }
6379
+
6380
+ return true;
6381
+ }
6382
+
6383
+ function liveSet(foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath) {
6384
+ // Following the specification steps for
6385
+ // OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ).
6386
+ // https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
6387
+ const safeOwnDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key);
6388
+ const safeDesc = safeOwnDesc || getInheritedPropertyDescriptor(foreignTargetPointer, key);
6389
+
6390
+ if (safeDesc) {
6391
+ if ('get' in safeDesc || 'set' in safeDesc) {
6392
+ const {
6393
+ set: setter
6394
+ } = safeDesc;
6395
+
6396
+ if (setter) {
6397
+ // Even though the setter function exists, we can't use
6398
+ // `ReflectSet` because there might be a distortion for
6399
+ // that setter function, in which case we must resolve
6400
+ // the local setter and call it instead.
6401
+ ReflectApply(setter, receiver, [value]); // If there is a setter, it either throw or we can assume
6402
+ // the value was set.
6403
+
6404
+ return true;
6405
+ }
6406
+
6407
+ return false;
6112
6408
  }
6113
- function liveGetPrototypeOf(foreignTargetPointer) {
6114
- return getLocalValue(foreignCallableGetPrototypeOf(foreignTargetPointer));
6409
+
6410
+ if (safeDesc.writable === false) {
6411
+ return false;
6115
6412
  }
6116
- function liveHas(foreignTargetPointer, key) {
6117
- if (foreignCallableHasOwnProperty(foreignTargetPointer, key)) {
6118
- return true;
6119
- }
6120
- // avoiding calling the has trap for any proto chain operation,
6121
- // instead we implement the regular logic here in this trap.
6122
- let currentObject = liveGetPrototypeOf(foreignTargetPointer);
6123
- while (currentObject) {
6124
- if (ReflectApply(ObjectProtoHasOwnProperty, currentObject, [key])) {
6125
- return true;
6126
- }
6127
- currentObject = ReflectGetPrototypeOf(currentObject);
6128
- }
6129
- return false;
6413
+ }
6414
+
6415
+ let safeReceiverDesc;
6416
+
6417
+ if (useFastPath) {
6418
+ // In the fast path we know the receiver is the proxy.
6419
+ safeReceiverDesc = safeOwnDesc;
6420
+ } else {
6421
+ // Exit early if receiver is not object like.
6422
+ if (receiver === null || typeof receiver !== 'function' && typeof receiver !== 'object') {
6423
+ return false;
6130
6424
  }
6131
- function liveIsExtensible(foreignTargetPointer, shadowTarget) {
6132
- // check if already locked
6133
- if (ReflectIsExtensible(shadowTarget)) {
6134
- if (foreignCallableIsExtensible(foreignTargetPointer)) {
6135
- return true;
6136
- }
6137
- lockShadowTarget(shadowTarget, foreignTargetPointer);
6138
- }
6139
- return false;
6425
+
6426
+ const unsafeReceiverDesc = ReflectGetOwnPropertyDescriptor(receiver, key);
6427
+
6428
+ if (unsafeReceiverDesc) {
6429
+ safeReceiverDesc = toSafeDescriptor(unsafeReceiverDesc);
6140
6430
  }
6141
- function liveOwnKeys(foreignTargetPointer) {
6142
- let keys;
6143
- foreignCallableOwnKeys(foreignTargetPointer, (...args) => {
6144
- keys = args;
6145
- });
6146
- // @ts-ignore: Prevent used before assignment error.
6147
- return keys || [];
6431
+ }
6432
+
6433
+ if (safeReceiverDesc) {
6434
+ // Exit early for accessor descriptors or non-writable data
6435
+ // descriptors.
6436
+ if ('get' in safeReceiverDesc || 'set' in safeReceiverDesc || safeReceiverDesc.writable === false) {
6437
+ return false;
6148
6438
  }
6149
- function livePreventExtensions(foreignTargetPointer, shadowTarget) {
6150
- if (ReflectIsExtensible(shadowTarget)) {
6151
- if (!foreignCallablePreventExtensions(foreignTargetPointer)) {
6152
- // if the target is a proxy manually created, it might
6153
- // reject the preventExtension call, in which case we
6154
- // should not attempt to lock down the shadow target.
6155
- if (!foreignCallableIsExtensible(foreignTargetPointer)) {
6156
- lockShadowTarget(shadowTarget, foreignTargetPointer);
6157
- }
6158
- return false;
6159
- }
6160
- lockShadowTarget(shadowTarget, foreignTargetPointer);
6161
- }
6162
- return true;
6439
+
6440
+ if (isMarkedMagic(receiver)) {
6441
+ // Workaround for Safari <= 14 bug on CSSStyleDeclaration
6442
+ // objects which lose their magic setters if set with
6443
+ // defineProperty.
6444
+ foreignCallableSet(foreignTargetPointer, key, getTransferableValue(value), getTransferablePointer(receiver));
6445
+ } else {
6446
+ // Setting the descriptor with only a value entry should not
6447
+ // affect existing descriptor traits.
6448
+ ReflectDefineProperty(receiver, key, {
6449
+ // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6450
+ __proto__: null,
6451
+ value
6452
+ });
6163
6453
  }
6164
- function liveSet(foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath) {
6165
- // Following the specification steps for
6166
- // OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ).
6167
- // https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
6168
- const safeOwnDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key);
6169
- const safeDesc = safeOwnDesc || getInheritedPropertyDescriptor(foreignTargetPointer, key);
6170
- if (safeDesc) {
6171
- if ('get' in safeDesc || 'set' in safeDesc) {
6172
- const { set: setter } = safeDesc;
6173
- if (setter) {
6174
- // Even though the setter function exists, we can't use
6175
- // `ReflectSet` because there might be a distortion for
6176
- // that setter function, in which case we must resolve
6177
- // the local setter and call it instead.
6178
- ReflectApply(setter, receiver, [value]);
6179
- // If there is a setter, it either throw or we can assume
6180
- // the value was set.
6181
- return true;
6182
- }
6183
- return false;
6184
- }
6185
- if (safeDesc.writable === false) {
6186
- return false;
6187
- }
6188
- }
6189
- let safeReceiverDesc;
6190
- if (useFastPath) {
6191
- // In the fast path we know the receiver is the proxy.
6192
- safeReceiverDesc = safeOwnDesc;
6193
- }
6194
- else {
6195
- // Exit early if receiver is not object like.
6196
- if (receiver === null ||
6197
- (typeof receiver !== 'function' && typeof receiver !== 'object')) {
6198
- return false;
6199
- }
6200
- const unsafeReceiverDesc = ReflectGetOwnPropertyDescriptor(receiver, key);
6201
- if (unsafeReceiverDesc) {
6202
- safeReceiverDesc = toSafeDescriptor(unsafeReceiverDesc);
6203
- }
6454
+
6455
+ return true;
6456
+ } // `ReflectDefineProperty` and `ReflectSet` both are expected to
6457
+ // return `false` when attempting to add a new property if the
6458
+ // receiver is not extensible.
6459
+
6460
+
6461
+ return ReflectDefineProperty(receiver, key, {
6462
+ // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6463
+ __proto__: null,
6464
+ configurable: true,
6465
+ enumerable: true,
6466
+ value,
6467
+ writable: true
6468
+ });
6469
+ }
6470
+
6471
+ function liveSetPrototypeOf(foreignTargetPointer, proto) {
6472
+ const transferableProto = getTransferableValue(proto);
6473
+ return foreignCallableSetPrototypeOf(foreignTargetPointer, transferableProto);
6474
+ }
6475
+
6476
+ function lockShadowTarget(shadowTarget, foreignTargetPointer) {
6477
+ copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer); // setting up __proto__ of the shadowTarget
6478
+
6479
+ const proto = liveGetPrototypeOf(foreignTargetPointer);
6480
+ ReflectSetPrototypeOf(shadowTarget, proto); // locking down the extensibility of shadowTarget
6481
+
6482
+ ReflectPreventExtensions(shadowTarget);
6483
+ }
6484
+
6485
+ function pushErrorAcrossBoundary(e) {
6486
+ const transferableError = getTransferableValue(e);
6487
+
6488
+ if (typeof transferableError === 'function') {
6489
+ transferableError();
6490
+ }
6491
+
6492
+ return e;
6493
+ }
6494
+
6495
+ function toSafeDescriptor(desc) {
6496
+ ReflectSetPrototypeOf(desc, null);
6497
+ return desc;
6498
+ }
6499
+
6500
+ class BoundaryProxyHandler {
6501
+ constructor(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) {
6502
+ // the purpose of this public field is to help developers to identify
6503
+ // what side of the membrane they are debugging.
6504
+ this.color = color; // apply trap is generic, and should never change independently of the type of membrane
6505
+
6506
+ this.apply = function applyTrap(_shadowTarget, thisArg, args) {
6507
+ const {
6508
+ foreignTargetPointer
6509
+ } = this;
6510
+ const transferableThisArg = getTransferableValue(thisArg);
6511
+ const combinedArgs = [foreignTargetPointer, transferableThisArg];
6512
+ const {
6513
+ length: argsLen
6514
+ } = args;
6515
+ const {
6516
+ length: combinedOffset
6517
+ } = combinedArgs;
6518
+ combinedArgs.length += argsLen;
6519
+
6520
+ for (let i = 0, len = argsLen; i < len; i += 1) {
6521
+ const arg = args[i];
6522
+ const combinedIndex = i + combinedOffset; // Inlining `getTransferableValue`.
6523
+
6524
+ if (typeof arg === 'undefined') {
6525
+ combinedArgs[combinedIndex] = undefined;
6526
+ } else if (arg === null || typeof arg !== 'function' && typeof arg !== 'object') {
6527
+ combinedArgs[combinedIndex] = arg;
6528
+ } else {
6529
+ combinedArgs[combinedIndex] = getTransferablePointer(arg);
6204
6530
  }
6205
- if (safeReceiverDesc) {
6206
- // Exit early for accessor descriptors or non-writable data
6207
- // descriptors.
6208
- if ('get' in safeReceiverDesc ||
6209
- 'set' in safeReceiverDesc ||
6210
- safeReceiverDesc.writable === false) {
6211
- return false;
6212
- }
6213
- if (isMarkedMagic(receiver)) {
6214
- // Workaround for Safari <= 14 bug on CSSStyleDeclaration
6215
- // objects which lose their magic setters if set with
6216
- // defineProperty.
6217
- foreignCallableSet(foreignTargetPointer, key, getTransferableValue(value), getTransferablePointer(receiver));
6218
- }
6219
- else {
6220
- // Setting the descriptor with only a value entry should not
6221
- // affect existing descriptor traits.
6222
- ReflectDefineProperty(receiver, key, {
6223
- // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6224
- __proto__: null,
6225
- value,
6226
- });
6227
- }
6228
- return true;
6531
+ }
6532
+
6533
+ return getLocalValue(ReflectApply(foreignCallableApply, undefined, combinedArgs));
6534
+ }; // construct trap is generic, and should never change independently
6535
+ // of the type of membrane
6536
+
6537
+
6538
+ this.construct = function constructTrap(_shadowTarget, args, newTarget) {
6539
+ if (newTarget === undefined) {
6540
+ throw new TypeErrorCtor();
6541
+ }
6542
+
6543
+ const {
6544
+ foreignTargetPointer
6545
+ } = this;
6546
+ const transferableNewTarget = getTransferableValue(newTarget);
6547
+ const combinedArgs = [foreignTargetPointer, transferableNewTarget];
6548
+ const {
6549
+ length: argsLen
6550
+ } = args;
6551
+ const {
6552
+ length: combinedOffset
6553
+ } = combinedArgs;
6554
+ combinedArgs.length += argsLen;
6555
+
6556
+ for (let i = 0, len = argsLen; i < len; i += 1) {
6557
+ const arg = args[i];
6558
+ const combinedIndex = i + combinedOffset; // Inline `getTransferableValue`.
6559
+
6560
+ if (typeof arg === 'undefined') {
6561
+ combinedArgs[combinedIndex] = undefined;
6562
+ } else if (arg === null || typeof arg !== 'function' && typeof arg !== 'object') {
6563
+ combinedArgs[combinedIndex] = arg;
6564
+ } else {
6565
+ combinedArgs[combinedIndex] = getTransferablePointer(arg);
6229
6566
  }
6230
- // `ReflectDefineProperty` and `ReflectSet` both are expected to
6231
- // return `false` when attempting to add a new property if the
6232
- // receiver is not extensible.
6233
- return ReflectDefineProperty(receiver, key, {
6234
- // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6235
- __proto__: null,
6236
- configurable: true,
6237
- enumerable: true,
6238
- value,
6239
- writable: true,
6240
- });
6241
- }
6242
- function liveSetPrototypeOf(foreignTargetPointer, proto) {
6243
- const transferableProto = getTransferableValue(proto);
6244
- return foreignCallableSetPrototypeOf(foreignTargetPointer, transferableProto);
6245
- }
6246
- function lockShadowTarget(shadowTarget, foreignTargetPointer) {
6247
- copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer);
6248
- // setting up __proto__ of the shadowTarget
6249
- const proto = liveGetPrototypeOf(foreignTargetPointer);
6250
- ReflectSetPrototypeOf(shadowTarget, proto);
6251
- // locking down the extensibility of shadowTarget
6252
- ReflectPreventExtensions(shadowTarget);
6567
+ }
6568
+
6569
+ return getLocalValue(ReflectApply(foreignCallableConstruct, undefined, combinedArgs));
6570
+ };
6571
+
6572
+ const shadowTarget = createShadowTarget(foreignTargetTraits, foreignTargetFunctionName);
6573
+ const {
6574
+ proxy,
6575
+ revoke
6576
+ } = ProxyRevocable(shadowTarget, this);
6577
+ this.foreignTargetPointer = foreignTargetPointer;
6578
+ this.proxy = proxy;
6579
+ this.revoke = revoke; // inserting default traps
6580
+
6581
+ this.defineProperty = BoundaryProxyHandler.defaultDefinePropertyTrap;
6582
+ this.deleteProperty = BoundaryProxyHandler.defaultDeletePropertyTrap;
6583
+ this.isExtensible = BoundaryProxyHandler.defaultIsExtensibleTrap;
6584
+ this.getOwnPropertyDescriptor = BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap;
6585
+ this.getPrototypeOf = BoundaryProxyHandler.defaultGetPrototypeOfTrap;
6586
+ this.get = BoundaryProxyHandler.defaultGetTrap;
6587
+ this.has = BoundaryProxyHandler.defaultHasTrap;
6588
+ this.ownKeys = BoundaryProxyHandler.defaultOwnKeysTrap;
6589
+ this.preventExtensions = BoundaryProxyHandler.defaultPreventExtensionsTrap;
6590
+ this.setPrototypeOf = BoundaryProxyHandler.defaultSetPrototypeOfTrap;
6591
+ this.set = BoundaryProxyHandler.defaultSetTrap;
6592
+
6593
+ if (foreignTargetTraits & TargetTraits.Revoked) {
6594
+ revoke();
6253
6595
  }
6254
- function pushErrorAcrossBoundary(e) {
6255
- const transferableError = getTransferableValue(e);
6256
- if (typeof transferableError === 'function') {
6257
- transferableError();
6258
- }
6259
- return e;
6596
+
6597
+ if (!trapMutations) {
6598
+ // if local mutations are not trapped, then freezing the handler is ok
6599
+ // because it is not expecting to change in the future.
6600
+ // future optimization: hoping that proxies with frozen handlers can be faster
6601
+ ObjectFreeze(this);
6260
6602
  }
6261
- function toSafeDescriptor(desc) {
6262
- ReflectSetPrototypeOf(desc, null);
6263
- return desc;
6603
+ } // internal utilities
6604
+
6605
+
6606
+ makeProxyLive() {
6607
+ // assert: trapMutations must be true
6608
+ // replacing pending traps with live traps that can work with
6609
+ // the target without taking snapshots.
6610
+ this.defineProperty = BoundaryProxyHandler.liveDefinePropertyTrap;
6611
+ this.deleteProperty = BoundaryProxyHandler.liveDeletePropertyTrap;
6612
+ this.preventExtensions = BoundaryProxyHandler.livePreventExtensionsTrap;
6613
+ this.set = BoundaryProxyHandler.liveSetTrap;
6614
+ this.setPrototypeOf = BoundaryProxyHandler.liveSetPrototypeOfTrap; // future optimization: hoping that proxies with frozen handlers can be faster
6615
+
6616
+ ObjectFreeze(this);
6617
+ }
6618
+
6619
+ makeProxyStatic(shadowTarget) {
6620
+ // assert: trapMutations must be true
6621
+ const {
6622
+ foreignTargetPointer
6623
+ } = this;
6624
+ const targetIntegrityTraits = foreignCallableGetTargetIntegrityTraits(foreignTargetPointer);
6625
+
6626
+ if (targetIntegrityTraits & TargetIntegrityTraits.Revoked) {
6627
+ // the target is a revoked proxy, in which case we revoke
6628
+ // this proxy as well.
6629
+ this.revoke();
6630
+ return;
6631
+ } // adjusting the proto chain of the shadowTarget
6632
+
6633
+
6634
+ try {
6635
+ // a proxy that revoke itself when the __proto__ is accessed
6636
+ // can break the membrane, therefore we need protection
6637
+ const proto = liveGetPrototypeOf(foreignTargetPointer);
6638
+ ReflectSetPrototypeOf(shadowTarget, proto);
6639
+ } catch (_unused5) {
6640
+ // TODO: is revoke the right action here? maybe just setting
6641
+ // proto to null instead?
6642
+ this.revoke();
6643
+ return;
6644
+ } // defining own descriptors
6645
+
6646
+
6647
+ copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer); // preserving the semantics of the object
6648
+
6649
+ if (targetIntegrityTraits & TargetIntegrityTraits.IsFrozen) {
6650
+ ObjectFreeze(shadowTarget);
6651
+ } else if (targetIntegrityTraits & TargetIntegrityTraits.IsSealed) {
6652
+ ObjectSeal(shadowTarget);
6653
+ } else if (targetIntegrityTraits & TargetIntegrityTraits.IsNotExtensible) {
6654
+ ReflectPreventExtensions(shadowTarget);
6655
+ } // resetting all traps except apply and construct for static
6656
+ // proxies since the proxy target is the shadow target and all
6657
+ // operations are going to be applied to it rather than the real
6658
+ // target.
6659
+
6660
+
6661
+ this.defineProperty = BoundaryProxyHandler.staticDefinePropertyTrap;
6662
+ this.deleteProperty = BoundaryProxyHandler.staticDeletePropertyTrap;
6663
+ this.get = BoundaryProxyHandler.staticGetTrap;
6664
+ this.getOwnPropertyDescriptor = BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap;
6665
+ this.getPrototypeOf = BoundaryProxyHandler.staticGetPrototypeOfTrap;
6666
+ this.has = BoundaryProxyHandler.staticHasTrap;
6667
+ this.isExtensible = BoundaryProxyHandler.staticIsExtensibleTrap;
6668
+ this.ownKeys = BoundaryProxyHandler.staticOwnKeysTrap;
6669
+ this.preventExtensions = BoundaryProxyHandler.staticPreventExtensionsTrap;
6670
+ this.set = BoundaryProxyHandler.staticSetTrap;
6671
+ this.setPrototypeOf = BoundaryProxyHandler.staticSetPrototypeOfTrap; // future optimization: hoping that proxies with frozen handlers can be faster
6672
+
6673
+ ObjectFreeze(this);
6674
+ }
6675
+
6676
+ makeProxyUnambiguous(shadowTarget) {
6677
+ // assert: trapMutations must be true
6678
+ if (isForeignTargetMarkedLive(this.foreignTargetPointer)) {
6679
+ this.makeProxyLive();
6680
+ } else {
6681
+ this.makeProxyStatic(shadowTarget);
6264
6682
  }
6265
- class BoundaryProxyHandler {
6266
- constructor(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) {
6267
- // the purpose of this public field is to help developers to identify
6268
- // what side of the membrane they are debugging.
6269
- this.color = color;
6270
- // apply trap is generic, and should never change independently of the type of membrane
6271
- this.apply = function applyTrap(_shadowTarget, thisArg, args) {
6272
- const { foreignTargetPointer } = this;
6273
- const transferableThisArg = getTransferableValue(thisArg);
6274
- const combinedArgs = [foreignTargetPointer, transferableThisArg];
6275
- const { length: argsLen } = args;
6276
- const { length: combinedOffset } = combinedArgs;
6277
- combinedArgs.length += argsLen;
6278
- for (let i = 0, len = argsLen; i < len; i += 1) {
6279
- combinedArgs[i + combinedOffset] = getTransferableValue(args[i]);
6280
- }
6281
- return getLocalValue(ReflectApply(foreignCallableApply, undefined, combinedArgs));
6282
- };
6283
- // construct trap is generic, and should never change independently
6284
- // of the type of membrane
6285
- this.construct = function constructTrap(_shadowTarget, args, newTarget) {
6286
- if (newTarget === undefined) {
6287
- throw new TypeErrorCtor();
6288
- }
6289
- const { foreignTargetPointer } = this;
6290
- const transferableNewTarget = getTransferableValue(newTarget);
6291
- const combinedArgs = [foreignTargetPointer, transferableNewTarget];
6292
- const { length: argsLen } = args;
6293
- const { length: combinedOffset } = combinedArgs;
6294
- combinedArgs.length += argsLen;
6295
- for (let i = 0, len = argsLen; i < len; i += 1) {
6296
- combinedArgs[i + combinedOffset] = getTransferableValue(args[i]);
6297
- }
6298
- return getLocalValue(ReflectApply(foreignCallableConstruct, undefined, combinedArgs));
6299
- };
6300
- const shadowTarget = createShadowTarget(foreignTargetTraits, foreignTargetFunctionName);
6301
- const { proxy, revoke } = ProxyRevocable(shadowTarget, this);
6302
- this.foreignTargetPointer = foreignTargetPointer;
6303
- this.proxy = proxy;
6304
- this.revoke = revoke;
6305
- // inserting default traps
6306
- this.defineProperty = BoundaryProxyHandler.defaultDefinePropertyTrap;
6307
- this.deleteProperty = BoundaryProxyHandler.defaultDeletePropertyTrap;
6308
- this.isExtensible = BoundaryProxyHandler.defaultIsExtensibleTrap;
6309
- this.getOwnPropertyDescriptor =
6310
- BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap;
6311
- this.getPrototypeOf = BoundaryProxyHandler.defaultGetPrototypeOfTrap;
6312
- this.get = BoundaryProxyHandler.defaultGetTrap;
6313
- this.has = BoundaryProxyHandler.defaultHasTrap;
6314
- this.ownKeys = BoundaryProxyHandler.defaultOwnKeysTrap;
6315
- this.preventExtensions = BoundaryProxyHandler.defaultPreventExtensionsTrap;
6316
- this.setPrototypeOf = BoundaryProxyHandler.defaultSetPrototypeOfTrap;
6317
- this.set = BoundaryProxyHandler.defaultSetTrap;
6318
- if (foreignTargetTraits & TargetTraits.Revoked) {
6319
- revoke();
6320
- }
6321
- if (!trapMutations) {
6322
- // if local mutations are not trapped, then freezing the handler is ok
6323
- // because it is not expecting to change in the future.
6324
- // future optimization: hoping that proxies with frozen handlers can be faster
6325
- ObjectFreeze(this);
6326
- }
6327
- }
6328
- // internal utilities
6329
- makeProxyLive() {
6330
- // assert: trapMutations must be true
6331
- // replacing pending traps with live traps that can work with
6332
- // the target without taking snapshots.
6333
- this.defineProperty = BoundaryProxyHandler.liveDefinePropertyTrap;
6334
- this.deleteProperty = BoundaryProxyHandler.liveDeletePropertyTrap;
6335
- this.preventExtensions = BoundaryProxyHandler.livePreventExtensionsTrap;
6336
- this.set = BoundaryProxyHandler.liveSetTrap;
6337
- this.setPrototypeOf = BoundaryProxyHandler.liveSetPrototypeOfTrap;
6338
- // future optimization: hoping that proxies with frozen handlers can be faster
6339
- ObjectFreeze(this);
6340
- }
6341
- makeProxyStatic(shadowTarget) {
6342
- // assert: trapMutations must be true
6343
- const { foreignTargetPointer } = this;
6344
- const targetIntegrityTraits = foreignCallableGetTargetIntegrityTraits(foreignTargetPointer);
6345
- if (targetIntegrityTraits & TargetIntegrityTraits.Revoked) {
6346
- // the target is a revoked proxy, in which case we revoke
6347
- // this proxy as well.
6348
- this.revoke();
6349
- return;
6350
- }
6351
- // adjusting the proto chain of the shadowTarget
6352
- try {
6353
- // a proxy that revoke itself when the __proto__ is accessed
6354
- // can break the membrane, therefore we need protection
6355
- const proto = liveGetPrototypeOf(foreignTargetPointer);
6356
- ReflectSetPrototypeOf(shadowTarget, proto);
6357
- }
6358
- catch {
6359
- // TODO: is revoke the right action here? maybe just setting
6360
- // proto to null instead?
6361
- this.revoke();
6362
- return;
6363
- }
6364
- // defining own descriptors
6365
- copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer);
6366
- // preserving the semantics of the object
6367
- if (targetIntegrityTraits & TargetIntegrityTraits.IsFrozen) {
6368
- ObjectFreeze(shadowTarget);
6369
- }
6370
- else if (targetIntegrityTraits & TargetIntegrityTraits.IsSealed) {
6371
- ObjectSeal(shadowTarget);
6372
- }
6373
- else if (targetIntegrityTraits & TargetIntegrityTraits.IsNotExtensible) {
6374
- ReflectPreventExtensions(shadowTarget);
6375
- }
6376
- // resetting all traps except apply and construct for static
6377
- // proxies since the proxy target is the shadow target and all
6378
- // operations are going to be applied to it rather than the real
6379
- // target.
6380
- this.defineProperty = BoundaryProxyHandler.staticDefinePropertyTrap;
6381
- this.deleteProperty = BoundaryProxyHandler.staticDeletePropertyTrap;
6382
- this.get = BoundaryProxyHandler.staticGetTrap;
6383
- this.getOwnPropertyDescriptor =
6384
- BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap;
6385
- this.getPrototypeOf = BoundaryProxyHandler.staticGetPrototypeOfTrap;
6386
- this.has = BoundaryProxyHandler.staticHasTrap;
6387
- this.isExtensible = BoundaryProxyHandler.staticIsExtensibleTrap;
6388
- this.ownKeys = BoundaryProxyHandler.staticOwnKeysTrap;
6389
- this.preventExtensions = BoundaryProxyHandler.staticPreventExtensionsTrap;
6390
- this.set = BoundaryProxyHandler.staticSetTrap;
6391
- this.setPrototypeOf = BoundaryProxyHandler.staticSetPrototypeOfTrap;
6392
- // future optimization: hoping that proxies with frozen handlers can be faster
6393
- ObjectFreeze(this);
6394
- }
6395
- makeProxyUnambiguous(shadowTarget) {
6396
- // assert: trapMutations must be true
6397
- if (isForeignTargetMarkedLive(this.foreignTargetPointer)) {
6398
- this.makeProxyLive();
6399
- }
6400
- else {
6401
- this.makeProxyStatic(shadowTarget);
6402
- }
6403
- }
6404
- // logic implementation of all traps
6405
- // live traps:
6406
- /**
6407
- * Traps with proto chain traversal capabilities are the exception of
6408
- * the rules here, the problem is that the other side might or might
6409
- * not have:
6410
- * a) local mutations only
6411
- * b) distortions
6412
- *
6413
- * Therefore, the logic has to be bound to the caller, the one
6414
- * initiating the across membrane access.
6415
- */
6416
- static liveDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6417
- return liveDefineProperty(this.foreignTargetPointer, shadowTarget, key, unsafePartialDesc);
6418
- }
6419
- static liveDeletePropertyTrap(shadowTarget, key) {
6420
- return liveDeleteProperty(this.foreignTargetPointer, shadowTarget, key);
6421
- }
6422
- static liveGetOwnPropertyDescriptorTrap(shadowTarget, key) {
6423
- return liveGetOwnPropertyDescriptor(this.foreignTargetPointer, shadowTarget, key);
6424
- }
6425
- static liveGetPrototypeOfTrap(_shadowTarget) {
6426
- return liveGetPrototypeOf(this.foreignTargetPointer);
6427
- }
6428
- /**
6429
- * This trap cannot just use `ReflectGet` directly on the `target`
6430
- * because the red object graph might have mutations that are only
6431
- * visible on the red side, which means looking into `target` directly
6432
- * is not viable. Instead, we need to implement a more crafty solution
6433
- * that looks into target's own properties, or in the red proto chain
6434
- * when needed.
6435
- *
6436
- * In a transparent membrane, this method will have been a lot simpler, like:
6437
- *
6438
- * const { foreignTargetPointer } = this;
6439
- * const receiverPointer = getValueOrPointer(receiver);
6440
- * const foreignValueOrCallable =
6441
- * foreignCallableGet(foreignTargetPointer, key, receiverPointer);
6442
- * return getLocalValue(foreignValueOrCallable);
6443
- *
6444
- */
6445
- static liveGetTrap(shadowTarget, key, receiver) {
6446
- // assert: trapMutations must be true
6447
- return liveGet(this.foreignTargetPointer, shadowTarget, key, receiver);
6448
- }
6449
- /**
6450
- * This trap cannot just use `Reflect.has` or the `in` operator
6451
- * directly because the red object graph might have mutations that
6452
- * are only visible on the red side, which means looking into `target`
6453
- * directly is not viable. Instead, we need to implement a more crafty
6454
- * solution that looks into target's own properties, or in the red
6455
- * proto chain when needed.
6456
- *
6457
- * In a transparent membrane, this method will have been a lot
6458
- * simpler, like:
6459
- *
6460
- * const { foreignTargetPointer } = this;
6461
- * return foreignCallableHas(foreignTargetPointer, key);
6462
- *
6463
- */
6464
- static liveHasTrap(_shadowTarget, key) {
6465
- // assert: trapMutations must be true
6466
- return liveHas(this.foreignTargetPointer, key);
6467
- }
6468
- static liveIsExtensibleTrap(shadowTarget) {
6469
- return liveIsExtensible(this.foreignTargetPointer, shadowTarget);
6470
- }
6471
- static liveOwnKeysTrap(_shadowTarget) {
6472
- return liveOwnKeys(this.foreignTargetPointer);
6473
- }
6474
- static livePreventExtensionsTrap(shadowTarget) {
6475
- return livePreventExtensions(this.foreignTargetPointer, shadowTarget);
6476
- }
6477
- static liveSetPrototypeOfTrap(_shadowTarget, proto) {
6478
- return liveSetPrototypeOf(this.foreignTargetPointer, proto);
6479
- }
6480
- /**
6481
- * This trap cannot just use `ReflectSet` directly on the `target` because
6482
- * the red object graph might have mutations that are only visible on the red side,
6483
- * which means looking into `target` directly is not viable. Instead, we need to
6484
- * implement a more crafty solution that looks into target's own properties, or
6485
- * in the red proto chain when needed.
6486
- *
6487
- * const { foreignTargetPointer } = this;
6488
- * const valuePointer = getValueOrPointer(value);
6489
- * const receiverPointer = getValueOrPointer(receiver);
6490
- * return foreignCallableSet(foreignTargetPointer, key, valuePointer, receiverPointer);
6491
- *
6492
- */
6493
- static liveSetTrap(shadowTarget, key, value, receiver) {
6494
- // assert: trapMutations must be true
6495
- const useFastPath = this.proxy === receiver;
6496
- return liveSet(this.foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath);
6497
- }
6498
- // pending traps
6499
- static pendingDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6500
- // assert: trapMutations must be true
6501
- this.makeProxyUnambiguous(shadowTarget);
6502
- return this.defineProperty(shadowTarget, key, unsafePartialDesc);
6503
- }
6504
- static pendingDeletePropertyTrap(shadowTarget, key) {
6505
- // assert: trapMutations must be true
6506
- this.makeProxyUnambiguous(shadowTarget);
6507
- return this.deleteProperty(shadowTarget, key);
6508
- }
6509
- static pendingPreventExtensionsTrap(shadowTarget) {
6510
- // assert: trapMutations must be true
6511
- this.makeProxyUnambiguous(shadowTarget);
6512
- return this.preventExtensions(shadowTarget);
6513
- }
6514
- static pendingSetPrototypeOfTrap(shadowTarget, proto) {
6515
- // assert: trapMutations must be true
6516
- this.makeProxyUnambiguous(shadowTarget);
6517
- return this.setPrototypeOf(shadowTarget, proto);
6518
- }
6519
- static pendingSetTrap(shadowTarget, key, value, receiver) {
6520
- // assert: trapMutations must be true
6521
- this.makeProxyUnambiguous(shadowTarget);
6522
- return this.set(shadowTarget, key, value, receiver);
6523
- }
6524
- /**
6525
- * This trap is just `ReflectGet` plus handling of object branding
6526
- * for proxies.
6527
- *
6528
- */
6529
- static staticGetTrap(shadowTarget, key, receiver) {
6530
- if (key === TO_STRING_TAG_SYMBOL) {
6531
- return foreignCallableGetUnbrandedTag(this.foreignTargetPointer);
6532
- }
6533
- return ReflectGet(shadowTarget, key, receiver);
6534
- }
6683
+ } // logic implementation of all traps
6684
+ // live traps:
6685
+
6686
+ /**
6687
+ * Traps with proto chain traversal capabilities are the exception of
6688
+ * the rules here, the problem is that the other side might or might
6689
+ * not have:
6690
+ * a) local mutations only
6691
+ * b) distortions
6692
+ *
6693
+ * Therefore, the logic has to be bound to the caller, the one
6694
+ * initiating the across membrane access.
6695
+ */
6696
+
6697
+
6698
+ static liveDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6699
+ return liveDefineProperty(this.foreignTargetPointer, shadowTarget, key, unsafePartialDesc);
6700
+ }
6701
+
6702
+ static liveDeletePropertyTrap(shadowTarget, key) {
6703
+ return liveDeleteProperty(this.foreignTargetPointer, shadowTarget, key);
6704
+ }
6705
+
6706
+ static liveGetOwnPropertyDescriptorTrap(shadowTarget, key) {
6707
+ return liveGetOwnPropertyDescriptor(this.foreignTargetPointer, shadowTarget, key);
6708
+ }
6709
+
6710
+ static liveGetPrototypeOfTrap(_shadowTarget) {
6711
+ return liveGetPrototypeOf(this.foreignTargetPointer);
6712
+ }
6713
+ /**
6714
+ * This trap cannot just use `ReflectGet` directly on the `target`
6715
+ * because the red object graph might have mutations that are only
6716
+ * visible on the red side, which means looking into `target` directly
6717
+ * is not viable. Instead, we need to implement a more crafty solution
6718
+ * that looks into target's own properties, or in the red proto chain
6719
+ * when needed.
6720
+ *
6721
+ * In a transparent membrane, this method will have been a lot simpler, like:
6722
+ *
6723
+ * const { foreignTargetPointer } = this;
6724
+ * const receiverPointer = getValueOrPointer(receiver);
6725
+ * const foreignValueOrCallable =
6726
+ * foreignCallableGet(foreignTargetPointer, key, receiverPointer);
6727
+ * return getLocalValue(foreignValueOrCallable);
6728
+ *
6729
+ */
6730
+
6731
+
6732
+ static liveGetTrap(shadowTarget, key, receiver) {
6733
+ // assert: trapMutations must be true
6734
+ return liveGet(this.foreignTargetPointer, shadowTarget, key, receiver);
6735
+ }
6736
+ /**
6737
+ * This trap cannot just use `Reflect.has` or the `in` operator
6738
+ * directly because the red object graph might have mutations that
6739
+ * are only visible on the red side, which means looking into `target`
6740
+ * directly is not viable. Instead, we need to implement a more crafty
6741
+ * solution that looks into target's own properties, or in the red
6742
+ * proto chain when needed.
6743
+ *
6744
+ * In a transparent membrane, this method will have been a lot
6745
+ * simpler, like:
6746
+ *
6747
+ * const { foreignTargetPointer } = this;
6748
+ * return foreignCallableHas(foreignTargetPointer, key);
6749
+ *
6750
+ */
6751
+
6752
+
6753
+ static liveHasTrap(_shadowTarget, key) {
6754
+ // assert: trapMutations must be true
6755
+ return liveHas(this.foreignTargetPointer, key);
6756
+ }
6757
+
6758
+ static liveIsExtensibleTrap(shadowTarget) {
6759
+ return liveIsExtensible(this.foreignTargetPointer, shadowTarget);
6760
+ }
6761
+
6762
+ static liveOwnKeysTrap(_shadowTarget) {
6763
+ return liveOwnKeys(this.foreignTargetPointer);
6764
+ }
6765
+
6766
+ static livePreventExtensionsTrap(shadowTarget) {
6767
+ return livePreventExtensions(this.foreignTargetPointer, shadowTarget);
6768
+ }
6769
+
6770
+ static liveSetPrototypeOfTrap(_shadowTarget, proto) {
6771
+ return liveSetPrototypeOf(this.foreignTargetPointer, proto);
6772
+ }
6773
+ /**
6774
+ * This trap cannot just use `ReflectSet` directly on the `target` because
6775
+ * the red object graph might have mutations that are only visible on the red side,
6776
+ * which means looking into `target` directly is not viable. Instead, we need to
6777
+ * implement a more crafty solution that looks into target's own properties, or
6778
+ * in the red proto chain when needed.
6779
+ *
6780
+ * const { foreignTargetPointer } = this;
6781
+ * const valuePointer = getValueOrPointer(value);
6782
+ * const receiverPointer = getValueOrPointer(receiver);
6783
+ * return foreignCallableSet(foreignTargetPointer, key, valuePointer, receiverPointer);
6784
+ *
6785
+ */
6786
+
6787
+
6788
+ static liveSetTrap(shadowTarget, key, value, receiver) {
6789
+ // assert: trapMutations must be true
6790
+ const useFastPath = this.proxy === receiver;
6791
+ return liveSet(this.foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath);
6792
+ } // pending traps
6793
+
6794
+
6795
+ static pendingDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6796
+ // assert: trapMutations must be true
6797
+ this.makeProxyUnambiguous(shadowTarget);
6798
+ return this.defineProperty(shadowTarget, key, unsafePartialDesc);
6799
+ }
6800
+
6801
+ static pendingDeletePropertyTrap(shadowTarget, key) {
6802
+ // assert: trapMutations must be true
6803
+ this.makeProxyUnambiguous(shadowTarget);
6804
+ return this.deleteProperty(shadowTarget, key);
6805
+ }
6806
+
6807
+ static pendingPreventExtensionsTrap(shadowTarget) {
6808
+ // assert: trapMutations must be true
6809
+ this.makeProxyUnambiguous(shadowTarget);
6810
+ return this.preventExtensions(shadowTarget);
6811
+ }
6812
+
6813
+ static pendingSetPrototypeOfTrap(shadowTarget, proto) {
6814
+ // assert: trapMutations must be true
6815
+ this.makeProxyUnambiguous(shadowTarget);
6816
+ return this.setPrototypeOf(shadowTarget, proto);
6817
+ }
6818
+
6819
+ static pendingSetTrap(shadowTarget, key, value, receiver) {
6820
+ // assert: trapMutations must be true
6821
+ this.makeProxyUnambiguous(shadowTarget);
6822
+ return this.set(shadowTarget, key, value, receiver);
6823
+ }
6824
+ /**
6825
+ * This trap is just `ReflectGet` plus handling of object branding
6826
+ * for proxies.
6827
+ *
6828
+ */
6829
+
6830
+
6831
+ static staticGetTrap(shadowTarget, key, receiver) {
6832
+ if (key === TO_STRING_TAG_SYMBOL) {
6833
+ return foreignCallableGetUnbrandedTag(this.foreignTargetPointer);
6535
6834
  }
6536
- BoundaryProxyHandler.staticDefinePropertyTrap = ReflectDefineProperty;
6537
- BoundaryProxyHandler.staticDeletePropertyTrap = ReflectDeleteProperty;
6538
- BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap = ReflectGetOwnPropertyDescriptor;
6539
- BoundaryProxyHandler.staticGetPrototypeOfTrap = ReflectGetPrototypeOf;
6540
- BoundaryProxyHandler.staticHasTrap = ReflectHas;
6541
- BoundaryProxyHandler.staticIsExtensibleTrap = ReflectIsExtensible;
6542
- BoundaryProxyHandler.staticOwnKeysTrap = ReflectOwnKeys;
6543
- BoundaryProxyHandler.staticPreventExtensionsTrap = ReflectPreventExtensions;
6544
- BoundaryProxyHandler.staticSetTrap = ReflectSet;
6545
- BoundaryProxyHandler.staticSetPrototypeOfTrap = ReflectSetPrototypeOf;
6546
- // static default traps
6547
- // (optimization to avoid computations of the proper trap in constructor)
6548
- BoundaryProxyHandler.defaultGetTrap = BoundaryProxyHandler.liveGetTrap;
6549
- BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap = BoundaryProxyHandler.liveGetOwnPropertyDescriptorTrap;
6550
- BoundaryProxyHandler.defaultGetPrototypeOfTrap = BoundaryProxyHandler.liveGetPrototypeOfTrap;
6551
- BoundaryProxyHandler.defaultHasTrap = BoundaryProxyHandler.liveHasTrap;
6552
- BoundaryProxyHandler.defaultIsExtensibleTrap = BoundaryProxyHandler.liveIsExtensibleTrap;
6553
- BoundaryProxyHandler.defaultOwnKeysTrap = BoundaryProxyHandler.liveOwnKeysTrap;
6554
- // pending traps are only really needed if this membrane traps
6555
- // mutations to avoid mutations operations on the side of the membrane.
6556
- // TODO: find a way to optimize the declaration rather than instantiation
6557
- BoundaryProxyHandler.defaultDefinePropertyTrap = trapMutations
6558
- ? BoundaryProxyHandler.pendingDefinePropertyTrap
6559
- : BoundaryProxyHandler.liveDefinePropertyTrap;
6560
- BoundaryProxyHandler.defaultDeletePropertyTrap = trapMutations
6561
- ? BoundaryProxyHandler.pendingDeletePropertyTrap
6562
- : BoundaryProxyHandler.liveDeletePropertyTrap;
6563
- BoundaryProxyHandler.defaultPreventExtensionsTrap = trapMutations
6564
- ? BoundaryProxyHandler.pendingPreventExtensionsTrap
6565
- : BoundaryProxyHandler.livePreventExtensionsTrap;
6566
- BoundaryProxyHandler.defaultSetTrap = trapMutations
6567
- ? BoundaryProxyHandler.pendingSetTrap
6568
- : BoundaryProxyHandler.liveSetTrap;
6569
- BoundaryProxyHandler.defaultSetPrototypeOfTrap = trapMutations
6570
- ? BoundaryProxyHandler.pendingSetPrototypeOfTrap
6571
- : BoundaryProxyHandler.liveSetPrototypeOfTrap;
6572
- ReflectSetPrototypeOf(BoundaryProxyHandler.prototype, null);
6573
- // future optimization: hoping proxies with frozen handlers can be faster
6574
- ObjectFreeze(BoundaryProxyHandler.prototype);
6575
- // exporting callable hooks for a foreign realm
6576
- foreignCallableHooksCallback(
6577
- // globalThisPointer
6578
- // When crossing, should be mapped to the foreign globalThis
6579
- createPointer(globalThis),
6580
- // getSelectedTarget
6581
- getSelectedTarget,
6582
- // getTransferableValue
6583
- getTransferableValue,
6584
- // callableGetPropertyValuePointer: this callable function allows
6585
- // the foreign realm to access a linkable pointer for a property value.
6586
- // In order to do that, the foreign side must provide a pointer and
6587
- // a key access the value in order to produce a pointer
6588
- (targetPointer, key) => {
6589
- targetPointer();
6590
- const target = getSelectedTarget();
6591
- const value = target[key];
6592
- // TODO: what if the value is not a valid proxy target?
6593
- return createPointer(value);
6594
- },
6595
- // callableEvaluate
6596
- (sourceText) => {
6597
- try {
6598
- return getTransferableValue(cachedLocalEval(sourceText));
6599
- }
6600
- catch (e) {
6601
- throw pushErrorAcrossBoundary(e);
6602
- }
6603
- },
6604
- // callableLinkPointers: this callable function allows the foreign
6605
- // realm to define a linkage between two values across the membrane.
6606
- (targetPointer, newPointer) => {
6607
- targetPointer();
6608
- const target = getSelectedTarget();
6609
- ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [target, newPointer]);
6610
- },
6611
- /**
6612
- * callablePushTarget: This function can be used by a foreign realm to install a proxy
6613
- * into this realm that correspond to an object from the foreign realm. It returns
6614
- * a Pointer that can be used by the foreign realm to pass back a reference to this
6615
- * realm when passing arguments or returning from a foreign callable invocation. This
6616
- * function is extremely important to understand the mechanics of this membrane.
6617
- */
6618
- (foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) => {
6619
- const { proxy } = new BoundaryProxyHandler(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName);
6620
- ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [
6621
- proxy,
6622
- foreignTargetPointer,
6623
- ]);
6624
- return createPointer(proxy);
6625
- },
6626
- // callableApply
6627
- instrumentCallableWrapper((targetPointer, thisArgPointerOrValue, ...listOfValuesOrPointers) => {
6628
- targetPointer();
6629
- const fn = getSelectedTarget();
6630
- const thisArg = getLocalValue(thisArgPointerOrValue);
6631
- const { length: argsLen } = listOfValuesOrPointers;
6632
- const args = new ArrayCtor(argsLen);
6633
- for (let i = 0, len = argsLen; i < len; i += 1) {
6634
- args[i] = getLocalValue(listOfValuesOrPointers[i]);
6635
- }
6636
- let value;
6637
- try {
6638
- value = ReflectApply(fn, thisArg, args);
6639
- }
6640
- catch (e) {
6641
- throw pushErrorAcrossBoundary(e);
6642
- }
6643
- return getTransferableValue(value);
6644
- }, 'callableApply', INBOUND_INSTRUMENTATION_LABEL),
6645
- // callableConstruct
6646
- instrumentCallableWrapper((targetPointer, newTargetPointerOrValue, ...listOfValuesOrPointers) => {
6647
- targetPointer();
6648
- const constructor = getSelectedTarget();
6649
- const newTarget = getLocalValue(newTargetPointerOrValue);
6650
- const { length: argsLen } = listOfValuesOrPointers;
6651
- const args = new ArrayCtor(argsLen);
6652
- for (let i = 0, len = argsLen; i < len; i += 1) {
6653
- args[i] = getLocalValue(listOfValuesOrPointers[i]);
6654
- }
6655
- let value;
6656
- try {
6657
- value = ReflectConstruct(constructor, args, newTarget);
6658
- }
6659
- catch (e) {
6660
- throw pushErrorAcrossBoundary(e);
6661
- }
6662
- return getTransferableValue(value);
6663
- }, 'callableConstruct', INBOUND_INSTRUMENTATION_LABEL),
6664
- // callableDefineProperty
6665
- instrumentCallableWrapper((targetPointer, key, configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6666
- targetPointer();
6667
- const target = getSelectedTarget();
6668
- try {
6669
- return ReflectDefineProperty(target, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
6670
- }
6671
- catch (e) {
6672
- throw pushErrorAcrossBoundary(e);
6673
- }
6674
- }, 'callableDefineProperty', INBOUND_INSTRUMENTATION_LABEL),
6675
- // callableDeleteProperty
6676
- instrumentCallableWrapper((targetPointer, key) => {
6677
- targetPointer();
6678
- const target = getSelectedTarget();
6679
- try {
6680
- return ReflectDeleteProperty(target, key);
6681
- }
6682
- catch (e) {
6683
- throw pushErrorAcrossBoundary(e);
6684
- }
6685
- }, 'callableDeleteProperty', INBOUND_INSTRUMENTATION_LABEL),
6686
- // callableGetOwnPropertyDescriptor
6687
- instrumentCallableWrapper((targetPointer, key, foreignCallableDescriptorCallback) => {
6688
- targetPointer();
6689
- const target = getSelectedTarget();
6690
- let unsafeDesc;
6691
- try {
6692
- unsafeDesc = ReflectGetOwnPropertyDescriptor(target, key);
6693
- }
6694
- catch (e) {
6695
- throw pushErrorAcrossBoundary(e);
6696
- }
6697
- if (unsafeDesc) {
6698
- const descMeta = getDescriptorMeta(unsafeDesc);
6699
- foreignCallableDescriptorCallback(descMeta[0], // configurable
6700
- descMeta[1], // enumerable
6701
- descMeta[2], // writable
6702
- descMeta[3], // valuePointer
6703
- descMeta[4], // getPointer
6704
- descMeta[5] // setPointer
6705
- );
6706
- }
6707
- }, 'callableGetOwnPropertyDescriptor', INBOUND_INSTRUMENTATION_LABEL),
6708
- // callableGetPrototypeOf
6709
- instrumentCallableWrapper((targetPointer) => {
6710
- targetPointer();
6711
- const target = getSelectedTarget();
6712
- let proto;
6713
- try {
6714
- proto = ReflectGetPrototypeOf(target);
6715
- }
6716
- catch (e) {
6717
- throw pushErrorAcrossBoundary(e);
6718
- }
6719
- return getTransferableValue(proto);
6720
- }, 'callableGetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL),
6721
- // callableIsExtensible
6722
- instrumentCallableWrapper((targetPointer) => {
6723
- targetPointer();
6724
- const target = getSelectedTarget();
6725
- try {
6726
- return ReflectIsExtensible(target);
6727
- }
6728
- catch (e) {
6729
- throw pushErrorAcrossBoundary(e);
6730
- }
6731
- }, 'callableIsExtensible', INBOUND_INSTRUMENTATION_LABEL),
6732
- // callableOwnKeys
6733
- instrumentCallableWrapper((targetPointer, foreignCallableKeysCallback) => {
6734
- targetPointer();
6735
- const target = getSelectedTarget();
6736
- let keys;
6737
- try {
6738
- keys = ReflectOwnKeys(target);
6739
- }
6740
- catch (e) {
6741
- throw pushErrorAcrossBoundary(e);
6742
- }
6743
- ReflectApply(foreignCallableKeysCallback, undefined, keys);
6744
- }, 'callableOwnKeys', INBOUND_INSTRUMENTATION_LABEL),
6745
- // callablePreventExtensions
6746
- instrumentCallableWrapper((targetPointer) => {
6747
- targetPointer();
6748
- const target = getSelectedTarget();
6749
- try {
6750
- return ReflectPreventExtensions(target);
6751
- }
6752
- catch (e) {
6753
- throw pushErrorAcrossBoundary(e);
6754
- }
6755
- }, 'callablePreventExtensions', INBOUND_INSTRUMENTATION_LABEL),
6756
- // callableSet
6757
- instrumentCallableWrapper((targetPointer, propertyKey, valuePointer, receiverPointer) => {
6758
- targetPointer();
6759
- const target = getSelectedTarget();
6760
- try {
6761
- return ReflectSet(target, propertyKey, getLocalValue(valuePointer), getLocalValue(receiverPointer));
6762
- }
6763
- catch (e) {
6764
- throw pushErrorAcrossBoundary(e);
6765
- }
6766
- }, 'callableSet', INBOUND_INSTRUMENTATION_LABEL),
6767
- // callableSetPrototypeOf
6768
- instrumentCallableWrapper((targetPointer, protoPointerOrNull) => {
6769
- targetPointer();
6770
- const target = getSelectedTarget();
6771
- const proto = getLocalValue(protoPointerOrNull);
6772
- try {
6773
- return ReflectSetPrototypeOf(target, proto);
6774
- }
6775
- catch (e) {
6776
- throw pushErrorAcrossBoundary(e);
6777
- }
6778
- }, 'callableSetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL),
6779
- // callableGetTargetIntegrityTraits
6780
- instrumentCallableWrapper((targetPointer) => {
6781
- targetPointer();
6782
- const target = getSelectedTarget();
6783
- return getTargetIntegrityTraits(target);
6784
- }, 'callableGetTargetIntegrityTraits', INBOUND_INSTRUMENTATION_LABEL),
6785
- // callableGetUnbrandedTag
6786
- instrumentCallableWrapper((targetPointer) => {
6787
- targetPointer();
6788
- const target = getSelectedTarget();
6789
- try {
6790
- if (typeof target === 'object' &&
6791
- target !== null &&
6792
- !isArrayOrNotOrThrowForRevoked(target)) {
6793
- // Section 19.1.3.6: Object.prototype.toString()
6794
- // Step 16: If `Type(tag)` is not `String`, let `tag` be `builtinTag`.
6795
- // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
6796
- const toStringValue = ReflectApply(ObjectProtoToString, target, []);
6797
- return ReflectApply(StringProtoSlice, toStringValue, [8, -1]);
6798
- }
6799
- // eslint-disable-next-line no-empty
6800
- }
6801
- catch { }
6802
- return undefined;
6803
- }, 'callableGetUnbrandedTag', INBOUND_INSTRUMENTATION_LABEL),
6804
- // callableHasOwnProperty
6805
- instrumentCallableWrapper((targetPointer, key) => {
6806
- targetPointer();
6807
- const target = getSelectedTarget();
6808
- try {
6809
- return ReflectApply(ObjectProtoHasOwnProperty, target, [key]);
6810
- }
6811
- catch (e) {
6812
- throw pushErrorAcrossBoundary(e);
6813
- }
6814
- }, 'callableHasOwnProperty', INBOUND_INSTRUMENTATION_LABEL));
6815
- return (...hooks) => {
6816
- const {
6817
- // 0: globalThisPointer,
6818
- // 1: getSelectedTarget,
6819
- // 2: getTransferableValue,
6820
- // 3: callableGetPropertyValuePointer,
6821
- // 4: callableEvaluate,
6822
- // 5: callableLinkPointers,
6823
- 6: callablePushTarget, 7: callableApply, 8: callableConstruct, 9: callableDefineProperty, 10: callableDeleteProperty, 11: callableGetOwnPropertyDescriptor, 12: callableGetPrototypeOf, 13: callableIsExtensible, 14: callableOwnKeys, 15: callablePreventExtensions, 16: callableSet, 17: callableSetPrototypeOf, 18: callableGetTargetIntegrityTraits, 19: callableGetUnbrandedTag, 20: callableHasOwnProperty, } = hooks;
6824
- foreignCallablePushTarget = callablePushTarget;
6825
- // traps utilities
6826
- foreignCallableApply = foreignErrorControl(instrumentCallableWrapper(callableApply, 'callableApply', OUTBOUND_INSTRUMENTATION_LABEL));
6827
- foreignCallableConstruct = foreignErrorControl(instrumentCallableWrapper(callableConstruct, 'callableConstruct', OUTBOUND_INSTRUMENTATION_LABEL));
6828
- foreignCallableDefineProperty = foreignErrorControl(instrumentCallableWrapper(callableDefineProperty, 'callableDefineProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6829
- foreignCallableDeleteProperty = foreignErrorControl(instrumentCallableWrapper(callableDeleteProperty, 'callableDeleteProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6830
- foreignCallableGetOwnPropertyDescriptor = foreignErrorControl(instrumentCallableWrapper(callableGetOwnPropertyDescriptor, 'callableGetOwnPropertyDescriptor', OUTBOUND_INSTRUMENTATION_LABEL));
6831
- foreignCallableGetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableGetPrototypeOf, 'callableGetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
6832
- foreignCallableIsExtensible = foreignErrorControl(instrumentCallableWrapper(callableIsExtensible, 'callableIsExtensible', OUTBOUND_INSTRUMENTATION_LABEL));
6833
- foreignCallableOwnKeys = foreignErrorControl(instrumentCallableWrapper(callableOwnKeys, 'callableOwnKeys', OUTBOUND_INSTRUMENTATION_LABEL));
6834
- foreignCallablePreventExtensions = foreignErrorControl(instrumentCallableWrapper(callablePreventExtensions, 'callablePreventExtensions', OUTBOUND_INSTRUMENTATION_LABEL));
6835
- foreignCallableSet = foreignErrorControl(instrumentCallableWrapper(callableSet, 'callableSet', OUTBOUND_INSTRUMENTATION_LABEL));
6836
- foreignCallableSetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableSetPrototypeOf, 'callableSetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
6837
- foreignCallableGetTargetIntegrityTraits = foreignErrorControl(instrumentCallableWrapper(callableGetTargetIntegrityTraits, 'callableGetTargetIntegrityTraits', OUTBOUND_INSTRUMENTATION_LABEL));
6838
- foreignCallableGetUnbrandedTag = foreignErrorControl(instrumentCallableWrapper(callableGetUnbrandedTag, 'callableGetUnbrandedTag', OUTBOUND_INSTRUMENTATION_LABEL));
6839
- foreignCallableHasOwnProperty = foreignErrorControl(instrumentCallableWrapper(callableHasOwnProperty, 'callableHasOwnProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6840
- };
6835
+
6836
+ return ReflectGet(shadowTarget, key, receiver);
6837
+ }
6838
+
6839
+ }
6840
+
6841
+ BoundaryProxyHandler.staticDefinePropertyTrap = ReflectDefineProperty;
6842
+ BoundaryProxyHandler.staticDeletePropertyTrap = ReflectDeleteProperty;
6843
+ BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap = ReflectGetOwnPropertyDescriptor;
6844
+ BoundaryProxyHandler.staticGetPrototypeOfTrap = ReflectGetPrototypeOf;
6845
+ BoundaryProxyHandler.staticHasTrap = ReflectHas;
6846
+ BoundaryProxyHandler.staticIsExtensibleTrap = ReflectIsExtensible;
6847
+ BoundaryProxyHandler.staticOwnKeysTrap = ReflectOwnKeys;
6848
+ BoundaryProxyHandler.staticPreventExtensionsTrap = ReflectPreventExtensions;
6849
+ BoundaryProxyHandler.staticSetTrap = ReflectSet;
6850
+ BoundaryProxyHandler.staticSetPrototypeOfTrap = ReflectSetPrototypeOf; // static default traps
6851
+ // (optimization to avoid computations of the proper trap in constructor)
6852
+
6853
+ BoundaryProxyHandler.defaultGetTrap = BoundaryProxyHandler.liveGetTrap;
6854
+ BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap = BoundaryProxyHandler.liveGetOwnPropertyDescriptorTrap;
6855
+ BoundaryProxyHandler.defaultGetPrototypeOfTrap = BoundaryProxyHandler.liveGetPrototypeOfTrap;
6856
+ BoundaryProxyHandler.defaultHasTrap = BoundaryProxyHandler.liveHasTrap;
6857
+ BoundaryProxyHandler.defaultIsExtensibleTrap = BoundaryProxyHandler.liveIsExtensibleTrap;
6858
+ BoundaryProxyHandler.defaultOwnKeysTrap = BoundaryProxyHandler.liveOwnKeysTrap; // pending traps are only really needed if this membrane traps
6859
+ // mutations to avoid mutations operations on the side of the membrane.
6860
+ // TODO: find a way to optimize the declaration rather than instantiation
6861
+
6862
+ BoundaryProxyHandler.defaultDefinePropertyTrap = trapMutations ? BoundaryProxyHandler.pendingDefinePropertyTrap : BoundaryProxyHandler.liveDefinePropertyTrap;
6863
+ BoundaryProxyHandler.defaultDeletePropertyTrap = trapMutations ? BoundaryProxyHandler.pendingDeletePropertyTrap : BoundaryProxyHandler.liveDeletePropertyTrap;
6864
+ BoundaryProxyHandler.defaultPreventExtensionsTrap = trapMutations ? BoundaryProxyHandler.pendingPreventExtensionsTrap : BoundaryProxyHandler.livePreventExtensionsTrap;
6865
+ BoundaryProxyHandler.defaultSetTrap = trapMutations ? BoundaryProxyHandler.pendingSetTrap : BoundaryProxyHandler.liveSetTrap;
6866
+ BoundaryProxyHandler.defaultSetPrototypeOfTrap = trapMutations ? BoundaryProxyHandler.pendingSetPrototypeOfTrap : BoundaryProxyHandler.liveSetPrototypeOfTrap;
6867
+ ReflectSetPrototypeOf(BoundaryProxyHandler.prototype, null); // future optimization: hoping proxies with frozen handlers can be faster
6868
+
6869
+ ObjectFreeze(BoundaryProxyHandler.prototype); // exporting callable hooks for a foreign realm
6870
+
6871
+ foreignCallableHooksCallback( // globalThisPointer
6872
+ // When crossing, should be mapped to the foreign globalThis
6873
+ createPointer(globalThis), // getSelectedTarget
6874
+ getSelectedTarget, // getTransferableValue
6875
+ getTransferableValue, // callableGetPropertyValuePointer: this callable function allows
6876
+ // the foreign realm to access a linkable pointer for a property value.
6877
+ // In order to do that, the foreign side must provide a pointer and
6878
+ // a key access the value in order to produce a pointer
6879
+ (targetPointer, key) => {
6880
+ targetPointer();
6881
+ const target = getSelectedTarget();
6882
+ const value = target[key]; // TODO: what if the value is not a valid proxy target?
6883
+
6884
+ return createPointer(value);
6885
+ }, // callableEvaluate
6886
+ sourceText => {
6887
+ try {
6888
+ return getTransferableValue(cachedLocalEval(sourceText));
6889
+ } catch (e) {
6890
+ throw pushErrorAcrossBoundary(e);
6891
+ }
6892
+ }, // callableLinkPointers: this callable function allows the foreign
6893
+ // realm to define a linkage between two values across the membrane.
6894
+ (targetPointer, newPointer) => {
6895
+ targetPointer();
6896
+ const target = getSelectedTarget();
6897
+ ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [target, newPointer]);
6898
+ },
6899
+ /**
6900
+ * callablePushTarget: This function can be used by a foreign realm to install a proxy
6901
+ * into this realm that correspond to an object from the foreign realm. It returns
6902
+ * a Pointer that can be used by the foreign realm to pass back a reference to this
6903
+ * realm when passing arguments or returning from a foreign callable invocation. This
6904
+ * function is extremely important to understand the mechanics of this membrane.
6905
+ */
6906
+ (foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) => {
6907
+ const {
6908
+ proxy
6909
+ } = new BoundaryProxyHandler(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName);
6910
+ ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [proxy, foreignTargetPointer]);
6911
+ return createPointer(proxy);
6912
+ }, // callableApply
6913
+ instrumentCallableWrapper(function (targetPointer, thisArgPointerOrValue) {
6914
+ targetPointer();
6915
+ const fn = getSelectedTarget();
6916
+ const thisArg = getLocalValue(thisArgPointerOrValue);
6917
+
6918
+ for (var _len5 = arguments.length, listOfValuesOrPointers = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
6919
+ listOfValuesOrPointers[_key5 - 2] = arguments[_key5];
6920
+ }
6921
+
6922
+ const {
6923
+ length: argsLen
6924
+ } = listOfValuesOrPointers;
6925
+ const args = new ArrayCtor(argsLen);
6926
+
6927
+ for (let i = 0, len = argsLen; i < len; i += 1) {
6928
+ args[i] = getLocalValue(listOfValuesOrPointers[i]);
6929
+ }
6930
+
6931
+ let value;
6932
+
6933
+ try {
6934
+ value = ReflectApply(fn, thisArg, args);
6935
+ } catch (e) {
6936
+ throw pushErrorAcrossBoundary(e);
6937
+ }
6938
+
6939
+ return getTransferableValue(value);
6940
+ }, 'callableApply', INBOUND_INSTRUMENTATION_LABEL), // callableConstruct
6941
+ instrumentCallableWrapper(function (targetPointer, newTargetPointerOrValue) {
6942
+ targetPointer();
6943
+ const constructor = getSelectedTarget();
6944
+ const newTarget = getLocalValue(newTargetPointerOrValue);
6945
+
6946
+ for (var _len6 = arguments.length, listOfValuesOrPointers = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
6947
+ listOfValuesOrPointers[_key6 - 2] = arguments[_key6];
6948
+ }
6949
+
6950
+ const {
6951
+ length: argsLen
6952
+ } = listOfValuesOrPointers;
6953
+ const args = new ArrayCtor(argsLen);
6954
+
6955
+ for (let i = 0, len = argsLen; i < len; i += 1) {
6956
+ args[i] = getLocalValue(listOfValuesOrPointers[i]);
6957
+ }
6958
+
6959
+ let value;
6960
+
6961
+ try {
6962
+ value = ReflectConstruct(constructor, args, newTarget);
6963
+ } catch (e) {
6964
+ throw pushErrorAcrossBoundary(e);
6965
+ }
6966
+
6967
+ return getTransferableValue(value);
6968
+ }, 'callableConstruct', INBOUND_INSTRUMENTATION_LABEL), // callableDefineProperty
6969
+ instrumentCallableWrapper((targetPointer, key, configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6970
+ targetPointer();
6971
+ const target = getSelectedTarget();
6972
+
6973
+ try {
6974
+ return ReflectDefineProperty(target, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
6975
+ } catch (e) {
6976
+ throw pushErrorAcrossBoundary(e);
6977
+ }
6978
+ }, 'callableDefineProperty', INBOUND_INSTRUMENTATION_LABEL), // callableDeleteProperty
6979
+ instrumentCallableWrapper((targetPointer, key) => {
6980
+ targetPointer();
6981
+ const target = getSelectedTarget();
6982
+
6983
+ try {
6984
+ return ReflectDeleteProperty(target, key);
6985
+ } catch (e) {
6986
+ throw pushErrorAcrossBoundary(e);
6987
+ }
6988
+ }, 'callableDeleteProperty', INBOUND_INSTRUMENTATION_LABEL), // callableGetOwnPropertyDescriptor
6989
+ instrumentCallableWrapper((targetPointer, key, foreignCallableDescriptorCallback) => {
6990
+ targetPointer();
6991
+ const target = getSelectedTarget();
6992
+ let unsafeDesc;
6993
+
6994
+ try {
6995
+ unsafeDesc = ReflectGetOwnPropertyDescriptor(target, key);
6996
+ } catch (e) {
6997
+ throw pushErrorAcrossBoundary(e);
6998
+ }
6999
+
7000
+ if (unsafeDesc) {
7001
+ const descMeta = getDescriptorMeta(unsafeDesc);
7002
+ foreignCallableDescriptorCallback(descMeta[0], // configurable
7003
+ descMeta[1], // enumerable
7004
+ descMeta[2], // writable
7005
+ descMeta[3], // valuePointer
7006
+ descMeta[4], // getPointer
7007
+ descMeta[5] // setPointer
7008
+ );
7009
+ }
7010
+ }, 'callableGetOwnPropertyDescriptor', INBOUND_INSTRUMENTATION_LABEL), // callableGetPrototypeOf
7011
+ instrumentCallableWrapper(targetPointer => {
7012
+ targetPointer();
7013
+ const target = getSelectedTarget();
7014
+ let proto;
7015
+
7016
+ try {
7017
+ proto = ReflectGetPrototypeOf(target);
7018
+ } catch (e) {
7019
+ throw pushErrorAcrossBoundary(e);
7020
+ }
7021
+
7022
+ return getTransferableValue(proto);
7023
+ }, 'callableGetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL), // callableIsExtensible
7024
+ instrumentCallableWrapper(targetPointer => {
7025
+ targetPointer();
7026
+ const target = getSelectedTarget();
7027
+
7028
+ try {
7029
+ return ReflectIsExtensible(target);
7030
+ } catch (e) {
7031
+ throw pushErrorAcrossBoundary(e);
7032
+ }
7033
+ }, 'callableIsExtensible', INBOUND_INSTRUMENTATION_LABEL), // callableOwnKeys
7034
+ instrumentCallableWrapper((targetPointer, foreignCallableKeysCallback) => {
7035
+ targetPointer();
7036
+ const target = getSelectedTarget();
7037
+ let keys;
7038
+
7039
+ try {
7040
+ keys = ReflectOwnKeys(target);
7041
+ } catch (e) {
7042
+ throw pushErrorAcrossBoundary(e);
7043
+ }
7044
+
7045
+ ReflectApply(foreignCallableKeysCallback, undefined, keys);
7046
+ }, 'callableOwnKeys', INBOUND_INSTRUMENTATION_LABEL), // callablePreventExtensions
7047
+ instrumentCallableWrapper(targetPointer => {
7048
+ targetPointer();
7049
+ const target = getSelectedTarget();
7050
+
7051
+ try {
7052
+ return ReflectPreventExtensions(target);
7053
+ } catch (e) {
7054
+ throw pushErrorAcrossBoundary(e);
7055
+ }
7056
+ }, 'callablePreventExtensions', INBOUND_INSTRUMENTATION_LABEL), // callableSet
7057
+ instrumentCallableWrapper((targetPointer, propertyKey, valuePointer, receiverPointer) => {
7058
+ targetPointer();
7059
+ const target = getSelectedTarget();
7060
+
7061
+ try {
7062
+ return ReflectSet(target, propertyKey, getLocalValue(valuePointer), getLocalValue(receiverPointer));
7063
+ } catch (e) {
7064
+ throw pushErrorAcrossBoundary(e);
7065
+ }
7066
+ }, 'callableSet', INBOUND_INSTRUMENTATION_LABEL), // callableSetPrototypeOf
7067
+ instrumentCallableWrapper((targetPointer, protoPointerOrNull) => {
7068
+ targetPointer();
7069
+ const target = getSelectedTarget();
7070
+ const proto = getLocalValue(protoPointerOrNull);
7071
+
7072
+ try {
7073
+ return ReflectSetPrototypeOf(target, proto);
7074
+ } catch (e) {
7075
+ throw pushErrorAcrossBoundary(e);
7076
+ }
7077
+ }, 'callableSetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL), // callableGetTargetIntegrityTraits
7078
+ instrumentCallableWrapper(targetPointer => {
7079
+ targetPointer();
7080
+ const target = getSelectedTarget();
7081
+ return getTargetIntegrityTraits(target);
7082
+ }, 'callableGetTargetIntegrityTraits', INBOUND_INSTRUMENTATION_LABEL), // callableGetUnbrandedTag
7083
+ instrumentCallableWrapper(targetPointer => {
7084
+ targetPointer();
7085
+ const target = getSelectedTarget();
7086
+
7087
+ try {
7088
+ if (typeof target === 'object' && target !== null && !isArrayOrNotOrThrowForRevoked(target)) {
7089
+ // Section 19.1.3.6: Object.prototype.toString()
7090
+ // Step 16: If `Type(tag)` is not `String`, let `tag` be `builtinTag`.
7091
+ // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
7092
+ const toStringValue = ReflectApply(ObjectProtoToString, target, []);
7093
+ return ReflectApply(StringProtoSlice, toStringValue, [8, -1]);
7094
+ } // eslint-disable-next-line no-empty
7095
+
7096
+ } catch (_unused6) {}
7097
+
7098
+ return undefined;
7099
+ }, 'callableGetUnbrandedTag', INBOUND_INSTRUMENTATION_LABEL), // callableHasOwnProperty
7100
+ instrumentCallableWrapper((targetPointer, key) => {
7101
+ targetPointer();
7102
+ const target = getSelectedTarget();
7103
+
7104
+ try {
7105
+ return ReflectApply(ObjectProtoHasOwnProperty, target, [key]);
7106
+ } catch (e) {
7107
+ throw pushErrorAcrossBoundary(e);
7108
+ }
7109
+ }, 'callableHasOwnProperty', INBOUND_INSTRUMENTATION_LABEL));
7110
+ return function () {
7111
+ for (var _len7 = arguments.length, hooks = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
7112
+ hooks[_key7] = arguments[_key7];
7113
+ }
7114
+
7115
+ const {
7116
+ // 0: globalThisPointer,
7117
+ // 1: getSelectedTarget,
7118
+ // 2: getTransferableValue,
7119
+ // 3: callableGetPropertyValuePointer,
7120
+ // 4: callableEvaluate,
7121
+ // 5: callableLinkPointers,
7122
+ 6: callablePushTarget,
7123
+ 7: callableApply,
7124
+ 8: callableConstruct,
7125
+ 9: callableDefineProperty,
7126
+ 10: callableDeleteProperty,
7127
+ 11: callableGetOwnPropertyDescriptor,
7128
+ 12: callableGetPrototypeOf,
7129
+ 13: callableIsExtensible,
7130
+ 14: callableOwnKeys,
7131
+ 15: callablePreventExtensions,
7132
+ 16: callableSet,
7133
+ 17: callableSetPrototypeOf,
7134
+ 18: callableGetTargetIntegrityTraits,
7135
+ 19: callableGetUnbrandedTag,
7136
+ 20: callableHasOwnProperty
7137
+ } = hooks;
7138
+ foreignCallablePushTarget = callablePushTarget; // traps utilities
7139
+
7140
+ foreignCallableApply = foreignErrorControl(instrumentCallableWrapper(callableApply, 'callableApply', OUTBOUND_INSTRUMENTATION_LABEL));
7141
+ foreignCallableConstruct = foreignErrorControl(instrumentCallableWrapper(callableConstruct, 'callableConstruct', OUTBOUND_INSTRUMENTATION_LABEL));
7142
+ foreignCallableDefineProperty = foreignErrorControl(instrumentCallableWrapper(callableDefineProperty, 'callableDefineProperty', OUTBOUND_INSTRUMENTATION_LABEL));
7143
+ foreignCallableDeleteProperty = foreignErrorControl(instrumentCallableWrapper(callableDeleteProperty, 'callableDeleteProperty', OUTBOUND_INSTRUMENTATION_LABEL));
7144
+ foreignCallableGetOwnPropertyDescriptor = foreignErrorControl(instrumentCallableWrapper(callableGetOwnPropertyDescriptor, 'callableGetOwnPropertyDescriptor', OUTBOUND_INSTRUMENTATION_LABEL));
7145
+ foreignCallableGetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableGetPrototypeOf, 'callableGetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
7146
+ foreignCallableIsExtensible = foreignErrorControl(instrumentCallableWrapper(callableIsExtensible, 'callableIsExtensible', OUTBOUND_INSTRUMENTATION_LABEL));
7147
+ foreignCallableOwnKeys = foreignErrorControl(instrumentCallableWrapper(callableOwnKeys, 'callableOwnKeys', OUTBOUND_INSTRUMENTATION_LABEL));
7148
+ foreignCallablePreventExtensions = foreignErrorControl(instrumentCallableWrapper(callablePreventExtensions, 'callablePreventExtensions', OUTBOUND_INSTRUMENTATION_LABEL));
7149
+ foreignCallableSet = foreignErrorControl(instrumentCallableWrapper(callableSet, 'callableSet', OUTBOUND_INSTRUMENTATION_LABEL));
7150
+ foreignCallableSetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableSetPrototypeOf, 'callableSetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
7151
+ foreignCallableGetTargetIntegrityTraits = foreignErrorControl(instrumentCallableWrapper(callableGetTargetIntegrityTraits, 'callableGetTargetIntegrityTraits', OUTBOUND_INSTRUMENTATION_LABEL));
7152
+ foreignCallableGetUnbrandedTag = foreignErrorControl(instrumentCallableWrapper(callableGetUnbrandedTag, 'callableGetUnbrandedTag', OUTBOUND_INSTRUMENTATION_LABEL));
7153
+ foreignCallableHasOwnProperty = foreignErrorControl(instrumentCallableWrapper(callableHasOwnProperty, 'callableHasOwnProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6841
7154
  };
7155
+ };
6842
7156
  }
6843
7157
 
6844
- const TypeErrorCtor$1 = TypeError;
6845
- const marshallSourceTextInStrictMode = `(function(){'use strict';return (${createMembraneMarshall.toString()})})()`;
6846
- // eslint-disable-next-line no-eval
7158
+ const TypeErrorCtor$1 = TypeError; // istanbul ignore next
7159
+
7160
+ const marshallSourceTextInStrictMode = `
7161
+ (function(){
7162
+ 'use strict';
7163
+ (${function initializeShadowRealm() {
7164
+ if (typeof Error.stackTraceLimit === 'number') {
7165
+ // The default stack trace limit is 10.
7166
+ // Increasing to 20 as a baby step.
7167
+ Error.stackTraceLimit *= 2;
7168
+ }
7169
+ }.toString()})();
7170
+ return (${createMembraneMarshall.toString()})
7171
+ })()`; // eslint-disable-next-line no-eval
7172
+
6847
7173
  function createConnector(evaluator) {
6848
- if (!evaluator) {
6849
- throw new TypeErrorCtor$1('Missing evaluator function');
6850
- }
6851
- // The result of this eval will be a function that returns a function.
6852
- // The hooks connector is the last returned function, so we invoke the
6853
- // result of the eval operation and return that result.
6854
- return evaluator(marshallSourceTextInStrictMode)();
7174
+ if (!evaluator) {
7175
+ throw new TypeErrorCtor$1('Missing evaluator function.');
7176
+ } // The result of this eval will be a function that returns a function.
7177
+ // The hooks connector is the last returned function, so we invoke the
7178
+ // result of the eval operation and return that result.
7179
+
7180
+
7181
+ return evaluator(marshallSourceTextInStrictMode)();
6855
7182
  }
6856
7183
 
6857
7184
  const SHOULD_TRAP_MUTATION = true;
6858
7185
  const SHOULD_NOT_TRAP_MUTATION = false;
6859
7186
  const UNDEFINED_SYMBOL = Symbol.for('@@membraneUndefinedValue');
6860
7187
  const ErrorCtor = Error;
6861
- const { assign: ObjectAssign$2, keys: ObjectKeys } = Object;
6862
- const { hasOwnProperty: ObjectProtoHasOwnProperty$1 } = Object.prototype;
6863
- const { apply: ReflectApply$1$1, ownKeys: ReflectOwnKeys$1 } = Reflect;
6864
- const { slice: StringProtoSlice, toUpperCase: StringProtoToUpperCase } = String.prototype;
7188
+ const {
7189
+ assign: ObjectAssign$2,
7190
+ keys: ObjectKeys
7191
+ } = Object;
7192
+ const {
7193
+ apply: ReflectApply$1$1,
7194
+ ownKeys: ReflectOwnKeys$1
7195
+ } = Reflect;
7196
+ const {
7197
+ slice: StringProtoSlice,
7198
+ toUpperCase: StringProtoToUpperCase
7199
+ } = String.prototype;
7200
+
6865
7201
  function capitalizeFirstChar(string) {
6866
- const { length } = string;
6867
- if (!length) {
6868
- return string;
6869
- }
6870
- const upper = ReflectApply$1$1(StringProtoToUpperCase, string[0], []);
6871
- return length === 1 ? upper : upper + ReflectApply$1$1(StringProtoSlice, string, [1]);
7202
+ const {
7203
+ length
7204
+ } = string;
7205
+
7206
+ if (!length) {
7207
+ return string;
7208
+ }
7209
+
7210
+ const upper = ReflectApply$1$1(StringProtoToUpperCase, string[0], []);
7211
+ return length === 1 ? upper : upper + ReflectApply$1$1(StringProtoSlice, string, [1]);
6872
7212
  }
7213
+
6873
7214
  class VirtualEnvironment {
6874
- constructor(options) {
6875
- if (options === undefined) {
6876
- throw new ErrorCtor(`Missing VirtualEnvironmentOptions options bag.`);
6877
- }
6878
- const { blueConnector, redConnector, distortionCallback, support, instrumentation } = options;
6879
- this.blueConnector = blueConnector;
6880
- this.redConnector = redConnector;
6881
- let supportFlags = SupportFlagsEnum.None;
6882
- const supportProps = support ? ObjectKeys(support) : [];
6883
- for (let i = 0, len = supportProps.length; i < len; i += 1) {
6884
- const key = capitalizeFirstChar(supportProps[i]);
6885
- if (ReflectApply$1$1(ObjectProtoHasOwnProperty$1, SupportFlagsEnum, [key])) {
6886
- supportFlags |= SupportFlagsEnum[key];
6887
- }
6888
- }
6889
- let blueHooks;
6890
- let redHooks;
6891
- const blueExportsCallback = (...hooks) => {
6892
- blueHooks = hooks;
6893
- };
6894
- const redExportsCallback = (...hooks) => {
6895
- redHooks = hooks;
6896
- };
6897
- const initLocalOptions = {
6898
- distortionCallback,
6899
- instrumentation,
6900
- };
6901
- const localConnect = blueConnector('blue', SHOULD_NOT_TRAP_MUTATION, supportFlags, blueExportsCallback, initLocalOptions);
6902
- const foreignConnect = redConnector('red', SHOULD_TRAP_MUTATION, supportFlags, redExportsCallback);
6903
- ReflectApply$1$1(localConnect, undefined, redHooks);
6904
- ReflectApply$1$1(foreignConnect, undefined, blueHooks);
6905
- const { 0: blueGlobalThisPointer, 1: blueGetSelectedTarget, 2: blueGetTransferableValue, 3: blueCallableGetPropertyValuePointer,
6906
- // 4: blueCallableEvaluate,
6907
- 5: blueCallableLinkPointers, } = blueHooks;
6908
- this.blueGlobalThisPointer = blueGlobalThisPointer;
6909
- this.blueGetSelectedTarget = blueGetSelectedTarget;
6910
- this.blueGetTransferableValue = blueGetTransferableValue;
6911
- this.blueCallableGetPropertyValuePointer = blueCallableGetPropertyValuePointer;
6912
- this.blueCallableLinkPointers = blueCallableLinkPointers;
6913
- const { 0: redGlobalThisPointer,
6914
- // 1: redGetSelectedTarget,
6915
- // 2: redGetTransferableValue,
6916
- 3: redCallableGetPropertyValuePointer, 4: redCallableEvaluate, 5: redCallableLinkPointers,
6917
- // 6: redCallablePushTarget,
6918
- // 7: redCallableApply,
6919
- // 8: redCallableConstruct,
6920
- 9: redCallableDefineProperty,
6921
- // 10: redCallableDeleteProperty,
6922
- // 11: redCallableGetOwnPropertyDescriptor,
6923
- // 12: redCallableGetPrototypeOf,
6924
- // 13: redCallableIsExtensible,
6925
- // 14: redCallableOwnKeys,
6926
- // 15: redCallablePreventExtensions,
6927
- // 16: redCallableSet,
6928
- 17: redCallableSetPrototypeOf, } = redHooks;
6929
- this.redGlobalThisPointer = redGlobalThisPointer;
6930
- this.redCallableEvaluate = redCallableEvaluate;
6931
- this.redCallableSetPrototypeOf = redCallableSetPrototypeOf;
6932
- this.redCallableDefineProperty = redCallableDefineProperty;
6933
- this.redCallableGetPropertyValuePointer = redCallableGetPropertyValuePointer;
6934
- this.redCallableLinkPointers = redCallableLinkPointers;
6935
- }
6936
- evaluate(sourceText) {
6937
- try {
6938
- const pointerOrPrimitiveValue = this.redCallableEvaluate(sourceText);
6939
- if (typeof pointerOrPrimitiveValue === 'function') {
6940
- pointerOrPrimitiveValue();
6941
- return this.blueGetSelectedTarget();
6942
- }
6943
- return pointerOrPrimitiveValue;
6944
- }
6945
- catch (e) {
6946
- const pushedError = this.blueGetSelectedTarget();
6947
- if (pushedError) {
6948
- throw pushedError;
6949
- }
6950
- throw e;
6951
- }
7215
+ constructor(options) {
7216
+ if (options === undefined) {
7217
+ throw new ErrorCtor(`Missing VirtualEnvironmentOptions options bag.`);
6952
7218
  }
6953
- link(...keys) {
6954
- let bluePointer = this.blueGlobalThisPointer;
6955
- let redPointer = this.redGlobalThisPointer;
6956
- for (let i = 0, len = keys.length; i < len; i += 1) {
6957
- const key = keys[i];
6958
- bluePointer = this.blueCallableGetPropertyValuePointer(bluePointer, key);
6959
- redPointer = this.redCallableGetPropertyValuePointer(redPointer, key);
6960
- }
6961
- this.redCallableLinkPointers(redPointer, bluePointer);
6962
- this.blueCallableLinkPointers(bluePointer, redPointer);
6963
- }
6964
- remap(target, blueDescriptors) {
6965
- const keys = ReflectOwnKeys$1(blueDescriptors);
6966
- const targetPointer = this.blueGetTransferableValue(target);
6967
- // prettier-ignore
6968
- for (let i = 0, len = keys.length; i < len; i += 1) {
6969
- const key = keys[i];
6970
- const unsafeBlueDesc = blueDescriptors[key];
6971
- // Avoid poisoning by only installing own properties from blueDescriptors
6972
- // eslint-disable-next-line prefer-object-spread
6973
- const safeBlueDesc = ObjectAssign$2({ __proto__: null }, unsafeBlueDesc);
6974
- // Install descriptor into the red side.
6975
- this.redCallableDefineProperty(targetPointer, key, 'configurable' in safeBlueDesc
6976
- ? !!safeBlueDesc.configurable
6977
- : UNDEFINED_SYMBOL, 'enumerable' in safeBlueDesc
6978
- ? !!safeBlueDesc.enumerable
6979
- : UNDEFINED_SYMBOL, 'writable' in safeBlueDesc
6980
- ? !!safeBlueDesc.writable
6981
- : UNDEFINED_SYMBOL, 'value' in safeBlueDesc
6982
- ? this.blueGetTransferableValue(safeBlueDesc.value)
6983
- : UNDEFINED_SYMBOL, 'get' in safeBlueDesc
6984
- ? this.blueGetTransferableValue(safeBlueDesc.get)
6985
- : UNDEFINED_SYMBOL, 'set' in safeBlueDesc
6986
- ? this.blueGetTransferableValue(safeBlueDesc.set)
6987
- : UNDEFINED_SYMBOL);
6988
- }
7219
+
7220
+ const {
7221
+ blueConnector,
7222
+ redConnector,
7223
+ distortionCallback,
7224
+ support,
7225
+ instrumentation
7226
+ } = options;
7227
+ this.blueConnector = blueConnector;
7228
+ this.redConnector = redConnector;
7229
+ let supportFlags = SupportFlagsEnum.None;
7230
+ const supportKeys = support ? ObjectKeys(support) : [];
7231
+
7232
+ for (let i = 0, len = supportKeys.length; i < len; i += 1) {
7233
+ const enumKey = capitalizeFirstChar(supportKeys[i]);
7234
+ supportFlags |= SupportFlagsEnum[enumKey];
7235
+ }
7236
+
7237
+ let blueHooks;
7238
+ let redHooks;
7239
+
7240
+ const blueExportsCallback = function blueExportsCallback() {
7241
+ for (var _len8 = arguments.length, hooks = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
7242
+ hooks[_key8] = arguments[_key8];
7243
+ }
7244
+
7245
+ blueHooks = hooks;
7246
+ };
7247
+
7248
+ const redExportsCallback = function redExportsCallback() {
7249
+ for (var _len9 = arguments.length, hooks = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
7250
+ hooks[_key9] = arguments[_key9];
7251
+ }
7252
+
7253
+ redHooks = hooks;
7254
+ };
7255
+
7256
+ const initLocalOptions = {
7257
+ distortionCallback,
7258
+ instrumentation
7259
+ };
7260
+ const localConnect = blueConnector('blue', SHOULD_NOT_TRAP_MUTATION, supportFlags, blueExportsCallback, initLocalOptions);
7261
+ const foreignConnect = redConnector('red', SHOULD_TRAP_MUTATION, supportFlags, redExportsCallback);
7262
+ ReflectApply$1$1(localConnect, undefined, redHooks);
7263
+ ReflectApply$1$1(foreignConnect, undefined, blueHooks);
7264
+ const {
7265
+ 0: blueGlobalThisPointer,
7266
+ 1: blueGetSelectedTarget,
7267
+ 2: blueGetTransferableValue,
7268
+ 3: blueCallableGetPropertyValuePointer,
7269
+ // 4: blueCallableEvaluate,
7270
+ 5: blueCallableLinkPointers
7271
+ } = blueHooks;
7272
+ this.blueGlobalThisPointer = blueGlobalThisPointer;
7273
+ this.blueGetSelectedTarget = blueGetSelectedTarget;
7274
+ this.blueGetTransferableValue = blueGetTransferableValue;
7275
+ this.blueCallableGetPropertyValuePointer = blueCallableGetPropertyValuePointer;
7276
+ this.blueCallableLinkPointers = blueCallableLinkPointers;
7277
+ const {
7278
+ 0: redGlobalThisPointer,
7279
+ // 1: redGetSelectedTarget,
7280
+ // 2: redGetTransferableValue,
7281
+ 3: redCallableGetPropertyValuePointer,
7282
+ 4: redCallableEvaluate,
7283
+ 5: redCallableLinkPointers,
7284
+ // 6: redCallablePushTarget,
7285
+ // 7: redCallableApply,
7286
+ // 8: redCallableConstruct,
7287
+ 9: redCallableDefineProperty,
7288
+ // 10: redCallableDeleteProperty,
7289
+ // 11: redCallableGetOwnPropertyDescriptor,
7290
+ // 12: redCallableGetPrototypeOf,
7291
+ // 13: redCallableIsExtensible,
7292
+ // 14: redCallableOwnKeys,
7293
+ // 15: redCallablePreventExtensions,
7294
+ // 16: redCallableSet,
7295
+ 17: redCallableSetPrototypeOf
7296
+ } = redHooks;
7297
+ this.redGlobalThisPointer = redGlobalThisPointer;
7298
+ this.redCallableEvaluate = redCallableEvaluate;
7299
+ this.redCallableSetPrototypeOf = redCallableSetPrototypeOf;
7300
+ this.redCallableDefineProperty = redCallableDefineProperty;
7301
+ this.redCallableGetPropertyValuePointer = redCallableGetPropertyValuePointer;
7302
+ this.redCallableLinkPointers = redCallableLinkPointers;
7303
+ }
7304
+
7305
+ evaluate(sourceText) {
7306
+ try {
7307
+ const pointerOrPrimitiveValue = this.redCallableEvaluate(sourceText);
7308
+
7309
+ if (typeof pointerOrPrimitiveValue === 'function') {
7310
+ pointerOrPrimitiveValue();
7311
+ return this.blueGetSelectedTarget();
7312
+ }
7313
+
7314
+ return pointerOrPrimitiveValue;
7315
+ } catch (e) {
7316
+ const pushedError = this.blueGetSelectedTarget();
7317
+
7318
+ if (pushedError) {
7319
+ throw pushedError;
7320
+ }
7321
+
7322
+ throw e;
7323
+ }
7324
+ }
7325
+
7326
+ link() {
7327
+ let bluePointer = this.blueGlobalThisPointer;
7328
+ let redPointer = this.redGlobalThisPointer;
7329
+
7330
+ for (let i = 0, len = arguments.length; i < len; i += 1) {
7331
+ const key = i < 0 || arguments.length <= i ? undefined : arguments[i];
7332
+ bluePointer = this.blueCallableGetPropertyValuePointer(bluePointer, key);
7333
+ redPointer = this.redCallableGetPropertyValuePointer(redPointer, key);
6989
7334
  }
6990
- remapProto(target, proto) {
6991
- const targetPointer = this.blueGetTransferableValue(target);
6992
- const pointerOrNull = this.blueGetTransferableValue(proto);
6993
- this.redCallableSetPrototypeOf(targetPointer, pointerOrNull);
7335
+
7336
+ this.redCallableLinkPointers(redPointer, bluePointer);
7337
+ this.blueCallableLinkPointers(bluePointer, redPointer);
7338
+ }
7339
+
7340
+ remap(target, blueDescriptors) {
7341
+ const keys = ReflectOwnKeys$1(blueDescriptors);
7342
+ const targetPointer = this.blueGetTransferableValue(target); // prettier-ignore
7343
+
7344
+ for (let i = 0, len = keys.length; i < len; i += 1) {
7345
+ const key = keys[i];
7346
+ const unsafeBlueDesc = blueDescriptors[key]; // Avoid poisoning by only installing own properties from blueDescriptors
7347
+ // eslint-disable-next-line prefer-object-spread
7348
+
7349
+ const safeBlueDesc = ObjectAssign$2({
7350
+ __proto__: null
7351
+ }, unsafeBlueDesc); // Install descriptor into the red side.
7352
+
7353
+ this.redCallableDefineProperty(targetPointer, key, 'configurable' in safeBlueDesc ? !!safeBlueDesc.configurable : UNDEFINED_SYMBOL, 'enumerable' in safeBlueDesc ? !!safeBlueDesc.enumerable : UNDEFINED_SYMBOL, 'writable' in safeBlueDesc ? !!safeBlueDesc.writable : UNDEFINED_SYMBOL, 'value' in safeBlueDesc ? this.blueGetTransferableValue(safeBlueDesc.value) : UNDEFINED_SYMBOL, 'get' in safeBlueDesc ? this.blueGetTransferableValue(safeBlueDesc.get) : UNDEFINED_SYMBOL, 'set' in safeBlueDesc ? this.blueGetTransferableValue(safeBlueDesc.set) : UNDEFINED_SYMBOL);
6994
7354
  }
7355
+ }
7356
+
7357
+ remapProto(target, proto) {
7358
+ const targetPointer = this.blueGetTransferableValue(target);
7359
+ const pointerOrNull = this.blueGetTransferableValue(proto);
7360
+ this.redCallableSetPrototypeOf(targetPointer, pointerOrNull);
7361
+ }
7362
+
6995
7363
  }
6996
7364
 
6997
- const { includes: ArrayProtoIncludes } = Array.prototype;
6998
- const { has: SetProtoHas } = Set.prototype;
6999
- const { apply: ReflectApply$2, getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor, ownKeys: ReflectOwnKeys, } = Reflect;
7365
+ const {
7366
+ includes: ArrayProtoIncludes
7367
+ } = Array.prototype;
7368
+ const {
7369
+ has: SetProtoHas
7370
+ } = Set.prototype;
7371
+ const {
7372
+ apply: ReflectApply$2,
7373
+ getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
7374
+ ownKeys: ReflectOwnKeys
7375
+ } = Reflect;
7000
7376
  /**
7001
7377
  * This list must be in sync with ecma-262, anything new added to the global object
7002
7378
  * should be considered, to decide whether or not they need remapping. The default
@@ -7016,194 +7392,147 @@ const { apply: ReflectApply$2, getOwnPropertyDescriptor: ReflectGetOwnPropertyDe
7016
7392
  * problematic, and requires a lot more work to guarantee that objects from both sides
7017
7393
  * can be considered equivalents (without identity discontinuity).
7018
7394
  */
7019
- const ESGlobalKeys = new Set([
7020
- // *** 19.1 Value Properties of the Global Object
7021
- 'globalThis',
7022
- 'Infinity',
7023
- 'NaN',
7024
- 'undefined',
7025
- // *** 19.2 Function Properties of the Global Object
7026
- 'eval',
7027
- 'isFinite',
7028
- 'isNaN',
7029
- 'parseFloat',
7030
- 'parseInt',
7031
- 'decodeURI',
7032
- 'decodeURIComponent',
7033
- 'encodeURI',
7034
- 'encodeURIComponent',
7035
- // *** 19.3 Constructor Properties of the Global Object
7036
- 'AggregateError',
7037
- 'Array',
7038
- 'ArrayBuffer',
7039
- 'BigInt',
7040
- 'BigInt64Array',
7041
- 'BigUint64Array',
7042
- 'Boolean',
7043
- 'DataView',
7044
- // 'Date', // Unstable & Remapped
7045
- 'Error',
7046
- 'EvalError',
7047
- 'FinalizationRegistry',
7048
- 'Float32Array',
7049
- 'Float64Array',
7050
- 'Function',
7051
- 'Int8Array',
7052
- 'Int16Array',
7053
- 'Int32Array',
7054
- // 'Map', // Remapped
7055
- 'Number',
7056
- 'Object',
7057
- // Allow Blue `Promise` constructor to overwrite the Red one so that promises
7058
- // created by the `Promise` constructor or APIs like `fetch` will work.
7059
- // 'Promise', // Remapped
7060
- 'Proxy',
7061
- 'RangeError',
7062
- 'ReferenceError',
7063
- 'RegExp',
7064
- // 'Set', // Remapped
7065
- 'SharedArrayBuffer',
7066
- 'String',
7067
- 'Symbol',
7068
- 'SyntaxError',
7069
- 'TypeError',
7070
- 'Uint8Array',
7071
- 'Uint8ClampedArray',
7072
- 'Uint16Array',
7073
- 'Uint32Array',
7074
- 'URIError',
7075
- // 'WeakMap', // Remapped
7076
- // 'WeakSet', // Remapped
7077
- 'WeakRef',
7078
- // *** 18.4 Other Properties of the Global Object
7079
- 'Atomics',
7080
- 'JSON',
7081
- 'Math',
7082
- 'Reflect',
7083
- // *** Annex B
7084
- 'escape',
7085
- 'unescape',
7086
- // *** ECMA-402
7087
- // 'Intl', // Unstable & Remapped
7088
- ]);
7089
- // These are foundational things that should never be wrapped but are equivalent
7395
+
7396
+ const ESGlobalKeys = new Set([// *** 19.1 Value Properties of the Global Object
7397
+ 'globalThis', 'Infinity', 'NaN', 'undefined', // *** 19.2 Function Properties of the Global Object
7398
+ 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', // *** 19.3 Constructor Properties of the Global Object
7399
+ 'AggregateError', 'Array', 'ArrayBuffer', 'BigInt', 'BigInt64Array', 'BigUint64Array', 'Boolean', 'DataView', // 'Date', // Unstable & Remapped
7400
+ 'Error', 'EvalError', 'FinalizationRegistry', 'Float32Array', 'Float64Array', 'Function', 'Int8Array', 'Int16Array', 'Int32Array', // 'Map', // Remapped
7401
+ 'Number', 'Object', // Allow Blue `Promise` constructor to overwrite the Red one so that promises
7402
+ // created by the `Promise` constructor or APIs like `fetch` will work.
7403
+ // 'Promise', // Remapped
7404
+ 'Proxy', 'RangeError', 'ReferenceError', 'RegExp', // 'Set', // Remapped
7405
+ 'SharedArrayBuffer', 'String', 'Symbol', 'SyntaxError', 'TypeError', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'URIError', // 'WeakMap', // Remapped
7406
+ // 'WeakSet', // Remapped
7407
+ 'WeakRef', // *** 18.4 Other Properties of the Global Object
7408
+ 'Atomics', 'JSON', 'Math', 'Reflect', // *** Annex B
7409
+ 'escape', 'unescape' // *** ECMA-402
7410
+ // 'Intl', // Unstable & Remapped
7411
+ ]); // These are foundational things that should never be wrapped but are equivalent
7090
7412
  // TODO: revisit this list.
7091
- const ReflectiveIntrinsicObjectNames = [
7092
- 'AggregateError',
7093
- 'Array',
7094
- 'Error',
7095
- 'EvalError',
7096
- 'Function',
7097
- 'Object',
7098
- 'Proxy',
7099
- 'RangeError',
7100
- 'ReferenceError',
7101
- 'SyntaxError',
7102
- 'TypeError',
7103
- 'URIError',
7104
- 'eval',
7105
- ];
7413
+
7414
+ const ReflectiveIntrinsicObjectNames = ['AggregateError', 'Array', 'Error', 'EvalError', 'Function', 'Object', 'Proxy', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', 'eval'];
7415
+
7106
7416
  function assignFilteredGlobalObjectShapeDescriptors(descriptorMap, source) {
7107
- const keys = ReflectOwnKeys(source);
7108
- for (let i = 0, len = keys.length; i < len; i += 1) {
7109
- // forcing to string here because of TypeScript's PropertyDescriptorMap
7110
- // definition, which doesn't support symbols as entries.
7111
- const key = keys[i];
7112
- // avoid overriding ECMAScript global names that correspond
7113
- // to global intrinsics. This guarantee that those entries
7114
- // will be ignored if present in the endowments object.
7115
- // TODO: what if the intent is to polyfill one of those
7116
- // intrinsics?
7117
- if (!isIntrinsicGlobalName(key) && !isReflectiveGlobalName(key)) {
7118
- const unsafeDesc = ReflectGetOwnPropertyDescriptor(source, key);
7119
- // Safari 14.0.x (macOS) and 14.2 (iOS) have a bug where 'showModalDialog'
7120
- // is returned in the list of own keys produces by ReflectOwnKeys(iframeWindow),
7121
- // however 'showModalDialog' is not an own property and produces
7122
- // undefined at ReflectGetOwnPropertyDescriptor(window, key);
7123
- //
7124
- // In all other browsers, 'showModalDialog' is not an own property
7125
- // and does not appear in the list produces by ReflectOwnKeys(iframeWindow).
7126
- //
7127
- // So, as a general rule: if there is not an own descriptor,
7128
- // ignore the entry and continue.
7129
- if (unsafeDesc) {
7130
- descriptorMap[key] = unsafeDesc;
7131
- }
7132
- }
7417
+ const keys = ReflectOwnKeys(source);
7418
+
7419
+ for (let i = 0, len = keys.length; i < len; i += 1) {
7420
+ // forcing to string here because of TypeScript's PropertyDescriptorMap
7421
+ // definition, which doesn't support symbols as entries.
7422
+ const key = keys[i]; // avoid overriding ECMAScript global names that correspond
7423
+ // to global intrinsics. This guarantee that those entries
7424
+ // will be ignored if present in the endowments object.
7425
+ // TODO: what if the intent is to polyfill one of those
7426
+ // intrinsics?
7427
+
7428
+ if (!ReflectApply$2(SetProtoHas, ESGlobalKeys, [key]) && !ReflectApply$2(ArrayProtoIncludes, ReflectiveIntrinsicObjectNames, [key])) {
7429
+ const unsafeDesc = ReflectGetOwnPropertyDescriptor(source, key); // Safari 14.0.x (macOS) and 14.2 (iOS) have a bug where 'showModalDialog'
7430
+ // is returned in the list of own keys produces by ReflectOwnKeys(iframeWindow),
7431
+ // however 'showModalDialog' is not an own property and produces
7432
+ // undefined at ReflectGetOwnPropertyDescriptor(window, key);
7433
+ //
7434
+ // In all other browsers, 'showModalDialog' is not an own property
7435
+ // and does not appear in the list produces by ReflectOwnKeys(iframeWindow).
7436
+ //
7437
+ // So, as a general rule: if there is not an own descriptor,
7438
+ // ignore the entry and continue.
7439
+
7440
+ if (unsafeDesc) {
7441
+ descriptorMap[key] = unsafeDesc;
7442
+ }
7133
7443
  }
7134
- return descriptorMap;
7135
- }
7136
- function isIntrinsicGlobalName(key) {
7137
- return ReflectApply$2(SetProtoHas, ESGlobalKeys, [key]);
7138
- }
7139
- function isReflectiveGlobalName(key) {
7140
- return ReflectApply$2(ArrayProtoIncludes, ReflectiveIntrinsicObjectNames, [key]);
7444
+ }
7445
+
7446
+ return descriptorMap;
7141
7447
  }
7448
+
7142
7449
  function linkIntrinsics(env, globalObjectVirtualizationTarget) {
7143
- // remapping intrinsics that are realm's agnostic
7144
- for (let i = 0, len = ReflectiveIntrinsicObjectNames.length; i < len; i += 1) {
7145
- const globalName = ReflectiveIntrinsicObjectNames[i];
7146
- const reflectiveValue = globalObjectVirtualizationTarget[globalName];
7147
- if (reflectiveValue) {
7148
- env.link(globalName);
7149
- // Proxy.prototype is undefined, being the only weird thing here
7150
- if (reflectiveValue.prototype) {
7151
- env.link(globalName, 'prototype');
7152
- }
7153
- }
7450
+ // remapping intrinsics that are realm's agnostic
7451
+ for (let i = 0, len = ReflectiveIntrinsicObjectNames.length; i < len; i += 1) {
7452
+ const globalName = ReflectiveIntrinsicObjectNames[i];
7453
+ const reflectiveValue = globalObjectVirtualizationTarget[globalName];
7454
+
7455
+ if (reflectiveValue) {
7456
+ env.link(globalName); // Proxy.prototype is undefined, being the only weird thing here
7457
+
7458
+ if (reflectiveValue.prototype) {
7459
+ env.link(globalName, 'prototype');
7460
+ }
7154
7461
  }
7462
+ }
7155
7463
  }
7156
- function getResolvedShapeDescriptors(...sources) {
7157
- const descriptors = {};
7158
- for (let i = 0, len = sources.length; i < len; i += 1) {
7159
- const source = sources[i];
7160
- if (source) {
7161
- assignFilteredGlobalObjectShapeDescriptors(descriptors, source);
7162
- }
7464
+
7465
+ function getResolvedShapeDescriptors() {
7466
+ const descriptors = {};
7467
+
7468
+ for (let i = 0, len = arguments.length; i < len; i += 1) {
7469
+ const source = i < 0 || arguments.length <= i ? undefined : arguments[i];
7470
+
7471
+ if (source) {
7472
+ assignFilteredGlobalObjectShapeDescriptors(descriptors, source);
7163
7473
  }
7164
- return descriptors;
7474
+ }
7475
+
7476
+ return descriptors;
7165
7477
  }
7166
7478
 
7167
7479
  const TypeErrorCtor = TypeError;
7480
+
7168
7481
  function validateRequiredGlobalShapeAndVirtualizationObjects(globalObjectShape, globalObjectVirtualizationTarget) {
7169
- if (!globalObjectShape) {
7170
- throw new TypeErrorCtor('Missing global object shape.');
7171
- }
7172
- if (!globalObjectVirtualizationTarget) {
7173
- throw new TypeErrorCtor('Missing global object virtualization target.');
7174
- }
7175
- return undefined;
7482
+ if (!globalObjectShape) {
7483
+ throw new TypeErrorCtor('Missing global object shape.');
7484
+ }
7485
+
7486
+ if (!globalObjectVirtualizationTarget) {
7487
+ throw new TypeErrorCtor('Missing global object virtualization target.');
7488
+ }
7489
+
7490
+ return undefined;
7176
7491
  }
7177
7492
 
7178
- const { assign: ObjectAssign$1, getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors } = Object;
7179
- const { getPrototypeOf: ReflectGetPrototypeOf, apply: ReflectApply$1 } = Reflect;
7180
- const { get: WeakMapProtoGet, set: WeakMapProtoSet } = WeakMap.prototype;
7493
+ const {
7494
+ assign: ObjectAssign$1,
7495
+ getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors
7496
+ } = Object;
7497
+ const {
7498
+ getPrototypeOf: ReflectGetPrototypeOf,
7499
+ apply: ReflectApply$1
7500
+ } = Reflect;
7501
+ const {
7502
+ get: WeakMapProtoGet,
7503
+ set: WeakMapProtoSet
7504
+ } = WeakMap.prototype;
7181
7505
  const cachedBlueGlobalMap = new WeakMap();
7506
+
7182
7507
  function getBaseReferences(window) {
7183
- const record = { __proto__: null };
7184
- // caching references to object values that can't be replaced
7185
- // window -> Window -> WindowProperties -> EventTarget
7186
- record.window = window.window;
7187
- record.document = window.document;
7188
- record.WindowProto = ReflectGetPrototypeOf(record.window);
7189
- record.WindowPropertiesProto = ReflectGetPrototypeOf(record.WindowProto);
7190
- record.EventTargetProto = ReflectGetPrototypeOf(record.WindowPropertiesProto);
7191
- record.DocumentProto = ReflectGetPrototypeOf(record.document);
7192
- return record;
7508
+ const record = {
7509
+ __proto__: null
7510
+ }; // caching references to object values that can't be replaced
7511
+ // window -> Window -> WindowProperties -> EventTarget
7512
+
7513
+ record.window = window.window;
7514
+ record.document = window.document;
7515
+ record.WindowProto = ReflectGetPrototypeOf(record.window);
7516
+ record.WindowPropertiesProto = ReflectGetPrototypeOf(record.WindowProto);
7517
+ record.EventTargetProto = ReflectGetPrototypeOf(record.WindowPropertiesProto);
7518
+ record.DocumentProto = ReflectGetPrototypeOf(record.document);
7519
+ return record;
7193
7520
  }
7521
+
7194
7522
  function getCachedBlueReferences(window) {
7195
- let record = ReflectApply$1(WeakMapProtoGet, cachedBlueGlobalMap, [window]);
7196
- if (record) {
7197
- return record;
7198
- }
7199
- record = getBaseReferences(window);
7200
- // caching the record
7201
- ReflectApply$1(WeakMapProtoSet, cachedBlueGlobalMap, [window, record]);
7202
- // intentionally avoiding remapping any Window.prototype descriptor,
7203
- // there is nothing in this prototype that needs to be remapped.
7204
- record.WindowProtoDescriptors = {};
7205
- record.EventTargetProtoDescriptors = ObjectGetOwnPropertyDescriptors(record.EventTargetProto);
7523
+ let record = ReflectApply$1(WeakMapProtoGet, cachedBlueGlobalMap, [window]);
7524
+
7525
+ if (record) {
7206
7526
  return record;
7527
+ }
7528
+
7529
+ record = getBaseReferences(window); // caching the record
7530
+
7531
+ ReflectApply$1(WeakMapProtoSet, cachedBlueGlobalMap, [window, record]); // intentionally avoiding remapping any Window.prototype descriptor,
7532
+ // there is nothing in this prototype that needs to be remapped.
7533
+
7534
+ record.EventTargetProtoDescriptors = ObjectGetOwnPropertyDescriptors(record.EventTargetProto);
7535
+ return record;
7207
7536
  }
7208
7537
  /**
7209
7538
  * Initialization operation to capture and cache all unforgeable references
@@ -7211,6 +7540,8 @@ function getCachedBlueReferences(window) {
7211
7540
  * usually help because this library runs before anything else that can poison
7212
7541
  * the environment.
7213
7542
  */
7543
+
7544
+
7214
7545
  getCachedBlueReferences(window);
7215
7546
  /**
7216
7547
  * global descriptors are a combination of 3 set of descriptors:
@@ -7239,212 +7570,254 @@ getCachedBlueReferences(window);
7239
7570
  * that will be installed (via the membrane) as global descriptors in
7240
7571
  * the red realm.
7241
7572
  */
7573
+
7242
7574
  function filterWindowDescriptors(endowmentsDescriptors) {
7243
- const to = {};
7244
- // endowments descriptors will overrule any default descriptor inferred
7245
- // from the detached iframe. note that they are already filtered, not need
7246
- // to check against intrinsics again.
7247
- ObjectAssign$1(to, endowmentsDescriptors);
7248
- // removing unforgeable descriptors that cannot be installed
7249
- delete to.location;
7250
- delete to.document;
7251
- delete to.window;
7252
- delete to.top;
7253
- // Some DOM APIs do brand checks for TypeArrays and others objects,
7254
- // in this case, if the API is not dangerous, and works in a detached
7255
- // iframe, we can let the sandbox to use the iframe's api directly,
7256
- // instead of remapping it to the blue realm.
7257
- // TODO [issue #67]: review this list
7258
- delete to.crypto;
7259
- // others browser specific undeniable globals
7260
- delete to.chrome;
7261
- return to;
7575
+ const to = {}; // endowments descriptors will overrule any default descriptor inferred
7576
+ // from the detached iframe. note that they are already filtered, not need
7577
+ // to check against intrinsics again.
7578
+
7579
+ ObjectAssign$1(to, endowmentsDescriptors); // removing unforgeable descriptors that cannot be installed
7580
+
7581
+ delete to.document;
7582
+ delete to.location;
7583
+ delete to.top;
7584
+ delete to.window; // Some DOM APIs do brand checks for TypeArrays and others objects,
7585
+ // in this case, if the API is not dangerous, and works in a detached
7586
+ // iframe, we can let the sandbox to use the iframe's api directly,
7587
+ // instead of remapping it to the blue realm.
7588
+ // TODO [issue #67]: review this list
7589
+
7590
+ delete to.crypto; // others browser specific undeniable globals
7591
+
7592
+ delete to.chrome;
7593
+ return to;
7262
7594
  }
7595
+
7263
7596
  function tameDOM(env, blueRefs, endowmentsDescriptors) {
7264
- // adjusting proto chain of window.document
7265
- env.remapProto(blueRefs.document, blueRefs.DocumentProto);
7266
- const globalDescriptors = filterWindowDescriptors(endowmentsDescriptors);
7267
- // remapping globals
7268
- env.remap(blueRefs.window, globalDescriptors);
7269
- // remapping unforgeable objects
7270
- env.remap(blueRefs.EventTargetProto, blueRefs.EventTargetProtoDescriptors);
7271
- env.remap(blueRefs.WindowProto, blueRefs.WindowProtoDescriptors);
7272
- /**
7273
- * WindowProperties.prototype is magical, it provide access to any
7274
- * object that "clobbers" the WindowProxy instance for easy access. E.g.:
7275
- *
7276
- * var object = document.createElement('object');
7277
- * object.id = 'foo';
7278
- * document.body.appendChild(object);
7279
- *
7280
- * The result of this code is that `window.foo` points to the HTMLObjectElement
7281
- * instance, and in some browsers, those are not even reported as descriptors
7282
- * installed on WindowProperties.prototype, but they are instead magically
7283
- * resolved when accessing `foo` from `window`.
7284
- *
7285
- * This forces us to avoid using the descriptors from the blue window directly,
7286
- * and instead, we might only need to shadow the descriptors installed in the brand
7287
- * new iframe, that way any magical entry from the blue window will not be
7288
- * installed on the iframe. That turns out to be also empty, therefore we
7289
- * don't need to remap `blueRefs.WindowPropertiesProto` descriptors at all.
7290
- */
7597
+ // adjusting proto chain of window.document
7598
+ env.remapProto(blueRefs.document, blueRefs.DocumentProto);
7599
+ const globalDescriptors = filterWindowDescriptors(endowmentsDescriptors); // remapping globals
7600
+
7601
+ env.remap(blueRefs.window, globalDescriptors); // remapping unforgeable objects
7602
+
7603
+ env.remap(blueRefs.EventTargetProto, blueRefs.EventTargetProtoDescriptors);
7604
+ /**
7605
+ * WindowProperties.prototype is magical, it provide access to any
7606
+ * object that "clobbers" the WindowProxy instance for easy access. E.g.:
7607
+ *
7608
+ * var object = document.createElement('object');
7609
+ * object.id = 'foo';
7610
+ * document.body.appendChild(object);
7611
+ *
7612
+ * The result of this code is that `window.foo` points to the HTMLObjectElement
7613
+ * instance, and in some browsers, those are not even reported as descriptors
7614
+ * installed on WindowProperties.prototype, but they are instead magically
7615
+ * resolved when accessing `foo` from `window`.
7616
+ *
7617
+ * This forces us to avoid using the descriptors from the blue window directly,
7618
+ * and instead, we might only need to shadow the descriptors installed in the brand
7619
+ * new iframe, that way any magical entry from the blue window will not be
7620
+ * installed on the iframe. That turns out to be also empty, therefore we
7621
+ * don't need to remap `blueRefs.WindowPropertiesProto` descriptors at all.
7622
+ */
7291
7623
  }
7624
+
7292
7625
  function linkUnforgeables(env, blueGlobalThis) {
7293
- // The test of instance of event target is important to discard environments
7294
- // in which a fake window (e.g. jest) is not following the specs, and can
7295
- // break this membrane.
7296
- if (blueGlobalThis.EventTarget && blueGlobalThis instanceof EventTarget) {
7297
- // window.document
7298
- env.link('document');
7299
- // window.__proto__ (aka Window.prototype)
7300
- env.link('__proto__');
7301
- // window.__proto__.__proto__ (aka WindowProperties.prototype)
7302
- env.link('__proto__', '__proto__');
7303
- // window.__proto__.__proto__.__proto__ (aka EventTarget.prototype)
7304
- env.link('__proto__', '__proto__', '__proto__');
7305
- }
7626
+ // The test of instance of event target is important to discard environments
7627
+ // in which a fake window (e.g. jest) is not following the specs, and can
7628
+ // break this membrane.
7629
+ if (blueGlobalThis.EventTarget && blueGlobalThis instanceof EventTarget) {
7630
+ // window.document
7631
+ env.link('document'); // window.__proto__ (aka Window.prototype)
7632
+
7633
+ env.link('__proto__'); // window.__proto__.__proto__ (aka WindowProperties.prototype)
7634
+
7635
+ env.link('__proto__', '__proto__'); // window.__proto__.__proto__.__proto__ (aka EventTarget.prototype)
7636
+
7637
+ env.link('__proto__', '__proto__', '__proto__');
7638
+ }
7306
7639
  }
7307
7640
 
7308
7641
  const IFRAME_SANDBOX_ATTRIBUTE_VALUE = 'allow-same-origin allow-scripts';
7309
7642
  const emptyArray = [];
7310
- const { close: DocumentProtoClose, createElement: DocumentProtoCreateElement, open: DocumentProtoOpen, } = document;
7311
- const { remove: ElementProtoRemove, setAttribute: ElementProtoSetAttribute } = Element.prototype;
7312
- const { appendChild: NodeProtoAppendChild } = Node.prototype;
7313
- const { assign: ObjectAssign } = Object;
7314
- const {
7315
- // eslint-disable-next-line @typescript-eslint/naming-convention
7316
- __lookupGetter__: ObjectProto__lookupGetter__, hasOwnProperty: ObjectProtoHasOwnProperty, } = Object.prototype;
7317
- const { apply: ReflectApply } = Reflect;
7643
+ const {
7644
+ close: DocumentProtoClose,
7645
+ createElement: DocumentProtoCreateElement,
7646
+ open: DocumentProtoOpen
7647
+ } = document;
7648
+ const {
7649
+ remove: ElementProtoRemove,
7650
+ setAttribute: ElementProtoSetAttribute
7651
+ } = Element.prototype;
7652
+ const {
7653
+ appendChild: NodeProtoAppendChild
7654
+ } = Node.prototype;
7655
+ const {
7656
+ assign: ObjectAssign
7657
+ } = Object;
7658
+ const {
7659
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7660
+ __lookupGetter__: ObjectProto__lookupGetter__,
7661
+ hasOwnProperty: ObjectProtoHasOwnProperty
7662
+ } = Object.prototype;
7663
+ const {
7664
+ apply: ReflectApply
7665
+ } = Reflect;
7666
+
7318
7667
  function ObjectLookupOwnGetter(obj, key) {
7319
- // Since this function is only used internally, and would not otherwise be
7320
- // reachable by user code, istanbul can ignore test coverage for the
7321
- // following condition.
7322
- // istanbul ignore next
7323
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
7324
- if (obj === null || obj === undefined || !ReflectApply(ObjectProtoHasOwnProperty, obj, [key])) {
7325
- return undefined;
7326
- }
7327
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
7328
- return ReflectApply(ObjectProto__lookupGetter__, obj, [key]);
7668
+ // Since this function is only used internally, and would not otherwise be
7669
+ // reachable by user code, istanbul can ignore test coverage for the
7670
+ // following condition.
7671
+ // istanbul ignore next
7672
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
7673
+ if (obj === null || obj === undefined || !ReflectApply(ObjectProtoHasOwnProperty, obj, [key])) {
7674
+ return undefined;
7675
+ } // eslint-disable-next-line @typescript-eslint/no-use-before-define
7676
+
7677
+
7678
+ return ReflectApply(ObjectProto__lookupGetter__, obj, [key]);
7329
7679
  }
7680
+
7330
7681
  const DocumentProtoBodyGetter = ObjectLookupOwnGetter(Document.prototype, 'body');
7331
7682
  const HTMLElementProtoStyleGetter = ObjectLookupOwnGetter(HTMLElement.prototype, 'style');
7332
7683
  const HTMLIFrameElementProtoContentWindowGetter = ObjectLookupOwnGetter(HTMLIFrameElement.prototype, 'contentWindow');
7333
7684
  const NodeProtoIsConnectedGetter = ObjectLookupOwnGetter(Node.prototype, 'isConnected');
7334
7685
  const NodeProtoLastChildGetter = ObjectLookupOwnGetter(Node.prototype, 'lastChild');
7686
+
7335
7687
  function DocumentBody(doc) {
7336
- return ReflectApply(DocumentProtoBodyGetter, doc, emptyArray);
7688
+ return ReflectApply(DocumentProtoBodyGetter, doc, emptyArray);
7337
7689
  }
7690
+
7338
7691
  function DocumentClose(doc) {
7339
- return ReflectApply(DocumentProtoClose, doc, emptyArray);
7692
+ return ReflectApply(DocumentProtoClose, doc, emptyArray);
7340
7693
  }
7694
+
7341
7695
  function DocumentCreateElement(doc, tagName) {
7342
- return ReflectApply(DocumentProtoCreateElement, doc, [tagName]);
7696
+ return ReflectApply(DocumentProtoCreateElement, doc, [tagName]);
7343
7697
  }
7698
+
7344
7699
  function DocumentOpen(doc) {
7345
- return ReflectApply(DocumentProtoOpen, doc, emptyArray);
7700
+ return ReflectApply(DocumentProtoOpen, doc, emptyArray);
7346
7701
  }
7702
+
7347
7703
  function ElementSetAttribute(el, name, value) {
7348
- return ReflectApply(ElementProtoSetAttribute, el, [name, value]);
7704
+ return ReflectApply(ElementProtoSetAttribute, el, [name, value]);
7349
7705
  }
7706
+
7350
7707
  function ElementRemove(element) {
7351
- return ReflectApply(ElementProtoRemove, element, emptyArray);
7708
+ return ReflectApply(ElementProtoRemove, element, emptyArray);
7352
7709
  }
7710
+
7353
7711
  function HTMLElementStyleGetter(el) {
7354
- return ReflectApply(HTMLElementProtoStyleGetter, el, emptyArray);
7712
+ return ReflectApply(HTMLElementProtoStyleGetter, el, emptyArray);
7355
7713
  }
7714
+
7356
7715
  function HTMLIFrameElementContentWindowGetter(iframe) {
7357
- return ReflectApply(HTMLIFrameElementProtoContentWindowGetter, iframe, emptyArray);
7716
+ return ReflectApply(HTMLIFrameElementProtoContentWindowGetter, iframe, emptyArray);
7358
7717
  }
7718
+
7359
7719
  function NodeAppendChild(parent, child) {
7360
- return ReflectApply(NodeProtoAppendChild, parent, [child]);
7361
- }
7362
- // It's impossible to test whether NodeLastChild(document) is reached
7720
+ return ReflectApply(NodeProtoAppendChild, parent, [child]);
7721
+ } // It's impossible to test whether NodeLastChild(document) is reached
7363
7722
  // in a normal Karma test environment, because the document will always
7364
7723
  // have a body element. Ignore this in coverage reporting to
7365
7724
  // avoid a penalty.
7366
7725
  // istanbul ignore next
7726
+
7727
+
7367
7728
  function NodeLastChild(node) {
7368
- return ReflectApply(NodeProtoLastChildGetter, node, emptyArray);
7729
+ return ReflectApply(NodeProtoLastChildGetter, node, emptyArray);
7369
7730
  }
7731
+
7370
7732
  function NodeIsConnected(node) {
7371
- return ReflectApply(NodeProtoIsConnectedGetter, node, emptyArray);
7733
+ return ReflectApply(NodeProtoIsConnectedGetter, node, emptyArray);
7372
7734
  }
7735
+
7373
7736
  function createDetachableIframe$1() {
7374
- // @ts-ignore document global ref - in browsers
7375
- const iframe = DocumentCreateElement(document, 'iframe');
7376
- // It's impossible to test whether NodeLastChild(document) is reached
7377
- // in a normal Karma test environment. (See explanation above,
7378
- // at NodeLastChild definition.)
7379
- const parent = DocumentBody(document) || /* istanbul ignore next */ NodeLastChild(document);
7380
- const style = HTMLElementStyleGetter(iframe);
7381
- style.display = 'none';
7382
- ElementSetAttribute(iframe, 'sandbox', IFRAME_SANDBOX_ATTRIBUTE_VALUE);
7383
- NodeAppendChild(parent, iframe);
7384
- return iframe;
7737
+ // @ts-ignore document global ref - in browsers
7738
+ const iframe = DocumentCreateElement(document, 'iframe'); // It's impossible to test whether NodeLastChild(document) is reached
7739
+ // in a normal Karma test environment. (See explanation above,
7740
+ // at NodeLastChild definition.)
7741
+
7742
+ const parent = DocumentBody(document) ||
7743
+ /* istanbul ignore next */
7744
+ NodeLastChild(document);
7745
+ const style = HTMLElementStyleGetter(iframe);
7746
+ style.display = 'none';
7747
+ ElementSetAttribute(iframe, 'sandbox', IFRAME_SANDBOX_ATTRIBUTE_VALUE);
7748
+ NodeAppendChild(parent, iframe);
7749
+ return iframe;
7385
7750
  }
7751
+
7386
7752
  function removeIframe(iframe) {
7387
- // In Chrome debugger statements will be ignored when the iframe is removed
7388
- // from the document. Other browsers like Firefox and Safari work as expected.
7389
- // https://bugs.chromium.org/p/chromium/issues/detail?id=1015462
7390
- // Because the detachable iframe is created, and then optionally removed, all
7391
- // within the execution of createVirtualEnvironment, there is no point in which
7392
- // test code can interfere with iframe element, or its prototype chain, in
7393
- // order to remove it from the DOM, or stub the isConnected accessor
7394
- // (the latter is already too late before createVirtualEnvironment is ever called).
7395
- // For this reason, ignore the lack of `else` path coverage.
7396
- //
7397
- // istanbul ignore else
7398
- if (NodeIsConnected(iframe)) {
7399
- ElementRemove(iframe);
7400
- }
7753
+ // In Chrome debugger statements will be ignored when the iframe is removed
7754
+ // from the document. Other browsers like Firefox and Safari work as expected.
7755
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=1015462
7756
+ // Because the detachable iframe is created, and then optionally removed, all
7757
+ // within the execution of createVirtualEnvironment, there is no point in which
7758
+ // test code can interfere with iframe element, or its prototype chain, in
7759
+ // order to remove it from the DOM, or stub the isConnected accessor
7760
+ // (the latter is already too late before createVirtualEnvironment is ever called).
7761
+ // For this reason, ignore the lack of `else` path coverage.
7762
+ //
7763
+ // istanbul ignore else
7764
+ if (NodeIsConnected(iframe)) {
7765
+ ElementRemove(iframe);
7766
+ }
7401
7767
  }
7768
+
7402
7769
  const createHooksCallback = createMembraneMarshall();
7770
+
7403
7771
  function createVirtualEnvironment(globalObjectShape, globalObjectVirtualizationTarget, providedOptions) {
7404
- validateRequiredGlobalShapeAndVirtualizationObjects(globalObjectShape, globalObjectVirtualizationTarget);
7405
- // eslint-disable-next-line prefer-object-spread
7406
- const options = ObjectAssign({
7407
- __proto__: null,
7408
- keepAlive: false,
7409
- }, providedOptions);
7410
- // eslint-disable-next-line prefer-object-spread
7411
- const { distortionCallback, endowments = {}, keepAlive, support, instrumentation } = options;
7412
- const iframe = createDetachableIframe$1();
7413
- const redWindow = HTMLIFrameElementContentWindowGetter(iframe).window;
7414
- const { document: redDocument } = redWindow;
7415
- const blueConnector = createHooksCallback;
7416
- const redConnector = createConnector(redWindow.eval);
7417
- // Extract the global references and descriptors before any interference.
7418
- const blueRefs = getCachedBlueReferences(globalObjectVirtualizationTarget);
7419
- // Create a new environment.
7420
- const env = new VirtualEnvironment({
7421
- blueConnector,
7422
- distortionCallback,
7423
- redConnector,
7424
- support,
7425
- instrumentation,
7426
- });
7427
- env.link('window');
7428
- linkIntrinsics(env, globalObjectVirtualizationTarget);
7429
- linkUnforgeables(env, globalObjectVirtualizationTarget);
7430
- tameDOM(env, blueRefs, getResolvedShapeDescriptors(globalObjectShape, endowments));
7431
- // Once we get the iframe info ready, and all mapped, we can proceed
7432
- // to detach the iframe only if the keepAlive option isn't true.
7433
- if (keepAlive !== true) {
7434
- removeIframe(iframe);
7435
- }
7436
- else {
7437
- // TODO: Temporary hack to preserve the document reference in Firefox.
7438
- // https://bugzilla.mozilla.org/show_bug.cgi?id=543435
7439
- DocumentOpen(redDocument);
7440
- DocumentClose(redDocument);
7441
- }
7442
- return env;
7772
+ validateRequiredGlobalShapeAndVirtualizationObjects(globalObjectShape, globalObjectVirtualizationTarget); // eslint-disable-next-line prefer-object-spread
7773
+
7774
+ const options = ObjectAssign({
7775
+ __proto__: null,
7776
+ keepAlive: false
7777
+ }, providedOptions); // eslint-disable-next-line prefer-object-spread
7778
+
7779
+ const {
7780
+ distortionCallback,
7781
+ endowments = {},
7782
+ keepAlive,
7783
+ support,
7784
+ instrumentation
7785
+ } = options;
7786
+ const iframe = createDetachableIframe$1();
7787
+ const redWindow = HTMLIFrameElementContentWindowGetter(iframe).window;
7788
+ const {
7789
+ document: redDocument
7790
+ } = redWindow;
7791
+ const blueConnector = createHooksCallback;
7792
+ const redConnector = createConnector(redWindow.eval); // Extract the global references and descriptors before any interference.
7793
+
7794
+ const blueRefs = getCachedBlueReferences(globalObjectVirtualizationTarget); // Create a new environment.
7795
+
7796
+ const env = new VirtualEnvironment({
7797
+ blueConnector,
7798
+ distortionCallback,
7799
+ redConnector,
7800
+ support,
7801
+ instrumentation
7802
+ });
7803
+ env.link('window');
7804
+ linkIntrinsics(env, globalObjectVirtualizationTarget);
7805
+ linkUnforgeables(env, globalObjectVirtualizationTarget);
7806
+ tameDOM(env, blueRefs, getResolvedShapeDescriptors(globalObjectShape, endowments)); // Once we get the iframe info ready, and all mapped, we can proceed
7807
+ // to detach the iframe only if the keepAlive option isn't true.
7808
+
7809
+ if (keepAlive !== true) {
7810
+ removeIframe(iframe);
7811
+ } else {
7812
+ // TODO: Temporary hack to preserve the document reference in Firefox.
7813
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=543435
7814
+ DocumentOpen(redDocument);
7815
+ DocumentClose(redDocument);
7816
+ }
7817
+
7818
+ return env;
7443
7819
  }
7444
7820
 
7445
- /*!
7446
- * Copyright (C) 2019 salesforce.com, inc.
7447
- */
7448
7821
  let lockerBlueRealmGlobalObjectShape;
7449
7822
  let lockerEvalContextValue;
7450
7823
  let lockerEvalHelpersValue;
@@ -7683,8 +8056,8 @@ function createSandbox(key, distortionFactory, endowments, instrumentation) {
7683
8056
  const headRef = docRef.head;
7684
8057
 
7685
8058
  function DocumentCreateElement(doc) {
7686
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key2 = 1; _key2 < _len; _key2++) {
7687
- args[_key2 - 1] = arguments[_key2];
8059
+ for (var _len10 = arguments.length, args = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
8060
+ args[_key10 - 1] = arguments[_key10];
7688
8061
  }
7689
8062
 
7690
8063
  return ReflectApply(DocumentProtoCreateElement, doc, args);
@@ -7703,8 +8076,8 @@ function createSandbox(key, distortionFactory, endowments, instrumentation) {
7703
8076
  }
7704
8077
 
7705
8078
  function EventTargetAddEventListener(target) {
7706
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key3 = 1; _key3 < _len2; _key3++) {
7707
- args[_key3 - 1] = arguments[_key3];
8079
+ for (var _len11 = arguments.length, args = new Array(_len11 > 1 ? _len11 - 1 : 0), _key11 = 1; _key11 < _len11; _key11++) {
8080
+ args[_key11 - 1] = arguments[_key11];
7708
8081
  }
7709
8082
 
7710
8083
  return ReflectApply(EventTargetProtoAddEventListener, target, args);
@@ -7933,7 +8306,7 @@ function evaluateInSandbox(key, sourceText, context, endowments, instrumentation
7933
8306
  activityEvaluateInSandbox.stop();
7934
8307
  return result;
7935
8308
  }
7936
- /*! version: 0.14.13 */
8309
+ /*! version: 0.14.15 */
7937
8310
 
7938
8311
  const loaderDefine = globalThis.LWR.define;
7939
8312
  /**