@naanlang/naan 1.6.0 → 1.7.0

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.
Files changed (50) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +1 -1
  3. package/bin/index.js +2 -2
  4. package/dist/env_web.js +3 -31
  5. package/dist/naan.min.js +10 -10
  6. package/frameworks/browser/sworker.js +23 -23
  7. package/frameworks/browser/terminals.nlg +44 -122
  8. package/frameworks/browser/worker.nlg +64 -24
  9. package/frameworks/browser/workers.nlg +1 -1
  10. package/frameworks/client/apiclient.nlg +73 -43
  11. package/frameworks/client/psm_client.nlg +10 -14
  12. package/frameworks/common/common.nlg +2 -0
  13. package/frameworks/node/apiserver.nlg +0 -1
  14. package/frameworks/node/node.nlg +1 -0
  15. package/frameworks/node/pty.nlg +21 -21
  16. package/frameworks/node/shell.nlg +26 -3
  17. package/frameworks/node/worker.nlg +153 -79
  18. package/frameworks/project/build.nlg +55 -13
  19. package/frameworks/project/projects.nlg +1 -1
  20. package/frameworks/running/debugcom.nlg +20 -3
  21. package/frameworks/running/debugnub.nlg +16 -7
  22. package/frameworks/running/executors.nlg +14 -12
  23. package/frameworks/running/instances.nlg +1 -0
  24. package/frameworks/running/remote_req.nlg +4 -8
  25. package/frameworks/running/remote_res.nlg +1 -1
  26. package/frameworks/running/sourcecode.nlg +3 -2
  27. package/frameworks/running/taskexec.nlg +14 -57
  28. package/frameworks/service/imp.nlg +15 -0
  29. package/frameworks/service/nubnode.nlg +35 -4
  30. package/frameworks/service/nubweb.nlg +22 -4
  31. package/frameworks/storage/file_manager.nlg +3 -2
  32. package/lib/browser/env_web.js +10 -38
  33. package/lib/browser/env_webworker.js +1 -30
  34. package/lib/core/naanlib.js +10 -10
  35. package/lib/env_node.js +5 -22
  36. package/lib/env_nodeworker.js +8 -43
  37. package/lib/node_server_init.nlg +149 -0
  38. package/lib/node_worker.js +36 -0
  39. package/lib/node_worker_init.nlg +43 -0
  40. package/package.json +1 -1
  41. package/plugins/openSearch/openSearch.nlg +3 -2
  42. package/plugins/openSearch/os_dynamo.nlg +3 -2
  43. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +44 -2
  44. package/plugins/serviceAws/aws_dynamo.nlg +144 -63
  45. package/plugins/serviceAws/aws_utils.nlg +6 -11
  46. package/plugins/serviceAws/serviceAws.nlg +3 -2
  47. package/test/test_01_core.nlg +2 -2
  48. package/test/test_02_context.nlg +8 -8
  49. package/test/test_03_jsinterop.nlg +3 -3
  50. package/test/test_07_lingo.nlg +1 -1
@@ -36,7 +36,7 @@
36
36
  *
37
37
  */
38
38
 
39
- var CurrentCacheName = "Naanlang-1.6.0+1";
39
+ var CurrentCacheName = "Naanlang-1.7.0+1";
40
40
 
41
41
 
42
42
  //
@@ -92,18 +92,18 @@ var terminated; // flag that this service worker
92
92
  var pubVersion = event.data.hereIsMyVersion;
93
93
  var sourceId = event.source.id; // client id of sender of message
94
94
  msgPorts[sourceId] = msgport;
