pyret-embed 0.1.7 → 0.1.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.
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/build/web/js/cpo-main.jarr
3
- size: 39417727 bytes
4
- sha256: a6b0d42c360be26d9d7292b2d8b0fb5113a711bc18e638f24da49f25aaa81128
3
+ size: 39425070 bytes
4
+ sha256: e538bdded88d99cf1f4b5054ba82c446f75118fb31c768cfc3f7811cafbe648e
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/build/web/js/cpo-main.jarr.js
3
- size: 39417727 bytes
4
- sha256: a6b0d42c360be26d9d7292b2d8b0fb5113a711bc18e638f24da49f25aaa81128
3
+ size: 39425070 bytes
4
+ sha256: e538bdded88d99cf1f4b5054ba82c446f75118fb31c768cfc3f7811cafbe648e
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/build/web/js/cpo-main.jarr.min
3
- size: 36462951 bytes
4
- sha256: fcbd5e96dbe981c069dcbc391fc6c27ca83c08ee1eac55ba9e3bd13995144597
3
+ size: 36467830 bytes
4
+ sha256: 240e5f973fccc25df91da15592f0d665e9daa4e4dcc2cec6e0c165f8fef37bd8
@@ -230,6 +230,8 @@
230
230
  const realpath = window.MESSAGES.sendRpc('path', 'resolve', [info.path]);
231
231
  realpath.then((realpath) => {
232
232
  restarter.resume(`js-file://${realpath}`);
233
+ }, (err) => {
234
+ restarter.error(runtime.ffi.makeMessageException("Error resolving import path: " + String(err)));
233
235
  });
234
236
  });
235
237
  }
@@ -242,6 +244,8 @@
242
244
  const realpath = window.MESSAGES.sendRpc('path', 'resolve', [info.path]);
243
245
  realpath.then((realpath) => {
244
246
  restarter.resume(`file://${realpath}`);
247
+ }, (err) => {
248
+ restarter.error(runtime.ffi.makeMessageException("Error resolving import path: " + String(err)));
245
249
  });
246
250
  });
247
251
  }
@@ -341,30 +345,45 @@
341
345
  return fileLocatorConstructor.makeFileLocator(info.path);
342
346
  case "local-if-present":
343
347
  return runtime.pauseStack(async (restarter) => {
344
- const exists = await fsInternal.exists(info.path);
348
+ // This callback is async, so anything it throws is a
349
+ // rejected promise nobody looks at; catch it here or
350
+ // the run never resumes.
351
+ let exists;
352
+ try {
353
+ exists = await fsInternal.exists(info.path);
354
+ }
355
+ catch(err) {
356
+ restarter.error(runtime.isObject(err) ? err
357
+ : runtime.ffi.makeMessageException("Error checking for local file " + JSON.stringify(info.path) + ": " + String(err)));
358
+ return;
359
+ }
345
360
  if(exists) {
346
361
  fsInternal.readFile(info.path).then((contents) => {
347
362
  const strContents = Buffer.from(contents).toString('utf8');
348
363
  CPO.documents.set(fullUrl, new CodeMirror.Doc(strContents, "pyret"));
349
364
  });
350
- return runtime.runThunk(() => {
351
- var fileLocatorConstructor = fileLocator.makeFileLocatorConstructor(window.MESSAGES.sendRpc, runtime, compileLib, compileStructs, parsePyret, builtinModules, cpo);
352
- return fileLocatorConstructor.makeFileLocator(info.path);
353
- }, (result) => {
354
- if(runtime.isSuccessResult(result)) {
355
- restarter.resume(result.result);
356
- }
357
- else {
358
- restarter.error(result.error);
359
- }
360
- });
361
365
  }
362
366
  else {
363
367
  fetch(fullUrl).then(async (response) => {
364
368
  CPO.documents.set(fullUrl, new CodeMirror.Doc(await response.text(), "pyret"));
365
369
  });
366
- return restarter.resume(runtime.getField(runtime.getField(urlLoc, "values"), "url-locator").app(fullUrl, replGlobals));
367
370
  }
371
+ return runtime.runThunk(() => {
372
+ if(exists) {
373
+ var fileLocatorConstructor = fileLocator.makeFileLocatorConstructor(window.MESSAGES.sendRpc, runtime, compileLib, compileStructs, parsePyret, builtinModules, cpo);
374
+ return fileLocatorConstructor.makeFileLocator(info.path);
375
+ }
376
+ else {
377
+ return runtime.getField(runtime.getField(urlLoc, "values"), "url-locator").app(fullUrl, replGlobals);
378
+ }
379
+ }, (result) => {
380
+ if(runtime.isSuccessResult(result)) {
381
+ restarter.resume(result.result);
382
+ }
383
+ else {
384
+ restarter.error(result.exn);
385
+ }
386
+ });
368
387
  });
