From 62f0d62882b12acc6a1aadd92bab8dd580ebad12 Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Fri, 22 Jun 2018 12:26:21 -0500 Subject: [PATCH] making sure to actually set __CANJS_DEVTOOLS__ global --- can-debug-test.js | 26 +++++++++++++++----------- can-debug.js | 15 ++++++++++----- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/can-debug-test.js b/can-debug-test.js index 140c209..71073f5 100644 --- a/can-debug-test.js +++ b/can-debug-test.js @@ -75,6 +75,20 @@ testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if availab testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if __CANJS_DEVTOOLS__ is set later", function(assert) { var done = assert.async(); var fakeWindow = {}; + var fakeDevtoolsGlobal = { + register: function(can) { + assert.ok("Symbol" in can, "can.Symbol passed"); + assert.ok("Reflect" in can, "can.Reflect passed"); + assert.ok("queues" in can, "can.queues passed"); + assert.ok("getGraph" in can, "can.getGraph passed"); + assert.ok("formatGraph" in can, "can.formatGraph passed"); + assert.ok("mergeDeep" in can, "can.mergeDeep passed"); + + assert.equal(fakeWindow.__CANJS_DEVTOOLS__, fakeDevtoolsGlobal, "sets window.__CANJS_DEVTOOLS__"); + + done(); + } + }; clone({ "can-globals": { @@ -89,16 +103,6 @@ testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if __CANJS }) .import("can-debug") .then(function() { - fakeWindow.__CANJS_DEVTOOLS__ = { - register: function(can) { - assert.ok("Symbol" in can, "can.Symbol passed"); - assert.ok("Reflect" in can, "can.Reflect passed"); - assert.ok("queues" in can, "can.queues passed"); - assert.ok("getGraph" in can, "can.getGraph passed"); - assert.ok("formatGraph" in can, "can.formatGraph passed"); - assert.ok("mergeDeep" in can, "can.mergeDeep passed"); - done(); - } - }; + fakeWindow.__CANJS_DEVTOOLS__ = fakeDevtoolsGlobal; }); }); diff --git a/can-debug.js b/can-debug.js index 9d651fe..9403753 100644 --- a/can-debug.js +++ b/can-debug.js @@ -38,14 +38,19 @@ var devtoolsCanModules = { formatGraph: namespace.debug.formatGraph, mergeDeep: mergeDeep }; +var devtoolsGlobalName = "__CANJS_DEVTOOLS__"; -if (global.__CANJS_DEVTOOLS__) { - global.__CANJS_DEVTOOLS__.register(devtoolsCanModules); +if (global[devtoolsGlobalName]) { + global[devtoolsGlobalName].register(devtoolsCanModules); } else { - Object.defineProperty(global, "__CANJS_DEVTOOLS__", { + Object.defineProperty(global, devtoolsGlobalName, { set: function(devtoolsGlobal) { + Object.defineProperty(global, devtoolsGlobalName, { + value: devtoolsGlobal + }); + devtoolsGlobal.register(devtoolsCanModules); - return devtoolsGlobal; - } + }, + configurable: true }); }