on master help sign in
Debugger: fix module assignment to runtime with prototype magic.
cbe2c7aLaszlo Pandy
runtime/Debugger.js+11−4
@@ -113,12 +113,19 @@ function debugModule(module, runtime) {
113
113
114 // runtime is the prototype of wrappedRuntime
114 // runtime is the prototype of wrappedRuntime
115 // so we can access all runtime properties too
115 // so we can access all runtime properties too
116− var wrappedRuntime = Object.create(runtime, {
116+ var wrappedRuntime = Object.create(runtime);
117− notify: wrapNotify,
117+ wrappedRuntime.notify = wrapNotify;
118− runDelayed: wrapRunDelayed
118+ wrappedRuntime.runDelayed = wrapRunDelayed;
119+
120+ var assignedPropTracker = Object.create(wrappedRuntime);
121+ var moduleInstance = module.make(assignedPropTracker);
122+ // The main module stores imported modules onto the runtime.
123+ // To ensure only one instance of each module is created,
124+ // we assign them back on the original runtime object.
125+ Object.keys(assignedPropTracker).forEach(function(key) {
126+ runtime[key] = assignedPropTracker[key];
119 });
127 });
120
128
121− var moduleInstance = module.make(wrappedRuntime);
122 var moduleNodes = flattenNodes(wrappedRuntime.inputs);
129 var moduleNodes = flattenNodes(wrappedRuntime.inputs);
123 var tracePath = tracePathInit(runtime, moduleInstance.main);
130 var tracePath = tracePathInit(runtime, moduleInstance.main);
124
131