369
388
  }
370
389
 
@@ -67,6 +67,14 @@ define("cpo/file-locator", [], function() {
67
67
  var gmf = function(m, f) { return gf(gf(m, "values"), f); };
68
68
 
69
69
 
70
+ // Every RPC here runs under a paused stack, so a rejected RPC has to
71
+ // become restarter.error -- otherwise the run waits forever, silently.
72
+ function rpcFailed(restarter, what) {
73
+ return function(err) {
74
+ restarter.error(runtime.ffi.makeMessageException(what + ": " + String(err)));
75
+ };
76
+ }
77
+
70
78
  function makeFileLocator(path) {
71
79
  return runtime.pauseStack((restarter) => {
72
80
  const realpath = sendRpc('path', 'resolve', [path]);
@@ -89,10 +97,14 @@ define("cpo/file-locator", [], function() {
89
97
  return ast;
90
98
  }, "file-locator:parse-contents");
91
99
  }, function(result) {
92
- console.log("Result from getModule runThunk: ", result);
93
- restarter.resume(result.result);
100
+ if(runtime.isSuccessResult(result)) {
101
+ restarter.resume(result.result);
102
+ }
103
+ else {
104
+ restarter.error(result.exn);
105
+ }
94
106
  });
95
- });
107
+ }, rpcFailed(restarter, "Could not read file " + JSON.stringify(path)));
96
108
  });
97
109
  }
98
110
 
@@ -166,7 +178,7 @@ define("cpo/file-locator", [], function() {
166
178
  "set-compiled": m2(setCompiled),
167
179
  "get-compiled": m1(function() { return runtime.ffi.makeNone(); })
168
180
  }));
169
- });
181
+ }, rpcFailed(restarter, "Could not resolve file path " + JSON.stringify(path)));
170
182
  });
171
183
  }
172
184
 
@@ -25,6 +25,9 @@
25
25
  if(m) { window.CPO_COMPILER = decodeURIComponent(m[1]); }
26
26
  if(window.CPO_COMPILER === "ts" && window.PYRET_TS) {
27
27
  window.PYRET = window.PYRET_TS;
28
+ // Lets pure CSS show ts-only chrome (the "(ts mode)" badge in the
29
+ // REPL corner) without another script running at DOM-ready.
30
+ document.documentElement.classList.add("ts-mode");
28
31
  // In gzipped mode the host may serve assets without an executable MIME
29
32
  // type (nosniff), which refuses a <script src> load outright --
30
33
  // beforePyret.js fetches the compiler bundle alongside the jarr instead.
@@ -391,6 +394,7 @@
391
394
  </div>
392
395
  <div id="REPL" class="replContainer" role="region" aria-label="Interactions">
393
396
  <div id="handle" class="ui-resizable-handle ui-resizable-w"></div>
397
+ <div id="compilerFlavorBadge" title="This session uses the TypeScript version of Pyret. Visit /settings/clear-ts to turn it off.">(ts mode)</div>
394
398
  </div>
395
399
  <div id="help-keys">
396
400
  <p><b>Press <kbd>Esc</kbd> to close this help window</b></p>