Skip to content

Commit de506f8

Browse files
committed
Fix InjectedScriptHost for NODE_NEXT
1 parent 41e242d commit de506f8

File tree

4 files changed

+240
-53
lines changed

4 files changed

+240
-53
lines changed

InjectedScript/InjectedScriptHost.js

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,77 @@
11
"use strict";
22

33
(function (binding, DebuggerScript) {
4-
function InjectedScriptHost() {}
5-
4+
var lastBoundObjectId = 0;
5+
var idToWrappedObject = new Map();
6+
var idToObjectGroupName = new Map();
7+
var nameToObjectGroup = new Map();
8+
9+
function InjectedScriptHost() {
10+
}
11+
612
InjectedScriptHost.prototype = binding.InjectedScriptHost;
713

14+
InjectedScriptHost.prototype.bind = function(value, groupName) {
15+
if (lastBoundObjectId <= 0)
16+
lastBoundObjectId = 1;
17+
18+
var id = lastBoundObjectId++;
19+
idToWrappedObject.set(id, value);
20+
21+
if (!groupName) return;
22+
if (id < 0) return;
23+
24+
idToObjectGroupName.set(id, groupName);
25+
26+
if (!nameToObjectGroup.has(groupName))
27+
nameToObjectGroup.set(groupName, [id]);
28+
else
29+
nameToObjectGroup.get(groupName).push(id);
30+
31+
return id;
32+
};
33+
34+
InjectedScriptHost.prototype.objectForId = function(id) {
35+
if (!Number(id)) return;
36+
return idToWrappedObject.get(id);
37+
};
38+
39+
InjectedScriptHost.prototype.idToObjectGroupName = function(id) {
40+
if (!Number(id)) return;
41+
return idToObjectGroupName.get(id) || '';
42+
}
43+
844
InjectedScriptHost.prototype.isHTMLAllCollection = function(object) {
945
//We don't have `all` collection in NodeJS
1046
return false;
1147
};
1248

49+
InjectedScriptHost.prototype.isDOMWrapper = function(object) {
50+
return false;
51+
};
52+
1353
InjectedScriptHost.prototype.suppressWarningsAndCallFunction = function(func, receiver, args) {
1454
return this.callFunction(func, receiver, args);
1555
};
1656

1757
InjectedScriptHost.prototype.functionDetails = function(fun) {
1858
var details = this.functionDetailsWithoutScopes(fun);
1959
var scopes = DebuggerScript.getFunctionScopes(fun);
20-
60+
2161
if (scopes && scopes.length) {
2262
details.rawScopes = scopes;
2363
}
24-
64+
2565
return details;
2666
};
2767

28-
InjectedScriptHost.prototype.getInternalProperties = function(value) {
29-
return DebuggerScript.getInternalProperties(value);
68+
InjectedScriptHost.prototype.generatorObjectDetails = function(object) {
69+
return DebuggerScript.getGeneratorObjectDetails(object);
3070
};
31-
71+
72+
InjectedScriptHost.prototype.collectionEntries = function(object) {
73+
return DebuggerScript.getCollectionEntries(object);
74+
};
75+
3276
return new InjectedScriptHost();
3377
});

src/InjectedScriptHost.cc

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "tools.h"
55

66
using v8::Isolate;
7-
using v8::Handle;
87
using v8::Local;
98
using v8::Value;
109
using v8::Boolean;
@@ -31,7 +30,7 @@ using Nan::EmptyString;
3130
using Nan::Utf8String;
3231

3332
namespace nodex {
34-
void InjectedScriptHost::Initialize(Handle<Object> target) {
33+
void InjectedScriptHost::Initialize(Local<Object> target) {
3534
Local<Object> injectedScriptHost = New<Object>();
3635
SetMethod(injectedScriptHost, "eval", Eval);
3736
SetMethod(injectedScriptHost, "evaluateWithExceptionDetails", EvaluateWithExceptionDetails);
@@ -40,11 +39,12 @@ namespace nodex {
4039
SetMethod(injectedScriptHost, "internalConstructorName", InternalConstructorName);
4140
SetMethod(injectedScriptHost, "functionDetailsWithoutScopes", FunctionDetailsWithoutScopes);
4241
SetMethod(injectedScriptHost, "callFunction", CallFunction);
42+
SetMethod(injectedScriptHost, "getInternalProperties", GetInternalProperties);
4343

4444
SET(target, "InjectedScriptHost", injectedScriptHost);
4545
}
4646

47-
Handle<Object> InjectedScriptHost::createExceptionDetails(Handle<Message> message) {
47+
Local<Object> InjectedScriptHost::createExceptionDetails(Local<Message> message) {
4848
EscapableHandleScope scope;
4949

5050
Local<Object> exceptionDetails = New<Object>();
@@ -133,51 +133,48 @@ namespace nodex {
133133
RETURN(Undefined());
134134
};
135135

136-
Local<String> InjectedScriptHost::functionDisplayName(Handle<Function> function) {
137-
EscapableHandleScope scope;
136+
const char* InjectedScriptHost::toCoreStringWithUndefinedOrNullCheck(Local<String> result) {
137+
if (result.IsEmpty() || result->IsNull() || result->IsUndefined())
138+
return "";
139+
else
140+
return *Utf8String(result);
141+
};
138142

139-
Local<String> value = CHK(To<String>(function->GetDisplayName()));
140-
if (value->Length())
141-
return scope.Escape(value);
143+
Local<String> InjectedScriptHost::functionDisplayName(Local<Function> function) {
144+
Local<Value> value = function->GetDisplayName();
145+
if (value->IsString() && Local<v8::String>::Cast(value)->Length())
146+
return Local<String>::Cast(value);
142147

143-
value = CHK(To<String>(function->GetName()));
144-
if (value->Length())
145-
return scope.Escape(value);
148+
value = function->GetName();
149+
if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length())
150+
return v8::Local<v8::String>::Cast(value);
146151

147-
value = CHK(To<String>(function->GetInferredName()));
148-
if (value->Length())
149-
return scope.Escape(value);
152+
value = function->GetInferredName();
153+
if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length())
154+
return v8::Local<v8::String>::Cast(value);
150155

151-
return scope.Escape(EmptyString());
156+
return v8::Local<v8::String>();
152157
};
153158

154159
NAN_METHOD(InjectedScriptHost::InternalConstructorName) {
155-
if (info.Length() < 1)
156-
return ThrowError("One argument expected.");
157-
if (!info[0]->IsObject())
158-
return ThrowTypeError("The argument must be an object.");
160+
if (info.Length() < 1 || !info[0]->IsObject())
161+
return;
159162

160163
Local<Object> object = CHK(To<Object>(info[0]));
161164
Local<String> result = object->GetConstructorName();
162165

163-
const char* result_type;
164-
if (result.IsEmpty() || result->IsNull() || result->IsUndefined())
165-
result_type = "";
166-
else
167-
result_type = *Utf8String(info[0]);
168-
169-
if (!result.IsEmpty() && strcmp(result_type, "Object") == 0) {
166+
if (!result.IsEmpty() && strcmp(toCoreStringWithUndefinedOrNullCheck(result), "Object") == 0) {
170167
Local<String> constructorSymbol = CHK(New("constructor"));
171168
if (object->HasRealNamedProperty(constructorSymbol) && !object->HasRealNamedCallbackProperty(constructorSymbol)) {
172169
TryCatch tryCatch;
173170
Local<Value> constructor = object->GetRealNamedProperty(constructorSymbol);
174171
if (!constructor.IsEmpty() && constructor->IsFunction()) {
175-
Local<String> constructorName = functionDisplayName(Handle<Function>::Cast(constructor));
172+
Local<String> constructorName = functionDisplayName(Local<Function>::Cast(constructor));
176173
if (!constructorName.IsEmpty() && !tryCatch.HasCaught())
177174
result = constructorName;
178175
}
179176
}
180-
if (strcmp(result_type, "Object") == 0 && object->IsFunction())
177+
if (strcmp(toCoreStringWithUndefinedOrNullCheck(result), "Object") == 0 && object->IsFunction())
181178
result = CHK(New("Function"));
182179
}
183180

@@ -203,7 +200,7 @@ namespace nodex {
203200
Local<Object> result = New<Object>();
204201
SET(result, "location", location);
205202

206-
Handle<String> name = functionDisplayName(function);
203+
Local<String> name = functionDisplayName(function);
207204
SET(result, "functionName", name.IsEmpty() ? EmptyString() : name);
208205

209206
SET(result, "isGenerator", New<Boolean>(function->IsGeneratorFunction()));
@@ -217,8 +214,8 @@ namespace nodex {
217214
if (!info[0]->IsFunction())
218215
return ThrowTypeError("Argument 0 must be a function.");
219216

220-
Handle<Function> function = Handle<Function>::Cast(info[0]);
221-
Handle<Value> receiver = info[1];
217+
Local<Function> function = Local<Function>::Cast(info[0]);
218+
Local<Value> receiver = info[1];
222219

223220
TryCatch tryCatch;
224221
MaybeLocal<Value> result;
@@ -232,9 +229,9 @@ namespace nodex {
232229
if (!info[2]->IsArray())
233230
return ThrowTypeError("Argument 2 must be an array.");
234231

235-
Handle<Array> arguments = Handle<Array>::Cast(info[2]);
232+
Local<Array> arguments = Local<Array>::Cast(info[2]);
236233
int argc = arguments->Length();
237-
Handle<Value> *argv = new Handle<Value>[argc];
234+
Local<Value> *argv = new Local<Value>[argc];
238235
for (int i = 0; i < argc; ++i)
239236
argv[i] = CHK(Get(arguments, i));
240237

@@ -260,4 +257,13 @@ namespace nodex {
260257

261258
RETURN(CHK(result));
262259
};
260+
261+
NAN_METHOD(InjectedScriptHost::GetInternalProperties) {
262+
if (info.Length() < 1 || !info[0]->IsObject())
263+
return;
264+
265+
MaybeLocal<Array> result = v8::Debug::GetInternalProperties(info.GetIsolate(), info[0]);
266+
267+
RETURN(CHK(result));
268+
}
263269
}

src/InjectedScriptHost.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,11 @@ namespace nodex {
1515
static NAN_METHOD(InternalConstructorName);
1616
static NAN_METHOD(FunctionDetailsWithoutScopes);
1717
static NAN_METHOD(CallFunction);
18-
/*
19-
static v8::Local<v8::Value> New(const v8::CpuProfile* node);
20-
static Nan::Persistent<v8::Array> profiles;
21-
*/
18+
static NAN_METHOD(GetInternalProperties);
2219
private:
23-
static v8::Handle<v8::Object> createExceptionDetails(v8::Handle<v8::Message> message);
24-
static v8::Local<v8::String> functionDisplayName(v8::Handle<v8::Function> function);
25-
26-
/*
27-
static NAN_METHOD(Delete);
28-
static void Initialize();
29-
static Nan::Persistent<v8::ObjectTemplate> profile_template_;
30-
static uint32_t uid_counter;
31-
*/
20+
static v8::Local<v8::Object> createExceptionDetails(v8::Local<v8::Message> message);
21+
static v8::Local<v8::String> functionDisplayName(v8::Local<v8::Function> function);
22+
static const char* toCoreStringWithUndefinedOrNullCheck(v8::Local<v8::String> result);
3223
};
3324

3425
} //namespace nodex

0 commit comments

Comments
 (0)