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

Commit

Permalink
chakrashim: add dummy Debug.MakeMirror
Browse files Browse the repository at this point in the history
Latest node util uses Debug.MakeMirror to inspect Promise objects. This
change adds a dummy Debug.MakeMirror implementation which always returns
```Promise { '<unknown>' }```, to avoid displaying an exception stack
when inspecting Promise objects.

PR-URL: #42
Reviewed-By: Sandeep Agarwal <[email protected]>
Reviewed-By: Kunal Pathak <[email protected]>
  • Loading branch information
Jianchun Xu committed Mar 25, 2016
1 parent e7b09ef commit 803af69
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 9 deletions.
76 changes: 76 additions & 0 deletions deps/chakrashim/lib/chakra_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,81 @@
});
}

// Ensure global Debug object if not already exists, and patch it.
function ensureDebug(otherGlobal) {
if (!global.Debug) {
Object_defineProperty(global, 'Debug', {
value: {}, enumerable : false, configurable : false, writable : false
});
}

otherProcess = otherGlobal.process;
patchDebug(global.Debug);
}

var otherProcess;

function patchDebug(Debug) {
if (!Debug || Debug.MakeMirror) {
return;
}

class Mirror {
constructor(type) {
this.type_ = type;
}
type() {
return this.type_;
}
}

class ValueMirror extends Mirror {
constructor(type, value) {
super(type);
this.value_ = value;
}
value() {
return this.value_;
}
}

class UndefinedMirror extends ValueMirror {
constructor() {
super('undefined', undefined);
}
}
const undefinedMirror = new UndefinedMirror();

class ObjectMirror extends ValueMirror {
constructor(type, value) {
super(type || 'object', value);
}
}

class PromiseMirror extends ObjectMirror {
constructor(value) {
super('promise', value);
}
status() {
return '<unknown>';
}
promiseValue() {
return new ValueMirror('<unknown>', '<unknown>');
}
}

const util = otherProcess.binding('util');

Debug.MakeMirror = (value) => {
if (util.isPromise(value)) {
return new PromiseMirror(value);
}

// Not supporting other types
return undefinedMirror;
};
}

function patchUtils(utils) {
var isUintRegex = /^(0|[1-9]\\d*)$/;

Expand Down Expand Up @@ -437,6 +512,7 @@
utils.getSymbolFor = function(key) {
return Symbol_for(key);
};
utils.ensureDebug = ensureDebug;
}

patchErrorTypes();
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/src/jsrtcachedpropertyidref.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ DEF(getIndexedOwnKeys)
DEF(getStackTrace)
DEF(getSymbolKeyFor)
DEF(getSymbolFor)
DEF(ensureDebug)
DEF(getFunctionName)
DEF(getFileName)
DEF(getColumnNumber)
Expand Down
4 changes: 3 additions & 1 deletion deps/chakrashim/src/jsrtcontextshim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ ContextShim::ContextShim(IsolateShim * isolateShim,
getIndexedOwnKeysFunction(JS_INVALID_REFERENCE),
getStackTraceFunction(JS_INVALID_REFERENCE),
getSymbolKeyForFunction(JS_INVALID_REFERENCE),
getSymbolForFunction(JS_INVALID_REFERENCE) {
getSymbolForFunction(JS_INVALID_REFERENCE),
ensureDebugFunction(JS_INVALID_REFERENCE) {
memset(globalConstructor, 0, sizeof(globalConstructor));
memset(globalPrototypeFunction, 0, sizeof(globalPrototypeFunction));
}
Expand Down Expand Up @@ -578,6 +579,7 @@ CHAKRASHIM_FUNCTION_GETTER(getIndexedOwnKeys)
CHAKRASHIM_FUNCTION_GETTER(getStackTrace)
CHAKRASHIM_FUNCTION_GETTER(getSymbolKeyFor)
CHAKRASHIM_FUNCTION_GETTER(getSymbolFor)
CHAKRASHIM_FUNCTION_GETTER(ensureDebug)

#define DEF_IS_TYPE(F) CHAKRASHIM_FUNCTION_GETTER(F)
#include "jsrtcachedpropertyidref.inc"
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/src/jsrtcontextshim.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ JsValueRef F##Function; \
DECLARE_CHAKRASHIM_FUNCTION_GETTER(getStackTrace);
DECLARE_CHAKRASHIM_FUNCTION_GETTER(getSymbolKeyFor);
DECLARE_CHAKRASHIM_FUNCTION_GETTER(getSymbolFor);
DECLARE_CHAKRASHIM_FUNCTION_GETTER(ensureDebug);

#define DEF_IS_TYPE(F) DECLARE_CHAKRASHIM_FUNCTION_GETTER(F)
#include "jsrtcachedpropertyidref.inc"
Expand Down
14 changes: 6 additions & 8 deletions deps/chakrashim/src/v8debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,17 @@ Local<Context> Debug::GetDebugContext(Isolate* isolate) {
g_debugContext = *Context::New(isolate);
JsAddRef(g_debugContext, nullptr);

Local<Object> global = Context::GetCurrent()->Global();

// CHAKRA-TODO: Chakra doesn't fully implement the debugger without
// --debug flag. Add a dummy 'Debug' on global object if it doesn't
// already exist.
{
Context::Scope context_scope(g_debugContext);
wchar_t * debugScript = L""
"if(this['Debug'] == undefined) { "
"Object.defineProperty(this, 'Debug', { value: {}, "
"enumerable : false, configurable : false, writable : false "
"}); "
"}";
JsValueRef result;
if (JsRunScript(debugScript, JS_SOURCE_CONTEXT_NONE, L"", &result) != JsNoError) {
jsrt::ContextShim* contextShim = jsrt::ContextShim::GetCurrent();
JsValueRef ensureDebug = contextShim->GetensureDebugFunction();
JsValueRef unused;
if (jsrt::CallFunction(ensureDebug, *global, &unused) != JsNoError) {
return Local<Context>();
}
}
Expand Down

0 comments on commit 803af69

Please sign in to comment.