Skip to content

Instantly share code, notes, and snippets.

@Zirak
Created April 25, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zirak/18012f4ad44d5a3252e9 to your computer and use it in GitHub Desktop.
Save Zirak/18012f4ad44d5a3252e9 to your computer and use it in GitHub Desktop.
@@ -138,19 +142,28 @@ void V8InjectedScriptHost::internalConstructorNameMethodCustom(const v8::Functio
return;
v8::Local<v8::Object> object = info[0].As<v8::Object>();
- v8::Local<v8::String> result = object->GetConstructorName();
+ v8::Local<v8::String> result = object->GetConstructorName(); // <-- bug here
if (!result.IsEmpty() && toCoreStringWithUndefinedOrNullCheck(result) == "Object") {
+ v8::TryCatch tryCatch;
+ v8::MaybeLocal<v8::Value> maybeConstructor;
+ v8::Local<v8::Value> constructor;
v8::Local<v8::String> constructorSymbol = v8AtomicString(info.GetIsolate(), "constructor");
- if (object->HasRealNamedProperty(constructorSymbol) && !object->HasRealNamedCallbackProperty(constructorSymbol)) {
- v8::TryCatch tryCatch;
- v8::Local<v8::Value> constructor = object->GetRealNamedProperty(constructorSymbol);
- if (!constructor.IsEmpty() && constructor->IsFunction()) {
- v8::Local<v8::String> constructorName = functionDisplayName(v8::Local<v8::Function>::Cast(constructor));
- if (!constructorName.IsEmpty() && !tryCatch.HasCaught())
- result = constructorName;
- }
+
+ // Did the user define a constructor property?
+ if (object->HasRealNamedProperty(constructorSymbol) && !object->HasRealNamedCallbackProperty(constructorSymbol))
+ maybeConstructor = object->GetRealNamedProperty(constructorSymbol);
+
+ // Check the prototype chain for the constructor
+ if (maybeConstructor.IsEmpty())
+ maybeConstructor = object->GetRealNamedPropertyInPrototypeChain(constructorSymbol);
+
+ if (!maybeConstructor.IsEmpty() && maybeConstructor.ToLocal(&constructor) && constructor->IsFunction()) {
+ v8::Local<v8::String> constructorName = functionDisplayName(v8::Local<v8::Function>::Cast(constructor));
+ if (!constructorName.IsEmpty() && !tryCatch.HasCaught())
+ result = constructorName;
}
+
if (toCoreStringWithUndefinedOrNullCheck(result) == "Object" && object->IsFunction())
result = v8AtomicString(info.GetIsolate(), "Function");
}
void V8InjectedScriptHost::internalConstructorNameMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (info.Length() < 1 || !info[0]->IsObject())
return;
v8::Local<v8::Object> object = info[0].As<v8::Object>();
v8::Local<v8::String> result = object->GetConstructorName(); // <-- bug here
if (!result.IsEmpty() && toCoreStringWithUndefinedOrNullCheck(result) == "Object") {
v8::TryCatch tryCatch;
v8::MaybeLocal<v8::Value> maybeConstructor;
v8::Local<v8::Value> constructor;
v8::Local<v8::String> constructorSymbol = v8AtomicString(info.GetIsolate(), "constructor");
// Did the user define a constructor property?
if (object->HasRealNamedProperty(constructorSymbol) && !object->HasRealNamedCallbackProperty(constructorSymbol))
maybeConstructor = object->GetRealNamedProperty(constructorSymbol);
// Check the prototype chain for the constructor
if (maybeConstructor.IsEmpty())
maybeConstructor = object->GetRealNamedPropertyInPrototypeChain(constructorSymbol);
if (!maybeConstructor.IsEmpty() && maybeConstructor.ToLocal(&constructor) && constructor->IsFunction()) {
v8::Local<v8::String> constructorName = functionDisplayName(v8::Local<v8::Function>::Cast(constructor));
if (!constructorName.IsEmpty() && !tryCatch.HasCaught())
result = constructorName;
}
if (toCoreStringWithUndefinedOrNullCheck(result) == "Object" && object->IsFunction())
result = v8AtomicString(info.GetIsolate(), "Function");
}
v8SetReturnValue(info, result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment