@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
@@ -5437,8 +5513,8 @@ function makeBlockedPropertyDistortionFactories(globalObject) {
5437
5513
 
5438
5514
  const instrumentDistortionForSandbox = (sandboxKey, value, errorBeacon) => function instrumentedDistortionWrapper() {
5439
5515
  try {
5440
- for (var _len14 = arguments.length, args = new Array(_len14), _key15 = 0; _key15 < _len14; _key15++) {
5441
- args[_key15] = arguments[_key15];
5516
+ for (var _len15 = arguments.length, args = new Array(_len15), _key16 = 0; _key16 < _len15; _key16++) {
5517
+ args[_key16] = arguments[_key16];
5442
5518
  }
5443
5519
 
5444
5520
  return ReflectApply$3(value, this, args);
@@ -5574,7 +5650,7 @@ function createInternalDistortionEntries(globalObject, key, evaluator, config) {
5574
5650
  ReflectApply$3(ArrayProtoPush, entries, makeElementDistortionsForSandboxKey(key));
5575
5651
  return entries;
5576
5652
  }
5577
- /*! version: 0.14.13 */
5653
+ /*! version: 0.14.15 */
5578
5654
 
5579
5655
  /*!
5580
5656
  * Copyright (C) 2021 salesforce.com, inc.
@@ -5697,8 +5773,11 @@ class DefaultInstrumentation {
5697
5773
 
5698
5774
 
5699
5775
  const defaultInstrumentation = new DefaultInstrumentation();
5700
- /*! version: 0.14.13 */
5776
+ /*! version: 0.14.15 */
5701
5777
 
5778
+ /*!
5779
+ * Copyright (C) 2019 salesforce.com, inc.
5780
+ */
5702
5781
  /**
5703
5782
  * This file contains an exportable (portable) function `init` used to initialize
5704
5783
  * one side of a membrane on any realm. The only prerequisite is the ability to evaluate
@@ -5719,1347 +5798,1644 @@ const defaultInstrumentation = new DefaultInstrumentation();
5719
5798
  * the foreign operation operates, it is always the first argument of the foreign
5720
5799
  * callable for proxies, and the other side can use it via `getSelectedTarget`.
5721
5800
  */
5722
- // eslint-disable-next-line no-shadow
5801
+
5802
+ const {
5803
+ setPrototypeOf: ReflectSetPrototypeOf
5804
+ } = Reflect; // eslint-disable-next-line no-shadow
5805
+
5723
5806
  var SupportFlagsEnum;
5807
+
5724
5808
  (function (SupportFlagsEnum) {
5725
- SupportFlagsEnum[SupportFlagsEnum["None"] = 0] = "None";
5726
- SupportFlagsEnum[SupportFlagsEnum["MagicMarker"] = 1] = "MagicMarker";
5809
+ SupportFlagsEnum[SupportFlagsEnum["None"] = 0] = "None";
5810
+ SupportFlagsEnum[SupportFlagsEnum["MagicMarker"] = 1] = "MagicMarker";
5727
5811
  })(SupportFlagsEnum || (SupportFlagsEnum = {}));
5728
- // istanbul ignore next
5812
+
5813
+ ReflectSetPrototypeOf(SupportFlagsEnum, null); // istanbul ignore next
5814
+
5729
5815
  function createMembraneMarshall() {
5730
- // eslint-disable-next-line no-shadow
5731
- let MarshallSupportFlagsField;
5732
- (function (MarshallSupportFlagsField) {
5733
- MarshallSupportFlagsField[MarshallSupportFlagsField["None"] = 0] = "None";
5734
- MarshallSupportFlagsField[MarshallSupportFlagsField["MagicMarker"] = 1] = "MagicMarker";
5735
- })(MarshallSupportFlagsField || (MarshallSupportFlagsField = {}));
5736
- // eslint-disable-next-line no-shadow
5737
- let TargetIntegrityTraits;
5738
- (function (TargetIntegrityTraits) {
5739
- TargetIntegrityTraits[TargetIntegrityTraits["None"] = 0] = "None";
5740
- TargetIntegrityTraits[TargetIntegrityTraits["IsNotExtensible"] = 1] = "IsNotExtensible";
5741
- TargetIntegrityTraits[TargetIntegrityTraits["IsSealed"] = 2] = "IsSealed";
5742
- TargetIntegrityTraits[TargetIntegrityTraits["IsFrozen"] = 4] = "IsFrozen";
5743
- TargetIntegrityTraits[TargetIntegrityTraits["Revoked"] = 16] = "Revoked";
5744
- })(TargetIntegrityTraits || (TargetIntegrityTraits = {}));
5745
- // eslint-disable-next-line no-shadow
5746
- let TargetTraits;
5747
- (function (TargetTraits) {
5748
- TargetTraits[TargetTraits["None"] = 0] = "None";
5749
- TargetTraits[TargetTraits["IsArray"] = 1] = "IsArray";
5750
- TargetTraits[TargetTraits["IsFunction"] = 2] = "IsFunction";
5751
- TargetTraits[TargetTraits["IsObject"] = 4] = "IsObject";
5752
- TargetTraits[TargetTraits["IsArrowFunction"] = 8] = "IsArrowFunction";
5753
- TargetTraits[TargetTraits["Revoked"] = 16] = "Revoked";
5754
- })(TargetTraits || (TargetTraits = {}));
5755
- const { eval: cachedLocalEval } = globalThis;
5756
- const ArrayCtor = Array;
5757
- const { isArray: isArrayOrNotOrThrowForRevoked } = Array;
5758
- const { defineProperties: ObjectDefineProperties, freeze: ObjectFreeze, isFrozen: ObjectIsFrozen, isSealed: ObjectIsSealed, seal: ObjectSeal, } = Object;
5759
- const { hasOwnProperty: ObjectProtoHasOwnProperty, toString: ObjectProtoToString } = Object.prototype;
5760
- const { revocable: ProxyRevocable } = Proxy;
5761
- 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;
5762
- const { slice: StringProtoSlice } = String.prototype;
5763
- const TypeErrorCtor = TypeError;
5764
- const { get: WeakMapProtoGet, set: WeakMapProtoSet } = WeakMap.prototype;
5765
- const LOCKER_LIVE_MARKER_SYMBOL = Symbol.for('@@lockerLiveValue');
5766
- const LOCKER_MAGIC_MARKER_SYMBOL = Symbol.for('@@lockerMagicValue');
5767
- const { toStringTag: TO_STRING_TAG_SYMBOL } = Symbol;
5768
- const UNDEFINED_SYMBOL = Symbol.for('@@membraneUndefinedValue');
5769
- return function createHooksCallback(color, trapMutations, supportFlags = SupportFlagsEnum.None, foreignCallableHooksCallback, options) {
5770
- const { distortionCallback = (o) => o, instrumentation } = options || {
5771
- __proto__: null,
5772
- };
5773
- const proxyTargetToPointerMap = new WeakMap();
5774
- const SUPPORT_MAGIC_MARKER = !!(supportFlags & MarshallSupportFlagsField.MagicMarker);
5775
- const INBOUND_INSTRUMENTATION_LABEL = `to:${color}`;
5776
- const OUTBOUND_INSTRUMENTATION_LABEL = `from:${color}`;
5777
- let foreignCallablePushTarget;
5778
- let foreignCallableApply;
5779
- let foreignCallableConstruct;
5780
- let foreignCallableDefineProperty;
5781
- let foreignCallableDeleteProperty;
5782
- let foreignCallableGetOwnPropertyDescriptor;
5783
- let foreignCallableGetPrototypeOf;
5784
- let foreignCallableIsExtensible;
5785
- let foreignCallableOwnKeys;
5786
- let foreignCallablePreventExtensions;
5787
- let foreignCallableSet;
5788
- let foreignCallableSetPrototypeOf;
5789
- let foreignCallableGetTargetIntegrityTraits;
5790
- let foreignCallableGetUnbrandedTag;
5791
- let foreignCallableHasOwnProperty;
5792
- let selectedTarget;
5793
- if (ReflectApply(ObjectProtoHasOwnProperty, Error, ['stackTraceLimit']) &&
5794
- typeof Error.stackTraceLimit === 'number') {
5795
- // The default stack trace limit is 10.
5796
- // Increasing to 20 as a baby step.
5797
- Error.stackTraceLimit *= 2;
5816
+ const {
5817
+ eval: cachedLocalEval
5818
+ } = globalThis;
5819
+ const ArrayCtor = Array;
5820
+ const {
5821
+ isArray: isArrayOrNotOrThrowForRevoked
5822
+ } = Array;
5823
+ const {
5824
+ defineProperties: ObjectDefineProperties,
5825
+ freeze: ObjectFreeze,
5826
+ isFrozen: ObjectIsFrozen,
5827
+ isSealed: ObjectIsSealed,
5828
+ seal: ObjectSeal
5829
+ } = Object;
5830
+ const {
5831
+ hasOwnProperty: ObjectProtoHasOwnProperty,
5832
+ toString: ObjectProtoToString
5833
+ } = Object.prototype;
5834
+ const {
5835
+ revocable: ProxyRevocable
5836
+ } = Proxy;
5837
+ const {
5838
+ apply: ReflectApply,
5839
+ construct: ReflectConstruct,
5840
+ defineProperty: ReflectDefineProperty,
5841
+ deleteProperty: ReflectDeleteProperty,
5842
+ get: ReflectGet,
5843
+ getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
5844
+ getPrototypeOf: ReflectGetPrototypeOf,
5845
+ has: ReflectHas,
5846
+ isExtensible: ReflectIsExtensible,
5847
+ ownKeys: ReflectOwnKeys,
5848
+ preventExtensions: ReflectPreventExtensions,
5849
+ set: ReflectSet,
5850
+ // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
5851
+ setPrototypeOf: ReflectSetPrototypeOf
5852
+ } = Reflect;
5853
+ const {
5854
+ slice: StringProtoSlice
5855
+ } = String.prototype;
5856
+ const TypeErrorCtor = TypeError;
5857
+ const {
5858
+ get: WeakMapProtoGet,
5859
+ set: WeakMapProtoSet
5860
+ } = WeakMap.prototype;
5861
+ const LOCKER_LIVE_MARKER_SYMBOL = Symbol.for('@@lockerLiveValue');
5862
+ const LOCKER_MAGIC_MARKER_SYMBOL = Symbol.for('@@lockerMagicValue');
5863
+ const {
5864
+ toStringTag: TO_STRING_TAG_SYMBOL
5865
+ } = Symbol;
5866
+ const UNDEFINED_SYMBOL = Symbol.for('@@membraneUndefinedValue'); // eslint-disable-next-line no-shadow
5867
+
5868
+ let MarshallSupportFlagsField;
5869
+
5870
+ (function (MarshallSupportFlagsField) {
5871
+ MarshallSupportFlagsField[MarshallSupportFlagsField["None"] = 0] = "None";
5872
+ MarshallSupportFlagsField[MarshallSupportFlagsField["MagicMarker"] = 1] = "MagicMarker";
5873
+ })(MarshallSupportFlagsField || (MarshallSupportFlagsField = {}));
5874
+
5875
+ ReflectSetPrototypeOf(MarshallSupportFlagsField, null); // eslint-disable-next-line no-shadow
5876
+
5877
+ let TargetIntegrityTraits;
5878
+
5879
+ (function (TargetIntegrityTraits) {
5880
+ TargetIntegrityTraits[TargetIntegrityTraits["None"] = 0] = "None";
5881
+ TargetIntegrityTraits[TargetIntegrityTraits["IsNotExtensible"] = 1] = "IsNotExtensible";
5882
+ TargetIntegrityTraits[TargetIntegrityTraits["IsSealed"] = 2] = "IsSealed";
5883
+ TargetIntegrityTraits[TargetIntegrityTraits["IsFrozen"] = 4] = "IsFrozen";
5884
+ TargetIntegrityTraits[TargetIntegrityTraits["Revoked"] = 16] = "Revoked";
5885
+ })(TargetIntegrityTraits || (TargetIntegrityTraits = {}));
5886
+
5887
+ ReflectSetPrototypeOf(TargetIntegrityTraits, null); // eslint-disable-next-line no-shadow
5888
+
5889
+ let TargetTraits;
5890
+
5891
+ (function (TargetTraits) {
5892
+ TargetTraits[TargetTraits["None"] = 0] = "None";
5893
+ TargetTraits[TargetTraits["IsArray"] = 1] = "IsArray";
5894
+ TargetTraits[TargetTraits["IsFunction"] = 2] = "IsFunction";
5895
+ TargetTraits[TargetTraits["IsObject"] = 4] = "IsObject";
5896
+ TargetTraits[TargetTraits["IsArrowFunction"] = 8] = "IsArrowFunction";
5897
+ TargetTraits[TargetTraits["Revoked"] = 16] = "Revoked";
5898
+ })(TargetTraits || (TargetTraits = {}));
5899
+
5900
+ ReflectSetPrototypeOf(TargetTraits, null);
5901
+ return function createHooksCallback(color, trapMutations) {
5902
+ let supportFlags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SupportFlagsEnum.None;
5903
+ let foreignCallableHooksCallback = arguments.length > 3 ? arguments[3] : undefined;
5904
+ let options = arguments.length > 4 ? arguments[4] : undefined;
5905
+ const {
5906
+ distortionCallback = o => o,
5907
+ instrumentation
5908
+ } = options || {
5909
+ __proto__: null
5910
+ };
5911
+ const proxyTargetToPointerMap = new WeakMap();
5912
+ const INBOUND_INSTRUMENTATION_LABEL = `to:${color}`;
5913
+ const OUTBOUND_INSTRUMENTATION_LABEL = `from:${color}`;
5914
+ const SUPPORT_MAGIC_MARKER = !!(supportFlags & MarshallSupportFlagsField.MagicMarker);
5915
+ let foreignCallablePushTarget;
5916
+ let foreignCallableApply;
5917
+ let foreignCallableConstruct;
5918
+ let foreignCallableDefineProperty;
5919
+ let foreignCallableDeleteProperty;
5920
+ let foreignCallableGetOwnPropertyDescriptor;
5921
+ let foreignCallableGetPrototypeOf;
5922
+ let foreignCallableIsExtensible;
5923
+ let foreignCallableOwnKeys;
5924
+ let foreignCallablePreventExtensions;
5925
+ let foreignCallableSet;
5926
+ let foreignCallableSetPrototypeOf;
5927
+ let foreignCallableGetTargetIntegrityTraits;
5928
+ let foreignCallableGetUnbrandedTag;
5929
+ let foreignCallableHasOwnProperty;
5930
+ let selectedTarget;
5931
+
5932
+ function copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer) {
5933
+ let keys = [];
5934
+ foreignCallableOwnKeys(foreignTargetPointer, function () {
5935
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5936
+ args[_key] = arguments[_key];
5798
5937
  }
5799
- function copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer) {
5800
- let keys = [];
5801
- foreignCallableOwnKeys(foreignTargetPointer, (...args) => {
5802
- keys = args;
5803
- });
5804
- const descriptors = {};
5805
- let safeDesc;
5806
- const callbackWithDescriptor = (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
5807
- safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
5808
- };
5809
- for (let i = 0, len = keys.length; i < len; i += 1) {
5810
- const key = keys[i];
5811
- foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, callbackWithDescriptor);
5812
- descriptors[key] = safeDesc;
5813
- }
5814
- // Use `ObjectDefineProperties` instead of individual
5815
- // `ReflectDefineProperty` calls for better performance.
5816
- ObjectDefineProperties(shadowTarget, descriptors);
5938
+
5939
+ keys = args;
5940
+ });
5941
+ const descriptors = {};
5942
+ let safeDesc;
5943
+
5944
+ const callbackWithDescriptor = (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
5945
+ safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
5946
+ };
5947
+
5948
+ for (let i = 0, len = keys.length; i < len; i += 1) {
5949
+ const key = keys[i];
5950
+ foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, callbackWithDescriptor);
5951
+
5952
+ if (safeDesc) {
5953
+ descriptors[key] = safeDesc;
5817
5954
  }
5818
- // metadata is the transferable descriptor definition
5819
- function createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer) {
5955
+ } // Use `ObjectDefineProperties` instead of individual
5956
+ // `ReflectDefineProperty` calls for better performance.
5957
+
5958
+
5959
+ ObjectDefineProperties(shadowTarget, descriptors);
5960
+ } // metadata is the transferable descriptor definition
5961
+
5962
+
5963
+ function createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer) {
5964
+ // @ts-ignore: TS doesn't like __proto__ on property descriptors.
5965
+ const safeDesc = {
5966
+ __proto__: null
5967
+ };
5968
+
5969
+ if (configurable !== UNDEFINED_SYMBOL) {
5970
+ safeDesc.configurable = !!configurable;
5971
+ }
5972
+
5973
+ if (enumerable !== UNDEFINED_SYMBOL) {
5974
+ safeDesc.enumerable = !!enumerable;
5975
+ }
5976
+
5977
+ if (writable !== UNDEFINED_SYMBOL) {
5978
+ safeDesc.writable = !!writable;
5979
+ }
5980
+
5981
+ if (getPointer !== UNDEFINED_SYMBOL) {
5982
+ safeDesc.get = getLocalValue(getPointer);
5983
+ }
5984
+
5985
+ if (setPointer !== UNDEFINED_SYMBOL) {
5986
+ safeDesc.set = getLocalValue(setPointer);
5987
+ }
5988
+
5989
+ if (valuePointer !== UNDEFINED_SYMBOL) {
5990
+ safeDesc.value = getLocalValue(valuePointer);
5991
+ }
5992
+
5993
+ return safeDesc;
5994
+ }
5995
+
5996
+ function createPointer(originalTarget) {
5997
+ // assert: originalTarget is a ProxyTarget
5998
+ const pointer = () => {
5999
+ // assert: selectedTarget is undefined
6000
+ selectedTarget = originalTarget;
6001
+ };
6002
+
6003
+ {
6004
+ // In case debugging is needed, the following lines can help:
6005
+ pointer['[[OriginalTarget]]'] = originalTarget;
6006
+ pointer['[[Color]]'] = color;
6007
+ }
6008
+ return pointer;
6009
+ }
6010
+
6011
+ function createShadowTarget(targetTraits, targetFunctionName) {
6012
+ let shadowTarget;
6013
+
6014
+ if (targetTraits & TargetTraits.IsFunction) {
6015
+ // This shadow target is never invoked. It's needed to avoid
6016
+ // proxy trap invariants. Because it's not invoked the code does
6017
+ // not need to be instrumented for code coverage.
6018
+ //
6019
+ // istanbul ignore next
6020
+ shadowTarget = // eslint-disable-next-line func-names
6021
+ targetTraits & TargetTraits.IsArrowFunction ? () => {} : function () {};
6022
+ {
6023
+ // This is only really needed for debugging,
6024
+ // it helps to identify the proxy by name
6025
+ ReflectDefineProperty(shadowTarget, 'name', {
5820
6026
  // @ts-ignore: TS doesn't like __proto__ on property descriptors.
5821
- const safeDesc = { __proto__: null };
5822
- if (configurable !== UNDEFINED_SYMBOL) {
5823
- safeDesc.configurable = !!configurable;
5824
- }
5825
- if (enumerable !== UNDEFINED_SYMBOL) {
5826
- safeDesc.enumerable = !!enumerable;
5827
- }
5828
- if (writable !== UNDEFINED_SYMBOL) {
5829
- safeDesc.writable = !!writable;
5830
- }
5831
- if (getPointer !== UNDEFINED_SYMBOL) {
5832
- safeDesc.get = getLocalValue(getPointer);
5833
- }
5834
- if (setPointer !== UNDEFINED_SYMBOL) {
5835
- safeDesc.set = getLocalValue(setPointer);
5836
- }
5837
- if (valuePointer !== UNDEFINED_SYMBOL) {
5838
- safeDesc.value = getLocalValue(valuePointer);
5839
- }
5840
- return safeDesc;
6027
+ __proto__: null,
6028
+ configurable: true,
6029
+ enumerable: false,
6030
+ value: targetFunctionName,
6031
+ writable: false
6032
+ });
5841
6033
  }
5842
- function createPointer(originalTarget) {
5843
- // assert: originalTarget is a ProxyTarget
5844
- const pointer = () => {
5845
- // assert: selectedTarget is undefined
5846
- selectedTarget = originalTarget;
5847
- };
5848
- {
5849
- // In case debugging is needed, the following lines can help:
5850
- pointer['[[OriginalTarget]]'] = originalTarget;
5851
- pointer['[[Color]]'] = color;
5852
- }
5853
- return pointer;
6034
+ } else {
6035
+ // target is array or object
6036
+ shadowTarget = targetTraits & TargetTraits.IsArray ? [] : {};
6037
+ }
6038
+
6039
+ return shadowTarget;
6040
+ } // this is needed even when using ShadowRealm, because the errors are not going
6041
+ // to cross the callable boundary in a try/catch, instead, they need to be ported
6042
+ // via the membrane artifacts.
6043
+
6044
+
6045
+ function foreignErrorControl(foreignFn) {
6046
+ return function foreignErrorControlFn() {
6047
+ try {
6048
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
6049
+ args[_key2] = arguments[_key2];
6050
+ }
6051
+
6052
+ return ReflectApply(foreignFn, this, args);
6053
+ } catch (e) {
6054
+ const pushedError = getSelectedTarget();
6055
+
6056
+ if (pushedError) {
6057
+ throw pushedError;
6058
+ }
6059
+
6060
+ throw new TypeErrorCtor(e === null || e === void 0 ? void 0 : e.message);
5854
6061
  }
5855
- function createShadowTarget(targetTraits, targetFunctionName) {
5856
- let shadowTarget;
5857
- if (targetTraits & TargetTraits.IsFunction) {
5858
- // This shadow target is never invoked. It's needed to avoid
5859
- // proxy trap invariants. Because it's not invoked the code does
5860
- // not need to be instrumented for code coverage.
5861
- //
5862
- // istanbul ignore next
5863
- shadowTarget =
5864
- // eslint-disable-next-line func-names
5865
- targetTraits & TargetTraits.IsArrowFunction ? () => { } : function () { };
5866
- {
5867
- // This is only really needed for debugging,
5868
- // it helps to identify the proxy by name
5869
- ReflectDefineProperty(shadowTarget, 'name', {
5870
- // @ts-ignore: TS doesn't like __proto__ on property descriptors.
5871
- __proto__: null,
5872
- configurable: true,
5873
- enumerable: false,
5874
- value: targetFunctionName,
5875
- writable: false,
5876
- });
5877
- }
5878
- }
5879
- else {
5880
- // target is array or object
5881
- shadowTarget = targetTraits & TargetTraits.IsArray ? [] : {};
5882
- }
5883
- return shadowTarget;
6062
+ };
6063
+ }
6064
+
6065
+ function getDescriptorMeta(unsafePartialDesc) {
6066
+ const safePartialDesc = toSafeDescriptor(unsafePartialDesc);
6067
+ const {
6068
+ configurable,
6069
+ enumerable,
6070
+ writable,
6071
+ value,
6072
+ get,
6073
+ set
6074
+ } = safePartialDesc;
6075
+ 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];
6076
+ }
6077
+
6078
+ function getDistortedValue(target) {
6079
+ let distortedTarget;
6080
+
6081
+ try {
6082
+ distortedTarget = distortionCallback(target);
6083
+ return distortedTarget;
6084
+ } finally {
6085
+ // if a distortion entry is found, it must be a valid proxy target
6086
+ if (distortedTarget !== target && typeof distortedTarget !== typeof target) {
6087
+ // eslint-disable-next-line no-unsafe-finally
6088
+ throw new TypeErrorCtor(`Invalid distortion ${target}.`);
5884
6089
  }
5885
- // this is needed even when using ShadowRealm, because the errors are not going
5886
- // to cross the callable boundary in a try/catch, instead, they need to be ported
5887
- // via the membrane artifacts.
5888
- function foreignErrorControl(foreignFn) {
5889
- return function foreignErrorControlFn(...args) {
5890
- try {
5891
- return ReflectApply(foreignFn, this, args);
5892
- }
5893
- catch (e) {
5894
- const pushedError = getSelectedTarget();
5895
- if (pushedError) {
5896
- throw pushedError;
5897
- }
5898
- throw new TypeErrorCtor(e?.message);
5899
- }
5900
- };
6090
+ }
6091
+ }
6092
+
6093
+ function getInheritedPropertyDescriptor(foreignTargetPointer, key) {
6094
+ // Avoiding calling the has trap for any proto chain operation,
6095
+ // instead we implement the regular logic here in this trap.
6096
+ let currentObject = liveGetPrototypeOf(foreignTargetPointer);
6097
+
6098
+ while (currentObject) {
6099
+ const unsafeParentDesc = ReflectGetOwnPropertyDescriptor(currentObject, key);
6100
+
6101
+ if (unsafeParentDesc) {
6102
+ return toSafeDescriptor(unsafeParentDesc);
5901
6103
  }
5902
- function getDescriptorMeta(unsafePartialDesc) {
5903
- const safePartialDesc = toSafeDescriptor(unsafePartialDesc);
5904
- const { configurable, enumerable, writable, value, get, set } = safePartialDesc;
5905
- return [
5906
- 'configurable' in safePartialDesc ? !!configurable : UNDEFINED_SYMBOL,
5907
- 'enumerable' in safePartialDesc ? !!enumerable : UNDEFINED_SYMBOL,
5908
- 'writable' in safePartialDesc ? !!writable : UNDEFINED_SYMBOL,
5909
- 'value' in safePartialDesc ? getTransferableValue(value) : UNDEFINED_SYMBOL,
5910
- 'get' in safePartialDesc ? getTransferableValue(get) : UNDEFINED_SYMBOL,
5911
- 'set' in safePartialDesc ? getTransferableValue(set) : UNDEFINED_SYMBOL,
5912
- ];
6104
+
6105
+ currentObject = ReflectGetPrototypeOf(currentObject);
6106
+ }
6107
+
6108
+ return undefined;
6109
+ }
6110
+
6111
+ function getLocalValue(pointerOrPrimitive) {
6112
+ if (typeof pointerOrPrimitive === 'function') {
6113
+ pointerOrPrimitive();
6114
+ return getSelectedTarget();
6115
+ }
6116
+
6117
+ return pointerOrPrimitive;
6118
+ }
6119
+
6120
+ function getSelectedTarget() {
6121
+ // assert: selectedTarget is a ProxyTarget
6122
+ const result = selectedTarget;
6123
+ selectedTarget = undefined;
6124
+ return result;
6125
+ }
6126
+
6127
+ function getTargetTraits(target) {
6128
+ let targetTraits = TargetTraits.None;
6129
+
6130
+ if (typeof target === 'function') {
6131
+ targetTraits |= TargetTraits.IsFunction; // detecting arrow function vs function
6132
+
6133
+ try {
6134
+ targetTraits |= +!('prototype' in target) && TargetTraits.IsArrowFunction;
6135
+ } catch (_unused) {// target is either a revoked proxy, or a proxy that
6136
+ // throws on the `has` trap, in which case going with
6137
+ // a strict mode function seems appropriate.
5913
6138
  }
5914
- function getDistortedValue(target) {
5915
- let distortedTarget;
5916
- try {
5917
- distortedTarget = distortionCallback(target);
5918
- return distortedTarget;
5919
- }
5920
- finally {
5921
- // if a distortion entry is found, it must be a valid proxy target
5922
- if (distortedTarget !== target && typeof distortedTarget !== typeof target) {
5923
- // eslint-disable-next-line no-unsafe-finally
5924
- throw new TypeErrorCtor(`Invalid distortion ${target}.`);
5925
- }
5926
- }
6139
+ } else {
6140
+ let targetIsArray = false;
6141
+
6142
+ try {
6143
+ // try/catch in case Array.isArray throws when target
6144
+ // is a revoked proxy
6145
+ targetIsArray = isArrayOrNotOrThrowForRevoked(target);
6146
+ } catch (_unused2) {
6147
+ // TODO: this might be problematic, because functions
6148
+ // and arrow functions should also be subject to this,
6149
+ // but it seems that we can still create a proxy of
6150
+ // a revoke, and wait until the user-land code actually
6151
+ // access something out of it to throw the proper error.
6152
+ // target is a revoked proxy, so the type doesn't matter
6153
+ // much from this point on
6154
+ targetTraits |= TargetTraits.Revoked;
5927
6155
  }
5928
- function getInheritedPropertyDescriptor(foreignTargetPointer, key) {
5929
- // Avoiding calling the has trap for any proto chain operation,
5930
- // instead we implement the regular logic here in this trap.
5931
- let currentObject = liveGetPrototypeOf(foreignTargetPointer);
5932
- while (currentObject) {
5933
- const unsafeParentDesc = ReflectGetOwnPropertyDescriptor(currentObject, key);
5934
- if (unsafeParentDesc) {
5935
- return toSafeDescriptor(unsafeParentDesc);
5936
- }
5937
- currentObject = ReflectGetPrototypeOf(currentObject);
5938
- }
5939
- return undefined;
6156
+
6157
+ targetTraits |= +targetIsArray && TargetTraits.IsArray;
6158
+ targetTraits |= +!targetIsArray && TargetTraits.IsObject;
6159
+ }
6160
+
6161
+ return targetTraits;
6162
+ }
6163
+
6164
+ function getTargetIntegrityTraits(target) {
6165
+ let targetIntegrityTraits = TargetIntegrityTraits.None;
6166
+
6167
+ try {
6168
+ // a revoked proxy will break the membrane when reading the meta
6169
+ if (ObjectIsFrozen(target)) {
6170
+ targetIntegrityTraits |= TargetIntegrityTraits.IsSealed & TargetIntegrityTraits.IsFrozen & TargetIntegrityTraits.IsNotExtensible;
6171
+ } else if (ObjectIsSealed(target)) {
6172
+ targetIntegrityTraits |= TargetIntegrityTraits.IsSealed;
6173
+ } else if (!ReflectIsExtensible(target)) {
6174
+ targetIntegrityTraits |= TargetIntegrityTraits.IsNotExtensible;
6175
+ } // if the target was revoked or become revoked during the extraction
6176
+ // of the metadata, we mark it as broken in the catch.
6177
+
6178
+
6179
+ isArrayOrNotOrThrowForRevoked(target);
6180
+ } catch (_unused3) {
6181
+ // intentionally swallowing the error because this method is just
6182
+ // extracting the metadata in a way that it should always succeed
6183
+ // except for the cases in which the target is a proxy that is
6184
+ // either revoked or has some logic that is incompatible with the
6185
+ // membrane, in which case we will just create the proxy for the
6186
+ // membrane but revoke it right after to prevent any leakage.
6187
+ targetIntegrityTraits |= TargetIntegrityTraits.Revoked;
6188
+ }
6189
+
6190
+ return targetIntegrityTraits;
6191
+ }
6192
+
6193
+ function getTransferablePointer(originalTarget) {
6194
+ let proxyPointer = ReflectApply(WeakMapProtoGet, proxyTargetToPointerMap, [originalTarget]);
6195
+
6196
+ if (proxyPointer) {
6197
+ return proxyPointer;
6198
+ }
6199
+
6200
+ const distortedTarget = getDistortedValue(originalTarget); // the closure works as the implicit WeakMap
6201
+
6202
+ const targetPointer = createPointer(distortedTarget);
6203
+ const targetTraits = getTargetTraits(distortedTarget);
6204
+ let targetFunctionName;
6205
+
6206
+ if (typeof originalTarget === 'function') {
6207
+ try {
6208
+ // a revoked proxy will throw when reading the function name
6209
+ const unsafeDesc = ReflectGetOwnPropertyDescriptor(originalTarget, 'name');
6210
+
6211
+ if (unsafeDesc) {
6212
+ const safeDesc = toSafeDescriptor(unsafeDesc);
6213
+ targetFunctionName = safeDesc.value;
6214
+ }
6215
+ } catch (_unused4) {// intentionally swallowing the error because this method is just extracting
6216
+ // the function in a way that it should always succeed except for the cases
6217
+ // in which the provider is a proxy that is either revoked or has some logic
6218
+ // to prevent reading the name property descriptor.
5940
6219
  }
5941
- function getLocalValue(pointerOrPrimitive) {
5942
- if (typeof pointerOrPrimitive === 'function') {
5943
- pointerOrPrimitive();
5944
- return getSelectedTarget();
6220
+ }
6221
+
6222
+ proxyPointer = foreignCallablePushTarget(targetPointer, targetTraits, targetFunctionName); // the WeakMap is populated with the original target rather then the distorted one
6223
+ // while the pointer always uses the distorted one.
6224
+ // TODO: this mechanism poses another issue, which is that the return value of
6225
+ // getSelectedTarget() can never be used to call across the membrane because that
6226
+ // will cause a wrapping around the potential distorted value instead of the original
6227
+ // value. This is not fatal, but implies that for every distorted value where will
6228
+ // two proxies that are not ===, which is weird. Guaranteeing this is not easy because
6229
+ // it means auditing the code.
6230
+
6231
+ ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [originalTarget, proxyPointer]);
6232
+ return proxyPointer;
6233
+ }
6234
+
6235
+ function getTransferableValue(value) {
6236
+ // Internationally ignoring the case of (typeof document.all === 'undefined')
6237
+ // because in the reserve membrane, you never get one of those exotic objects.
6238
+ if (typeof value === 'undefined') {
6239
+ return undefined;
6240
+ } // TODO: What other ways to optimize this method?
6241
+
6242
+
6243
+ if (value === null || typeof value !== 'function' && typeof value !== 'object') {
6244
+ return value;
6245
+ }
6246
+
6247
+ return getTransferablePointer(value);
6248
+ } // This wrapping mechanism provides the means to add instrumentation
6249
+ // to the callable functions used to coordinate work between the sides
6250
+ // of the membrane.
6251
+ // TODO: do we need to pass more info into instrumentation hooks?
6252
+ // prettier-ignore
6253
+
6254
+
6255
+ function instrumentCallableWrapper(fn, activityName, crossingDirection) {
6256
+ if (instrumentation) {
6257
+ return function instrumentedFn() {
6258
+ const activity = instrumentation.startActivity(activityName, {
6259
+ crossingDirection
6260
+ });
6261
+
6262
+ try {
6263
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
6264
+ args[_key3] = arguments[_key3];
5945
6265
  }
5946
- return pointerOrPrimitive;
5947
- }
5948
- function getSelectedTarget() {
5949
- // assert: selectedTarget is a ProxyTarget
5950
- const r = selectedTarget;
5951
- selectedTarget = undefined;
5952
- return r;
6266
+
6267
+ return ReflectApply(fn, this, args);
6268
+ } catch (e) {
6269
+ activity.error(e);
6270
+ throw e;
6271
+ } finally {
6272
+ activity.stop();
6273
+ }
6274
+ };
6275
+ }
6276
+
6277
+ return fn;
6278
+ }
6279
+ /**
6280
+ * An object is marked as a "live" object when it has a
6281
+ * LOCKER_LIVE_MARKER_SYMBOL property. Live objects have their
6282
+ * defineProperty, deleteProperty, preventExtensions, set, and
6283
+ * setPrototypeOf proxy traps as "live" variations meaning that when
6284
+ * mutation occurs instead of maintaining a separate object graph of
6285
+ * changes the mutations are performed directly on the foreign target.
6286
+ *
6287
+ */
6288
+
6289
+
6290
+ function isForeignTargetMarkedLive(foreignTargetPointer) {
6291
+ return foreignCallableHasOwnProperty(foreignTargetPointer, LOCKER_LIVE_MARKER_SYMBOL);
6292
+ }
6293
+ /**
6294
+ * An object is marked as a "magic" object when it has a
6295
+ * LOCKER_MAGIC_MARKER_SYMBOL property. These objects have magical side
6296
+ * effects when setting properties, which would be broken by a Define
6297
+ * Property operation. For example, the `style` object of an HTMLElement
6298
+ * in Safari <= 14. This marker is a signal to the membrane that it must
6299
+ * use a Set operation, instead of a Define Property operation.
6300
+ *
6301
+ */
6302
+
6303
+
6304
+ function isMarkedMagic(object) {
6305
+ return SUPPORT_MAGIC_MARKER && ReflectApply(ObjectProtoHasOwnProperty, object, [LOCKER_MAGIC_MARKER_SYMBOL]);
6306
+ }
6307
+
6308
+ function liveDefineProperty(foreignTargetPointer, shadowTarget, key, unsafePartialDesc) {
6309
+ const descMeta = getDescriptorMeta(unsafePartialDesc);
6310
+ const result = foreignCallableDefineProperty(foreignTargetPointer, key, descMeta[0], // configurable
6311
+ descMeta[1], // enumerable
6312
+ descMeta[2], // writable
6313
+ descMeta[3], // valuePointer
6314
+ descMeta[4], // getPointer
6315
+ descMeta[5] // setPointer
6316
+ );
6317
+
6318
+ if (result) {
6319
+ // Intentionally testing against false since it could be
6320
+ // undefined as well
6321
+ if (descMeta[0]
6322
+ /* configurable */
6323
+ === false) {
6324
+ foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6325
+ ReflectDefineProperty(shadowTarget, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
6326
+ });
5953
6327
  }
5954
- function getTargetTraits(target) {
5955
- let targetTraits = TargetTraits.None;
5956
- if (typeof target === 'function') {
5957
- targetTraits |= TargetTraits.IsFunction;
5958
- // detecting arrow function vs function
5959
- try {
5960
- targetTraits |= +!('prototype' in target) && TargetTraits.IsArrowFunction;
5961
- }
5962
- catch {
5963
- // target is either a revoked proxy, or a proxy that
5964
- // throws on the `has` trap, in which case going with
5965
- // a strict mode function seems appropriate.
5966
- }
5967
- }
5968
- else {
5969
- let targetIsArray = false;
5970
- try {
5971
- // try/catch in case Array.isArray throws when target
5972
- // is a revoked proxy
5973
- targetIsArray = isArrayOrNotOrThrowForRevoked(target);
5974
- }
5975
- catch {
5976
- // TODO: this might be problematic, because functions
5977
- // and arrow functions should also be subject to this,
5978
- // but it seems that we can still create a proxy of
5979
- // a revoke, and wait until the user-land code actually
5980
- // access something out of it to throw the proper error.
5981
- // target is a revoked proxy, so the type doesn't matter
5982
- // much from this point on
5983
- targetTraits |= TargetTraits.Revoked;
5984
- }
5985
- targetTraits |= +targetIsArray && TargetTraits.IsArray;
5986
- targetTraits |= +!targetIsArray && TargetTraits.IsObject;
5987
- }
5988
- return targetTraits;
6328
+ }
6329
+
6330
+ return result;
6331
+ }
6332
+
6333
+ function liveDeleteProperty(foreignTargetPointer, _shadowTarget, key) {
6334
+ return foreignCallableDeleteProperty(foreignTargetPointer, key);
6335
+ }
6336
+
6337
+ function liveGet(foreignTargetPointer, shadowTarget, key, receiver) {
6338
+ const safeDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) || getInheritedPropertyDescriptor(foreignTargetPointer, key);
6339
+
6340
+ if (safeDesc) {
6341
+ const {
6342
+ get: getter,
6343
+ value: localValue
6344
+ } = safeDesc;
6345
+
6346
+ if (getter) {
6347
+ // Even though the getter function exists, we can't use
6348
+ // `ReflectGet` because there might be a distortion for
6349
+ // that getter function, in which case we must resolve
6350
+ // the local getter and call it instead.
6351
+ return ReflectApply(getter, receiver, []);
5989
6352
  }
5990
- function getTargetIntegrityTraits(target) {
5991
- let targetIntegrityTraits = TargetIntegrityTraits.None;
5992
- try {
5993
- // a revoked proxy will break the membrane when reading the meta
5994
- if (ObjectIsFrozen(target)) {
5995
- targetIntegrityTraits |=
5996
- TargetIntegrityTraits.IsSealed &
5997
- TargetIntegrityTraits.IsFrozen &
5998
- TargetIntegrityTraits.IsNotExtensible;
5999
- }
6000
- else if (ObjectIsSealed(target)) {
6001
- targetIntegrityTraits |= TargetIntegrityTraits.IsSealed;
6002
- }
6003
- else if (!ReflectIsExtensible(target)) {
6004
- targetIntegrityTraits |= TargetIntegrityTraits.IsNotExtensible;
6005
- }
6006
- // if the target was revoked or become revoked during the extraction
6007
- // of the metadata, we mark it as broken in the catch.
6008
- isArrayOrNotOrThrowForRevoked(target);
6009
- }
6010
- catch {
6011
- // intentionally swallowing the error because this method is just
6012
- // extracting the metadata in a way that it should always succeed
6013
- // except for the cases in which the target is a proxy that is
6014
- // either revoked or has some logic that is incompatible with the
6015
- // membrane, in which case we will just create the proxy for the
6016
- // membrane but revoke it right after to prevent any leakage.
6017
- targetIntegrityTraits |= TargetIntegrityTraits.Revoked;
6018
- }
6019
- return targetIntegrityTraits;
6353
+
6354
+ return localValue;
6355
+ }
6356
+
6357
+ if (key === TO_STRING_TAG_SYMBOL) {
6358
+ return foreignCallableGetUnbrandedTag(foreignTargetPointer);
6359
+ }
6360
+
6361
+ return undefined;
6362
+ }
6363
+
6364
+ function liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) {
6365
+ let safeDesc;
6366
+ foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6367
+ safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
6368
+
6369
+ if (safeDesc.configurable === false) {
6370
+ // updating the descriptor to non-configurable on the shadow
6371
+ ReflectDefineProperty(shadowTarget, key, safeDesc);
6020
6372
  }
6021
- function getTransferablePointer(originalTarget) {
6022
- let proxyPointer = ReflectApply(WeakMapProtoGet, proxyTargetToPointerMap, [
6023
- originalTarget,
6024
- ]);
6025
- if (proxyPointer) {
6026
- return proxyPointer;
6027
- }
6028
- const distortedTarget = getDistortedValue(originalTarget);
6029
- // the closure works as the implicit WeakMap
6030
- const targetPointer = createPointer(distortedTarget);
6031
- const targetTraits = getTargetTraits(distortedTarget);
6032
- let targetFunctionName;
6033
- if (typeof originalTarget === 'function') {
6034
- try {
6035
- // a revoked proxy will throw when reading the function name
6036
- const unsafeDesc = ReflectGetOwnPropertyDescriptor(originalTarget, 'name');
6037
- if (unsafeDesc) {
6038
- const safeDesc = toSafeDescriptor(unsafeDesc);
6039
- targetFunctionName = safeDesc.value;
6040
- }
6041
- }
6042
- catch {
6043
- // intentionally swallowing the error because this method is just extracting
6044
- // the function in a way that it should always succeed except for the cases
6045
- // in which the provider is a proxy that is either revoked or has some logic
6046
- // to prevent reading the name property descriptor.
6047
- }
6048
- }
6049
- proxyPointer = foreignCallablePushTarget(targetPointer, targetTraits, targetFunctionName);
6050
- // the WeakMap is populated with the original target rather then the distorted one
6051
- // while the pointer always uses the distorted one.
6052
- // TODO: this mechanism poses another issue, which is that the return value of
6053
- // getSelectedTarget() can never be used to call across the membrane because that
6054
- // will cause a wrapping around the potential distorted value instead of the original
6055
- // value. This is not fatal, but implies that for every distorted value where will
6056
- // two proxies that are not ===, which is weird. Guaranteeing this is not easy because
6057
- // it means auditing the code.
6058
- ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [originalTarget, proxyPointer]);
6059
- return proxyPointer;
6373
+ });
6374
+ return safeDesc;
6375
+ }
6376
+
6377
+ function liveGetPrototypeOf(foreignTargetPointer) {
6378
+ return getLocalValue(foreignCallableGetPrototypeOf(foreignTargetPointer));
6379
+ }
6380
+
6381
+ function liveHas(foreignTargetPointer, key) {
6382
+ if (foreignCallableHasOwnProperty(foreignTargetPointer, key)) {
6383
+ return true;
6384
+ } // Avoiding calling the has trap for any proto chain operation,
6385
+ // instead we implement the regular logic here in this trap.
6386
+
6387
+
6388
+ let currentObject = liveGetPrototypeOf(foreignTargetPointer);
6389
+
6390
+ while (currentObject) {
6391
+ if (ReflectApply(ObjectProtoHasOwnProperty, currentObject, [key])) {
6392
+ return true;
6060
6393
  }
6061
- function getTransferableValue(value) {
6062
- // internationally ignoring the case of (typeof document.all === 'undefined') because
6063
- // in the reserve membrane, you never get one of those exotic objects
6064
- if (typeof value === 'undefined') {
6065
- return undefined;
6066
- }
6067
- // TODO: what other ways to optimize this method?
6068
- if (value === null || (typeof value !== 'function' && typeof value !== 'object')) {
6069
- return value;
6070
- }
6071
- return getTransferablePointer(value);
6394
+
6395
+ currentObject = ReflectGetPrototypeOf(currentObject);
6396
+ }
6397
+
6398
+ return false;
6399
+ }
6400
+
6401
+ function liveIsExtensible(foreignTargetPointer, shadowTarget) {
6402
+ // check if already locked
6403
+ if (ReflectIsExtensible(shadowTarget)) {
6404
+ if (foreignCallableIsExtensible(foreignTargetPointer)) {
6405
+ return true;
6072
6406
  }
6073
- // This wrapping mechanism provides the means to add instrumentation
6074
- // to the callable functions used to coordinate work between the sides
6075
- // of the membrane.
6076
- // TODO: do we need to pass more info into instrumentation hooks?
6077
- // prettier-ignore
6078
- function instrumentCallableWrapper(fn, activityName, crossingDirection) {
6079
- if (instrumentation) {
6080
- return function instrumentedFn(...args) {
6081
- const activity = instrumentation.startActivity(activityName, {
6082
- crossingDirection
6083
- });
6084
- try {
6085
- return ReflectApply(fn, this, args);
6086
- }
6087
- catch (e) {
6088
- activity.error(e);
6089
- throw e;
6090
- }
6091
- finally {
6092
- activity.stop();
6093
- }
6094
- };
6095
- }
6096
- return fn;
6097
- }
6098
- /**
6099
- * An object is marked as a "live" object when it has a
6100
- * LOCKER_LIVE_MARKER_SYMBOL property. Live objects have their
6101
- * defineProperty, deleteProperty, preventExtensions, set, and
6102
- * setPrototypeOf proxy traps as "live" variations meaning that when
6103
- * mutation occurs instead of maintaining a separate object graph of
6104
- * changes the mutations are performed directly on the foreign target.
6105
- *
6106
- */
6107
- function isForeignTargetMarkedLive(foreignTargetPointer) {
6108
- return foreignCallableHasOwnProperty(foreignTargetPointer, LOCKER_LIVE_MARKER_SYMBOL);
6109
- }
6110
- /**
6111
- * An object is marked as a "magic" object when it has a
6112
- * LOCKER_MAGIC_MARKER_SYMBOL property. These objects have magical side
6113
- * effects when setting properties, which would be broken by a Define
6114
- * Property operation. For example, the `style` object of an HTMLElement
6115
- * in Safari <= 14. This marker is a signal to the membrane that it must
6116
- * use a Set operation, instead of a Define Property operation.
6117
- *
6118
- */
6119
- function isMarkedMagic(object) {
6120
- return (SUPPORT_MAGIC_MARKER &&
6121
- ReflectApply(ObjectProtoHasOwnProperty, object, [LOCKER_MAGIC_MARKER_SYMBOL]));
6122
- }
6123
- function liveDefineProperty(foreignTargetPointer, shadowTarget, key, unsafePartialDesc) {
6124
- const descMeta = getDescriptorMeta(unsafePartialDesc);
6125
- const result = foreignCallableDefineProperty(foreignTargetPointer, key, descMeta[0], // configurable
6126
- descMeta[1], // enumerable
6127
- descMeta[2], // writable
6128
- descMeta[3], // valuePointer
6129
- descMeta[4], // getPointer
6130
- descMeta[5] // setPointer
6131
- );
6132
- if (result) {
6133
- // Intentionally testing against false since it could be
6134
- // undefined as well
6135
- if (descMeta[0] /* configurable */ === false) {
6136
- foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6137
- ReflectDefineProperty(shadowTarget, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
6138
- });
6139
- }
6140
- }
6141
- return result;
6142
- }
6143
- function liveDeleteProperty(foreignTargetPointer, _shadowTarget, key) {
6144
- return foreignCallableDeleteProperty(foreignTargetPointer, key);
6407
+
6408
+ lockShadowTarget(shadowTarget, foreignTargetPointer);
6409
+ }
6410
+
6411
+ return false;
6412
+ }
6413
+
6414
+ function liveOwnKeys(foreignTargetPointer) {
6415
+ let keys;
6416
+ foreignCallableOwnKeys(foreignTargetPointer, function () {
6417
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
6418
+ args[_key4] = arguments[_key4];
6145
6419
  }
6146
- function liveGet(foreignTargetPointer, shadowTarget, key, receiver) {
6147
- const safeDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) ||
6148
- getInheritedPropertyDescriptor(foreignTargetPointer, key);
6149
- if (safeDesc) {
6150
- const { get: getter, value: localValue } = safeDesc;
6151
- if (getter) {
6152
- // Even though the getter function exists, we can't use
6153
- // `ReflectGet` because there might be a distortion for
6154
- // that getter function, in which case we must resolve
6155
- // the local getter and call it instead.
6156
- return ReflectApply(getter, receiver, []);
6157
- }
6158
- return localValue;
6159
- }
6160
- if (key === TO_STRING_TAG_SYMBOL) {
6161
- return foreignCallableGetUnbrandedTag(foreignTargetPointer);
6162
- }
6163
- return undefined;
6420
+
6421
+ keys = args;
6422
+ }); // @ts-ignore: Prevent used before assignment error.
6423
+
6424
+ return keys || [];
6425
+ }
6426
+
6427
+ function livePreventExtensions(foreignTargetPointer, shadowTarget) {
6428
+ if (ReflectIsExtensible(shadowTarget)) {
6429
+ if (!foreignCallablePreventExtensions(foreignTargetPointer)) {
6430
+ // if the target is a proxy manually created, it might
6431
+ // reject the preventExtension call, in which case we
6432
+ // should not attempt to lock down the shadow target.
6433
+ if (!foreignCallableIsExtensible(foreignTargetPointer)) {
6434
+ lockShadowTarget(shadowTarget, foreignTargetPointer);
6435
+ }
6436
+
6437
+ return false;
6164
6438
  }
6165
- function liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key) {
6166
- let safeDesc;
6167
- foreignCallableGetOwnPropertyDescriptor(foreignTargetPointer, key, (configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6168
- safeDesc = createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer);
6169
- if (safeDesc.configurable === false) {
6170
- // updating the descriptor to non-configurable on the shadow
6171
- ReflectDefineProperty(shadowTarget, key, safeDesc);
6172
- }
6173
- });
6174
- return safeDesc;
6439
+
6440
+ lockShadowTarget(shadowTarget, foreignTargetPointer);
6441
+ }
6442
+
6443
+ return true;
6444
+ }
6445
+
6446
+ function liveSet(foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath) {
6447
+ // Following the specification steps for
6448
+ // OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ).
6449
+ // https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
6450
+ const safeOwnDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key);
6451
+ const safeDesc = safeOwnDesc || getInheritedPropertyDescriptor(foreignTargetPointer, key);
6452
+
6453
+ if (safeDesc) {
6454
+ if ('get' in safeDesc || 'set' in safeDesc) {
6455
+ const {
6456
+ set: setter
6457
+ } = safeDesc;
6458
+
6459
+ if (setter) {
6460
+ // Even though the setter function exists, we can't use
6461
+ // `ReflectSet` because there might be a distortion for
6462
+ // that setter function, in which case we must resolve
6463
+ // the local setter and call it instead.
6464
+ ReflectApply(setter, receiver, [value]); // If there is a setter, it either throw or we can assume
6465
+ // the value was set.
6466
+
6467
+ return true;
6468
+ }
6469
+
6470
+ return false;
6175
6471
  }
6176
- function liveGetPrototypeOf(foreignTargetPointer) {
6177
- return getLocalValue(foreignCallableGetPrototypeOf(foreignTargetPointer));
6472
+
6473
+ if (safeDesc.writable === false) {
6474
+ return false;
6178
6475
  }
6179
- function liveHas(foreignTargetPointer, key) {
6180
- if (foreignCallableHasOwnProperty(foreignTargetPointer, key)) {
6181
- return true;
6182
- }
6183
- // avoiding calling the has trap for any proto chain operation,
6184
- // instead we implement the regular logic here in this trap.
6185
- let currentObject = liveGetPrototypeOf(foreignTargetPointer);
6186
- while (currentObject) {
6187
- if (ReflectApply(ObjectProtoHasOwnProperty, currentObject, [key])) {
6188
- return true;
6189
- }
6190
- currentObject = ReflectGetPrototypeOf(currentObject);
6191
- }
6192
- return false;
6476
+ }
6477
+
6478
+ let safeReceiverDesc;
6479
+
6480
+ if (useFastPath) {
6481
+ // In the fast path we know the receiver is the proxy.
6482
+ safeReceiverDesc = safeOwnDesc;
6483
+ } else {
6484
+ // Exit early if receiver is not object like.
6485
+ if (receiver === null || typeof receiver !== 'function' && typeof receiver !== 'object') {
6486
+ return false;
6193
6487
  }
6194
- function liveIsExtensible(foreignTargetPointer, shadowTarget) {
6195
- // check if already locked
6196
- if (ReflectIsExtensible(shadowTarget)) {
6197
- if (foreignCallableIsExtensible(foreignTargetPointer)) {
6198
- return true;
6199
- }
6200
- lockShadowTarget(shadowTarget, foreignTargetPointer);
6201
- }
6202
- return false;
6488
+
6489
+ const unsafeReceiverDesc = ReflectGetOwnPropertyDescriptor(receiver, key);
6490
+
6491
+ if (unsafeReceiverDesc) {
6492
+ safeReceiverDesc = toSafeDescriptor(unsafeReceiverDesc);
6203
6493
  }
6204
- function liveOwnKeys(foreignTargetPointer) {
6205
- let keys;
6206
- foreignCallableOwnKeys(foreignTargetPointer, (...args) => {
6207
- keys = args;
6208
- });
6209
- // @ts-ignore: Prevent used before assignment error.
6210
- return keys || [];
6494
+ }
6495
+
6496
+ if (safeReceiverDesc) {
6497
+ // Exit early for accessor descriptors or non-writable data
6498
+ // descriptors.
6499
+ if ('get' in safeReceiverDesc || 'set' in safeReceiverDesc || safeReceiverDesc.writable === false) {
6500
+ return false;
6211
6501
  }
6212
- function livePreventExtensions(foreignTargetPointer, shadowTarget) {
6213
- if (ReflectIsExtensible(shadowTarget)) {
6214
- if (!foreignCallablePreventExtensions(foreignTargetPointer)) {
6215
- // if the target is a proxy manually created, it might
6216
- // reject the preventExtension call, in which case we
6217
- // should not attempt to lock down the shadow target.
6218
- if (!foreignCallableIsExtensible(foreignTargetPointer)) {
6219
- lockShadowTarget(shadowTarget, foreignTargetPointer);
6220
- }
6221
- return false;
6222
- }
6223
- lockShadowTarget(shadowTarget, foreignTargetPointer);
6224
- }
6225
- return true;
6502
+
6503
+ if (isMarkedMagic(receiver)) {
6504
+ // Workaround for Safari <= 14 bug on CSSStyleDeclaration
6505
+ // objects which lose their magic setters if set with
6506
+ // defineProperty.
6507
+ foreignCallableSet(foreignTargetPointer, key, getTransferableValue(value), getTransferablePointer(receiver));
6508
+ } else {
6509
+ // Setting the descriptor with only a value entry should not
6510
+ // affect existing descriptor traits.
6511
+ ReflectDefineProperty(receiver, key, {
6512
+ // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6513
+ __proto__: null,
6514
+ value
6515
+ });
6226
6516
  }
6227
- function liveSet(foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath) {
6228
- // Following the specification steps for
6229
- // OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ).
6230
- // https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
6231
- const safeOwnDesc = liveGetOwnPropertyDescriptor(foreignTargetPointer, shadowTarget, key);
6232
- const safeDesc = safeOwnDesc || getInheritedPropertyDescriptor(foreignTargetPointer, key);
6233
- if (safeDesc) {
6234
- if ('get' in safeDesc || 'set' in safeDesc) {
6235
- const { set: setter } = safeDesc;
6236
- if (setter) {
6237
- // Even though the setter function exists, we can't use
6238
- // `ReflectSet` because there might be a distortion for
6239
- // that setter function, in which case we must resolve
6240
- // the local setter and call it instead.
6241
- ReflectApply(setter, receiver, [value]);
6242
- // If there is a setter, it either throw or we can assume
6243
- // the value was set.
6244
- return true;
6245
- }
6246
- return false;
6247
- }
6248
- if (safeDesc.writable === false) {
6249
- return false;
6250
- }
6251
- }
6252
- let safeReceiverDesc;
6253
- if (useFastPath) {
6254
- // In the fast path we know the receiver is the proxy.
6255
- safeReceiverDesc = safeOwnDesc;
6256
- }
6257
- else {
6258
- // Exit early if receiver is not object like.
6259
- if (receiver === null ||
6260
- (typeof receiver !== 'function' && typeof receiver !== 'object')) {
6261
- return false;
6262
- }
6263
- const unsafeReceiverDesc = ReflectGetOwnPropertyDescriptor(receiver, key);
6264
- if (unsafeReceiverDesc) {
6265
- safeReceiverDesc = toSafeDescriptor(unsafeReceiverDesc);
6266
- }
6517
+
6518
+ return true;
6519
+ } // `ReflectDefineProperty` and `ReflectSet` both are expected to
6520
+ // return `false` when attempting to add a new property if the
6521
+ // receiver is not extensible.
6522
+
6523
+
6524
+ return ReflectDefineProperty(receiver, key, {
6525
+ // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6526
+ __proto__: null,
6527
+ configurable: true,
6528
+ enumerable: true,
6529
+ value,
6530
+ writable: true
6531
+ });
6532
+ }
6533
+
6534
+ function liveSetPrototypeOf(foreignTargetPointer, proto) {
6535
+ const transferableProto = getTransferableValue(proto);
6536
+ return foreignCallableSetPrototypeOf(foreignTargetPointer, transferableProto);
6537
+ }
6538
+
6539
+ function lockShadowTarget(shadowTarget, foreignTargetPointer) {
6540
+ copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer); // setting up __proto__ of the shadowTarget
6541
+
6542
+ const proto = liveGetPrototypeOf(foreignTargetPointer);
6543
+ ReflectSetPrototypeOf(shadowTarget, proto); // locking down the extensibility of shadowTarget
6544
+
6545
+ ReflectPreventExtensions(shadowTarget);
6546
+ }
6547
+
6548
+ function pushErrorAcrossBoundary(e) {
6549
+ const transferableError = getTransferableValue(e);
6550
+
6551
+ if (typeof transferableError === 'function') {
6552
+ transferableError();
6553
+ }
6554
+
6555
+ return e;
6556
+ }
6557
+
6558
+ function toSafeDescriptor(desc) {
6559
+ ReflectSetPrototypeOf(desc, null);
6560
+ return desc;
6561
+ }
6562
+
6563
+ class BoundaryProxyHandler {
6564
+ constructor(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) {
6565
+ // the purpose of this public field is to help developers to identify
6566
+ // what side of the membrane they are debugging.
6567
+ this.color = color; // apply trap is generic, and should never change independently of the type of membrane
6568
+
6569
+ this.apply = function applyTrap(_shadowTarget, thisArg, args) {
6570
+ const {
6571
+ foreignTargetPointer
6572
+ } = this;
6573
+ const transferableThisArg = getTransferableValue(thisArg);
6574
+ const combinedArgs = [foreignTargetPointer, transferableThisArg];
6575
+ const {
6576
+ length: argsLen
6577
+ } = args;
6578
+ const {
6579
+ length: combinedOffset
6580
+ } = combinedArgs;
6581
+ combinedArgs.length += argsLen;
6582
+
6583
+ for (let i = 0, len = argsLen; i < len; i += 1) {
6584
+ const arg = args[i];
6585
+ const combinedIndex = i + combinedOffset; // Inlining `getTransferableValue`.
6586
+
6587
+ if (typeof arg === 'undefined') {
6588
+ combinedArgs[combinedIndex] = undefined;
6589
+ } else if (arg === null || typeof arg !== 'function' && typeof arg !== 'object') {
6590
+ combinedArgs[combinedIndex] = arg;
6591
+ } else {
6592
+ combinedArgs[combinedIndex] = getTransferablePointer(arg);
6267
6593
  }
6268
- if (safeReceiverDesc) {
6269
- // Exit early for accessor descriptors or non-writable data
6270
- // descriptors.
6271
- if ('get' in safeReceiverDesc ||
6272
- 'set' in safeReceiverDesc ||
6273
- safeReceiverDesc.writable === false) {
6274
- return false;
6275
- }
6276
- if (isMarkedMagic(receiver)) {
6277
- // Workaround for Safari <= 14 bug on CSSStyleDeclaration
6278
- // objects which lose their magic setters if set with
6279
- // defineProperty.
6280
- foreignCallableSet(foreignTargetPointer, key, getTransferableValue(value), getTransferablePointer(receiver));
6281
- }
6282
- else {
6283
- // Setting the descriptor with only a value entry should not
6284
- // affect existing descriptor traits.
6285
- ReflectDefineProperty(receiver, key, {
6286
- // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6287
- __proto__: null,
6288
- value,
6289
- });
6290
- }
6291
- return true;
6594
+ }
6595
+
6596
+ return getLocalValue(ReflectApply(foreignCallableApply, undefined, combinedArgs));
6597
+ }; // construct trap is generic, and should never change independently
6598
+ // of the type of membrane
6599
+
6600
+
6601
+ this.construct = function constructTrap(_shadowTarget, args, newTarget) {
6602
+ if (newTarget === undefined) {
6603
+ throw new TypeErrorCtor();
6604
+ }
6605
+
6606
+ const {
6607
+ foreignTargetPointer
6608
+ } = this;
6609
+ const transferableNewTarget = getTransferableValue(newTarget);
6610
+ const combinedArgs = [foreignTargetPointer, transferableNewTarget];
6611
+ const {
6612
+ length: argsLen
6613
+ } = args;
6614
+ const {
6615
+ length: combinedOffset
6616
+ } = combinedArgs;
6617
+ combinedArgs.length += argsLen;
6618
+
6619
+ for (let i = 0, len = argsLen; i < len; i += 1) {
6620
+ const arg = args[i];
6621
+ const combinedIndex = i + combinedOffset; // Inline `getTransferableValue`.
6622
+
6623
+ if (typeof arg === 'undefined') {
6624
+ combinedArgs[combinedIndex] = undefined;
6625
+ } else if (arg === null || typeof arg !== 'function' && typeof arg !== 'object') {
6626
+ combinedArgs[combinedIndex] = arg;
6627
+ } else {
6628
+ combinedArgs[combinedIndex] = getTransferablePointer(arg);
6292
6629
  }
6293
- // `ReflectDefineProperty` and `ReflectSet` both are expected to
6294
- // return `false` when attempting to add a new property if the
6295
- // receiver is not extensible.
6296
- return ReflectDefineProperty(receiver, key, {
6297
- // @ts-ignore: TS doesn't like __proto__ on property descriptors.
6298
- __proto__: null,
6299
- configurable: true,
6300
- enumerable: true,
6301
- value,
6302
- writable: true,
6303
- });
6304
- }
6305
- function liveSetPrototypeOf(foreignTargetPointer, proto) {
6306
- const transferableProto = getTransferableValue(proto);
6307
- return foreignCallableSetPrototypeOf(foreignTargetPointer, transferableProto);
6308
- }
6309
- function lockShadowTarget(shadowTarget, foreignTargetPointer) {
6310
- copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer);
6311
- // setting up __proto__ of the shadowTarget
6312
- const proto = liveGetPrototypeOf(foreignTargetPointer);
6313
- ReflectSetPrototypeOf(shadowTarget, proto);
6314
- // locking down the extensibility of shadowTarget
6315
- ReflectPreventExtensions(shadowTarget);
6630
+ }
6631
+
6632
+ return getLocalValue(ReflectApply(foreignCallableConstruct, undefined, combinedArgs));
6633
+ };
6634
+
6635
+ const shadowTarget = createShadowTarget(foreignTargetTraits, foreignTargetFunctionName);
6636
+ const {
6637
+ proxy,
6638
+ revoke
6639
+ } = ProxyRevocable(shadowTarget, this);
6640
+ this.foreignTargetPointer = foreignTargetPointer;
6641
+ this.proxy = proxy;
6642
+ this.revoke = revoke; // inserting default traps
6643
+
6644
+ this.defineProperty = BoundaryProxyHandler.defaultDefinePropertyTrap;
6645
+ this.deleteProperty = BoundaryProxyHandler.defaultDeletePropertyTrap;
6646
+ this.isExtensible = BoundaryProxyHandler.defaultIsExtensibleTrap;
6647
+ this.getOwnPropertyDescriptor = BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap;
6648
+ this.getPrototypeOf = BoundaryProxyHandler.defaultGetPrototypeOfTrap;
6649
+ this.get = BoundaryProxyHandler.defaultGetTrap;
6650
+ this.has = BoundaryProxyHandler.defaultHasTrap;
6651
+ this.ownKeys = BoundaryProxyHandler.defaultOwnKeysTrap;
6652
+ this.preventExtensions = BoundaryProxyHandler.defaultPreventExtensionsTrap;
6653
+ this.setPrototypeOf = BoundaryProxyHandler.defaultSetPrototypeOfTrap;
6654
+ this.set = BoundaryProxyHandler.defaultSetTrap;
6655
+
6656
+ if (foreignTargetTraits & TargetTraits.Revoked) {
6657
+ revoke();
6316
6658
  }
6317
- function pushErrorAcrossBoundary(e) {
6318
- const transferableError = getTransferableValue(e);
6319
- if (typeof transferableError === 'function') {
6320
- transferableError();
6321
- }
6322
- return e;
6659
+
6660
+ if (!trapMutations) {
6661
+ // if local mutations are not trapped, then freezing the handler is ok
6662
+ // because it is not expecting to change in the future.
6663
+ // future optimization: hoping that proxies with frozen handlers can be faster
6664
+ ObjectFreeze(this);
6323
6665
  }
6324
- function toSafeDescriptor(desc) {
6325
- ReflectSetPrototypeOf(desc, null);
6326
- return desc;
6666
+ } // internal utilities
6667
+
6668
+
6669
+ makeProxyLive() {
6670
+ // assert: trapMutations must be true
6671
+ // replacing pending traps with live traps that can work with
6672
+ // the target without taking snapshots.
6673
+ this.defineProperty = BoundaryProxyHandler.liveDefinePropertyTrap;
6674
+ this.deleteProperty = BoundaryProxyHandler.liveDeletePropertyTrap;
6675
+ this.preventExtensions = BoundaryProxyHandler.livePreventExtensionsTrap;
6676
+ this.set = BoundaryProxyHandler.liveSetTrap;
6677
+ this.setPrototypeOf = BoundaryProxyHandler.liveSetPrototypeOfTrap; // future optimization: hoping that proxies with frozen handlers can be faster
6678
+
6679
+ ObjectFreeze(this);
6680
+ }
6681
+
6682
+ makeProxyStatic(shadowTarget) {
6683
+ // assert: trapMutations must be true
6684
+ const {
6685
+ foreignTargetPointer
6686
+ } = this;
6687
+ const targetIntegrityTraits = foreignCallableGetTargetIntegrityTraits(foreignTargetPointer);
6688
+
6689
+ if (targetIntegrityTraits & TargetIntegrityTraits.Revoked) {
6690
+ // the target is a revoked proxy, in which case we revoke
6691
+ // this proxy as well.
6692
+ this.revoke();
6693
+ return;
6694
+ } // adjusting the proto chain of the shadowTarget
6695
+
6696
+
6697
+ try {
6698
+ // a proxy that revoke itself when the __proto__ is accessed
6699
+ // can break the membrane, therefore we need protection
6700
+ const proto = liveGetPrototypeOf(foreignTargetPointer);
6701
+ ReflectSetPrototypeOf(shadowTarget, proto);
6702
+ } catch (_unused5) {
6703
+ // TODO: is revoke the right action here? maybe just setting
6704
+ // proto to null instead?
6705
+ this.revoke();
6706
+ return;
6707
+ } // defining own descriptors
6708
+
6709
+
6710
+ copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer); // preserving the semantics of the object
6711
+
6712
+ if (targetIntegrityTraits & TargetIntegrityTraits.IsFrozen) {
6713
+ ObjectFreeze(shadowTarget);
6714
+ } else if (targetIntegrityTraits & TargetIntegrityTraits.IsSealed) {
6715
+ ObjectSeal(shadowTarget);
6716
+ } else if (targetIntegrityTraits & TargetIntegrityTraits.IsNotExtensible) {
6717
+ ReflectPreventExtensions(shadowTarget);
6718
+ } // resetting all traps except apply and construct for static
6719
+ // proxies since the proxy target is the shadow target and all
6720
+ // operations are going to be applied to it rather than the real
6721
+ // target.
6722
+
6723
+
6724
+ this.defineProperty = BoundaryProxyHandler.staticDefinePropertyTrap;
6725
+ this.deleteProperty = BoundaryProxyHandler.staticDeletePropertyTrap;
6726
+ this.get = BoundaryProxyHandler.staticGetTrap;
6727
+ this.getOwnPropertyDescriptor = BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap;
6728
+ this.getPrototypeOf = BoundaryProxyHandler.staticGetPrototypeOfTrap;
6729
+ this.has = BoundaryProxyHandler.staticHasTrap;
6730
+ this.isExtensible = BoundaryProxyHandler.staticIsExtensibleTrap;
6731
+ this.ownKeys = BoundaryProxyHandler.staticOwnKeysTrap;
6732
+ this.preventExtensions = BoundaryProxyHandler.staticPreventExtensionsTrap;
6733
+ this.set = BoundaryProxyHandler.staticSetTrap;
6734
+ this.setPrototypeOf = BoundaryProxyHandler.staticSetPrototypeOfTrap; // future optimization: hoping that proxies with frozen handlers can be faster
6735
+
6736
+ ObjectFreeze(this);
6737
+ }
6738
+
6739
+ makeProxyUnambiguous(shadowTarget) {
6740
+ // assert: trapMutations must be true
6741
+ if (isForeignTargetMarkedLive(this.foreignTargetPointer)) {
6742
+ this.makeProxyLive();
6743
+ } else {
6744
+ this.makeProxyStatic(shadowTarget);
6327
6745
  }
6328
- class BoundaryProxyHandler {
6329
- constructor(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) {
6330
- // the purpose of this public field is to help developers to identify
6331
- // what side of the membrane they are debugging.
6332
- this.color = color;
6333
- // apply trap is generic, and should never change independently of the type of membrane
6334
- this.apply = function applyTrap(_shadowTarget, thisArg, args) {
6335
- const { foreignTargetPointer } = this;
6336
- const transferableThisArg = getTransferableValue(thisArg);
6337
- const combinedArgs = [foreignTargetPointer, transferableThisArg];
6338
- const { length: argsLen } = args;
6339
- const { length: combinedOffset } = combinedArgs;
6340
- combinedArgs.length += argsLen;
6341
- for (let i = 0, len = argsLen; i < len; i += 1) {
6342
- combinedArgs[i + combinedOffset] = getTransferableValue(args[i]);
6343
- }
6344
- return getLocalValue(ReflectApply(foreignCallableApply, undefined, combinedArgs));
6345
- };
6346
- // construct trap is generic, and should never change independently
6347
- // of the type of membrane
6348
- this.construct = function constructTrap(_shadowTarget, args, newTarget) {
6349
- if (newTarget === undefined) {
6350
- throw new TypeErrorCtor();
6351
- }
6352
- const { foreignTargetPointer } = this;
6353
- const transferableNewTarget = getTransferableValue(newTarget);
6354
- const combinedArgs = [foreignTargetPointer, transferableNewTarget];
6355
- const { length: argsLen } = args;
6356
- const { length: combinedOffset } = combinedArgs;
6357
- combinedArgs.length += argsLen;
6358
- for (let i = 0, len = argsLen; i < len; i += 1) {
6359
- combinedArgs[i + combinedOffset] = getTransferableValue(args[i]);
6360
- }
6361
- return getLocalValue(ReflectApply(foreignCallableConstruct, undefined, combinedArgs));
6362
- };
6363
- const shadowTarget = createShadowTarget(foreignTargetTraits, foreignTargetFunctionName);
6364
- const { proxy, revoke } = ProxyRevocable(shadowTarget, this);
6365
- this.foreignTargetPointer = foreignTargetPointer;
6366
- this.proxy = proxy;
6367
- this.revoke = revoke;
6368
- // inserting default traps
6369
- this.defineProperty = BoundaryProxyHandler.defaultDefinePropertyTrap;
6370
- this.deleteProperty = BoundaryProxyHandler.defaultDeletePropertyTrap;
6371
- this.isExtensible = BoundaryProxyHandler.defaultIsExtensibleTrap;
6372
- this.getOwnPropertyDescriptor =
6373
- BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap;
6374
- this.getPrototypeOf = BoundaryProxyHandler.defaultGetPrototypeOfTrap;
6375
- this.get = BoundaryProxyHandler.defaultGetTrap;
6376
- this.has = BoundaryProxyHandler.defaultHasTrap;
6377
- this.ownKeys = BoundaryProxyHandler.defaultOwnKeysTrap;
6378
- this.preventExtensions = BoundaryProxyHandler.defaultPreventExtensionsTrap;
6379
- this.setPrototypeOf = BoundaryProxyHandler.defaultSetPrototypeOfTrap;
6380
- this.set = BoundaryProxyHandler.defaultSetTrap;
6381
- if (foreignTargetTraits & TargetTraits.Revoked) {
6382
- revoke();
6383
- }
6384
- if (!trapMutations) {
6385
- // if local mutations are not trapped, then freezing the handler is ok
6386
- // because it is not expecting to change in the future.
6387
- // future optimization: hoping that proxies with frozen handlers can be faster
6388
- ObjectFreeze(this);
6389
- }
6390
- }
6391
- // internal utilities
6392
- makeProxyLive() {
6393
- // assert: trapMutations must be true
6394
- // replacing pending traps with live traps that can work with
6395
- // the target without taking snapshots.
6396
- this.defineProperty = BoundaryProxyHandler.liveDefinePropertyTrap;
6397
- this.deleteProperty = BoundaryProxyHandler.liveDeletePropertyTrap;
6398
- this.preventExtensions = BoundaryProxyHandler.livePreventExtensionsTrap;
6399
- this.set = BoundaryProxyHandler.liveSetTrap;
6400
- this.setPrototypeOf = BoundaryProxyHandler.liveSetPrototypeOfTrap;
6401
- // future optimization: hoping that proxies with frozen handlers can be faster
6402
- ObjectFreeze(this);
6403
- }
6404
- makeProxyStatic(shadowTarget) {
6405
- // assert: trapMutations must be true
6406
- const { foreignTargetPointer } = this;
6407
- const targetIntegrityTraits = foreignCallableGetTargetIntegrityTraits(foreignTargetPointer);
6408
- if (targetIntegrityTraits & TargetIntegrityTraits.Revoked) {
6409
- // the target is a revoked proxy, in which case we revoke
6410
- // this proxy as well.
6411
- this.revoke();
6412
- return;
6413
- }
6414
- // adjusting the proto chain of the shadowTarget
6415
- try {
6416
- // a proxy that revoke itself when the __proto__ is accessed
6417
- // can break the membrane, therefore we need protection
6418
- const proto = liveGetPrototypeOf(foreignTargetPointer);
6419
- ReflectSetPrototypeOf(shadowTarget, proto);
6420
- }
6421
- catch {
6422
- // TODO: is revoke the right action here? maybe just setting
6423
- // proto to null instead?
6424
- this.revoke();
6425
- return;
6426
- }
6427
- // defining own descriptors
6428
- copyForeignDescriptorsIntoShadowTarget(shadowTarget, foreignTargetPointer);
6429
- // preserving the semantics of the object
6430
- if (targetIntegrityTraits & TargetIntegrityTraits.IsFrozen) {
6431
- ObjectFreeze(shadowTarget);
6432
- }
6433
- else if (targetIntegrityTraits & TargetIntegrityTraits.IsSealed) {
6434
- ObjectSeal(shadowTarget);
6435
- }
6436
- else if (targetIntegrityTraits & TargetIntegrityTraits.IsNotExtensible) {
6437
- ReflectPreventExtensions(shadowTarget);
6438
- }
6439
- // resetting all traps except apply and construct for static
6440
- // proxies since the proxy target is the shadow target and all
6441
- // operations are going to be applied to it rather than the real
6442
- // target.
6443
- this.defineProperty = BoundaryProxyHandler.staticDefinePropertyTrap;
6444
- this.deleteProperty = BoundaryProxyHandler.staticDeletePropertyTrap;
6445
- this.get = BoundaryProxyHandler.staticGetTrap;
6446
- this.getOwnPropertyDescriptor =
6447
- BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap;
6448
- this.getPrototypeOf = BoundaryProxyHandler.staticGetPrototypeOfTrap;
6449
- this.has = BoundaryProxyHandler.staticHasTrap;
6450
- this.isExtensible = BoundaryProxyHandler.staticIsExtensibleTrap;
6451
- this.ownKeys = BoundaryProxyHandler.staticOwnKeysTrap;
6452
- this.preventExtensions = BoundaryProxyHandler.staticPreventExtensionsTrap;
6453
- this.set = BoundaryProxyHandler.staticSetTrap;
6454
- this.setPrototypeOf = BoundaryProxyHandler.staticSetPrototypeOfTrap;
6455
- // future optimization: hoping that proxies with frozen handlers can be faster
6456
- ObjectFreeze(this);
6457
- }
6458
- makeProxyUnambiguous(shadowTarget) {
6459
- // assert: trapMutations must be true
6460
- if (isForeignTargetMarkedLive(this.foreignTargetPointer)) {
6461
- this.makeProxyLive();
6462
- }
6463
- else {
6464
- this.makeProxyStatic(shadowTarget);
6465
- }
6466
- }
6467
- // logic implementation of all traps
6468
- // live traps:
6469
- /**
6470
- * Traps with proto chain traversal capabilities are the exception of
6471
- * the rules here, the problem is that the other side might or might
6472
- * not have:
6473
- * a) local mutations only
6474
- * b) distortions
6475
- *
6476
- * Therefore, the logic has to be bound to the caller, the one
6477
- * initiating the across membrane access.
6478
- */
6479
- static liveDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6480
- return liveDefineProperty(this.foreignTargetPointer, shadowTarget, key, unsafePartialDesc);
6481
- }
6482
- static liveDeletePropertyTrap(shadowTarget, key) {
6483
- return liveDeleteProperty(this.foreignTargetPointer, shadowTarget, key);
6484
- }
6485
- static liveGetOwnPropertyDescriptorTrap(shadowTarget, key) {
6486
- return liveGetOwnPropertyDescriptor(this.foreignTargetPointer, shadowTarget, key);
6487
- }
6488
- static liveGetPrototypeOfTrap(_shadowTarget) {
6489
- return liveGetPrototypeOf(this.foreignTargetPointer);
6490
- }
6491
- /**
6492
- * This trap cannot just use `ReflectGet` directly on the `target`
6493
- * because the red object graph might have mutations that are only
6494
- * visible on the red side, which means looking into `target` directly
6495
- * is not viable. Instead, we need to implement a more crafty solution
6496
- * that looks into target's own properties, or in the red proto chain
6497
- * when needed.
6498
- *
6499
- * In a transparent membrane, this method will have been a lot simpler, like:
6500
- *
6501
- * const { foreignTargetPointer } = this;
6502
- * const receiverPointer = getValueOrPointer(receiver);
6503
- * const foreignValueOrCallable =
6504
- * foreignCallableGet(foreignTargetPointer, key, receiverPointer);
6505
- * return getLocalValue(foreignValueOrCallable);
6506
- *
6507
- */
6508
- static liveGetTrap(shadowTarget, key, receiver) {
6509
- // assert: trapMutations must be true
6510
- return liveGet(this.foreignTargetPointer, shadowTarget, key, receiver);
6511
- }
6512
- /**
6513
- * This trap cannot just use `Reflect.has` or the `in` operator
6514
- * directly because the red object graph might have mutations that
6515
- * are only visible on the red side, which means looking into `target`
6516
- * directly is not viable. Instead, we need to implement a more crafty
6517
- * solution that looks into target's own properties, or in the red
6518
- * proto chain when needed.
6519
- *
6520
- * In a transparent membrane, this method will have been a lot
6521
- * simpler, like:
6522
- *
6523
- * const { foreignTargetPointer } = this;
6524
- * return foreignCallableHas(foreignTargetPointer, key);
6525
- *
6526
- */
6527
- static liveHasTrap(_shadowTarget, key) {
6528
- // assert: trapMutations must be true
6529
- return liveHas(this.foreignTargetPointer, key);
6530
- }
6531
- static liveIsExtensibleTrap(shadowTarget) {
6532
- return liveIsExtensible(this.foreignTargetPointer, shadowTarget);
6533
- }
6534
- static liveOwnKeysTrap(_shadowTarget) {
6535
- return liveOwnKeys(this.foreignTargetPointer);
6536
- }
6537
- static livePreventExtensionsTrap(shadowTarget) {
6538
- return livePreventExtensions(this.foreignTargetPointer, shadowTarget);
6539
- }
6540
- static liveSetPrototypeOfTrap(_shadowTarget, proto) {
6541
- return liveSetPrototypeOf(this.foreignTargetPointer, proto);
6542
- }
6543
- /**
6544
- * This trap cannot just use `ReflectSet` directly on the `target` because
6545
- * the red object graph might have mutations that are only visible on the red side,
6546
- * which means looking into `target` directly is not viable. Instead, we need to
6547
- * implement a more crafty solution that looks into target's own properties, or
6548
- * in the red proto chain when needed.
6549
- *
6550
- * const { foreignTargetPointer } = this;
6551
- * const valuePointer = getValueOrPointer(value);
6552
- * const receiverPointer = getValueOrPointer(receiver);
6553
- * return foreignCallableSet(foreignTargetPointer, key, valuePointer, receiverPointer);
6554
- *
6555
- */
6556
- static liveSetTrap(shadowTarget, key, value, receiver) {
6557
- // assert: trapMutations must be true
6558
- const useFastPath = this.proxy === receiver;
6559
- return liveSet(this.foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath);
6560
- }
6561
- // pending traps
6562
- static pendingDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6563
- // assert: trapMutations must be true
6564
- this.makeProxyUnambiguous(shadowTarget);
6565
- return this.defineProperty(shadowTarget, key, unsafePartialDesc);
6566
- }
6567
- static pendingDeletePropertyTrap(shadowTarget, key) {
6568
- // assert: trapMutations must be true
6569
- this.makeProxyUnambiguous(shadowTarget);
6570
- return this.deleteProperty(shadowTarget, key);
6571
- }
6572
- static pendingPreventExtensionsTrap(shadowTarget) {
6573
- // assert: trapMutations must be true
6574
- this.makeProxyUnambiguous(shadowTarget);
6575
- return this.preventExtensions(shadowTarget);
6576
- }
6577
- static pendingSetPrototypeOfTrap(shadowTarget, proto) {
6578
- // assert: trapMutations must be true
6579
- this.makeProxyUnambiguous(shadowTarget);
6580
- return this.setPrototypeOf(shadowTarget, proto);
6581
- }
6582
- static pendingSetTrap(shadowTarget, key, value, receiver) {
6583
- // assert: trapMutations must be true
6584
- this.makeProxyUnambiguous(shadowTarget);
6585
- return this.set(shadowTarget, key, value, receiver);
6586
- }
6587
- /**
6588
- * This trap is just `ReflectGet` plus handling of object branding
6589
- * for proxies.
6590
- *
6591
- */
6592
- static staticGetTrap(shadowTarget, key, receiver) {
6593
- if (key === TO_STRING_TAG_SYMBOL) {
6594
- return foreignCallableGetUnbrandedTag(this.foreignTargetPointer);
6595
- }
6596
- return ReflectGet(shadowTarget, key, receiver);
6597
- }
6746
+ } // logic implementation of all traps
6747
+ // live traps:
6748
+
6749
+ /**
6750
+ * Traps with proto chain traversal capabilities are the exception of
6751
+ * the rules here, the problem is that the other side might or might
6752
+ * not have:
6753
+ * a) local mutations only
6754
+ * b) distortions
6755
+ *
6756
+ * Therefore, the logic has to be bound to the caller, the one
6757
+ * initiating the across membrane access.
6758
+ */
6759
+
6760
+
6761
+ static liveDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6762
+ return liveDefineProperty(this.foreignTargetPointer, shadowTarget, key, unsafePartialDesc);
6763
+ }
6764
+
6765
+ static liveDeletePropertyTrap(shadowTarget, key) {
6766
+ return liveDeleteProperty(this.foreignTargetPointer, shadowTarget, key);
6767
+ }
6768
+
6769
+ static liveGetOwnPropertyDescriptorTrap(shadowTarget, key) {
6770
+ return liveGetOwnPropertyDescriptor(this.foreignTargetPointer, shadowTarget, key);
6771
+ }
6772
+
6773
+ static liveGetPrototypeOfTrap(_shadowTarget) {
6774
+ return liveGetPrototypeOf(this.foreignTargetPointer);
6775
+ }
6776
+ /**
6777
+ * This trap cannot just use `ReflectGet` directly on the `target`
6778
+ * because the red object graph might have mutations that are only
6779
+ * visible on the red side, which means looking into `target` directly
6780
+ * is not viable. Instead, we need to implement a more crafty solution
6781
+ * that looks into target's own properties, or in the red proto chain
6782
+ * when needed.
6783
+ *
6784
+ * In a transparent membrane, this method will have been a lot simpler, like:
6785
+ *
6786
+ * const { foreignTargetPointer } = this;
6787
+ * const receiverPointer = getValueOrPointer(receiver);
6788
+ * const foreignValueOrCallable =
6789
+ * foreignCallableGet(foreignTargetPointer, key, receiverPointer);
6790
+ * return getLocalValue(foreignValueOrCallable);
6791
+ *
6792
+ */
6793
+
6794
+
6795
+ static liveGetTrap(shadowTarget, key, receiver) {
6796
+ // assert: trapMutations must be true
6797
+ return liveGet(this.foreignTargetPointer, shadowTarget, key, receiver);
6798
+ }
6799
+ /**
6800
+ * This trap cannot just use `Reflect.has` or the `in` operator
6801
+ * directly because the red object graph might have mutations that
6802
+ * are only visible on the red side, which means looking into `target`
6803
+ * directly is not viable. Instead, we need to implement a more crafty
6804
+ * solution that looks into target's own properties, or in the red
6805
+ * proto chain when needed.
6806
+ *
6807
+ * In a transparent membrane, this method will have been a lot
6808
+ * simpler, like:
6809
+ *
6810
+ * const { foreignTargetPointer } = this;
6811
+ * return foreignCallableHas(foreignTargetPointer, key);
6812
+ *
6813
+ */
6814
+
6815
+
6816
+ static liveHasTrap(_shadowTarget, key) {
6817
+ // assert: trapMutations must be true
6818
+ return liveHas(this.foreignTargetPointer, key);
6819
+ }
6820
+
6821
+ static liveIsExtensibleTrap(shadowTarget) {
6822
+ return liveIsExtensible(this.foreignTargetPointer, shadowTarget);
6823
+ }
6824
+
6825
+ static liveOwnKeysTrap(_shadowTarget) {
6826
+ return liveOwnKeys(this.foreignTargetPointer);
6827
+ }
6828
+
6829
+ static livePreventExtensionsTrap(shadowTarget) {
6830
+ return livePreventExtensions(this.foreignTargetPointer, shadowTarget);
6831
+ }
6832
+
6833
+ static liveSetPrototypeOfTrap(_shadowTarget, proto) {
6834
+ return liveSetPrototypeOf(this.foreignTargetPointer, proto);
6835
+ }
6836
+ /**
6837
+ * This trap cannot just use `ReflectSet` directly on the `target` because
6838
+ * the red object graph might have mutations that are only visible on the red side,
6839
+ * which means looking into `target` directly is not viable. Instead, we need to
6840
+ * implement a more crafty solution that looks into target's own properties, or
6841
+ * in the red proto chain when needed.
6842
+ *
6843
+ * const { foreignTargetPointer } = this;
6844
+ * const valuePointer = getValueOrPointer(value);
6845
+ * const receiverPointer = getValueOrPointer(receiver);
6846
+ * return foreignCallableSet(foreignTargetPointer, key, valuePointer, receiverPointer);
6847
+ *
6848
+ */
6849
+
6850
+
6851
+ static liveSetTrap(shadowTarget, key, value, receiver) {
6852
+ // assert: trapMutations must be true
6853
+ const useFastPath = this.proxy === receiver;
6854
+ return liveSet(this.foreignTargetPointer, shadowTarget, key, value, receiver, useFastPath);
6855
+ } // pending traps
6856
+
6857
+
6858
+ static pendingDefinePropertyTrap(shadowTarget, key, unsafePartialDesc) {
6859
+ // assert: trapMutations must be true
6860
+ this.makeProxyUnambiguous(shadowTarget);
6861
+ return this.defineProperty(shadowTarget, key, unsafePartialDesc);
6862
+ }
6863
+
6864
+ static pendingDeletePropertyTrap(shadowTarget, key) {
6865
+ // assert: trapMutations must be true
6866
+ this.makeProxyUnambiguous(shadowTarget);
6867
+ return this.deleteProperty(shadowTarget, key);
6868
+ }
6869
+
6870
+ static pendingPreventExtensionsTrap(shadowTarget) {
6871
+ // assert: trapMutations must be true
6872
+ this.makeProxyUnambiguous(shadowTarget);
6873
+ return this.preventExtensions(shadowTarget);
6874
+ }
6875
+
6876
+ static pendingSetPrototypeOfTrap(shadowTarget, proto) {
6877
+ // assert: trapMutations must be true
6878
+ this.makeProxyUnambiguous(shadowTarget);
6879
+ return this.setPrototypeOf(shadowTarget, proto);
6880
+ }
6881
+
6882
+ static pendingSetTrap(shadowTarget, key, value, receiver) {
6883
+ // assert: trapMutations must be true
6884
+ this.makeProxyUnambiguous(shadowTarget);
6885
+ return this.set(shadowTarget, key, value, receiver);
6886
+ }
6887
+ /**
6888
+ * This trap is just `ReflectGet` plus handling of object branding
6889
+ * for proxies.
6890
+ *
6891
+ */
6892
+
6893
+
6894
+ static staticGetTrap(shadowTarget, key, receiver) {
6895
+ if (key === TO_STRING_TAG_SYMBOL) {
6896
+ return foreignCallableGetUnbrandedTag(this.foreignTargetPointer);
6598
6897
  }
6599
- BoundaryProxyHandler.staticDefinePropertyTrap = ReflectDefineProperty;
6600
- BoundaryProxyHandler.staticDeletePropertyTrap = ReflectDeleteProperty;
6601
- BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap = ReflectGetOwnPropertyDescriptor;
6602
- BoundaryProxyHandler.staticGetPrototypeOfTrap = ReflectGetPrototypeOf;
6603
- BoundaryProxyHandler.staticHasTrap = ReflectHas;
6604
- BoundaryProxyHandler.staticIsExtensibleTrap = ReflectIsExtensible;
6605
- BoundaryProxyHandler.staticOwnKeysTrap = ReflectOwnKeys;
6606
- BoundaryProxyHandler.staticPreventExtensionsTrap = ReflectPreventExtensions;
6607
- BoundaryProxyHandler.staticSetTrap = ReflectSet;
6608
- BoundaryProxyHandler.staticSetPrototypeOfTrap = ReflectSetPrototypeOf;
6609
- // static default traps
6610
- // (optimization to avoid computations of the proper trap in constructor)
6611
- BoundaryProxyHandler.defaultGetTrap = BoundaryProxyHandler.liveGetTrap;
6612
- BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap = BoundaryProxyHandler.liveGetOwnPropertyDescriptorTrap;
6613
- BoundaryProxyHandler.defaultGetPrototypeOfTrap = BoundaryProxyHandler.liveGetPrototypeOfTrap;
6614
- BoundaryProxyHandler.defaultHasTrap = BoundaryProxyHandler.liveHasTrap;
6615
- BoundaryProxyHandler.defaultIsExtensibleTrap = BoundaryProxyHandler.liveIsExtensibleTrap;
6616
- BoundaryProxyHandler.defaultOwnKeysTrap = BoundaryProxyHandler.liveOwnKeysTrap;
6617
- // pending traps are only really needed if this membrane traps
6618
- // mutations to avoid mutations operations on the side of the membrane.
6619
- // TODO: find a way to optimize the declaration rather than instantiation
6620
- BoundaryProxyHandler.defaultDefinePropertyTrap = trapMutations
6621
- ? BoundaryProxyHandler.pendingDefinePropertyTrap
6622
- : BoundaryProxyHandler.liveDefinePropertyTrap;
6623
- BoundaryProxyHandler.defaultDeletePropertyTrap = trapMutations
6624
- ? BoundaryProxyHandler.pendingDeletePropertyTrap
6625
- : BoundaryProxyHandler.liveDeletePropertyTrap;
6626
- BoundaryProxyHandler.defaultPreventExtensionsTrap = trapMutations
6627
- ? BoundaryProxyHandler.pendingPreventExtensionsTrap
6628
- : BoundaryProxyHandler.livePreventExtensionsTrap;
6629
- BoundaryProxyHandler.defaultSetTrap = trapMutations
6630
- ? BoundaryProxyHandler.pendingSetTrap
6631
- : BoundaryProxyHandler.liveSetTrap;
6632
- BoundaryProxyHandler.defaultSetPrototypeOfTrap = trapMutations
6633
- ? BoundaryProxyHandler.pendingSetPrototypeOfTrap
6634
- : BoundaryProxyHandler.liveSetPrototypeOfTrap;
6635
- ReflectSetPrototypeOf(BoundaryProxyHandler.prototype, null);
6636
- // future optimization: hoping proxies with frozen handlers can be faster
6637
- ObjectFreeze(BoundaryProxyHandler.prototype);
6638
- // exporting callable hooks for a foreign realm
6639
- foreignCallableHooksCallback(
6640
- // globalThisPointer
6641
- // When crossing, should be mapped to the foreign globalThis
6642
- createPointer(globalThis),
6643
- // getSelectedTarget
6644
- getSelectedTarget,
6645
- // getTransferableValue
6646
- getTransferableValue,
6647
- // callableGetPropertyValuePointer: this callable function allows
6648
- // the foreign realm to access a linkable pointer for a property value.
6649
- // In order to do that, the foreign side must provide a pointer and
6650
- // a key access the value in order to produce a pointer
6651
- (targetPointer, key) => {
6652
- targetPointer();
6653
- const target = getSelectedTarget();
6654
- const value = target[key];
6655
- // TODO: what if the value is not a valid proxy target?
6656
- return createPointer(value);
6657
- },
6658
- // callableEvaluate
6659
- (sourceText) => {
6660
- try {
6661
- return getTransferableValue(cachedLocalEval(sourceText));
6662
- }
6663
- catch (e) {
6664
- throw pushErrorAcrossBoundary(e);
6665
- }
6666
- },
6667
- // callableLinkPointers: this callable function allows the foreign
6668
- // realm to define a linkage between two values across the membrane.
6669
- (targetPointer, newPointer) => {
6670
- targetPointer();
6671
- const target = getSelectedTarget();
6672
- ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [target, newPointer]);
6673
- },
6674
- /**
6675
- * callablePushTarget: This function can be used by a foreign realm to install a proxy
6676
- * into this realm that correspond to an object from the foreign realm. It returns
6677
- * a Pointer that can be used by the foreign realm to pass back a reference to this
6678
- * realm when passing arguments or returning from a foreign callable invocation. This
6679
- * function is extremely important to understand the mechanics of this membrane.
6680
- */
6681
- (foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) => {
6682
- const { proxy } = new BoundaryProxyHandler(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName);
6683
- ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [
6684
- proxy,
6685
- foreignTargetPointer,
6686
- ]);
6687
- return createPointer(proxy);
6688
- },
6689
- // callableApply
6690
- instrumentCallableWrapper((targetPointer, thisArgPointerOrValue, ...listOfValuesOrPointers) => {
6691
- targetPointer();
6692
- const fn = getSelectedTarget();
6693
- const thisArg = getLocalValue(thisArgPointerOrValue);
6694
- const { length: argsLen } = listOfValuesOrPointers;
6695
- const args = new ArrayCtor(argsLen);
6696
- for (let i = 0, len = argsLen; i < len; i += 1) {
6697
- args[i] = getLocalValue(listOfValuesOrPointers[i]);
6698
- }
6699
- let value;
6700
- try {
6701
- value = ReflectApply(fn, thisArg, args);
6702
- }
6703
- catch (e) {
6704
- throw pushErrorAcrossBoundary(e);
6705
- }
6706
- return getTransferableValue(value);
6707
- }, 'callableApply', INBOUND_INSTRUMENTATION_LABEL),
6708
- // callableConstruct
6709
- instrumentCallableWrapper((targetPointer, newTargetPointerOrValue, ...listOfValuesOrPointers) => {
6710
- targetPointer();
6711
- const constructor = getSelectedTarget();
6712
- const newTarget = getLocalValue(newTargetPointerOrValue);
6713
- const { length: argsLen } = listOfValuesOrPointers;
6714
- const args = new ArrayCtor(argsLen);
6715
- for (let i = 0, len = argsLen; i < len; i += 1) {
6716
- args[i] = getLocalValue(listOfValuesOrPointers[i]);
6717
- }
6718
- let value;
6719
- try {
6720
- value = ReflectConstruct(constructor, args, newTarget);
6721
- }
6722
- catch (e) {
6723
- throw pushErrorAcrossBoundary(e);
6724
- }
6725
- return getTransferableValue(value);
6726
- }, 'callableConstruct', INBOUND_INSTRUMENTATION_LABEL),
6727
- // callableDefineProperty
6728
- instrumentCallableWrapper((targetPointer, key, configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
6729
- targetPointer();
6730
- const target = getSelectedTarget();
6731
- try {
6732
- return ReflectDefineProperty(target, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
6733
- }
6734
- catch (e) {
6735
- throw pushErrorAcrossBoundary(e);
6736
- }
6737
- }, 'callableDefineProperty', INBOUND_INSTRUMENTATION_LABEL),
6738
- // callableDeleteProperty
6739
- instrumentCallableWrapper((targetPointer, key) => {
6740
- targetPointer();
6741
- const target = getSelectedTarget();
6742
- try {
6743
- return ReflectDeleteProperty(target, key);
6744
- }
6745
- catch (e) {
6746
- throw pushErrorAcrossBoundary(e);
6747
- }
6748
- }, 'callableDeleteProperty', INBOUND_INSTRUMENTATION_LABEL),
6749
- // callableGetOwnPropertyDescriptor
6750
- instrumentCallableWrapper((targetPointer, key, foreignCallableDescriptorCallback) => {
6751
- targetPointer();
6752
- const target = getSelectedTarget();
6753
- let unsafeDesc;
6754
- try {
6755
- unsafeDesc = ReflectGetOwnPropertyDescriptor(target, key);
6756
- }
6757
- catch (e) {
6758
- throw pushErrorAcrossBoundary(e);
6759
- }
6760
- if (unsafeDesc) {
6761
- const descMeta = getDescriptorMeta(unsafeDesc);
6762
- foreignCallableDescriptorCallback(descMeta[0], // configurable
6763
- descMeta[1], // enumerable
6764
- descMeta[2], // writable
6765
- descMeta[3], // valuePointer
6766
- descMeta[4], // getPointer
6767
- descMeta[5] // setPointer
6768
- );
6769
- }
6770
- }, 'callableGetOwnPropertyDescriptor', INBOUND_INSTRUMENTATION_LABEL),
6771
- // callableGetPrototypeOf
6772
- instrumentCallableWrapper((targetPointer) => {
6773
- targetPointer();
6774
- const target = getSelectedTarget();
6775
- let proto;
6776
- try {
6777
- proto = ReflectGetPrototypeOf(target);
6778
- }
6779
- catch (e) {
6780
- throw pushErrorAcrossBoundary(e);
6781
- }
6782
- return getTransferableValue(proto);
6783
- }, 'callableGetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL),
6784
- // callableIsExtensible
6785
- instrumentCallableWrapper((targetPointer) => {
6786
- targetPointer();
6787
- const target = getSelectedTarget();
6788
- try {
6789
- return ReflectIsExtensible(target);
6790
- }
6791
- catch (e) {
6792
- throw pushErrorAcrossBoundary(e);
6793
- }
6794
- }, 'callableIsExtensible', INBOUND_INSTRUMENTATION_LABEL),
6795
- // callableOwnKeys
6796
- instrumentCallableWrapper((targetPointer, foreignCallableKeysCallback) => {
6797
- targetPointer();
6798
- const target = getSelectedTarget();
6799
- let keys;
6800
- try {
6801
- keys = ReflectOwnKeys(target);
6802
- }
6803
- catch (e) {
6804
- throw pushErrorAcrossBoundary(e);
6805
- }
6806
- ReflectApply(foreignCallableKeysCallback, undefined, keys);
6807
- }, 'callableOwnKeys', INBOUND_INSTRUMENTATION_LABEL),
6808
- // callablePreventExtensions
6809
- instrumentCallableWrapper((targetPointer) => {
6810
- targetPointer();
6811
- const target = getSelectedTarget();
6812
- try {
6813
- return ReflectPreventExtensions(target);
6814
- }
6815
- catch (e) {
6816
- throw pushErrorAcrossBoundary(e);
6817
- }
6818
- }, 'callablePreventExtensions', INBOUND_INSTRUMENTATION_LABEL),
6819
- // callableSet
6820
- instrumentCallableWrapper((targetPointer, propertyKey, valuePointer, receiverPointer) => {
6821
- targetPointer();
6822
- const target = getSelectedTarget();
6823
- try {
6824
- return ReflectSet(target, propertyKey, getLocalValue(valuePointer), getLocalValue(receiverPointer));
6825
- }
6826
- catch (e) {
6827
- throw pushErrorAcrossBoundary(e);
6828
- }
6829
- }, 'callableSet', INBOUND_INSTRUMENTATION_LABEL),
6830
- // callableSetPrototypeOf
6831
- instrumentCallableWrapper((targetPointer, protoPointerOrNull) => {
6832
- targetPointer();
6833
- const target = getSelectedTarget();
6834
- const proto = getLocalValue(protoPointerOrNull);
6835
- try {
6836
- return ReflectSetPrototypeOf(target, proto);
6837
- }
6838
- catch (e) {
6839
- throw pushErrorAcrossBoundary(e);
6840
- }
6841
- }, 'callableSetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL),
6842
- // callableGetTargetIntegrityTraits
6843
- instrumentCallableWrapper((targetPointer) => {
6844
- targetPointer();
6845
- const target = getSelectedTarget();
6846
- return getTargetIntegrityTraits(target);
6847
- }, 'callableGetTargetIntegrityTraits', INBOUND_INSTRUMENTATION_LABEL),
6848
- // callableGetUnbrandedTag
6849
- instrumentCallableWrapper((targetPointer) => {
6850
- targetPointer();
6851
- const target = getSelectedTarget();
6852
- try {
6853
- if (typeof target === 'object' &&
6854
- target !== null &&
6855
- !isArrayOrNotOrThrowForRevoked(target)) {
6856
- // Section 19.1.3.6: Object.prototype.toString()
6857
- // Step 16: If `Type(tag)` is not `String`, let `tag` be `builtinTag`.
6858
- // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
6859
- const toStringValue = ReflectApply(ObjectProtoToString, target, []);
6860
- return ReflectApply(StringProtoSlice, toStringValue, [8, -1]);
6861
- }
6862
- // eslint-disable-next-line no-empty
6863
- }
6864
- catch { }
6865
- return undefined;
6866
- }, 'callableGetUnbrandedTag', INBOUND_INSTRUMENTATION_LABEL),
6867
- // callableHasOwnProperty
6868
- instrumentCallableWrapper((targetPointer, key) => {
6869
- targetPointer();
6870
- const target = getSelectedTarget();
6871
- try {
6872
- return ReflectApply(ObjectProtoHasOwnProperty, target, [key]);
6873
- }
6874
- catch (e) {
6875
- throw pushErrorAcrossBoundary(e);
6876
- }
6877
- }, 'callableHasOwnProperty', INBOUND_INSTRUMENTATION_LABEL));
6878
- return (...hooks) => {
6879
- const {
6880
- // 0: globalThisPointer,
6881
- // 1: getSelectedTarget,
6882
- // 2: getTransferableValue,
6883
- // 3: callableGetPropertyValuePointer,
6884
- // 4: callableEvaluate,
6885
- // 5: callableLinkPointers,
6886
- 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;
6887
- foreignCallablePushTarget = callablePushTarget;
6888
- // traps utilities
6889
- foreignCallableApply = foreignErrorControl(instrumentCallableWrapper(callableApply, 'callableApply', OUTBOUND_INSTRUMENTATION_LABEL));
6890
- foreignCallableConstruct = foreignErrorControl(instrumentCallableWrapper(callableConstruct, 'callableConstruct', OUTBOUND_INSTRUMENTATION_LABEL));
6891
- foreignCallableDefineProperty = foreignErrorControl(instrumentCallableWrapper(callableDefineProperty, 'callableDefineProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6892
- foreignCallableDeleteProperty = foreignErrorControl(instrumentCallableWrapper(callableDeleteProperty, 'callableDeleteProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6893
- foreignCallableGetOwnPropertyDescriptor = foreignErrorControl(instrumentCallableWrapper(callableGetOwnPropertyDescriptor, 'callableGetOwnPropertyDescriptor', OUTBOUND_INSTRUMENTATION_LABEL));
6894
- foreignCallableGetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableGetPrototypeOf, 'callableGetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
6895
- foreignCallableIsExtensible = foreignErrorControl(instrumentCallableWrapper(callableIsExtensible, 'callableIsExtensible', OUTBOUND_INSTRUMENTATION_LABEL));
6896
- foreignCallableOwnKeys = foreignErrorControl(instrumentCallableWrapper(callableOwnKeys, 'callableOwnKeys', OUTBOUND_INSTRUMENTATION_LABEL));
6897
- foreignCallablePreventExtensions = foreignErrorControl(instrumentCallableWrapper(callablePreventExtensions, 'callablePreventExtensions', OUTBOUND_INSTRUMENTATION_LABEL));
6898
- foreignCallableSet = foreignErrorControl(instrumentCallableWrapper(callableSet, 'callableSet', OUTBOUND_INSTRUMENTATION_LABEL));
6899
- foreignCallableSetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableSetPrototypeOf, 'callableSetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
6900
- foreignCallableGetTargetIntegrityTraits = foreignErrorControl(instrumentCallableWrapper(callableGetTargetIntegrityTraits, 'callableGetTargetIntegrityTraits', OUTBOUND_INSTRUMENTATION_LABEL));
6901
- foreignCallableGetUnbrandedTag = foreignErrorControl(instrumentCallableWrapper(callableGetUnbrandedTag, 'callableGetUnbrandedTag', OUTBOUND_INSTRUMENTATION_LABEL));
6902
- foreignCallableHasOwnProperty = foreignErrorControl(instrumentCallableWrapper(callableHasOwnProperty, 'callableHasOwnProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6903
- };
6898
+
6899
+ return ReflectGet(shadowTarget, key, receiver);
6900
+ }
6901
+
6902
+ }
6903
+
6904
+ BoundaryProxyHandler.staticDefinePropertyTrap = ReflectDefineProperty;
6905
+ BoundaryProxyHandler.staticDeletePropertyTrap = ReflectDeleteProperty;
6906
+ BoundaryProxyHandler.staticGetOwnPropertyDescriptorTrap = ReflectGetOwnPropertyDescriptor;
6907
+ BoundaryProxyHandler.staticGetPrototypeOfTrap = ReflectGetPrototypeOf;
6908
+ BoundaryProxyHandler.staticHasTrap = ReflectHas;
6909
+ BoundaryProxyHandler.staticIsExtensibleTrap = ReflectIsExtensible;
6910
+ BoundaryProxyHandler.staticOwnKeysTrap = ReflectOwnKeys;
6911
+ BoundaryProxyHandler.staticPreventExtensionsTrap = ReflectPreventExtensions;
6912
+ BoundaryProxyHandler.staticSetTrap = ReflectSet;
6913
+ BoundaryProxyHandler.staticSetPrototypeOfTrap = ReflectSetPrototypeOf; // static default traps
6914
+ // (optimization to avoid computations of the proper trap in constructor)
6915
+
6916
+ BoundaryProxyHandler.defaultGetTrap = BoundaryProxyHandler.liveGetTrap;
6917
+ BoundaryProxyHandler.defaultGetOwnPropertyDescriptorTrap = BoundaryProxyHandler.liveGetOwnPropertyDescriptorTrap;
6918
+ BoundaryProxyHandler.defaultGetPrototypeOfTrap = BoundaryProxyHandler.liveGetPrototypeOfTrap;
6919
+ BoundaryProxyHandler.defaultHasTrap = BoundaryProxyHandler.liveHasTrap;
6920
+ BoundaryProxyHandler.defaultIsExtensibleTrap = BoundaryProxyHandler.liveIsExtensibleTrap;
6921
+ BoundaryProxyHandler.defaultOwnKeysTrap = BoundaryProxyHandler.liveOwnKeysTrap; // pending traps are only really needed if this membrane traps
6922
+ // mutations to avoid mutations operations on the side of the membrane.
6923
+ // TODO: find a way to optimize the declaration rather than instantiation
6924
+
6925
+ BoundaryProxyHandler.defaultDefinePropertyTrap = trapMutations ? BoundaryProxyHandler.pendingDefinePropertyTrap : BoundaryProxyHandler.liveDefinePropertyTrap;
6926
+ BoundaryProxyHandler.defaultDeletePropertyTrap = trapMutations ? BoundaryProxyHandler.pendingDeletePropertyTrap : BoundaryProxyHandler.liveDeletePropertyTrap;
6927
+ BoundaryProxyHandler.defaultPreventExtensionsTrap = trapMutations ? BoundaryProxyHandler.pendingPreventExtensionsTrap : BoundaryProxyHandler.livePreventExtensionsTrap;
6928
+ BoundaryProxyHandler.defaultSetTrap = trapMutations ? BoundaryProxyHandler.pendingSetTrap : BoundaryProxyHandler.liveSetTrap;
6929
+ BoundaryProxyHandler.defaultSetPrototypeOfTrap = trapMutations ? BoundaryProxyHandler.pendingSetPrototypeOfTrap : BoundaryProxyHandler.liveSetPrototypeOfTrap;
6930
+ ReflectSetPrototypeOf(BoundaryProxyHandler.prototype, null); // future optimization: hoping proxies with frozen handlers can be faster
6931
+
6932
+ ObjectFreeze(BoundaryProxyHandler.prototype); // exporting callable hooks for a foreign realm
6933
+
6934
+ foreignCallableHooksCallback( // globalThisPointer
6935
+ // When crossing, should be mapped to the foreign globalThis
6936
+ createPointer(globalThis), // getSelectedTarget
6937
+ getSelectedTarget, // getTransferableValue
6938
+ getTransferableValue, // callableGetPropertyValuePointer: this callable function allows
6939
+ // the foreign realm to access a linkable pointer for a property value.
6940
+ // In order to do that, the foreign side must provide a pointer and
6941
+ // a key access the value in order to produce a pointer
6942
+ (targetPointer, key) => {
6943
+ targetPointer();
6944
+ const target = getSelectedTarget();
6945
+ const value = target[key]; // TODO: what if the value is not a valid proxy target?
6946
+
6947
+ return createPointer(value);
6948
+ }, // callableEvaluate
6949
+ sourceText => {
6950
+ try {
6951
+ return getTransferableValue(cachedLocalEval(sourceText));
6952
+ } catch (e) {
6953
+ throw pushErrorAcrossBoundary(e);
6954
+ }
6955
+ }, // callableLinkPointers: this callable function allows the foreign
6956
+ // realm to define a linkage between two values across the membrane.
6957
+ (targetPointer, newPointer) => {
6958
+ targetPointer();
6959
+ const target = getSelectedTarget();
6960
+ ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [target, newPointer]);
6961
+ },
6962
+ /**
6963
+ * callablePushTarget: This function can be used by a foreign realm to install a proxy
6964
+ * into this realm that correspond to an object from the foreign realm. It returns
6965
+ * a Pointer that can be used by the foreign realm to pass back a reference to this
6966
+ * realm when passing arguments or returning from a foreign callable invocation. This
6967
+ * function is extremely important to understand the mechanics of this membrane.
6968
+ */
6969
+ (foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName) => {
6970
+ const {
6971
+ proxy
6972
+ } = new BoundaryProxyHandler(foreignTargetPointer, foreignTargetTraits, foreignTargetFunctionName);
6973
+ ReflectApply(WeakMapProtoSet, proxyTargetToPointerMap, [proxy, foreignTargetPointer]);
6974
+ return createPointer(proxy);
6975
+ }, // callableApply
6976
+ instrumentCallableWrapper(function (targetPointer, thisArgPointerOrValue) {
6977
+ targetPointer();
6978
+ const fn = getSelectedTarget();
6979
+ const thisArg = getLocalValue(thisArgPointerOrValue);
6980
+
6981
+ for (var _len5 = arguments.length, listOfValuesOrPointers = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
6982
+ listOfValuesOrPointers[_key5 - 2] = arguments[_key5];
6983
+ }
6984
+
6985
+ const {
6986
+ length: argsLen
6987
+ } = listOfValuesOrPointers;
6988
+ const args = new ArrayCtor(argsLen);
6989
+
6990
+ for (let i = 0, len = argsLen; i < len; i += 1) {
6991
+ args[i] = getLocalValue(listOfValuesOrPointers[i]);
6992
+ }
6993
+
6994
+ let value;
6995
+
6996
+ try {
6997
+ value = ReflectApply(fn, thisArg, args);
6998
+ } catch (e) {
6999
+ throw pushErrorAcrossBoundary(e);
7000
+ }
7001
+
7002
+ return getTransferableValue(value);
7003
+ }, 'callableApply', INBOUND_INSTRUMENTATION_LABEL), // callableConstruct
7004
+ instrumentCallableWrapper(function (targetPointer, newTargetPointerOrValue) {
7005
+ targetPointer();
7006
+ const constructor = getSelectedTarget();
7007
+ const newTarget = getLocalValue(newTargetPointerOrValue);
7008
+
7009
+ for (var _len6 = arguments.length, listOfValuesOrPointers = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
7010
+ listOfValuesOrPointers[_key6 - 2] = arguments[_key6];
7011
+ }
7012
+
7013
+ const {
7014
+ length: argsLen
7015
+ } = listOfValuesOrPointers;
7016
+ const args = new ArrayCtor(argsLen);
7017
+
7018
+ for (let i = 0, len = argsLen; i < len; i += 1) {
7019
+ args[i] = getLocalValue(listOfValuesOrPointers[i]);
7020
+ }
7021
+
7022
+ let value;
7023
+
7024
+ try {
7025
+ value = ReflectConstruct(constructor, args, newTarget);
7026
+ } catch (e) {
7027
+ throw pushErrorAcrossBoundary(e);
7028
+ }
7029
+
7030
+ return getTransferableValue(value);
7031
+ }, 'callableConstruct', INBOUND_INSTRUMENTATION_LABEL), // callableDefineProperty
7032
+ instrumentCallableWrapper((targetPointer, key, configurable, enumerable, writable, valuePointer, getPointer, setPointer) => {
7033
+ targetPointer();
7034
+ const target = getSelectedTarget();
7035
+
7036
+ try {
7037
+ return ReflectDefineProperty(target, key, createDescriptorFromMeta(configurable, enumerable, writable, valuePointer, getPointer, setPointer));
7038
+ } catch (e) {
7039
+ throw pushErrorAcrossBoundary(e);
7040
+ }
7041
+ }, 'callableDefineProperty', INBOUND_INSTRUMENTATION_LABEL), // callableDeleteProperty
7042
+ instrumentCallableWrapper((targetPointer, key) => {
7043
+ targetPointer();
7044
+ const target = getSelectedTarget();
7045
+
7046
+ try {
7047
+ return ReflectDeleteProperty(target, key);
7048
+ } catch (e) {
7049
+ throw pushErrorAcrossBoundary(e);
7050
+ }
7051
+ }, 'callableDeleteProperty', INBOUND_INSTRUMENTATION_LABEL), // callableGetOwnPropertyDescriptor
7052
+ instrumentCallableWrapper((targetPointer, key, foreignCallableDescriptorCallback) => {
7053
+ targetPointer();
7054
+ const target = getSelectedTarget();
7055
+ let unsafeDesc;
7056
+
7057
+ try {
7058
+ unsafeDesc = ReflectGetOwnPropertyDescriptor(target, key);
7059
+ } catch (e) {
7060
+ throw pushErrorAcrossBoundary(e);
7061
+ }
7062
+
7063
+ if (unsafeDesc) {
7064
+ const descMeta = getDescriptorMeta(unsafeDesc);
7065
+ foreignCallableDescriptorCallback(descMeta[0], // configurable
7066
+ descMeta[1], // enumerable
7067
+ descMeta[2], // writable
7068
+ descMeta[3], // valuePointer
7069
+ descMeta[4], // getPointer
7070
+ descMeta[5] // setPointer
7071
+ );
7072
+ }
7073
+ }, 'callableGetOwnPropertyDescriptor', INBOUND_INSTRUMENTATION_LABEL), // callableGetPrototypeOf
7074
+ instrumentCallableWrapper(targetPointer => {
7075
+ targetPointer();
7076
+ const target = getSelectedTarget();
7077
+ let proto;
7078
+
7079
+ try {
7080
+ proto = ReflectGetPrototypeOf(target);
7081
+ } catch (e) {
7082
+ throw pushErrorAcrossBoundary(e);
7083
+ }
7084
+
7085
+ return getTransferableValue(proto);
7086
+ }, 'callableGetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL), // callableIsExtensible
7087
+ instrumentCallableWrapper(targetPointer => {
7088
+ targetPointer();
7089
+ const target = getSelectedTarget();
7090
+
7091
+ try {
7092
+ return ReflectIsExtensible(target);
7093
+ } catch (e) {
7094
+ throw pushErrorAcrossBoundary(e);
7095
+ }
7096
+ }, 'callableIsExtensible', INBOUND_INSTRUMENTATION_LABEL), // callableOwnKeys
7097
+ instrumentCallableWrapper((targetPointer, foreignCallableKeysCallback) => {
7098
+ targetPointer();
7099
+ const target = getSelectedTarget();
7100
+ let keys;
7101
+
7102
+ try {
7103
+ keys = ReflectOwnKeys(target);
7104
+ } catch (e) {
7105
+ throw pushErrorAcrossBoundary(e);
7106
+ }
7107
+
7108
+ ReflectApply(foreignCallableKeysCallback, undefined, keys);
7109
+ }, 'callableOwnKeys', INBOUND_INSTRUMENTATION_LABEL), // callablePreventExtensions
7110
+ instrumentCallableWrapper(targetPointer => {
7111
+ targetPointer();
7112
+ const target = getSelectedTarget();
7113
+
7114
+ try {
7115
+ return ReflectPreventExtensions(target);
7116
+ } catch (e) {
7117
+ throw pushErrorAcrossBoundary(e);
7118
+ }
7119
+ }, 'callablePreventExtensions', INBOUND_INSTRUMENTATION_LABEL), // callableSet
7120
+ instrumentCallableWrapper((targetPointer, propertyKey, valuePointer, receiverPointer) => {
7121
+ targetPointer();
7122
+ const target = getSelectedTarget();
7123
+
7124
+ try {
7125
+ return ReflectSet(target, propertyKey, getLocalValue(valuePointer), getLocalValue(receiverPointer));
7126
+ } catch (e) {
7127
+ throw pushErrorAcrossBoundary(e);
7128
+ }
7129
+ }, 'callableSet', INBOUND_INSTRUMENTATION_LABEL), // callableSetPrototypeOf
7130
+ instrumentCallableWrapper((targetPointer, protoPointerOrNull) => {
7131
+ targetPointer();
7132
+ const target = getSelectedTarget();
7133
+ const proto = getLocalValue(protoPointerOrNull);
7134
+
7135
+ try {
7136
+ return ReflectSetPrototypeOf(target, proto);
7137
+ } catch (e) {
7138
+ throw pushErrorAcrossBoundary(e);
7139
+ }
7140
+ }, 'callableSetPrototypeOf', INBOUND_INSTRUMENTATION_LABEL), // callableGetTargetIntegrityTraits
7141
+ instrumentCallableWrapper(targetPointer => {
7142
+ targetPointer();
7143
+ const target = getSelectedTarget();
7144
+ return getTargetIntegrityTraits(target);
7145
+ }, 'callableGetTargetIntegrityTraits', INBOUND_INSTRUMENTATION_LABEL), // callableGetUnbrandedTag
7146
+ instrumentCallableWrapper(targetPointer => {
7147
+ targetPointer();
7148
+ const target = getSelectedTarget();
7149
+
7150
+ try {
7151
+ if (typeof target === 'object' && target !== null && !isArrayOrNotOrThrowForRevoked(target)) {
7152
+ // Section 19.1.3.6: Object.prototype.toString()
7153
+ // Step 16: If `Type(tag)` is not `String`, let `tag` be `builtinTag`.
7154
+ // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
7155
+ const toStringValue = ReflectApply(ObjectProtoToString, target, []);
7156
+ return ReflectApply(StringProtoSlice, toStringValue, [8, -1]);
7157
+ } // eslint-disable-next-line no-empty
7158
+
7159
+ } catch (_unused6) {}
7160
+
7161
+ return undefined;
7162
+ }, 'callableGetUnbrandedTag', INBOUND_INSTRUMENTATION_LABEL), // callableHasOwnProperty
7163
+ instrumentCallableWrapper((targetPointer, key) => {
7164
+ targetPointer();
7165
+ const target = getSelectedTarget();
7166
+
7167
+ try {
7168
+ return ReflectApply(ObjectProtoHasOwnProperty, target, [key]);
7169
+ } catch (e) {
7170
+ throw pushErrorAcrossBoundary(e);
7171
+ }
7172
+ }, 'callableHasOwnProperty', INBOUND_INSTRUMENTATION_LABEL));
7173
+ return function () {
7174
+ for (var _len7 = arguments.length, hooks = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
7175
+ hooks[_key7] = arguments[_key7];
7176
+ }
7177
+
7178
+ const {
7179
+ // 0: globalThisPointer,
7180
+ // 1: getSelectedTarget,
7181
+ // 2: getTransferableValue,
7182
+ // 3: callableGetPropertyValuePointer,
7183
+ // 4: callableEvaluate,
7184
+ // 5: callableLinkPointers,
7185
+ 6: callablePushTarget,
7186
+ 7: callableApply,
7187
+ 8: callableConstruct,
7188
+ 9: callableDefineProperty,
7189
+ 10: callableDeleteProperty,
7190
+ 11: callableGetOwnPropertyDescriptor,
7191
+ 12: callableGetPrototypeOf,
7192
+ 13: callableIsExtensible,
7193
+ 14: callableOwnKeys,
7194
+ 15: callablePreventExtensions,
7195
+ 16: callableSet,
7196
+ 17: callableSetPrototypeOf,
7197
+ 18: callableGetTargetIntegrityTraits,
7198
+ 19: callableGetUnbrandedTag,
7199
+ 20: callableHasOwnProperty
7200
+ } = hooks;
7201
+ foreignCallablePushTarget = callablePushTarget; // traps utilities
7202
+
7203
+ foreignCallableApply = foreignErrorControl(instrumentCallableWrapper(callableApply, 'callableApply', OUTBOUND_INSTRUMENTATION_LABEL));
7204
+ foreignCallableConstruct = foreignErrorControl(instrumentCallableWrapper(callableConstruct, 'callableConstruct', OUTBOUND_INSTRUMENTATION_LABEL));
7205
+ foreignCallableDefineProperty = foreignErrorControl(instrumentCallableWrapper(callableDefineProperty, 'callableDefineProperty', OUTBOUND_INSTRUMENTATION_LABEL));
7206
+ foreignCallableDeleteProperty = foreignErrorControl(instrumentCallableWrapper(callableDeleteProperty, 'callableDeleteProperty', OUTBOUND_INSTRUMENTATION_LABEL));
7207
+ foreignCallableGetOwnPropertyDescriptor = foreignErrorControl(instrumentCallableWrapper(callableGetOwnPropertyDescriptor, 'callableGetOwnPropertyDescriptor', OUTBOUND_INSTRUMENTATION_LABEL));
7208
+ foreignCallableGetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableGetPrototypeOf, 'callableGetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
7209
+ foreignCallableIsExtensible = foreignErrorControl(instrumentCallableWrapper(callableIsExtensible, 'callableIsExtensible', OUTBOUND_INSTRUMENTATION_LABEL));
7210
+ foreignCallableOwnKeys = foreignErrorControl(instrumentCallableWrapper(callableOwnKeys, 'callableOwnKeys', OUTBOUND_INSTRUMENTATION_LABEL));
7211
+ foreignCallablePreventExtensions = foreignErrorControl(instrumentCallableWrapper(callablePreventExtensions, 'callablePreventExtensions', OUTBOUND_INSTRUMENTATION_LABEL));
7212
+ foreignCallableSet = foreignErrorControl(instrumentCallableWrapper(callableSet, 'callableSet', OUTBOUND_INSTRUMENTATION_LABEL));
7213
+ foreignCallableSetPrototypeOf = foreignErrorControl(instrumentCallableWrapper(callableSetPrototypeOf, 'callableSetPrototypeOf', OUTBOUND_INSTRUMENTATION_LABEL));
7214
+ foreignCallableGetTargetIntegrityTraits = foreignErrorControl(instrumentCallableWrapper(callableGetTargetIntegrityTraits, 'callableGetTargetIntegrityTraits', OUTBOUND_INSTRUMENTATION_LABEL));
7215
+ foreignCallableGetUnbrandedTag = foreignErrorControl(instrumentCallableWrapper(callableGetUnbrandedTag, 'callableGetUnbrandedTag', OUTBOUND_INSTRUMENTATION_LABEL));
7216
+ foreignCallableHasOwnProperty = foreignErrorControl(instrumentCallableWrapper(callableHasOwnProperty, 'callableHasOwnProperty', OUTBOUND_INSTRUMENTATION_LABEL));
6904
7217
  };
7218
+ };
6905
7219
  }
6906
7220
 
6907
- const TypeErrorCtor$1 = TypeError;
6908
- const marshallSourceTextInStrictMode = `(function(){'use strict';return (${createMembraneMarshall.toString()})})()`;
6909
- // eslint-disable-next-line no-eval
7221
+ const TypeErrorCtor$1 = TypeError; // istanbul ignore next
7222
+
7223
+ const marshallSourceTextInStrictMode = `
7224
+ (function(){
7225
+ 'use strict';
7226
+ (${function initializeShadowRealm() {
7227
+ if (typeof Error.stackTraceLimit === 'number') {
7228
+ // The default stack trace limit is 10.
7229
+ // Increasing to 20 as a baby step.
7230
+ Error.stackTraceLimit *= 2;
7231
+ }
7232
+ }.toString()})();
7233
+ return (${createMembraneMarshall.toString()})
7234
+ })()`; // eslint-disable-next-line no-eval
7235
+
6910
7236
  function createConnector(evaluator) {
6911
- if (!evaluator) {
6912
- throw new TypeErrorCtor$1('Missing evaluator function');
6913
- }
6914
- // The result of this eval will be a function that returns a function.
6915
- // The hooks connector is the last returned function, so we invoke the
6916
- // result of the eval operation and return that result.
6917
- return evaluator(marshallSourceTextInStrictMode)();
7237
+ if (!evaluator) {
7238
+ throw new TypeErrorCtor$1('Missing evaluator function.');
7239
+ } // The result of this eval will be a function that returns a function.
7240
+ // The hooks connector is the last returned function, so we invoke the
7241
+ // result of the eval operation and return that result.
7242
+
7243
+
7244
+ return evaluator(marshallSourceTextInStrictMode)();
6918
7245
  }
6919
7246
 
6920
7247
  const SHOULD_TRAP_MUTATION = true;
6921
7248
  const SHOULD_NOT_TRAP_MUTATION = false;
6922
7249
  const UNDEFINED_SYMBOL = Symbol.for('@@membraneUndefinedValue');
6923
7250
  const ErrorCtor = Error;
6924
- const { assign: ObjectAssign$2, keys: ObjectKeys } = Object;
6925
- const { hasOwnProperty: ObjectProtoHasOwnProperty$1 } = Object.prototype;
6926
- const { apply: ReflectApply$1$1, ownKeys: ReflectOwnKeys$1 } = Reflect;
6927
- const { slice: StringProtoSlice, toUpperCase: StringProtoToUpperCase } = String.prototype;
7251
+ const {
7252
+ assign: ObjectAssign$2,
7253
+ keys: ObjectKeys
7254
+ } = Object;
7255
+ const {
7256
+ apply: ReflectApply$1$1,
7257
+ ownKeys: ReflectOwnKeys$1
7258
+ } = Reflect;
7259
+ const {
7260
+ slice: StringProtoSlice,
7261
+ toUpperCase: StringProtoToUpperCase
7262
+ } = String.prototype;
7263
+
6928
7264
  function capitalizeFirstChar(string) {
6929
- const { length } = string;
6930
- if (!length) {
6931
- return string;
6932
- }
6933
- const upper = ReflectApply$1$1(StringProtoToUpperCase, string[0], []);
6934
- return length === 1 ? upper : upper + ReflectApply$1$1(StringProtoSlice, string, [1]);
7265
+ const {
7266
+ length
7267
+ } = string;
7268
+
7269
+ if (!length) {
7270
+ return string;
7271
+ }
7272
+
7273
+ const upper = ReflectApply$1$1(StringProtoToUpperCase, string[0], []);
7274
+ return length === 1 ? upper : upper + ReflectApply$1$1(StringProtoSlice, string, [1]);
6935
7275
  }
7276
+
6936
7277
  class VirtualEnvironment {
6937
- constructor(options) {
6938
- if (options === undefined) {
6939
- throw new ErrorCtor(`Missing VirtualEnvironmentOptions options bag.`);
6940
- }
6941
- const { blueConnector, redConnector, distortionCallback, support, instrumentation } = options;
6942
- this.blueConnector = blueConnector;
6943
- this.redConnector = redConnector;
6944
- let supportFlags = SupportFlagsEnum.None;
6945
- const supportProps = support ? ObjectKeys(support) : [];
6946
- for (let i = 0, len = supportProps.length; i < len; i += 1) {
6947
- const key = capitalizeFirstChar(supportProps[i]);
6948
- if (ReflectApply$1$1(ObjectProtoHasOwnProperty$1, SupportFlagsEnum, [key])) {
6949
- supportFlags |= SupportFlagsEnum[key];
6950
- }
6951
- }
6952
- let blueHooks;
6953
- let redHooks;
6954
- const blueExportsCallback = (...hooks) => {
6955
- blueHooks = hooks;
6956
- };
6957
- const redExportsCallback = (...hooks) => {
6958
- redHooks = hooks;
6959
- };
6960
- const initLocalOptions = {
6961
- distortionCallback,
6962
- instrumentation,
6963
- };
6964
- const localConnect = blueConnector('blue', SHOULD_NOT_TRAP_MUTATION, supportFlags, blueExportsCallback, initLocalOptions);
6965
- const foreignConnect = redConnector('red', SHOULD_TRAP_MUTATION, supportFlags, redExportsCallback);
6966
- ReflectApply$1$1(localConnect, undefined, redHooks);
6967
- ReflectApply$1$1(foreignConnect, undefined, blueHooks);
6968
- const { 0: blueGlobalThisPointer, 1: blueGetSelectedTarget, 2: blueGetTransferableValue, 3: blueCallableGetPropertyValuePointer,
6969
- // 4: blueCallableEvaluate,
6970
- 5: blueCallableLinkPointers, } = blueHooks;
6971
- this.blueGlobalThisPointer = blueGlobalThisPointer;
6972
- this.blueGetSelectedTarget = blueGetSelectedTarget;
6973
- this.blueGetTransferableValue = blueGetTransferableValue;
6974
- this.blueCallableGetPropertyValuePointer = blueCallableGetPropertyValuePointer;
6975
- this.blueCallableLinkPointers = blueCallableLinkPointers;
6976
- const { 0: redGlobalThisPointer,
6977
- // 1: redGetSelectedTarget,
6978
- // 2: redGetTransferableValue,
6979
- 3: redCallableGetPropertyValuePointer, 4: redCallableEvaluate, 5: redCallableLinkPointers,
6980
- // 6: redCallablePushTarget,
6981
- // 7: redCallableApply,
6982
- // 8: redCallableConstruct,
6983
- 9: redCallableDefineProperty,
6984
- // 10: redCallableDeleteProperty,
6985
- // 11: redCallableGetOwnPropertyDescriptor,
6986
- // 12: redCallableGetPrototypeOf,
6987
- // 13: redCallableIsExtensible,
6988
- // 14: redCallableOwnKeys,
6989
- // 15: redCallablePreventExtensions,
6990
- // 16: redCallableSet,
6991
- 17: redCallableSetPrototypeOf, } = redHooks;
6992
- this.redGlobalThisPointer = redGlobalThisPointer;
6993
- this.redCallableEvaluate = redCallableEvaluate;
6994
- this.redCallableSetPrototypeOf = redCallableSetPrototypeOf;
6995
- this.redCallableDefineProperty = redCallableDefineProperty;
6996
- this.redCallableGetPropertyValuePointer = redCallableGetPropertyValuePointer;
6997
- this.redCallableLinkPointers = redCallableLinkPointers;
6998
- }
6999
- evaluate(sourceText) {
7000
- try {
7001
- const pointerOrPrimitiveValue = this.redCallableEvaluate(sourceText);
7002
- if (typeof pointerOrPrimitiveValue === 'function') {
7003
- pointerOrPrimitiveValue();
7004
- return this.blueGetSelectedTarget();
7005
- }
7006
- return pointerOrPrimitiveValue;
7007
- }
7008
- catch (e) {
7009
- const pushedError = this.blueGetSelectedTarget();
7010
- if (pushedError) {
7011
- throw pushedError;
7012
- }
7013
- throw e;
7014
- }
7278
+ constructor(options) {
7279
+ if (options === undefined) {
7280
+ throw new ErrorCtor(`Missing VirtualEnvironmentOptions options bag.`);
7015
7281
  }
7016
- link(...keys) {
7017
- let bluePointer = this.blueGlobalThisPointer;
7018
- let redPointer = this.redGlobalThisPointer;
7019
- for (let i = 0, len = keys.length; i < len; i += 1) {
7020
- const key = keys[i];
7021
- bluePointer = this.blueCallableGetPropertyValuePointer(bluePointer, key);
7022
- redPointer = this.redCallableGetPropertyValuePointer(redPointer, key);
7023
- }
7024
- this.redCallableLinkPointers(redPointer, bluePointer);
7025
- this.blueCallableLinkPointers(bluePointer, redPointer);
7026
- }
7027
- remap(target, blueDescriptors) {
7028
- const keys = ReflectOwnKeys$1(blueDescriptors);
7029
- const targetPointer = this.blueGetTransferableValue(target);
7030
- // prettier-ignore
7031
- for (let i = 0, len = keys.length; i < len; i += 1) {
7032
- const key = keys[i];
7033
- const unsafeBlueDesc = blueDescriptors[key];
7034
- // Avoid poisoning by only installing own properties from blueDescriptors
7035
- // eslint-disable-next-line prefer-object-spread
7036
- const safeBlueDesc = ObjectAssign$2({ __proto__: null }, unsafeBlueDesc);
7037
- // Install descriptor into the red side.
7038
- this.redCallableDefineProperty(targetPointer, key, 'configurable' in safeBlueDesc
7039
- ? !!safeBlueDesc.configurable
7040
- : UNDEFINED_SYMBOL, 'enumerable' in safeBlueDesc
7041
- ? !!safeBlueDesc.enumerable
7042
- : UNDEFINED_SYMBOL, 'writable' in safeBlueDesc
7043
- ? !!safeBlueDesc.writable
7044
- : UNDEFINED_SYMBOL, 'value' in safeBlueDesc
7045
- ? this.blueGetTransferableValue(safeBlueDesc.value)
7046
- : UNDEFINED_SYMBOL, 'get' in safeBlueDesc
7047
- ? this.blueGetTransferableValue(safeBlueDesc.get)
7048
- : UNDEFINED_SYMBOL, 'set' in safeBlueDesc
7049
- ? this.blueGetTransferableValue(safeBlueDesc.set)
7050
- : UNDEFINED_SYMBOL);
7051
- }
7282
+
7283
+ const {
7284
+ blueConnector,
7285
+ redConnector,
7286
+ distortionCallback,
7287
+ support,
7288
+ instrumentation
7289
+ } = options;
7290
+ this.blueConnector = blueConnector;
7291
+ this.redConnector = redConnector;
7292
+ let supportFlags = SupportFlagsEnum.None;
7293
+ const supportKeys = support ? ObjectKeys(support) : [];
7294
+
7295
+ for (let i = 0, len = supportKeys.length; i < len; i += 1) {
7296
+ const enumKey = capitalizeFirstChar(supportKeys[i]);
7297
+ supportFlags |= SupportFlagsEnum[enumKey];
7052
7298
  }
7053
- remapProto(target, proto) {
7054
- const targetPointer = this.blueGetTransferableValue(target);
7055
- const pointerOrNull = this.blueGetTransferableValue(proto);
7056
- this.redCallableSetPrototypeOf(targetPointer, pointerOrNull);
7299
+
7300
+ let blueHooks;
7301
+ let redHooks;
7302
+
7303
+ const blueExportsCallback = function blueExportsCallback() {
7304
+ for (var _len8 = arguments.length, hooks = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
7305
+ hooks[_key8] = arguments[_key8];
7306
+ }
7307
+
7308
+ blueHooks = hooks;
7309
+ };
7310
+
7311
+ const redExportsCallback = function redExportsCallback() {
7312
+ for (var _len9 = arguments.length, hooks = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
7313
+ hooks[_key9] = arguments[_key9];
7314
+ }
7315
+
7316
+ redHooks = hooks;
7317
+ };
7318
+
7319
+ const initLocalOptions = {
7320
+ distortionCallback,
7321
+ instrumentation
7322
+ };
7323
+ const localConnect = blueConnector('blue', SHOULD_NOT_TRAP_MUTATION, supportFlags, blueExportsCallback, initLocalOptions);
7324
+ const foreignConnect = redConnector('red', SHOULD_TRAP_MUTATION, supportFlags, redExportsCallback);
7325
+ ReflectApply$1$1(localConnect, undefined, redHooks);
7326
+ ReflectApply$1$1(foreignConnect, undefined, blueHooks);
7327
+ const {
7328
+ 0: blueGlobalThisPointer,
7329
+ 1: blueGetSelectedTarget,
7330
+ 2: blueGetTransferableValue,
7331
+ 3: blueCallableGetPropertyValuePointer,
7332
+ // 4: blueCallableEvaluate,
7333
+ 5: blueCallableLinkPointers
7334
+ } = blueHooks;
7335
+ this.blueGlobalThisPointer = blueGlobalThisPointer;
7336
+ this.blueGetSelectedTarget = blueGetSelectedTarget;
7337
+ this.blueGetTransferableValue = blueGetTransferableValue;
7338
+ this.blueCallableGetPropertyValuePointer = blueCallableGetPropertyValuePointer;
7339
+ this.blueCallableLinkPointers = blueCallableLinkPointers;
7340
+ const {
7341
+ 0: redGlobalThisPointer,
7342
+ // 1: redGetSelectedTarget,
7343
+ // 2: redGetTransferableValue,
7344
+ 3: redCallableGetPropertyValuePointer,
7345
+ 4: redCallableEvaluate,
7346
+ 5: redCallableLinkPointers,
7347
+ // 6: redCallablePushTarget,
7348
+ // 7: redCallableApply,
7349
+ // 8: redCallableConstruct,
7350
+ 9: redCallableDefineProperty,
7351
+ // 10: redCallableDeleteProperty,
7352
+ // 11: redCallableGetOwnPropertyDescriptor,
7353
+ // 12: redCallableGetPrototypeOf,
7354
+ // 13: redCallableIsExtensible,
7355
+ // 14: redCallableOwnKeys,
7356
+ // 15: redCallablePreventExtensions,
7357
+ // 16: redCallableSet,
7358
+ 17: redCallableSetPrototypeOf
7359
+ } = redHooks;
7360
+ this.redGlobalThisPointer = redGlobalThisPointer;
7361
+ this.redCallableEvaluate = redCallableEvaluate;
7362
+ this.redCallableSetPrototypeOf = redCallableSetPrototypeOf;
7363
+ this.redCallableDefineProperty = redCallableDefineProperty;
7364
+ this.redCallableGetPropertyValuePointer = redCallableGetPropertyValuePointer;
7365
+ this.redCallableLinkPointers = redCallableLinkPointers;
7366
+ }
7367
+
7368
+ evaluate(sourceText) {
7369
+ try {
7370
+ const pointerOrPrimitiveValue = this.redCallableEvaluate(sourceText);
7371
+
7372
+ if (typeof pointerOrPrimitiveValue === 'function') {
7373
+ pointerOrPrimitiveValue();
7374
+ return this.blueGetSelectedTarget();
7375
+ }
7376
+
7377
+ return pointerOrPrimitiveValue;
7378
+ } catch (e) {
7379
+ const pushedError = this.blueGetSelectedTarget();
7380
+
7381
+ if (pushedError) {
7382
+ throw pushedError;
7383
+ }
7384
+
7385
+ throw e;
7386
+ }
7387
+ }
7388
+
7389
+ link() {
7390
+ let bluePointer = this.blueGlobalThisPointer;
7391
+ let redPointer = this.redGlobalThisPointer;
7392
+
7393
+ for (let i = 0, len = arguments.length; i < len; i += 1) {
7394
+ const key = i < 0 || arguments.length <= i ? undefined : arguments[i];
7395
+ bluePointer = this.blueCallableGetPropertyValuePointer(bluePointer, key);
7396
+ redPointer = this.redCallableGetPropertyValuePointer(redPointer, key);
7057
7397
  }
7398
+
7399
+ this.redCallableLinkPointers(redPointer, bluePointer);
7400
+ this.blueCallableLinkPointers(bluePointer, redPointer);
7401
+ }
7402
+
7403
+ remap(target, blueDescriptors) {
7404
+ const keys = ReflectOwnKeys$1(blueDescriptors);
7405
+ const targetPointer = this.blueGetTransferableValue(target); // prettier-ignore
7406
+
7407
+ for (let i = 0, len = keys.length; i < len; i += 1) {
7408
+ const key = keys[i];
7409
+ const unsafeBlueDesc = blueDescriptors[key]; // Avoid poisoning by only installing own properties from blueDescriptors
7410
+ // eslint-disable-next-line prefer-object-spread
7411
+
7412
+ const safeBlueDesc = ObjectAssign$2({
7413
+ __proto__: null
7414
+ }, unsafeBlueDesc); // Install descriptor into the red side.
7415
+
7416
+ 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);
7417
+ }
7418
+ }
7419
+
7420
+ remapProto(target, proto) {
7421
+ const targetPointer = this.blueGetTransferableValue(target);
7422
+ const pointerOrNull = this.blueGetTransferableValue(proto);
7423
+ this.redCallableSetPrototypeOf(targetPointer, pointerOrNull);
7424
+ }
7425
+
7058
7426
  }
7059
7427
 
7060
- const { includes: ArrayProtoIncludes } = Array.prototype;
7061
- const { has: SetProtoHas } = Set.prototype;
7062
- const { apply: ReflectApply$2, getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor, ownKeys: ReflectOwnKeys, } = Reflect;
7428
+ const {
7429
+ includes: ArrayProtoIncludes
7430
+ } = Array.prototype;
7431
+ const {
7432
+ has: SetProtoHas
7433
+ } = Set.prototype;
7434
+ const {
7435
+ apply: ReflectApply$2,
7436
+ getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
7437
+ ownKeys: ReflectOwnKeys
7438
+ } = Reflect;
7063
7439
  /**
7064
7440
  * This list must be in sync with ecma-262, anything new added to the global object
7065
7441
  * should be considered, to decide whether or not they need remapping. The default
@@ -7079,194 +7455,147 @@ const { apply: ReflectApply$2, getOwnPropertyDescriptor: ReflectGetOwnPropertyDe
7079
7455
  * problematic, and requires a lot more work to guarantee that objects from both sides
7080
7456
  * can be considered equivalents (without identity discontinuity).
7081
7457
  */
7082
- const ESGlobalKeys = new Set([
7083
- // *** 19.1 Value Properties of the Global Object
7084
- 'globalThis',
7085
- 'Infinity',
7086
- 'NaN',
7087
- 'undefined',
7088
- // *** 19.2 Function Properties of the Global Object
7089
- 'eval',
7090
- 'isFinite',
7091
- 'isNaN',
7092
- 'parseFloat',
7093
- 'parseInt',
7094
- 'decodeURI',
7095
- 'decodeURIComponent',
7096
- 'encodeURI',
7097
- 'encodeURIComponent',
7098
- // *** 19.3 Constructor Properties of the Global Object
7099
- 'AggregateError',
7100
- 'Array',
7101
- 'ArrayBuffer',
7102
- 'BigInt',
7103
- 'BigInt64Array',
7104
- 'BigUint64Array',
7105
- 'Boolean',
7106
- 'DataView',
7107
- // 'Date', // Unstable & Remapped
7108
- 'Error',
7109
- 'EvalError',
7110
- 'FinalizationRegistry',
7111
- 'Float32Array',
7112
- 'Float64Array',
7113
- 'Function',
7114
- 'Int8Array',
7115
- 'Int16Array',
7116
- 'Int32Array',
7117
- // 'Map', // Remapped
7118
- 'Number',
7119
- 'Object',
7120
- // Allow Blue `Promise` constructor to overwrite the Red one so that promises
7121
- // created by the `Promise` constructor or APIs like `fetch` will work.
7122
- // 'Promise', // Remapped
7123
- 'Proxy',
7124
- 'RangeError',
7125
- 'ReferenceError',
7126
- 'RegExp',
7127
- // 'Set', // Remapped
7128
- 'SharedArrayBuffer',
7129
- 'String',
7130
- 'Symbol',
7131
- 'SyntaxError',
7132
- 'TypeError',
7133
- 'Uint8Array',
7134
- 'Uint8ClampedArray',
7135
- 'Uint16Array',
7136
- 'Uint32Array',
7137
- 'URIError',
7138
- // 'WeakMap', // Remapped
7139
- // 'WeakSet', // Remapped
7140
- 'WeakRef',
7141
- // *** 18.4 Other Properties of the Global Object
7142
- 'Atomics',
7143
- 'JSON',
7144
- 'Math',
7145
- 'Reflect',
7146
- // *** Annex B
7147
- 'escape',
7148
- 'unescape',
7149
- // *** ECMA-402
7150
- // 'Intl', // Unstable & Remapped
7151
- ]);
7152
- // These are foundational things that should never be wrapped but are equivalent
7458
+
7459
+ const ESGlobalKeys = new Set([// *** 19.1 Value Properties of the Global Object
7460
+ 'globalThis', 'Infinity', 'NaN', 'undefined', // *** 19.2 Function Properties of the Global Object
7461
+ 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', // *** 19.3 Constructor Properties of the Global Object
7462
+ 'AggregateError', 'Array', 'ArrayBuffer', 'BigInt', 'BigInt64Array', 'BigUint64Array', 'Boolean', 'DataView', // 'Date', // Unstable & Remapped
7463
+ 'Error', 'EvalError', 'FinalizationRegistry', 'Float32Array', 'Float64Array', 'Function', 'Int8Array', 'Int16Array', 'Int32Array', // 'Map', // Remapped
7464
+ 'Number', 'Object', // Allow Blue `Promise` constructor to overwrite the Red one so that promises
7465
+ // created by the `Promise` constructor or APIs like `fetch` will work.
7466
+ // 'Promise', // Remapped
7467
+ 'Proxy', 'RangeError', 'ReferenceError', 'RegExp', // 'Set', // Remapped
7468
+ 'SharedArrayBuffer', 'String', 'Symbol', 'SyntaxError', 'TypeError', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'URIError', // 'WeakMap', // Remapped
7469
+ // 'WeakSet', // Remapped
7470
+ 'WeakRef', // *** 18.4 Other Properties of the Global Object
7471
+ 'Atomics', 'JSON', 'Math', 'Reflect', // *** Annex B
7472
+ 'escape', 'unescape' // *** ECMA-402
7473
+ // 'Intl', // Unstable & Remapped
7474
+ ]); // These are foundational things that should never be wrapped but are equivalent
7153
7475
  // TODO: revisit this list.
7154
- const ReflectiveIntrinsicObjectNames = [
7155
- 'AggregateError',
7156
- 'Array',
7157
- 'Error',
7158
- 'EvalError',
7159
- 'Function',
7160
- 'Object',
7161
- 'Proxy',
7162
- 'RangeError',
7163
- 'ReferenceError',
7164
- 'SyntaxError',
7165
- 'TypeError',
7166
- 'URIError',
7167
- 'eval',
7168
- ];
7476
+
7477
+ const ReflectiveIntrinsicObjectNames = ['AggregateError', 'Array', 'Error', 'EvalError', 'Function', 'Object', 'Proxy', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', 'eval'];
7478
+
7169
7479
  function assignFilteredGlobalObjectShapeDescriptors(descriptorMap, source) {
7170
- const keys = ReflectOwnKeys(source);
7171
- for (let i = 0, len = keys.length; i < len; i += 1) {
7172
- // forcing to string here because of TypeScript's PropertyDescriptorMap
7173
- // definition, which doesn't support symbols as entries.
7174
- const key = keys[i];
7175
- // avoid overriding ECMAScript global names that correspond
7176
- // to global intrinsics. This guarantee that those entries
7177
- // will be ignored if present in the endowments object.
7178
- // TODO: what if the intent is to polyfill one of those
7179
- // intrinsics?
7180
- if (!isIntrinsicGlobalName(key) && !isReflectiveGlobalName(key)) {
7181
- const unsafeDesc = ReflectGetOwnPropertyDescriptor(source, key);
7182
- // Safari 14.0.x (macOS) and 14.2 (iOS) have a bug where 'showModalDialog'
7183
- // is returned in the list of own keys produces by ReflectOwnKeys(iframeWindow),
7184
- // however 'showModalDialog' is not an own property and produces
7185
- // undefined at ReflectGetOwnPropertyDescriptor(window, key);
7186
- //
7187
- // In all other browsers, 'showModalDialog' is not an own property
7188
- // and does not appear in the list produces by ReflectOwnKeys(iframeWindow).
7189
- //
7190
- // So, as a general rule: if there is not an own descriptor,
7191
- // ignore the entry and continue.
7192
- if (unsafeDesc) {
7193
- descriptorMap[key] = unsafeDesc;
7194
- }
7195
- }
7480
+ const keys = ReflectOwnKeys(source);
7481
+
7482
+ for (let i = 0, len = keys.length; i < len; i += 1) {
7483
+ // forcing to string here because of TypeScript's PropertyDescriptorMap
7484
+ // definition, which doesn't support symbols as entries.
7485
+ const key = keys[i]; // avoid overriding ECMAScript global names that correspond
7486
+ // to global intrinsics. This guarantee that those entries
7487
+ // will be ignored if present in the endowments object.
7488
+ // TODO: what if the intent is to polyfill one of those
7489
+ // intrinsics?
7490
+
7491
+ if (!ReflectApply$2(SetProtoHas, ESGlobalKeys, [key]) && !ReflectApply$2(ArrayProtoIncludes, ReflectiveIntrinsicObjectNames, [key])) {
7492
+ const unsafeDesc = ReflectGetOwnPropertyDescriptor(source, key); // Safari 14.0.x (macOS) and 14.2 (iOS) have a bug where 'showModalDialog'
7493
+ // is returned in the list of own keys produces by ReflectOwnKeys(iframeWindow),
7494
+ // however 'showModalDialog' is not an own property and produces
7495
+ // undefined at ReflectGetOwnPropertyDescriptor(window, key);
7496
+ //
7497
+ // In all other browsers, 'showModalDialog' is not an own property
7498
+ // and does not appear in the list produces by ReflectOwnKeys(iframeWindow).
7499
+ //
7500
+ // So, as a general rule: if there is not an own descriptor,
7501
+ // ignore the entry and continue.
7502
+
7503
+ if (unsafeDesc) {
7504
+ descriptorMap[key] = unsafeDesc;
7505
+ }
7196
7506
  }
7197
- return descriptorMap;
7198
- }
7199
- function isIntrinsicGlobalName(key) {
7200
- return ReflectApply$2(SetProtoHas, ESGlobalKeys, [key]);
7201
- }
7202
- function isReflectiveGlobalName(key) {
7203
- return ReflectApply$2(ArrayProtoIncludes, ReflectiveIntrinsicObjectNames, [key]);
7507
+ }
7508
+
7509
+ return descriptorMap;
7204
7510
  }
7511
+
7205
7512
  function linkIntrinsics(env, globalObjectVirtualizationTarget) {
7206
- // remapping intrinsics that are realm's agnostic
7207
- for (let i = 0, len = ReflectiveIntrinsicObjectNames.length; i < len; i += 1) {
7208
- const globalName = ReflectiveIntrinsicObjectNames[i];
7209
- const reflectiveValue = globalObjectVirtualizationTarget[globalName];
7210
- if (reflectiveValue) {
7211
- env.link(globalName);
7212
- // Proxy.prototype is undefined, being the only weird thing here
7213
- if (reflectiveValue.prototype) {
7214
- env.link(globalName, 'prototype');
7215
- }
7216
- }
7513
+ // remapping intrinsics that are realm's agnostic
7514
+ for (let i = 0, len = ReflectiveIntrinsicObjectNames.length; i < len; i += 1) {
7515
+ const globalName = ReflectiveIntrinsicObjectNames[i];
7516
+ const reflectiveValue = globalObjectVirtualizationTarget[globalName];
7517
+
7518
+ if (reflectiveValue) {
7519
+ env.link(globalName); // Proxy.prototype is undefined, being the only weird thing here
7520
+
7521
+ if (reflectiveValue.prototype) {
7522
+ env.link(globalName, 'prototype');
7523
+ }
7217
7524
  }
7525
+ }
7218
7526
  }
7219
- function getResolvedShapeDescriptors(...sources) {
7220
- const descriptors = {};
7221
- for (let i = 0, len = sources.length; i < len; i += 1) {
7222
- const source = sources[i];
7223
- if (source) {
7224
- assignFilteredGlobalObjectShapeDescriptors(descriptors, source);
7225
- }
7527
+
7528
+ function getResolvedShapeDescriptors() {
7529
+ const descriptors = {};
7530
+
7531
+ for (let i = 0, len = arguments.length; i < len; i += 1) {
7532
+ const source = i < 0 || arguments.length <= i ? undefined : arguments[i];
7533
+
7534
+ if (source) {
7535
+ assignFilteredGlobalObjectShapeDescriptors(descriptors, source);
7226
7536
  }
7227
- return descriptors;
7537
+ }
7538
+
7539
+ return descriptors;
7228
7540
  }
7229
7541
 
7230
7542
  const TypeErrorCtor = TypeError;
7543
+
7231
7544
  function validateRequiredGlobalShapeAndVirtualizationObjects(globalObjectShape, globalObjectVirtualizationTarget) {
7232
- if (!globalObjectShape) {
7233
- throw new TypeErrorCtor('Missing global object shape.');
7234
- }
7235
- if (!globalObjectVirtualizationTarget) {
7236
- throw new TypeErrorCtor('Missing global object virtualization target.');
7237
- }
7238
- return undefined;
7545
+ if (!globalObjectShape) {
7546
+ throw new TypeErrorCtor('Missing global object shape.');
7547
+ }
7548
+
7549
+ if (!globalObjectVirtualizationTarget) {
7550
+ throw new TypeErrorCtor('Missing global object virtualization target.');
7551
+ }
7552
+
7553
+ return undefined;
7239
7554
  }
7240
7555
 
7241
- const { assign: ObjectAssign$1, getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors } = Object;
7242
- const { getPrototypeOf: ReflectGetPrototypeOf, apply: ReflectApply$1 } = Reflect;
7243
- const { get: WeakMapProtoGet, set: WeakMapProtoSet } = WeakMap.prototype;
7556
+ const {
7557
+ assign: ObjectAssign$1,
7558
+ getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors
7559
+ } = Object;
7560
+ const {
7561
+ getPrototypeOf: ReflectGetPrototypeOf,
7562
+ apply: ReflectApply$1
7563
+ } = Reflect;
7564
+ const {
7565
+ get: WeakMapProtoGet,
7566
+ set: WeakMapProtoSet
7567
+ } = WeakMap.prototype;
7244
7568
  const cachedBlueGlobalMap = new WeakMap();
7569
+
7245
7570
  function getBaseReferences(window) {
7246
- const record = { __proto__: null };
7247
- // caching references to object values that can't be replaced
7248
- // window -> Window -> WindowProperties -> EventTarget
7249
- record.window = window.window;
7250
- record.document = window.document;
7251
- record.WindowProto = ReflectGetPrototypeOf(record.window);
7252
- record.WindowPropertiesProto = ReflectGetPrototypeOf(record.WindowProto);
7253
- record.EventTargetProto = ReflectGetPrototypeOf(record.WindowPropertiesProto);
7254
- record.DocumentProto = ReflectGetPrototypeOf(record.document);
7255
- return record;
7571
+ const record = {
7572
+ __proto__: null
7573
+ }; // caching references to object values that can't be replaced
7574
+ // window -> Window -> WindowProperties -> EventTarget
7575
+
7576
+ record.window = window.window;
7577
+ record.document = window.document;
7578
+ record.WindowProto = ReflectGetPrototypeOf(record.window);
7579
+ record.WindowPropertiesProto = ReflectGetPrototypeOf(record.WindowProto);
7580
+ record.EventTargetProto = ReflectGetPrototypeOf(record.WindowPropertiesProto);
7581
+ record.DocumentProto = ReflectGetPrototypeOf(record.document);
7582
+ return record;
7256
7583
  }
7584
+
7257
7585
  function getCachedBlueReferences(window) {
7258
- let record = ReflectApply$1(WeakMapProtoGet, cachedBlueGlobalMap, [window]);
7259
- if (record) {
7260
- return record;
7261
- }
7262
- record = getBaseReferences(window);
7263
- // caching the record
7264
- ReflectApply$1(WeakMapProtoSet, cachedBlueGlobalMap, [window, record]);
7265
- // intentionally avoiding remapping any Window.prototype descriptor,
7266
- // there is nothing in this prototype that needs to be remapped.
7267
- record.WindowProtoDescriptors = {};
7268
- record.EventTargetProtoDescriptors = ObjectGetOwnPropertyDescriptors(record.EventTargetProto);
7586
+ let record = ReflectApply$1(WeakMapProtoGet, cachedBlueGlobalMap, [window]);
7587
+
7588
+ if (record) {
7269
7589
  return record;
7590
+ }
7591
+
7592
+ record = getBaseReferences(window); // caching the record
7593
+
7594
+ ReflectApply$1(WeakMapProtoSet, cachedBlueGlobalMap, [window, record]); // intentionally avoiding remapping any Window.prototype descriptor,
7595
+ // there is nothing in this prototype that needs to be remapped.
7596
+
7597
+ record.EventTargetProtoDescriptors = ObjectGetOwnPropertyDescriptors(record.EventTargetProto);
7598
+ return record;
7270
7599
  }
7271
7600
  /**
7272
7601
  * Initialization operation to capture and cache all unforgeable references
@@ -7274,6 +7603,8 @@ function getCachedBlueReferences(window) {
7274
7603
  * usually help because this library runs before anything else that can poison
7275
7604
  * the environment.
7276
7605
  */
7606
+
7607
+
7277
7608
  getCachedBlueReferences(window);
7278
7609
  /**
7279
7610
  * global descriptors are a combination of 3 set of descriptors:
@@ -7302,212 +7633,254 @@ getCachedBlueReferences(window);
7302
7633
  * that will be installed (via the membrane) as global descriptors in
7303
7634
  * the red realm.
7304
7635
  */
7636
+
7305
7637
  function filterWindowDescriptors(endowmentsDescriptors) {
7306
- const to = {};
7307
- // endowments descriptors will overrule any default descriptor inferred
7308
- // from the detached iframe. note that they are already filtered, not need
7309
- // to check against intrinsics again.
7310
- ObjectAssign$1(to, endowmentsDescriptors);
7311
- // removing unforgeable descriptors that cannot be installed
7312
- delete to.location;
7313
- delete to.document;
7314
- delete to.window;
7315
- delete to.top;
7316
- // Some DOM APIs do brand checks for TypeArrays and others objects,
7317
- // in this case, if the API is not dangerous, and works in a detached
7318
- // iframe, we can let the sandbox to use the iframe's api directly,
7319
- // instead of remapping it to the blue realm.
7320
- // TODO [issue #67]: review this list
7321
- delete to.crypto;
7322
- // others browser specific undeniable globals
7323
- delete to.chrome;
7324
- return to;
7638
+ const to = {}; // endowments descriptors will overrule any default descriptor inferred
7639
+ // from the detached iframe. note that they are already filtered, not need
7640
+ // to check against intrinsics again.
7641
+
7642
+ ObjectAssign$1(to, endowmentsDescriptors); // removing unforgeable descriptors that cannot be installed
7643
+
7644
+ delete to.document;
7645
+ delete to.location;
7646
+ delete to.top;
7647
+ delete to.window; // Some DOM APIs do brand checks for TypeArrays and others objects,
7648
+ // in this case, if the API is not dangerous, and works in a detached
7649
+ // iframe, we can let the sandbox to use the iframe's api directly,
7650
+ // instead of remapping it to the blue realm.
7651
+ // TODO [issue #67]: review this list
7652
+
7653
+ delete to.crypto; // others browser specific undeniable globals
7654
+
7655
+ delete to.chrome;
7656
+ return to;
7325
7657
  }
7658
+
7326
7659
  function tameDOM(env, blueRefs, endowmentsDescriptors) {
7327
- // adjusting proto chain of window.document
7328
- env.remapProto(blueRefs.document, blueRefs.DocumentProto);
7329
- const globalDescriptors = filterWindowDescriptors(endowmentsDescriptors);
7330
- // remapping globals
7331
- env.remap(blueRefs.window, globalDescriptors);
7332
- // remapping unforgeable objects
7333
- env.remap(blueRefs.EventTargetProto, blueRefs.EventTargetProtoDescriptors);
7334
- env.remap(blueRefs.WindowProto, blueRefs.WindowProtoDescriptors);
7335
- /**
7336
- * WindowProperties.prototype is magical, it provide access to any
7337
- * object that "clobbers" the WindowProxy instance for easy access. E.g.:
7338
- *
7339
- * var object = document.createElement('object');
7340
- * object.id = 'foo';
7341
- * document.body.appendChild(object);
7342
- *
7343
- * The result of this code is that `window.foo` points to the HTMLObjectElement
7344
- * instance, and in some browsers, those are not even reported as descriptors
7345
- * installed on WindowProperties.prototype, but they are instead magically
7346
- * resolved when accessing `foo` from `window`.
7347
- *
7348
- * This forces us to avoid using the descriptors from the blue window directly,
7349
- * and instead, we might only need to shadow the descriptors installed in the brand
7350
- * new iframe, that way any magical entry from the blue window will not be
7351
- * installed on the iframe. That turns out to be also empty, therefore we
7352
- * don't need to remap `blueRefs.WindowPropertiesProto` descriptors at all.
7353
- */
7660
+ // adjusting proto chain of window.document
7661
+ env.remapProto(blueRefs.document, blueRefs.DocumentProto);
7662
+ const globalDescriptors = filterWindowDescriptors(endowmentsDescriptors); // remapping globals
7663
+
7664
+ env.remap(blueRefs.window, globalDescriptors); // remapping unforgeable objects
7665
+
7666
+ env.remap(blueRefs.EventTargetProto, blueRefs.EventTargetProtoDescriptors);
7667
+ /**
7668
+ * WindowProperties.prototype is magical, it provide access to any
7669
+ * object that "clobbers" the WindowProxy instance for easy access. E.g.:
7670
+ *
7671
+ * var object = document.createElement('object');
7672
+ * object.id = 'foo';
7673
+ * document.body.appendChild(object);
7674
+ *
7675
+ * The result of this code is that `window.foo` points to the HTMLObjectElement
7676
+ * instance, and in some browsers, those are not even reported as descriptors
7677
+ * installed on WindowProperties.prototype, but they are instead magically
7678
+ * resolved when accessing `foo` from `window`.
7679
+ *
7680
+ * This forces us to avoid using the descriptors from the blue window directly,
7681
+ * and instead, we might only need to shadow the descriptors installed in the brand
7682
+ * new iframe, that way any magical entry from the blue window will not be
7683
+ * installed on the iframe. That turns out to be also empty, therefore we
7684
+ * don't need to remap `blueRefs.WindowPropertiesProto` descriptors at all.
7685
+ */
7354
7686
  }
7687
+
7355
7688
  function linkUnforgeables(env, blueGlobalThis) {
7356
- // The test of instance of event target is important to discard environments
7357
- // in which a fake window (e.g. jest) is not following the specs, and can
7358
- // break this membrane.
7359
- if (blueGlobalThis.EventTarget && blueGlobalThis instanceof EventTarget) {
7360
- // window.document
7361
- env.link('document');
7362
- // window.__proto__ (aka Window.prototype)
7363
- env.link('__proto__');
7364
- // window.__proto__.__proto__ (aka WindowProperties.prototype)
7365
- env.link('__proto__', '__proto__');
7366
- // window.__proto__.__proto__.__proto__ (aka EventTarget.prototype)
7367
- env.link('__proto__', '__proto__', '__proto__');
7368
- }
7689
+ // The test of instance of event target is important to discard environments
7690
+ // in which a fake window (e.g. jest) is not following the specs, and can
7691
+ // break this membrane.
7692
+ if (blueGlobalThis.EventTarget && blueGlobalThis instanceof EventTarget) {
7693
+ // window.document
7694
+ env.link('document'); // window.__proto__ (aka Window.prototype)
7695
+
7696
+ env.link('__proto__'); // window.__proto__.__proto__ (aka WindowProperties.prototype)
7697
+
7698
+ env.link('__proto__', '__proto__'); // window.__proto__.__proto__.__proto__ (aka EventTarget.prototype)
7699
+
7700
+ env.link('__proto__', '__proto__', '__proto__');
7701
+ }
7369
7702
  }
7370
7703
 
7371
7704
  const IFRAME_SANDBOX_ATTRIBUTE_VALUE = 'allow-same-origin allow-scripts';
7372
7705
  const emptyArray = [];
7373
- const { close: DocumentProtoClose, createElement: DocumentProtoCreateElement, open: DocumentProtoOpen, } = document;
7374
- const { remove: ElementProtoRemove, setAttribute: ElementProtoSetAttribute } = Element.prototype;
7375
- const { appendChild: NodeProtoAppendChild } = Node.prototype;
7376
- const { assign: ObjectAssign } = Object;
7377
- const {
7378
- // eslint-disable-next-line @typescript-eslint/naming-convention
7379
- __lookupGetter__: ObjectProto__lookupGetter__, hasOwnProperty: ObjectProtoHasOwnProperty, } = Object.prototype;
7380
- const { apply: ReflectApply } = Reflect;
7706
+ const {
7707
+ close: DocumentProtoClose,
7708
+ createElement: DocumentProtoCreateElement,
7709
+ open: DocumentProtoOpen
7710
+ } = document;
7711
+ const {
7712
+ remove: ElementProtoRemove,
7713
+ setAttribute: ElementProtoSetAttribute
7714
+ } = Element.prototype;
7715
+ const {
7716
+ appendChild: NodeProtoAppendChild
7717
+ } = Node.prototype;
7718
+ const {
7719
+ assign: ObjectAssign
7720
+ } = Object;
7721
+ const {
7722
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7723
+ __lookupGetter__: ObjectProto__lookupGetter__,
7724
+ hasOwnProperty: ObjectProtoHasOwnProperty
7725
+ } = Object.prototype;
7726
+ const {
7727
+ apply: ReflectApply
7728
+ } = Reflect;
7729
+
7381
7730
  function ObjectLookupOwnGetter(obj, key) {
7382
- // Since this function is only used internally, and would not otherwise be
7383
- // reachable by user code, istanbul can ignore test coverage for the
7384
- // following condition.
7385
- // istanbul ignore next
7386
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
7387
- if (obj === null || obj === undefined || !ReflectApply(ObjectProtoHasOwnProperty, obj, [key])) {
7388
- return undefined;
7389
- }
7390
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
7391
- return ReflectApply(ObjectProto__lookupGetter__, obj, [key]);
7731
+ // Since this function is only used internally, and would not otherwise be
7732
+ // reachable by user code, istanbul can ignore test coverage for the
7733
+ // following condition.
7734
+ // istanbul ignore next
7735
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
7736
+ if (obj === null || obj === undefined || !ReflectApply(ObjectProtoHasOwnProperty, obj, [key])) {
7737
+ return undefined;
7738
+ } // eslint-disable-next-line @typescript-eslint/no-use-before-define
7739
+
7740
+
7741
+ return ReflectApply(ObjectProto__lookupGetter__, obj, [key]);
7392
7742
  }
7743
+
7393
7744
  const DocumentProtoBodyGetter = ObjectLookupOwnGetter(Document.prototype, 'body');
7394
7745
  const HTMLElementProtoStyleGetter = ObjectLookupOwnGetter(HTMLElement.prototype, 'style');
7395
7746
  const HTMLIFrameElementProtoContentWindowGetter = ObjectLookupOwnGetter(HTMLIFrameElement.prototype, 'contentWindow');
7396
7747
  const NodeProtoIsConnectedGetter = ObjectLookupOwnGetter(Node.prototype, 'isConnected');
7397
7748
  const NodeProtoLastChildGetter = ObjectLookupOwnGetter(Node.prototype, 'lastChild');
7749
+
7398
7750
  function DocumentBody(doc) {
7399
- return ReflectApply(DocumentProtoBodyGetter, doc, emptyArray);
7751
+ return ReflectApply(DocumentProtoBodyGetter, doc, emptyArray);
7400
7752
  }
7753
+
7401
7754
  function DocumentClose(doc) {
7402
- return ReflectApply(DocumentProtoClose, doc, emptyArray);
7755
+ return ReflectApply(DocumentProtoClose, doc, emptyArray);
7403
7756
  }
7757
+
7404
7758
  function DocumentCreateElement(doc, tagName) {
7405
- return ReflectApply(DocumentProtoCreateElement, doc, [tagName]);
7759
+ return ReflectApply(DocumentProtoCreateElement, doc, [tagName]);
7406
7760
  }
7761
+
7407
7762
  function DocumentOpen(doc) {
7408
- return ReflectApply(DocumentProtoOpen, doc, emptyArray);
7763
+ return ReflectApply(DocumentProtoOpen, doc, emptyArray);
7409
7764
  }
7765
+
7410
7766
  function ElementSetAttribute(el, name, value) {
7411
- return ReflectApply(ElementProtoSetAttribute, el, [name, value]);
7767
+ return ReflectApply(ElementProtoSetAttribute, el, [name, value]);
7412
7768
  }
7769
+
7413
7770
  function ElementRemove(element) {
7414
- return ReflectApply(ElementProtoRemove, element, emptyArray);
7771
+ return ReflectApply(ElementProtoRemove, element, emptyArray);
7415
7772
  }
7773
+
7416
7774
  function HTMLElementStyleGetter(el) {
7417
- return ReflectApply(HTMLElementProtoStyleGetter, el, emptyArray);
7775
+ return ReflectApply(HTMLElementProtoStyleGetter, el, emptyArray);
7418
7776
  }
7777
+
7419
7778
  function HTMLIFrameElementContentWindowGetter(iframe) {
7420
- return ReflectApply(HTMLIFrameElementProtoContentWindowGetter, iframe, emptyArray);
7779
+ return ReflectApply(HTMLIFrameElementProtoContentWindowGetter, iframe, emptyArray);
7421
7780
  }
7781
+
7422
7782
  function NodeAppendChild(parent, child) {
7423
- return ReflectApply(NodeProtoAppendChild, parent, [child]);
7424
- }
7425
- // It's impossible to test whether NodeLastChild(document) is reached
7783
+ return ReflectApply(NodeProtoAppendChild, parent, [child]);
7784
+ } // It's impossible to test whether NodeLastChild(document) is reached
7426
7785
  // in a normal Karma test environment, because the document will always
7427
7786
  // have a body element. Ignore this in coverage reporting to
7428
7787
  // avoid a penalty.
7429
7788
  // istanbul ignore next
7789
+
7790
+
7430
7791
  function NodeLastChild(node) {
7431
- return ReflectApply(NodeProtoLastChildGetter, node, emptyArray);
7792
+ return ReflectApply(NodeProtoLastChildGetter, node, emptyArray);
7432
7793
  }
7794
+
7433
7795
  function NodeIsConnected(node) {
7434
- return ReflectApply(NodeProtoIsConnectedGetter, node, emptyArray);
7796
+ return ReflectApply(NodeProtoIsConnectedGetter, node, emptyArray);
7435
7797
  }
7798
+
7436
7799
  function createDetachableIframe$1() {
7437
- // @ts-ignore document global ref - in browsers
7438
- const iframe = DocumentCreateElement(document, 'iframe');
7439
- // It's impossible to test whether NodeLastChild(document) is reached
7440
- // in a normal Karma test environment. (See explanation above,
7441
- // at NodeLastChild definition.)
7442
- const parent = DocumentBody(document) || /* istanbul ignore next */ NodeLastChild(document);
7443
- const style = HTMLElementStyleGetter(iframe);
7444
- style.display = 'none';
7445
- ElementSetAttribute(iframe, 'sandbox', IFRAME_SANDBOX_ATTRIBUTE_VALUE);
7446
- NodeAppendChild(parent, iframe);
7447
- return iframe;
7800
+ // @ts-ignore document global ref - in browsers
7801
+ const iframe = DocumentCreateElement(document, 'iframe'); // It's impossible to test whether NodeLastChild(document) is reached
7802
+ // in a normal Karma test environment. (See explanation above,
7803
+ // at NodeLastChild definition.)
7804
+
7805
+ const parent = DocumentBody(document) ||
7806
+ /* istanbul ignore next */
7807
+ NodeLastChild(document);
7808
+ const style = HTMLElementStyleGetter(iframe);
7809
+ style.display = 'none';
7810
+ ElementSetAttribute(iframe, 'sandbox', IFRAME_SANDBOX_ATTRIBUTE_VALUE);
7811
+ NodeAppendChild(parent, iframe);
7812
+ return iframe;
7448
7813
  }
7814
+
7449
7815
  function removeIframe(iframe) {
7450
- // In Chrome debugger statements will be ignored when the iframe is removed
7451
- // from the document. Other browsers like Firefox and Safari work as expected.
7452
- // https://bugs.chromium.org/p/chromium/issues/detail?id=1015462
7453
- // Because the detachable iframe is created, and then optionally removed, all
7454
- // within the execution of createVirtualEnvironment, there is no point in which
7455
- // test code can interfere with iframe element, or its prototype chain, in
7456
- // order to remove it from the DOM, or stub the isConnected accessor
7457
- // (the latter is already too late before createVirtualEnvironment is ever called).
7458
- // For this reason, ignore the lack of `else` path coverage.
7459
- //
7460
- // istanbul ignore else
7461
- if (NodeIsConnected(iframe)) {
7462
- ElementRemove(iframe);
7463
- }
7816
+ // In Chrome debugger statements will be ignored when the iframe is removed
7817
+ // from the document. Other browsers like Firefox and Safari work as expected.
7818
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=1015462
7819
+ // Because the detachable iframe is created, and then optionally removed, all
7820
+ // within the execution of createVirtualEnvironment, there is no point in which
7821
+ // test code can interfere with iframe element, or its prototype chain, in
7822
+ // order to remove it from the DOM, or stub the isConnected accessor
7823
+ // (the latter is already too late before createVirtualEnvironment is ever called).
7824
+ // For this reason, ignore the lack of `else` path coverage.
7825
+ //
7826
+ // istanbul ignore else
7827
+ if (NodeIsConnected(iframe)) {
7828
+ ElementRemove(iframe);
7829
+ }
7464
7830
  }
7831
+
7465
7832
  const createHooksCallback = createMembraneMarshall();
7833
+
7466
7834
  function createVirtualEnvironment(globalObjectShape, globalObjectVirtualizationTarget, providedOptions) {
7467
- validateRequiredGlobalShapeAndVirtualizationObjects(globalObjectShape, globalObjectVirtualizationTarget);
7468
- // eslint-disable-next-line prefer-object-spread
7469
- const options = ObjectAssign({
7470
- __proto__: null,
7471
- keepAlive: false,
7472
- }, providedOptions);
7473
- // eslint-disable-next-line prefer-object-spread
7474
- const { distortionCallback, endowments = {}, keepAlive, support, instrumentation } = options;
7475
- const iframe = createDetachableIframe$1();
7476
- const redWindow = HTMLIFrameElementContentWindowGetter(iframe).window;
7477
- const { document: redDocument } = redWindow;
7478
- const blueConnector = createHooksCallback;
7479
- const redConnector = createConnector(redWindow.eval);
7480
- // Extract the global references and descriptors before any interference.
7481
- const blueRefs = getCachedBlueReferences(globalObjectVirtualizationTarget);
7482
- // Create a new environment.
7483
- const env = new VirtualEnvironment({
7484
- blueConnector,
7485
- distortionCallback,
7486
- redConnector,
7487
- support,
7488
- instrumentation,
7489
- });
7490
- env.link('window');
7491
- linkIntrinsics(env, globalObjectVirtualizationTarget);
7492
- linkUnforgeables(env, globalObjectVirtualizationTarget);
7493
- tameDOM(env, blueRefs, getResolvedShapeDescriptors(globalObjectShape, endowments));
7494
- // Once we get the iframe info ready, and all mapped, we can proceed
7495
- // to detach the iframe only if the keepAlive option isn't true.
7496
- if (keepAlive !== true) {
7497
- removeIframe(iframe);
7498
- }
7499
- else {
7500
- // TODO: Temporary hack to preserve the document reference in Firefox.
7501
- // https://bugzilla.mozilla.org/show_bug.cgi?id=543435
7502
- DocumentOpen(redDocument);
7503
- DocumentClose(redDocument);
7504
- }
7505
- return env;
7835
+ validateRequiredGlobalShapeAndVirtualizationObjects(globalObjectShape, globalObjectVirtualizationTarget); // eslint-disable-next-line prefer-object-spread
7836
+
7837
+ const options = ObjectAssign({
7838
+ __proto__: null,
7839
+ keepAlive: false
7840
+ }, providedOptions); // eslint-disable-next-line prefer-object-spread
7841
+
7842
+ const {
7843
+ distortionCallback,
7844
+ endowments = {},
7845
+ keepAlive,
7846
+ support,
7847
+ instrumentation
7848
+ } = options;
7849
+ const iframe = createDetachableIframe$1();
7850
+ const redWindow = HTMLIFrameElementContentWindowGetter(iframe).window;
7851
+ const {
7852
+ document: redDocument
7853
+ } = redWindow;
7854
+ const blueConnector = createHooksCallback;
7855
+ const redConnector = createConnector(redWindow.eval); // Extract the global references and descriptors before any interference.
7856
+
7857
+ const blueRefs = getCachedBlueReferences(globalObjectVirtualizationTarget); // Create a new environment.
7858
+
7859
+ const env = new VirtualEnvironment({
7860
+ blueConnector,
7861
+ distortionCallback,
7862
+ redConnector,
7863
+ support,
7864
+ instrumentation
7865
+ });
7866
+ env.link('window');
7867
+ linkIntrinsics(env, globalObjectVirtualizationTarget);
7868
+ linkUnforgeables(env, globalObjectVirtualizationTarget);
7869
+ tameDOM(env, blueRefs, getResolvedShapeDescriptors(globalObjectShape, endowments)); // Once we get the iframe info ready, and all mapped, we can proceed
7870
+ // to detach the iframe only if the keepAlive option isn't true.
7871
+
7872
+ if (keepAlive !== true) {
7873
+ removeIframe(iframe);
7874
+ } else {
7875
+ // TODO: Temporary hack to preserve the document reference in Firefox.
7876
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=543435
7877
+ DocumentOpen(redDocument);
7878
+ DocumentClose(redDocument);
7879
+ }
7880
+
7881
+ return env;
7506
7882
  }
7507
7883
 
7508
- /*!
7509
- * Copyright (C) 2019 salesforce.com, inc.
7510
- */
7511
7884
  let lockerBlueRealmGlobalObjectShape;
7512
7885
  let lockerEvalContextValue;
7513
7886
  let lockerEvalHelpersValue;
@@ -7746,8 +8119,8 @@ function createSandbox(key, distortionFactory, endowments, instrumentation) {
7746
8119
  const headRef = docRef.head;
7747
8120
 
7748
8121
  function DocumentCreateElement(doc) {
7749
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key2 = 1; _key2 < _len; _key2++) {
7750
- args[_key2 - 1] = arguments[_key2];
8122
+ for (var _len10 = arguments.length, args = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
8123
+ args[_key10 - 1] = arguments[_key10];
7751
8124
  }
7752
8125
 
7753
8126
  return ReflectApply(DocumentProtoCreateElement, doc, args);
@@ -7766,8 +8139,8 @@ function createSandbox(key, distortionFactory, endowments, instrumentation) {
7766
8139
  }
7767
8140
 
7768
8141
  function EventTargetAddEventListener(target) {
7769
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key3 = 1; _key3 < _len2; _key3++) {
7770
- args[_key3 - 1] = arguments[_key3];
8142
+ for (var _len11 = arguments.length, args = new Array(_len11 > 1 ? _len11 - 1 : 0), _key11 = 1; _key11 < _len11; _key11++) {
8143
+ args[_key11 - 1] = arguments[_key11];
7771
8144
  }
7772
8145
 
7773
8146
  return ReflectApply(EventTargetProtoAddEventListener, target, args);
@@ -8068,6 +8441,6 @@ function evaluateInCoreSandbox(_key, sourceText, context, endowments, instrument
8068
8441
  activityEvaluateInCoreSandbox.stop();
8069
8442
  return result;
8070
8443
  }
8071
- /*! version: 0.14.13 */
8444
+ /*! version: 0.14.15 */
8072
8445
 
8073
8446
  export { CORE_SANDBOX_KEY, evaluateInCoreSandbox, evaluateInSandbox };