mustardscript 0.1.3 → 0.2.1

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/README.md CHANGED
@@ -38,9 +38,9 @@ The current implementation already supports:
38
38
  - `Map` and `Set` with supported iterable constructors, SameValueZero key and
39
39
  membership semantics, insertion-order-preserving storage, and iterator
40
40
  helpers
41
- - `async` functions, `await`, guest promises, `new Promise(...)`, Promise
42
- combinators and instance methods, basic thenable adoption, and internal
43
- microtask scheduling for the supported subset
41
+ - `async` functions, top-level `await`, guest promises, `new Promise(...)`,
42
+ Promise combinators and instance methods, basic thenable adoption, and
43
+ internal microtask scheduling for the supported subset
44
44
  - guest-internal `BigInt` literals with exact-integer arithmetic,
45
45
  comparison, keyed-collection membership, and string/property-key coercion
46
46
  - conservative array, string, object, and Math helper methods, including
@@ -348,7 +348,7 @@ JavaScript.
348
348
  - Arrays, plain objects, `Map`, and `Set`
349
349
  - `let` and `const`
350
350
  - Functions and closures
351
- - `async` functions and `await`
351
+ - `async` functions and `await`, including top-level `await`
352
352
  - Arrow functions
353
353
  - `if`, `switch`, loops, `break`, and `continue`
354
354
  - `throw`, `try`, `catch`, and `finally`
@@ -432,7 +432,7 @@ Currently implemented built-ins:
432
432
 
433
433
  Current Promise support is intentionally narrow:
434
434
 
435
- - async functions return internal guest promises
435
+ - async functions and top-level `await` return through internal guest promises
436
436
  - `new Promise(executor)` is supported when `executor` is callable and
437
437
  completes synchronously from the runtime's perspective
438
438
  - `Promise.resolve(...)`, `Promise.reject(...)`, `Promise.all(...)`,
@@ -807,6 +807,20 @@ inside the supported language subset, and lowers to an executable compiled
807
807
  program. It does not prove that a later `run()` or `start()` call will succeed
808
808
  with a particular host policy, input set, capability map, or runtime limit.
809
809
 
810
+ For LLM-generated snippets, hosts can opt into a narrow compile-time
811
+ compatibility mode:
812
+
813
+ ```ts
814
+ const program = new Mustard('const value = 41; return value + 1;', {
815
+ lenientMode: true,
816
+ })
817
+ ```
818
+
819
+ `lenientMode` only accepts a `return` when it is the final top-level statement;
820
+ that statement is treated like MustardScript's normal final expression result.
821
+ Nested top-level returns, non-final top-level returns, and all forbidden forms
822
+ still fail closed. Strict behavior remains the default.
823
+
810
824
  `Progress.load(...)` always requires explicit restore authority: the host must
811
825
  pass either a reusable `ExecutionContext` or explicit `capabilities` /
812
826
  `console`, explicit `limits` as an object (use `{}` for default runtime
@@ -28,7 +28,24 @@ function createMustardClass({ native, materializeStep, parseStep }) {
28
28
  })
29
29
  : null;
30
30
 
31
- function compileProgram(code) {
31
+ function compileOptionsJson(options = {}) {
32
+ if (options === null || typeof options !== 'object' || Array.isArray(options)) {
33
+ throw new TypeError('compile options must be a plain object');
34
+ }
35
+ if (options.lenientMode === undefined || options.lenientMode === false) {
36
+ return null;
37
+ }
38
+ if (options.lenientMode !== true) {
39
+ throw new TypeError('options.lenientMode must be a boolean');
40
+ }
41
+ return '{"lenient_mode":true}';
42
+ }
43
+
44
+ function compileProgram(code, options = {}) {
45
+ const optionsJson = compileOptionsJson(options);
46
+ if (optionsJson !== null) {
47
+ return callNative(native.compileProgramWithOptions, code, optionsJson);
48
+ }
32
49
  return callNative(native.compileProgram, code);
33
50
  }
34
51
 
@@ -38,15 +55,15 @@ function createMustardClass({ native, materializeStep, parseStep }) {
38
55
 
39
56
  return class Mustard {
40
57
  constructor(code, options = {}) {
41
- this._programHandle = compileProgram(code);
58
+ this._programHandle = compileProgram(code, options);
42
59
  this._program = null;
43
60
  this._inputNames = options.inputs ?? [];
44
61
  this._programHandleToken = {};
45
62
  programHandleRegistry?.register(this, this._programHandle, this._programHandleToken);
46
63
  }
47
64
 
48
- static validateProgram(code) {
49
- const programHandle = compileProgram(code);
65
+ static validateProgram(code, options = {}) {
66
+ const programHandle = compileProgram(code, options);
50
67
  releaseProgram(programHandle);
51
68
  }
52
69
 
package/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export declare function cancelCancellationToken(tokenId: string): void
4
4
 
5
5
  export declare function compileProgram(source: string): string
6
6
 
7
+ export declare function compileProgramWithOptions(source: string, optionsJson: string): string
8
+
7
9
  export declare function createCancellationToken(): string
8
10
 
9
11
  export declare function createExecutionContext(policyJson: string): string
package/mustard.d.ts CHANGED
@@ -24,6 +24,7 @@ export interface ConsoleCallbacks {
24
24
 
25
25
  export interface CompileOptions {
26
26
  inputs?: string[];
27
+ lenientMode?: boolean;
27
28
  }
28
29
 
29
30
  export type SnapshotKey = string | Buffer | Uint8Array;
@@ -203,7 +204,7 @@ export class Mustard {
203
204
  start(options?: ExecutionOptions): StructuredValue | Progress;
204
205
  dump(): Buffer;
205
206
 
206
- static validateProgram(code: string): void;
207
+ static validateProgram(code: string, options?: CompileOptions): void;
207
208
  static load(buffer: Buffer): Mustard;
208
209
  }
209
210
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mustardscript",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "Sandboxed, subset JavaScript runtime for Node services.",
5
5
  "main": "dist/index.js",
6
6
  "types": "mustard.d.ts",
@@ -28,10 +28,10 @@
28
28
  ]
29
29
  },
30
30
  "optionalDependencies": {
31
- "@mustardscript/binding-darwin-arm64": "0.1.3",
32
- "@mustardscript/binding-darwin-x64": "0.1.3",
33
- "@mustardscript/binding-linux-x64-gnu": "0.1.3",
34
- "@mustardscript/binding-win32-x64-msvc": "0.1.3"
31
+ "@mustardscript/binding-darwin-arm64": "0.2.1",
32
+ "@mustardscript/binding-darwin-x64": "0.2.1",
33
+ "@mustardscript/binding-linux-x64-gnu": "0.2.1",
34
+ "@mustardscript/binding-win32-x64-msvc": "0.2.1"
35
35
  },
36
36
  "scripts": {
37
37
  "prepack": "node scripts/build-ts-dist.ts",