poe-code 14.0.69 → 14.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -123052,7 +123052,7 @@ var init_parser3 = __esm({
123052
123052
  await: true
123053
123053
  };
123054
123054
  Parser = class {
123055
- constructor(tokens, source, compilation, functionContext = "normal", lexicalContext = { ...ordinaryFunctionContext, newTarget: false }) {
123055
+ constructor(tokens, source, compilation, functionContext = "top-level", lexicalContext = { ...ordinaryFunctionContext, newTarget: false }) {
123056
123056
  this.tokens = tokens;
123057
123057
  this.source = source;
123058
123058
  this.compilation = compilation;
@@ -123225,7 +123225,7 @@ var init_parser3 = __esm({
123225
123225
  ...this.lexicalContext,
123226
123226
  return: true,
123227
123227
  await: isAsync || this.lexicalContext.strictAwait !== true
123228
- }, () => this.parseArrowFunctionBody(params));
123228
+ }, () => this.parseArrowFunctionBody(params, isAsync));
123229
123229
  return this.withFunctionSource({
123230
123230
  type: "ArrowFunctionExpression",
123231
123231
  async: isAsync,
@@ -123265,11 +123265,11 @@ var init_parser3 = __esm({
123265
123265
  this.conditionalExpressionDepth -= 1;
123266
123266
  }
123267
123267
  }
123268
- parseArrowFunctionBody(params) {
123268
+ parseArrowFunctionBody(params, async) {
123269
123269
  if (this.currentToken().type === "punctuator" && this.currentToken().value === "{") {
123270
- return this.withFunctionContext("normal", () => this.parseBlockStatement(params));
123270
+ return this.withFunctionContext(async ? "async" : "normal", () => this.parseBlockStatement(params));
123271
123271
  }
123272
- return this.withFunctionContext("normal", () => this.parseExpression().node);
123272
+ return this.withFunctionContext(async ? "async" : "normal", () => this.parseExpression().node);
123273
123273
  }
123274
123274
  parseBlockStatement(params, catchParam) {
123275
123275
  const start = this.expectPunctuator("{");
@@ -123544,9 +123544,16 @@ var init_parser3 = __esm({
123544
123544
  }
123545
123545
  parseForStatement(labels) {
123546
123546
  const forToken = this.expectKeyword("for");
123547
+ const awaitToken = this.consumeKeyword("await");
123548
+ if (awaitToken !== void 0 && this.functionContext !== "top-level" && this.functionContext !== "async" && this.functionContext !== "async-generator") {
123549
+ throw new Error("for await is only valid at top level or inside an async function.");
123550
+ }
123547
123551
  return this.withScope(() => {
123548
123552
  this.expectPunctuator("(");
123549
123553
  const iterationOperator = this.findTopLevelForIterationOperator(this.index);
123554
+ if (awaitToken !== void 0 && iterationOperator?.value !== "of") {
123555
+ throw new Error("for await requires an of loop.");
123556
+ }
123550
123557
  if (iterationOperator?.value === "in") {
123551
123558
  const left = this.parseForInLeft();
123552
123559
  this.expectKeyword("in");
@@ -123570,6 +123577,7 @@ var init_parser3 = __esm({
123570
123577
  const body2 = this.withLoopContext(() => this.parseStatement());
123571
123578
  return {
123572
123579
  type: "ForOfStatement",
123580
+ ...awaitToken === void 0 ? {} : { await: true },
123573
123581
  left,
123574
123582
  right,
123575
123583
  body: body2,
@@ -123922,7 +123930,7 @@ var init_parser3 = __esm({
123922
123930
  if (accessor === "set" && (params.length !== 1 || params[0]?.type === "RestElement"))
123923
123931
  throw new Error("A setter must have exactly one non-rest parameter.");
123924
123932
  const bodyTokenIndex = this.index;
123925
- const body = this.withFunctionContext(generator ? async ? "async-generator" : "generator" : "normal", () => this.parseBlockStatement(params));
123933
+ const body = this.withFunctionContext(generator ? async ? "async-generator" : "generator" : async ? "async" : "normal", () => this.parseBlockStatement(params));
123926
123934
  if (accessor === "set" && params[0]?.type !== "Identifier") {
123927
123935
  let directiveTokenIndex = bodyTokenIndex + 1;
123928
123936
  for (const statement of body.body) {
@@ -129946,7 +129954,199 @@ var init_running_state = __esm({
129946
129954
  }
129947
129955
  });
129948
129956
 
129957
+ // packages/safe-js/src/interp/jobs.ts
129958
+ import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
129959
+ function runPromiseJob(task) {
129960
+ const job = activeJob.getStore();
129961
+ return job === void 0 ? Promise.resolve().then(task) : job.queue.run(task);
129962
+ }
129963
+ function runAsyncPrefix(task) {
129964
+ const parent = activeJob.getStore();
129965
+ if (parent === void 0) return task();
129966
+ let owner = parent;
129967
+ while (owner !== void 0 && !owner.ownsExecution) owner = owner.prefixParent;
129968
+ if (owner === void 0) return parent.queue.run(task);
129969
+ const job = { queue: parent.queue, ownsExecution: false, prefixParent: parent };
129970
+ return activeJob.run(job, async () => {
129971
+ try {
129972
+ return await task();
129973
+ } finally {
129974
+ job.queue.release(job);
129975
+ }
129976
+ });
129977
+ }
129978
+ async function suspendJob(pending) {
129979
+ const job = activeJob.getStore();
129980
+ if (job === void 0) return pending;
129981
+ job.queue.release(job);
129982
+ try {
129983
+ return await pending;
129984
+ } finally {
129985
+ await job.queue.acquire(job);
129986
+ }
129987
+ }
129988
+ var activeJob, SandboxJobQueue;
129989
+ var init_jobs4 = __esm({
129990
+ "packages/safe-js/src/interp/jobs.ts"() {
129991
+ "use strict";
129992
+ activeJob = new AsyncLocalStorage7();
129993
+ SandboxJobQueue = class {
129994
+ running = false;
129995
+ pending = [];
129996
+ ready = [];
129997
+ idle = [];
129998
+ generation = 0;
129999
+ acquire(job) {
130000
+ return new Promise((resolve16) => {
130001
+ this.pending.push(() => {
130002
+ this.running = true;
130003
+ this.generation += 1;
130004
+ job.ownsExecution = true;
130005
+ resolve16();
130006
+ });
130007
+ this.advance();
130008
+ });
130009
+ }
130010
+ release(job) {
130011
+ job.prefixParent = void 0;
130012
+ if (!job.ownsExecution) return;
130013
+ job.ownsExecution = false;
130014
+ this.running = false;
130015
+ this.advance();
130016
+ }
130017
+ async run(task) {
130018
+ const job = { queue: this, ownsExecution: false };
130019
+ await this.acquire(job);
130020
+ return activeJob.run(job, async () => {
130021
+ try {
130022
+ return await task();
130023
+ } finally {
130024
+ this.release(job);
130025
+ }
130026
+ });
130027
+ }
130028
+ async drain() {
130029
+ let idleTurns = 0;
130030
+ while (idleTurns < 20) {
130031
+ const generation = this.generation;
130032
+ if (this.running) await new Promise((resolve16) => this.idle.push(resolve16));
130033
+ await Promise.resolve();
130034
+ idleTurns = generation === this.generation ? idleTurns + 1 : 0;
130035
+ }
130036
+ }
130037
+ advance() {
130038
+ if (this.running) return;
130039
+ if (this.ready.length === 0 && this.pending.length > 0) {
130040
+ const empty = this.ready;
130041
+ this.ready = this.pending.reverse();
130042
+ this.pending = empty;
130043
+ }
130044
+ const next = this.ready.pop();
130045
+ if (next !== void 0) {
130046
+ next();
130047
+ } else {
130048
+ for (const resolve16 of this.idle.splice(0)) resolve16();
130049
+ }
130050
+ }
130051
+ };
130052
+ }
130053
+ });
130054
+
129949
130055
  // packages/safe-js/src/interp/iteration.ts
130056
+ function getSandboxAsyncIterator(value, budget, context, signal) {
130057
+ if (isSandboxGenerator(value) && value.async) {
130058
+ return { ...generatorIterator(value, budget), asyncProtocol: true };
130059
+ }
130060
+ if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
130061
+ const method = value[Symbol.asyncIterator];
130062
+ if (method !== void 0 && method !== null) {
130063
+ if (typeof method !== "function") throw new TypeError("Async iterator method must be callable.");
130064
+ const iterator2 = Reflect.apply(method, value, []);
130065
+ if (typeof iterator2 !== "object" && typeof iterator2 !== "function" || iterator2 === null) {
130066
+ throw new TypeError("Async iterator must be an object.");
130067
+ }
130068
+ const next = iterator2.next;
130069
+ const invoke3 = async (operation, args) => {
130070
+ if (typeof operation !== "function") throw new TypeError("Async iterator operation must be callable.");
130071
+ const pending = Promise.resolve(Reflect.apply(operation, iterator2, args)).then((result2) => ({ result: result2 }));
130072
+ const { result } = await awaitWithSignal(pending, signal);
130073
+ if (typeof result !== "object" && typeof result !== "function" || result === null) {
130074
+ throw new TypeError("Iterator result must be an object.");
130075
+ }
130076
+ return {
130077
+ get done() {
130078
+ return result.done;
130079
+ },
130080
+ get value() {
130081
+ return result.value;
130082
+ }
130083
+ };
130084
+ };
130085
+ return {
130086
+ asyncProtocol: true,
130087
+ retainedValue: value,
130088
+ next: (...args) => invoke3(next, args),
130089
+ get return() {
130090
+ const operation = iterator2.return;
130091
+ return operation === void 0 || operation === null ? void 0 : (...args) => invoke3(operation, args);
130092
+ },
130093
+ get throw() {
130094
+ const operation = iterator2.throw;
130095
+ return operation === void 0 || operation === null ? void 0 : (...args) => invoke3(operation, args);
130096
+ }
130097
+ };
130098
+ }
130099
+ }
130100
+ const iterator = getSandboxIterator(value, budget, context);
130101
+ if (iterator === void 0) return void 0;
130102
+ const invoke2 = async (method, args) => {
130103
+ const operation = iterator[method];
130104
+ if (operation === void 0) {
130105
+ if (method === "throw") {
130106
+ await closeIterator(iterator);
130107
+ throw new TypeError("Delegated iterator does not provide a throw method.");
130108
+ }
130109
+ return { done: true, value: args[0] };
130110
+ }
130111
+ const returned = operation(...args);
130112
+ const result = iterator.generator || iterator.asynchronous ? await returned : returned;
130113
+ if (typeof result !== "object" && typeof result !== "function" || result === null) {
130114
+ throw new TypeError("Iterator result must be an object.");
130115
+ }
130116
+ const done = Boolean(result.done);
130117
+ const resultValue = result.value;
130118
+ try {
130119
+ return { done, value: await awaitSandboxValue(resultValue, signal, budget) };
130120
+ } catch (error3) {
130121
+ if (isFatalSandboxError(error3) || error3 instanceof HostCallResumabilityError) throw error3;
130122
+ if (!done && method !== "return") await closeIterator(iterator, true);
130123
+ throw error3;
130124
+ }
130125
+ };
130126
+ return {
130127
+ asyncProtocol: true,
130128
+ snapshotIndex: iterator.snapshotIndex,
130129
+ get retainedValue() {
130130
+ return iterator.retainedValue;
130131
+ },
130132
+ next: (...args) => invoke2("next", args),
130133
+ return: (...args) => invoke2("return", args),
130134
+ throw: (...args) => invoke2("throw", args)
130135
+ };
130136
+ }
130137
+ async function closeIterator(iterator, preserveThrow = false) {
130138
+ try {
130139
+ const close = iterator.return;
130140
+ if (close === void 0) return;
130141
+ const returned = close();
130142
+ const result = iterator.asyncProtocol ? await suspendJob(Promise.resolve(returned)) : iterator.generator || iterator.asynchronous ? await returned : returned;
130143
+ if (typeof result !== "object" && typeof result !== "function" || result === null) {
130144
+ throw new TypeError("Iterator return result must be an object.");
130145
+ }
130146
+ } catch (error3) {
130147
+ if (!preserveThrow || isFatalSandboxError(error3) || error3 instanceof HostCallResumabilityError) throw error3;
130148
+ }
130149
+ }
129950
130150
  function getSandboxIterator(value, budget, context) {
129951
130151
  if (isSandboxBox(value) && typeof boxedValue(value) === "string") {
129952
130152
  const primitive = boxedValue(value);
@@ -130102,108 +130302,12 @@ var init_iteration = __esm({
130102
130302
  init_budget2();
130103
130303
  init_string_coercion();
130104
130304
  init_cancel2();
130305
+ init_host_call();
130306
+ init_jobs4();
130105
130307
  asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
130106
130308
  }
130107
130309
  });
130108
130310
 
130109
- // packages/safe-js/src/interp/jobs.ts
130110
- import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
130111
- function runPromiseJob(task) {
130112
- const job = activeJob.getStore();
130113
- return job === void 0 ? Promise.resolve().then(task) : job.queue.run(task);
130114
- }
130115
- function runAsyncPrefix(task) {
130116
- const parent = activeJob.getStore();
130117
- if (parent === void 0) return task();
130118
- let owner = parent;
130119
- while (owner !== void 0 && !owner.ownsExecution) owner = owner.prefixParent;
130120
- if (owner === void 0) return parent.queue.run(task);
130121
- const job = { queue: parent.queue, ownsExecution: false, prefixParent: parent };
130122
- return activeJob.run(job, async () => {
130123
- try {
130124
- return await task();
130125
- } finally {
130126
- job.queue.release(job);
130127
- }
130128
- });
130129
- }
130130
- async function suspendJob(pending) {
130131
- const job = activeJob.getStore();
130132
- if (job === void 0) return pending;
130133
- job.queue.release(job);
130134
- try {
130135
- return await pending;
130136
- } finally {
130137
- await job.queue.acquire(job);
130138
- }
130139
- }
130140
- var activeJob, SandboxJobQueue;
130141
- var init_jobs4 = __esm({
130142
- "packages/safe-js/src/interp/jobs.ts"() {
130143
- "use strict";
130144
- activeJob = new AsyncLocalStorage7();
130145
- SandboxJobQueue = class {
130146
- running = false;
130147
- pending = [];
130148
- ready = [];
130149
- idle = [];
130150
- generation = 0;
130151
- acquire(job) {
130152
- return new Promise((resolve16) => {
130153
- this.pending.push(() => {
130154
- this.running = true;
130155
- this.generation += 1;
130156
- job.ownsExecution = true;
130157
- resolve16();
130158
- });
130159
- this.advance();
130160
- });
130161
- }
130162
- release(job) {
130163
- job.prefixParent = void 0;
130164
- if (!job.ownsExecution) return;
130165
- job.ownsExecution = false;
130166
- this.running = false;
130167
- this.advance();
130168
- }
130169
- async run(task) {
130170
- const job = { queue: this, ownsExecution: false };
130171
- await this.acquire(job);
130172
- return activeJob.run(job, async () => {
130173
- try {
130174
- return await task();
130175
- } finally {
130176
- this.release(job);
130177
- }
130178
- });
130179
- }
130180
- async drain() {
130181
- let idleTurns = 0;
130182
- while (idleTurns < 20) {
130183
- const generation = this.generation;
130184
- if (this.running) await new Promise((resolve16) => this.idle.push(resolve16));
130185
- await Promise.resolve();
130186
- idleTurns = generation === this.generation ? idleTurns + 1 : 0;
130187
- }
130188
- }
130189
- advance() {
130190
- if (this.running) return;
130191
- if (this.ready.length === 0 && this.pending.length > 0) {
130192
- const empty = this.ready;
130193
- this.ready = this.pending.reverse();
130194
- this.pending = empty;
130195
- }
130196
- const next = this.ready.pop();
130197
- if (next !== void 0) {
130198
- next();
130199
- } else {
130200
- for (const resolve16 of this.idle.splice(0)) resolve16();
130201
- }
130202
- }
130203
- };
130204
- }
130205
- });
130206
-
130207
130311
  // packages/safe-js/src/interp/promise.ts
130208
130312
  function isSandboxPromiseConstructor(value) {
130209
130313
  return isSandboxClosure(value) && promiseConstructors.has(value);
@@ -137557,7 +137661,7 @@ function statementContainsAwait(node) {
137557
137661
  return (node.init?.type === "VariableDeclaration" ? variableDeclarationContainsAwait(node.init) : node.init !== void 0 && expressionContainsAwait(node.init)) || node.test !== void 0 && expressionContainsAwait(node.test) || node.update !== void 0 && expressionContainsAwait(node.update) || statementContainsAwait(node.body);
137558
137662
  case "ForInStatement":
137559
137663
  case "ForOfStatement":
137560
- return node.left.type === "VariableDeclaration" && variableDeclarationContainsAwait(node.left) || node.left.type !== "VariableDeclaration" && assignmentTargetContainsAwait(node.left) || expressionContainsAwait(node.right) || statementContainsAwait(node.body);
137664
+ return node.type === "ForOfStatement" && node.await === true || node.left.type === "VariableDeclaration" && variableDeclarationContainsAwait(node.left) || node.left.type !== "VariableDeclaration" && assignmentTargetContainsAwait(node.left) || expressionContainsAwait(node.right) || statementContainsAwait(node.body);
137561
137665
  case "WhileStatement":
137562
137666
  case "DoWhileStatement":
137563
137667
  return expressionContainsAwait(node.test) || statementContainsAwait(node.body);
@@ -150217,7 +150321,7 @@ async function evaluateForOfStatement(node, context) {
150217
150321
  const restored = context.scope.consumeRestoredBinding(restoredIteration.values[0]);
150218
150322
  if (restored.found && Array.isArray(restored.value)) {
150219
150323
  restoredEntry = { done: false, value: restored.value[1] };
150220
- if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0]) || isSandboxCollectionIterator(restored.value[0])) {
150324
+ if (Array.isArray(restored.value[0]) || isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0]) || isSandboxCollectionIterator(restored.value[0])) {
150221
150325
  return evaluateForOfIterator(node, restored.value[0], context, restoredEntry);
150222
150326
  }
150223
150327
  }
@@ -150226,7 +150330,7 @@ async function evaluateForOfStatement(node, context) {
150226
150330
  if (iterable.kind !== "normal") {
150227
150331
  return iterable;
150228
150332
  }
150229
- const values = snapshotableIterationValues(iterable.value);
150333
+ const values = node.await ? void 0 : snapshotableIterationValues(iterable.value);
150230
150334
  if (values === void 0) {
150231
150335
  return evaluateForOfIterator(node, iterable.value, context, restoredEntry);
150232
150336
  }
@@ -150265,16 +150369,27 @@ async function evaluateForOfStatement(node, context) {
150265
150369
  };
150266
150370
  }
150267
150371
  async function evaluateForOfIterator(node, value, context, restoredEntry) {
150268
- const iterator = getSandboxIterator(value, context.budget, createCoercionContext(context));
150372
+ const iterator = node.await ? getSandboxAsyncIterator(value, context.budget, createCoercionContext(context), context.signal) : getSandboxIterator(value, context.budget, createCoercionContext(context));
150269
150373
  if (iterator === void 0) {
150270
150374
  throw new TypeError(`${String(value)} is not a supported iterable`);
150271
150375
  }
150376
+ const nextIteration = async () => {
150377
+ const pending = Promise.resolve(iterator.next());
150378
+ if (!node.await) return pending;
150379
+ context.onSuspend?.();
150380
+ const leaveAwait = context.budget.enterAwait();
150381
+ try {
150382
+ return await suspendJob(pending);
150383
+ } finally {
150384
+ leaveAwait();
150385
+ }
150386
+ };
150272
150387
  const releaseIterator = retainValues(context.budget, () => [value, iterator.retainedValue]);
150273
150388
  try {
150274
150389
  const nodeId = node.nodeId ?? -1;
150275
150390
  let index = consumeRestoredLoopIterationIndex(node, context);
150276
150391
  for (let skipped = 0; skipped < index; skipped += 1) {
150277
- const skippedIteration = await iterator.next();
150392
+ const skippedIteration = await nextIteration();
150278
150393
  if (typeof skippedIteration !== "object" || skippedIteration === null) {
150279
150394
  throw new TypeError("Iterator result must be an object.");
150280
150395
  }
@@ -150283,7 +150398,7 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
150283
150398
  }
150284
150399
  }
150285
150400
  while (true) {
150286
- const iteration = restoredEntry ?? await iterator.next();
150401
+ const iteration = restoredEntry ?? await nextIteration();
150287
150402
  restoredEntry = void 0;
150288
150403
  if (typeof iteration !== "object" || iteration === null) {
150289
150404
  throw new TypeError("Iterator result must be an object.");
@@ -150578,7 +150693,7 @@ function createLoopIterationContext(context, scope) {
150578
150693
  if (context.activeLoopIterations.size === 0) return snapshot2;
150579
150694
  snapshot2.loopIterations = {};
150580
150695
  for (const [nodeId, iteration] of context.activeLoopIterations) {
150581
- if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]) || isSandboxCollectionIterator(iteration.values[0]))) {
150696
+ if (typeof iteration !== "number" && (Array.isArray(iteration.values[0]) || isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]) || isSandboxCollectionIterator(iteration.values[0]))) {
150582
150697
  const bindingName = `#for-of:${nodeId}`;
150583
150698
  snapshot2.bindings[bindingName] = iteration.values;
150584
150699
  snapshot2.loopIterations[nodeId] = { index: iteration.index, values: [bindingName] };
@@ -150689,7 +150804,7 @@ async function evaluateYieldExpression(node, context) {
150689
150804
  return generatorCompletionResult(completion);
150690
150805
  }
150691
150806
  async function yieldGeneratorValue(value, node, context) {
150692
- if (context.asyncGenerator) value = await suspendJob(awaitSandboxValue(value, context.signal, context.budget));
150807
+ if (context.asyncGenerator && !node.delegate) value = await suspendJob(awaitSandboxValue(value, context.signal, context.budget));
150693
150808
  const completionPromise = context.generatorYield(allocateProducedSandboxValue(value, context.budget), node.nodeId);
150694
150809
  emitResumeBreakpoint(context, {
150695
150810
  kind: "generator-yield",
@@ -150711,8 +150826,7 @@ async function evaluateYieldDelegate(node, context) {
150711
150826
  if (argument.kind !== "normal") {
150712
150827
  return argument;
150713
150828
  }
150714
- const asyncDelegate = context.asyncGenerator && isSandboxGenerator(argument.value) && argument.value.async ? argument.value : void 0;
150715
- const iterator = asyncDelegate ? generatorIterator(asyncDelegate, context.budget) : getSandboxIterator(
150829
+ const iterator = context.asyncGenerator ? getSandboxAsyncIterator(argument.value, context.budget, createCoercionContext(context), context.signal) : getSandboxIterator(
150716
150830
  argument.value,
150717
150831
  context.budget,
150718
150832
  createCoercionContext(context)
@@ -150747,16 +150861,7 @@ async function evaluateYieldDelegate(node, context) {
150747
150861
  throw new TypeError("Iterator result must be an object.");
150748
150862
  }
150749
150863
  const done = result.done;
150750
- let value = result.value;
150751
- if (context.asyncGenerator) {
150752
- try {
150753
- value = await suspendJob(awaitSandboxValue(value, context.signal, context.budget));
150754
- } catch (error3) {
150755
- if (isFatalSandboxError(error3) || error3 instanceof HostCallResumabilityError) throw error3;
150756
- if (!asyncDelegate && !done && method !== "return") await closeIterator(iterator, true);
150757
- throw error3;
150758
- }
150759
- }
150864
+ const value = result.value;
150760
150865
  if (done) {
150761
150866
  if (completion.type === "return") {
150762
150867
  return generatorCompletionResult({ type: "return", value });
@@ -152055,21 +152160,6 @@ function describeObjectSpreadValue(value) {
152055
152160
  }
152056
152161
  return typeof value;
152057
152162
  }
152058
- async function closeIterator(iterator, preserveThrow = false) {
152059
- try {
152060
- const close = iterator.return;
152061
- if (close === void 0) return;
152062
- const returned = close();
152063
- const result = iterator.generator || iterator.asynchronous ? await returned : returned;
152064
- if (typeof result !== "object" && typeof result !== "function" || result === null) {
152065
- throw new TypeError("Iterator return result must be an object.");
152066
- }
152067
- } catch (error3) {
152068
- if (!preserveThrow || isFatalSandboxError(error3) || error3 instanceof HostCallResumabilityError) {
152069
- throw error3;
152070
- }
152071
- }
152072
- }
152073
152163
  function defineSandboxProperty(target, key3, value) {
152074
152164
  Object.defineProperty(target, key3, {
152075
152165
  configurable: true,