Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit d69e2c8

Browse files
committed
chakrashim: Add 'Debug' object only when needed
If `--debug` is specified, the in-built 'Debug' object is exposed by chakra.dll that has some [APIs](https://msdn.microsoft.com/en-us/library/bs12a9wf(v=vs.94).aspx) that node-uwp relies on. With my change in #155, I had overriden 'Debug' global object and hence certain Debug APIs stopped working with `--debug` switch. The original intent of adding `Debug` object was that `util.js` fetches this object in Debugging context. In absense of `--debug` flag this object is unavailable and hence `util.js` throws TypeError. The fix is to expose `Debug` object only in the DebugContext (called from `util.js`). If ran with `--debug`, by the time `utill.js` code executes, engine would have already expose in-built `Debug` object and we won't overwrite it. Without `--debug` we would override `Debug` object. Thanks @agarwal-sandeep for helping debugging this issue. Fixes : #175
1 parent e300485 commit d69e2c8

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

deps/chakrashim/lib/chakra_shim.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
// IN THE SOFTWARE.
2020
'use strict';
2121

22-
// CHAKRA-TODO doesn't implement the debugger. So add a dummy 'Debug' on
23-
// global object for now.
24-
Object.defineProperty(this, 'Debug',
25-
{ value: {}, enumerable: false, configurable: false, writable: false });
26-
2722
(function() {
2823
// Save original builtIns
2924
var

deps/chakrashim/src/v8debug.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ Local<Context> Debug::GetDebugContext() {
6363
HandleScope scope(isolate);
6464
g_debugContext = *Context::New(isolate);
6565
JsAddRef(g_debugContext, nullptr);
66+
67+
// CHAKRA-TODO: Chakra doesn't fully implement the debugger without
68+
// --debug flag. Add a dummy 'Debug' on global object if it doesn't
69+
// already exist.
70+
{
71+
Context::Scope context_scope(g_debugContext);
72+
wchar_t * debugScript = L""
73+
"if(this['Debug'] == undefined) { "
74+
"Object.defineProperty(this, 'Debug', { value: {}, "
75+
"enumerable : false, configurable : false, writable : false "
76+
"}); "
77+
"}";
78+
JsValueRef result;
79+
if (JsRunScript(debugScript, JS_SOURCE_CONTEXT_NONE, L"", &result) != JsNoError) {
80+
return Local<Context>();
81+
}
82+
}
6683
}
6784

6885
return static_cast<Context*>(g_debugContext);

test/parallel/test-cli-syntax.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ var syntaxArgs = [
5555

5656
// stderr should have a syntax error message
5757
var match = c.stderr.match(common.engineSpecificMessage({
58-
v8: /^SyntaxError: Unexpected identifier$/m,
59-
chakracore: /^SyntaxError: Expected ';'$/m})
60-
);
58+
v8: /^SyntaxError: Unexpected identifier$/m,
59+
chakracore: /^SyntaxError: Expected ';'$/m})
60+
);
6161
assert(match, 'stderr incorrect');
6262

6363
assert.equal(c.status, 1, 'code == ' + c.status);

0 commit comments

Comments
 (0)