95
- console.log("[1.6.0+1] received new msgport for", sourceId, pubID, "-", pubVersion);
96
- if (pubVersion != "1.6.0+1") {
95
+ console.log("[1.7.0+1] received new msgport for", sourceId, pubID, "-", pubVersion);
96
+ if (pubVersion != "1.7.0+1") {
97
97
  if (upgradeMsgPorts) { // if not activated
98
- console.log("[1.6.0+1] update pending for", sourceId);
98
+ console.log("[1.7.0+1] update pending for", sourceId);
99
99
  upgradeMsgPorts[sourceId] = msgport;
100
100
  }
101
101
  else {
102
102
  msgport.postMessage({ // notify new version available
103
103
  id: "upgrade",
104
- version: "1.6.0+1"
104
+ version: "1.7.0+1"
105
105
  });
106
- console.log("[1.6.0+1] update sent for:", sourceId);
106
+ console.log("[1.7.0+1] update sent for:", sourceId);
107
107
  }
108
108
  }
109
109
  Reaper(); // clean up obsolete info
@@ -134,10 +134,10 @@ var terminated; // flag that this service worker
134
134
  msgport.onmessage = function(msg) {
135
135
  msg = msg.data;
136
136
  if (msg.id == "skipWaiting") { // try to activate this SW now
137
- console.log("[1.6.0+1] attempting skipWaiting");
137
+ console.log("[1.7.0+1] attempting skipWaiting");
138
138
  self.skipWaiting();
139
139
  } else if (msg.id == "terminate") { // termiante this SW now
140
- console.log("[1.6.0+1] terminated");
140
+ console.log("[1.7.0+1] terminated");
141
141
  terminate();
142
142
  } else if (msg.id == "abortURL") { // abort an I/O transaction
143
143
  var href = new URL(msg.url).href;
@@ -150,7 +150,7 @@ var terminated; // flag that this service worker
150
150
  } else if (msg.id == "response") // response from fetch request
151
151
  processResponse(msg);
152
152
  else if (msg.id == "text") // just log some text
153
- console.log("[1.6.0+1] msg received:", msg.text);
153
+ console.log("[1.7.0+1] msg received:", msg.text);
154
154
  };
155
155
 
156
156
  // send text to IDE log
@@ -161,7 +161,7 @@ var terminated; // flag that this service worker
161
161
  // don't clutter the log
162
162
  msgport.postMessage({
163
163
  id: "text",
164
- text: "port received by 1.6.0+1",
164
+ text: "port received by 1.7.0+1",
165
165
  });
166
166
  */
167
167
  if (--pending === 0)
@@ -178,7 +178,7 @@ var terminated; // flag that this service worker
178
178
  includeUncontrolled: true
179
179
  }).then(function(clientList) {
180
180
  clientList.every(function(client) {
181
- console.log("[1.6.0+1] requesting new msgport for", client.id);
181
+ console.log("[1.7.0+1] requesting new msgport for", client.id);
182
182
  ++pending;
183
183
  client.postMessage({ // tell client(s) we need this fetch source
184
184
  msg: "Naan_need_fetch_port",
@@ -224,12 +224,12 @@ function Reaper() {
224
224
  clients[clientList[clidex].id] = clientList[clidex];
225
225
  for (var sourceId in msgPorts)
226
226
  if (!clients[sourceId]) {
227
- console.log("[1.6.0+1] source gone:", sourceId);
227
+ console.log("[1.7.0+1] source gone:", sourceId);
228
228
  delete msgPorts[sourceId]; // no longer a source
229
229
  }
230
230
  for (var clientId in fetchPorts)
231
231
  if (!clients[clientId]) {
232
- console.log("[1.6.0+1] client gone:", clientId);
232
+ console.log("[1.7.0+1] client gone:", clientId);
233
233
  delete fetchPorts[clientId]; // no longer a client
234
234
  }
235
235
  for (var fqdex = 0; fqdex < fetchQueue.length; ++fqdex) {
@@ -263,16 +263,16 @@ function ClearCaches() {
263
263
  return (Promise.all(
264
264
  cacheNames.map(function(cacheName) {
265
265
  if (cacheName != CurrentCacheName) {
266
- console.log('[1.6.0+1] deleting old cache:', cacheName);
266
+ console.log('[1.7.0+1] deleting old cache:', cacheName);
267
267
  return (caches.delete(cacheName));
268
268
  }
269
269
  })
270
270
  ));
271
271
  }).then(function() { // claim all clients
272
- console.log('[1.6.0+1] claiming clients');
272
+ console.log('[1.7.0+1] claiming clients');
273
273
  return (self.clients.claim());
274
274
  }).then(function() {
275
- console.log('[1.6.0+1] clients claimed');
275
+ console.log('[1.7.0+1] clients claimed');
276
276
  return (Promise.resolve(true));
277
277
  });
278
278
  return (promise);
@@ -315,7 +315,7 @@ function GetClientResponse(event, urlpath) {
315
315
  msgport.postMessage({
316
316
  id: "fetch",
317
317
  seq: seqno,
318
- version: "1.6.0+1",
318
+ version: "1.7.0+1",
319
319
  request: {
320
320
  method: event.request.method,
321
321
  url: event.request.url
@@ -363,7 +363,7 @@ function GetClientResponse(event, urlpath) {
363
363
  */
364
364
 
365
365
  self.addEventListener('install', function(event) {
366
- console.log("[1.6.0+1] install");
366
+ console.log("[1.7.0+1] install");
367
367
  self.skipWaiting();
368
368
  });
369
369
 
@@ -376,20 +376,20 @@ self.addEventListener('install', function(event) {
376
376
  */
377
377
 
378
378
  self.addEventListener('activate', function(event) {
379
- console.log("[1.6.0+1] activate");
379
+ console.log("[1.7.0+1] activate");
380
380
  self.clients.matchAll({ // for debugging, list controlled clients
381
381
  includeUncontrolled: true
382
382
  }).then(function(clientList) {
383
383
  var urls = clientList.map(function(client) {
384
384
  return (client.url);
385
385
  });
386
- console.log('[1.6.0+1] matching clients:', urls.join(', '));
386
+ console.log('[1.7.0+1] matching clients:', urls.join(', '));
387
387
  });
388
388
  var promise = ClearCaches().then(function() {
389
389
  for (var sourceId in upgradeMsgPorts) {
390
390
  upgradeMsgPorts[sourceId].postMessage({ // notify new version available
391
391
  id: "upgrade",
392
- version: "1.6.0+1"
392
+ version: "1.7.0+1"
393
393
  });
394
394
  }
395
395
  upgradeMsgPorts = false;
@@ -421,7 +421,7 @@ self.addEventListener('fetch', function(event) {
421
421
  var promise;
422
422
  var url = new URL(request.url);
423
423
  var nocache = request.method != "GET"
424
- || url.search.length !== 0 && url.searchParams.get("naanver") !== "c38a11f669f27ff2730818e613d0671c"
424
+ || url.search.length !== 0 && url.searchParams.get("naanver") !== "a46b70b86094c7f89227b899497a7b9a"
425
425
  || request.headers.get('range');
426
426
  if (url.pathname.startsWith("/run/")) {
427
427
  nocache = true;
@@ -455,7 +455,7 @@ self.addEventListener('fetch', function(event) {
455
455
  statusText: "Request Cancelled"
456
456
  }));
457
457
  }
458
- console.log("[1.6.0+1] fetch failed", request.url, e);
458
+ console.log("[1.7.0+1] fetch failed", request.url, e);
459
459
  return (new Response(undefined, {
460
460
  status: 404,
461
461
  statusText: "Fetch Failed"
@@ -10,93 +10,24 @@
10
10
  *
11
11
  */
12
12
 
13
- /*
14
- * globals
15
- *
16
- */
17
-
18
- gWorkers;
19
-
20
-
21
- /*
22
- * ioctl terminal control and events
23
- *
24
- * Example "raw" mode:
25
- *
26
- // rawTest
27
- // echo typed keystrokes in BOLD until Control-C stops it.
28
- //
29
- closure rawTest(local dokey) {
30
- dokey = xnew(function(msg, arg) {
31
- if arg.key == "\x03" {
32
- js.t.ioctl("raw", false)
33
- js.t.ioctl_remove_listener("raw-key", dokey)
34
- }
35
- else
36
- print("\x1b[1m${arg.key}\x1b[22m")
37
- })
38
- js.t.ioctl_add_listener("raw-key", dokey)
39
- js.t.ioctl("raw", true)
40
- };
41
-
42
- rawTest();
43
- *
44
- *
45
- * Example echo control:
46
- *
47
- js.t.ioctl("echo", 0) // no echo at all
48
- js.t.ioctl("echo", 1) // echo newlines (best for hiding REPL commands)
49
- js.t.ioctl("echo", 2) // normal echo
50
-
51
- js.t.ioctl("sane") // restore echo and raw
52
- *
53
- *
54
- * Example simulated keystrokes:
55
- *
56
- future(function(){ js.t.ioctl("keystroke", "joe") }, 10); // "joe" in keyboard buffer
57
- *
58
- *
59
- * Example terminal resize notification:
60
- *
61
- doresize = xnew(function(msg, dim) { printline("(${dim.cols}, ${dim.rows})")})
62
- js.t.ioctl_add_listener("term-resize", doresize);
63
- *
64
- *
65
- * Example terminal connection notification:
66
- *
67
- // add removable listener:
68
- listener = xnew(function(msg,arg) { debuglog("listener:", msg, arg) });
69
- js.t.ioctl_add_listener("term-attach", listener);
70
- js.t.ioctl_add_listener("term-detach", listener);
71
-
72
- // remove the listeners:
73
- js.t.ioctl_remove_listener("term-attach", listener);
74
- js.t.ioctl_remove_listener("term-detach", listener);
75
- *
76
- * Note that js.t.ioctl(...) controls the *terminal* even if attached to a different instance. But
77
- * ioctl event listeners are attached to an *instance* regardless of what terminal is connected.
78
- * But in general it does the "right thing" for multiple terminals on a single instance, and when
79
- * switching among instances.
80
- *
81
- */
82
-
83
13
 
84
14
  /*
85
15
  * TermHost
86
16
  *
87
- * Make an Nide API Server debugger target.
17
+ * Make a debugger target on our Host NaanIDE Server or a remote one.
88
18
  *
89
19
  * Options:
90
20
  * {
91
- * type: <string> // target category, e.g. "Host", "api.yyy.com"
92
- * workerID: <string> // kind of worker in server subsystem
93
- * startup: <dictionary> // startup options
21
+ * serverID: <string> // target server if not our Host
22
+ * type: <string> // target category, e.g. "Remote", "api.yyy.com"
23
+ * workerID: <string> // kind of worker in server subsystem
24
+ * startup: <dictionary> // startup options
94
25
  * }
95
26
  *
96
27
  */
97
28
 
98
29
  closure TermHost(track, name, options,
99
- local relay, error, destID, target, xc)
30
+ local relay, error, serverID, targetID, target, xc)
100
31
  {
101
32
  global(App)
102
33
 
@@ -105,15 +36,20 @@ closure TermHost(track, name, options,
105
36
  // Find the host instance name/type, or create new remote worker. The default for no name/type is
106
37
  // the server itself.
107
38
  //
108
- function findHostInstance(relay, name, type, local error, found, dest, worker) {
109
- `(error, found) = relay.clients()
110
- if !error {
111
- dest = found.find(function(item) { item.name == "NaanIDE Server" && item.type == "Server IMP" })
112
- if !dest
113
- error = Error("cannot locate host")
39
+ function findHostInstance(relay, name, type,
40
+ local error, found, dest, worker) {
41
+ if !serverID {
42
+ `(error, found) = relay.clients()
43
+ if !error {
44
+ dest = found.find(function(item) { item.name == "NaanIDE Server" && item.type == "Server IMP" })
45
+ if dest
46
+ serverID = dest.destID
47
+ else
48
+ error = Error("cannot locate host")
49
+ }
114
50
  }
115
51
  if !error
116
- `(error, found) = relay.clients(dest.destID)
52
+ `(error, found) = relay.clients(serverID)
117
53
  if !error {
118
54
  if name && type {
119
55
  dest = found.find(function(item) { item.name == name && item.type == type })
@@ -143,6 +79,7 @@ closure TermHost(track, name, options,
143
79
  name: name
144
80
  type: options.type
145
81
  startup: options.startup
82
+ rootPath: options.rootPath || undefined
146
83
  topOriginID: App.imp.us.instanceID
147
84
  })
148
85
  if error
@@ -162,10 +99,11 @@ closure TermHost(track, name, options,
162
99
  return (list(false, target)) // already exists
163
100
 
164
101
  relay = require("naanlib:frameworks/client/relaycon.nlg").RelayCon(App.imp)
102
+ serverID = options.serverID
165
103
  if options.workerID == "NideServer" // server main thread
166
- `(error, destID) = findHostInstance(relay)
104
+ `(error, targetID) = findHostInstance(relay)
167
105
  else
168
- `(error, destID) = findHostInstance(relay, name, options.type)
106
+ `(error, targetID) = findHostInstance(relay, name, options.type)
169
107
  relay.close()
170
108
  if error
171
109
  return (list(error))
@@ -174,9 +112,10 @@ closure TermHost(track, name, options,
174
112
  name: name
175
113
  type: options.type
176
114
  })
177
- target.workerID = options.workerID
115
+ target.serverID = serverID // server instanceID
116
+ target.workerID = options.workerID // worker on server instanceID
178
117
 
179
- `(error) = target.open(destID)
118
+ `(error) = target.open(targetID)
180
119
  if error
181
120
  return (list(Error("cannot create InTop", error)))
182
121
 
@@ -201,11 +140,9 @@ closure TermHost(track, name, options,
201
140
  *
202
141
  */
203
142
 
204
- closure TermLocal(track, name, options, local target, worker, inbot, error)
143
+ closure TermLocal(track, name, options, local target, worker, wowbot, error)
205
144
  {
206
- global(js, window, gWorkers)
207
- if !dictionary(gWorkers)
208
- gWorkers = {}
145
+ global(js, window)
209
146
  options = merge({
210
147
  type: "Local"
211
148
  }, options)
@@ -221,7 +158,7 @@ closure TermLocal(track, name, options, local target, worker, inbot, error)
221
158
  return (list(false, target)) // already exists
222
159
 
223
160
  worker = xnew(window.Worker, "env_webworker.js")
224
- inbot = NubBot(worker, {
161
+ wowbot = WowBot(worker, {
225
162
  name: name
226
163
  type: options.workerID
227
164
  startup: options.startup
@@ -231,7 +168,7 @@ closure TermLocal(track, name, options, local target, worker, inbot, error)
231
168
  type: options.type
232
169
  workerID: options.workerID
233
170
  })
234
- `(error) = target.open(inbot.instanceID)
171
+ `(error) = target.open(wowbot.instanceID)
235
172
  if error
236
173
  return (list(Error("cannot create InTop", error)))
237
174
 
@@ -271,7 +208,7 @@ closure findIDEtarget(track, name, workerID, title, naancont, local target) {
271
208
  */
272
209
 
273
210
  closure termIDE(track, name, workerID, naancont, title, local target, connected) {
274
- global(js, gWorkers)
211
+ global(js)
275
212
  target = findIDEtarget(track, name, workerID, title, naancont)
276
213
  if target { // new naancont on existing target
277
214
  if target.naancont && naancont !== target.naancont
@@ -282,23 +219,23 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
282
219
  return (target)
283
220
  }
284
221
  target = require("../running/executors.nlg").ExecutorBase(track, "Local", name)
222
+ target.dispatcher = require("../running/taskexec.nlg").TaskDispatcher(false, false, "termIDE")
285
223
  target.name = name
286
224
  target.title = title
287
225
  target.workerID = workerID
288
226
  target.naancont = naancont
289
227
  naancont.ioctl_open(ioctl_callback.proc)
290
228
  connected = []
291
-
292
- // replyHook
229
+
230
+ // PostMessage
293
231
  //
294
- // Intercept the ReplyMessage function to see if we should handle it.
232
+ // Process a message through the dispatcher.
295
233
  //
296
- function replyHook(data) {
297
- if data._guid
298
- gWorkers[data._guid].worker.postMessage({
299
- id: "targetreceive"
300
- data: data
301
- })
234
+ target.PostMessage = function PostMessage(data) {
235
+ target.dispatcher(data, function(reply) {
236
+ target.execReceived(reply)
237
+ })
238
+ list(false, { posted: true })
302
239
  }
303
240
 
304
241
  // ioctl_callback
@@ -323,15 +260,6 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
323
260
  naancont.DispatchDebugger(data)
324
261
  }
325
262
 
326
- // target.PostMessage
327
- //
328
- // Post a message to the target, ourselves.
329
- //
330
- target.PostMessage = function PostMessage(data) {
331
- naancont.DispatchMessage(data)
332
- list(false, { posted: true })
333
- }
334
-
335
263
  // termAttach
336
264
  //
337
265
  // Create a closure for an attaching terminal.
@@ -350,11 +278,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
350
278
 
351
279
  function onstatus(status) {
352
280
  target.execSetStatus(status)
353
- statusCB(target, status)
354
- }
355
-
356
- function onmessageout(data) {
357
- target.execReceived(data)
281
+ notify.execStatus(target, status)
358
282
  }
359
283
 
360
284
  function ondebugout(data) {
@@ -399,7 +323,6 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
399
323
  OnMessage: jsterm.OnMessage
400
324
  StateSave: jsterm.StateSave
401
325
  OnStatus: onstatus.proc
402
- OnMessageOut: onmessageout.proc
403
326
  OnDebugOut: ondebugout.proc
404
327
  })
405
328
  naancont.Attach(inbound)
@@ -516,7 +439,6 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
516
439
  track.delete(target)
517
440
  }
518
441
 
519
- js.t.OnReplyHook(replyHook.proc)
520
442
  track.add(target)
521
443
 
522
444
  // finis
@@ -534,7 +456,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
534
456
  */
535
457
 
536
458
  closure termInstallVirtualWatcher(track, naancont) {
537
- global()
459
+ global(js)
538
460
 
539
461
  function watchVsites(msg, local error, target) {
540
462
  if msg.op == "VsiteOpen" {
@@ -553,7 +475,7 @@ closure termInstallVirtualWatcher(track, naancont) {
553
475
  }
554
476
  }
555
477
 
556
- require("../running/executors.nlg").TaskOnMessageHook(watchVsites)
478
+ js.t.OnMessage(watchVsites.proc)
557
479
  };
558
480
 
559
481
 
@@ -653,8 +575,8 @@ closure relayTab(destID, local comMod, relay, error, found, dest, xc, reterm, or
653
575
  if error
654
576
  return (list(Error("cannot get remote terminal", error)))
655
577
  originID = App.imp.us.instanceID
656
- `(error, inbot) = xc.evalq(InBot(window, {
657
- name: "inbot"
578
+ `(error, inbot) = xc.evalq(MewBot(window, {
579
+ name: "mewbot"
658
580
  type: reterm.workerID
659
581
  topOriginID: originID
660
582
  }), `(reterm, originID))
@@ -2,7 +2,7 @@
2
2
  * worker.nlg
3
3
  * Naanlib/frameworks/browser
4
4
  *
5
- * Manage NaaN instances.
5
+ * Manage web-based NaaN instances.
6
6
  *
7
7
  * NaaN instances are managed by a top/bottom pair of of objects. InBot (INstance BOTtom) objects
8
8
  * reside in the same JavaScript environment (node/browser) as their worker and communicate with the
@@ -24,7 +24,8 @@
24
24
  *
25
25
  * Create a remote interface for a single execution instance, returning the object. This provides
26
26
  * instance access to zero or more InTops via IMP connections. The tops subscribe to receive
27
- * notifications/responses.
27
+ * notifications/responses. This runs in the main thread and communicates with the worker via the
28
+ * standard JS messaging interface.
28
29
  *
29
30
  * Options:
30
31
  * {
@@ -32,7 +33,6 @@
32
33
  * type: <string> // target category, e.g. "Local"
33
34
  * startup: <dictionary> // startup options
34
35
  * workerID: <string> // initialize worker with this
35
- * workerGUID: <string> // initialize worker with this
36
36
  * topOriginID: <string> // so top can route to us through IMP
37
37
  * }
38
38
  *
@@ -148,10 +148,10 @@ closure InBot(worker, options, local inbot)
148
148
  state: false // resume state, if we have any
149
149
  altcmd: options.startup.initcmds
150
150
  workerID: options.workerID
151
- workerGUID: options.workerGUID
152
151
  metadata: {
153
152
  mainInstanceID: App.imp.us.instanceID
154
153
  name: options.name
154
+ maintext: options.startup.maintext.concat("\n")
155
155
  }
156
156
  })
157
157
  inbot.started = true
@@ -164,10 +164,14 @@ closure InBot(worker, options, local inbot)
164
164
  // The worker had an error.
165
165
  //
166
166
  inbot.worker.addEventListener("error", function(e) {
167
- debuglog("worker error:", e.message)
167
+ debuglog("worker error:", e.message, "in", e.filename, "at", e.lineno)
168
168
  notifyAll({
169
169
  id: "error"
170
- data: e.message
170
+ data: {
171
+ message: e.message
172
+ filename: e.filename
173
+ lineno: e.lineno
174
+ }
171
175
  })
172
176
  inbot.worker = false
173
177
  destroy()
@@ -185,13 +189,11 @@ closure InBot(worker, options, local inbot)
185
189
  notifyAll({
186
190
  id: "terminated"
187
191
  })
188
- inbot.impconn.close()
192
+ inbot.impconn.destroy()
189
193
  inbot.impconn = false
190
194
  App.imp.unregister(inbot.instanceID)
191
195
  }
192
196
 
193
- // register our connects *after* the receivers are configured above
194
-
195
197
  // finis
196
198
 
197
199
  inbot
@@ -199,41 +201,77 @@ closure InBot(worker, options, local inbot)
199
201
 
200
202
 
201
203
  /*
202
- * NubBot
204
+ * MewBot
205
+ *
206
+ * Create a remote InBot interface for the Main WEb browser thread.
207
+ *
208
+ */
209
+
210
+ closure MewBot(exec, options, local mewbot, inbot_impReceive)
211
+ {
212
+ global(App)
213
+ mewbot = InBot(exec, options)
214
+ mewbot.dispatcher = require("naanlib:frameworks/running/taskexec.nlg").TaskDispatcher()
215
+ inbot_impReceive = mewbot.impReceive
216
+
217
+ // impReceive
218
+ //
219
+ // Received a message from InTop.
220
+ //
221
+ mewbot.impReceive = function impReceive(message, sourceID) {
222
+ if message.id == "targetin"
223
+ mewbot.dispatcher(message.data, function(reply) {
224
+ mewbot.sender(sourceID, {
225
+ id: "targetout",
226
+ data: reply
227
+ })
228
+ })
229
+ else
230
+ inbot_impReceive(message, sourceID)
231
+ }
232
+
233
+ // finis
234
+
235
+ mewbot
236
+ }
237
+
238
+
239
+ /*
240
+ * WowBot
203
241
  *
204
- * Create a remote interface like InBot, but also provide messaging support for WebWorkerNub inside
205
- * the worker.
242
+ * Create a remote InBot interface for WebWorkerNub running in the worker. This forwards remoting
243
+ * messages to the worker so they can be handled in the correct place.
206
244
  *
207
245
  */
208
246
 
209
- closure NubBot(worker, options, local nubbot)
247
+ closure WowBot(worker, options, local wowbot)
210
248
  {
211
249
  global(App)
212
- nubbot = InBot(worker, options)
250
+ wowbot = InBot(worker, options)
213
251
 
214
252
  App.imp.addEventListener("active", function(event, info) {
215
- if info.ourID == nubbot.instanceID {
216
- nubbot.workerDestID = info.destID // handshake completed
217
- nubbot.notifyAll({ // send to tops
253
+ if info.ourID == wowbot.instanceID {
254
+ wowbot.workerDestID = info.destID // handshake completed
255
+ wowbot.notifyAll({ // send to tops
218
256
  id: "workerDestID"
219
- workerDestID: nubbot.workerDestID
257
+ workerDestID: wowbot.workerDestID
220
258
  })
221
259
  }
222
260
  })
223
261
 
224
- nubbot.impconn = App.imp.responder(function(data) {
225
- nubbot.worker.postMessage({ // send to worker
226
- scope: "naan-imp-web" // scoped for WorkerNub
262
+ wowbot.impconn = App.imp.responder(function(data) {
263
+ wowbot.worker.postMessage({ // send IMP messages to worker
264
+ scope: "naan-imp-web" // scoped for WebWorkerNub
227
265
  data: data
228
266
  })
229
267
  list(false, { sent: true })
230
268
  }, {
231
- ourID: nubbot.instanceID
269
+ ourID: wowbot.instanceID
232
270
  })
233
271
 
234
272
  // finis
235
273
 
236
- nubbot
274
+ wowbot
237
275
  };
238
276
 
239
277
 
@@ -245,11 +283,13 @@ closure NubBot(worker, options, local nubbot)
245
283
  */
246
284
 
247
285
  function workInit(local manifest) {
248
- manifest = `(InBot, NubBot, workInit)
286
+ manifest = `(InBot, MewBot, WowBot, workInit)
249
287
 
250
288
  Naan.module.build(module.id, "worker", function(modobj, compobj) {
251
289
  require("./browser.nlg")
252
290
  compobj.manifest = manifest
253
291
  modobj.exports.InBot = InBot
292
+ modobj.exports.MewBot = MewBot
293
+ modobj.exports.WowBot = WowBot
254
294
  })
255
295
  } ();
@@ -314,7 +314,7 @@ closure ScopedServiceWorker(pubID, pubVersion, callback, local scoper, result) {
314
314
  //
315
315
  // Destroy the service worker.
316
316
 
317
- worker.destroy = function destroy() {
317
+ scoper.destroy = function destroy() {
318
318
  scoper.serv.unregister()
319
319
  scoper.serv = false
320
320
  }