4
4
#include " tools.h"
5
5
6
6
using v8::Isolate;
7
- using v8::Handle;
8
7
using v8::Local;
9
8
using v8::Value;
10
9
using v8::Boolean;
@@ -31,7 +30,7 @@ using Nan::EmptyString;
31
30
using Nan::Utf8String;
32
31
33
32
namespace nodex {
34
- void InjectedScriptHost::Initialize (Handle <Object> target) {
33
+ void InjectedScriptHost::Initialize (Local <Object> target) {
35
34
Local<Object> injectedScriptHost = New<Object>();
36
35
SetMethod (injectedScriptHost, " eval" , Eval);
37
36
SetMethod (injectedScriptHost, " evaluateWithExceptionDetails" , EvaluateWithExceptionDetails);
@@ -40,11 +39,12 @@ namespace nodex {
40
39
SetMethod (injectedScriptHost, " internalConstructorName" , InternalConstructorName);
41
40
SetMethod (injectedScriptHost, " functionDetailsWithoutScopes" , FunctionDetailsWithoutScopes);
42
41
SetMethod (injectedScriptHost, " callFunction" , CallFunction);
42
+ SetMethod (injectedScriptHost, " getInternalProperties" , GetInternalProperties);
43
43
44
44
SET (target, " InjectedScriptHost" , injectedScriptHost);
45
45
}
46
46
47
- Handle <Object> InjectedScriptHost::createExceptionDetails (Handle <Message> message) {
47
+ Local <Object> InjectedScriptHost::createExceptionDetails (Local <Message> message) {
48
48
EscapableHandleScope scope;
49
49
50
50
Local<Object> exceptionDetails = New<Object>();
@@ -133,51 +133,48 @@ namespace nodex {
133
133
RETURN (Undefined ());
134
134
};
135
135
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
+ };
138
142
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);
142
147
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);
146
151
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);
150
155
151
- return scope. Escape ( EmptyString () );
156
+ return v8::Local<v8::String>( );
152
157
};
153
158
154
159
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 ;
159
162
160
163
Local<Object> object = CHK (To<Object>(info[0 ]));
161
164
Local<String> result = object->GetConstructorName ();
162
165
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 ) {
170
167
Local<String> constructorSymbol = CHK (New (" constructor" ));
171
168
if (object->HasRealNamedProperty (constructorSymbol) && !object->HasRealNamedCallbackProperty (constructorSymbol)) {
172
169
TryCatch tryCatch;
173
170
Local<Value> constructor = object->GetRealNamedProperty (constructorSymbol);
174
171
if (!constructor.IsEmpty () && constructor->IsFunction ()) {
175
- Local<String> constructorName = functionDisplayName (Handle <Function>::Cast (constructor));
172
+ Local<String> constructorName = functionDisplayName (Local <Function>::Cast (constructor));
176
173
if (!constructorName.IsEmpty () && !tryCatch.HasCaught ())
177
174
result = constructorName;
178
175
}
179
176
}
180
- if (strcmp (result_type , " Object" ) == 0 && object->IsFunction ())
177
+ if (strcmp (toCoreStringWithUndefinedOrNullCheck (result) , " Object" ) == 0 && object->IsFunction ())
181
178
result = CHK (New (" Function" ));
182
179
}
183
180
@@ -203,7 +200,7 @@ namespace nodex {
203
200
Local<Object> result = New<Object>();
204
201
SET (result, " location" , location);
205
202
206
- Handle <String> name = functionDisplayName (function);
203
+ Local <String> name = functionDisplayName (function);
207
204
SET (result, " functionName" , name.IsEmpty () ? EmptyString () : name);
208
205
209
206
SET (result, " isGenerator" , New<Boolean>(function->IsGeneratorFunction ()));
@@ -217,8 +214,8 @@ namespace nodex {
217
214
if (!info[0 ]->IsFunction ())
218
215
return ThrowTypeError (" Argument 0 must be a function." );
219
216
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 ];
222
219
223
220
TryCatch tryCatch;
224
221
MaybeLocal<Value> result;
@@ -232,9 +229,9 @@ namespace nodex {
232
229
if (!info[2 ]->IsArray ())
233
230
return ThrowTypeError (" Argument 2 must be an array." );
234
231
235
- Handle <Array> arguments = Handle <Array>::Cast (info[2 ]);
232
+ Local <Array> arguments = Local <Array>::Cast (info[2 ]);
236
233
int argc = arguments->Length ();
237
- Handle <Value> *argv = new Handle <Value>[argc];
234
+ Local <Value> *argv = new Local <Value>[argc];
238
235
for (int i = 0 ; i < argc; ++i)
239
236
argv[i] = CHK (Get (arguments, i));
240
237
@@ -260,4 +257,13 @@ namespace nodex {
260
257
261
258
RETURN (CHK (result));
262
259
};
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
+ }
263
269
}
0 commit comments