Showing the changes to libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp (1 of 7 files). Show all
Unified · Split
| @@ -225,14 +225,11 @@ void ScriptObjectV8Proxy::investigate() { · 224 unmodified lines | ||
| 225 | 225 | //auto objectTemplate = _v8ObjectTemplate.Get(_engine->getIsolate()); |
| 226 | 226 | auto objectTemplate = v8::ObjectTemplate::New(_engine->getIsolate()); |
| 227 | 227 | objectTemplate->SetInternalFieldCount(3); |
| 228 | − objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set)); | |
| 228 | + objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set, nullptr, nullptr, v8GetPropertyNames)); | |
| 229 | 229 | |
| 230 | 230 | const QMetaObject* metaObject = qobject->metaObject(); |
| 231 | 231 | |
| 232 | 232 | //qDebug(scriptengine) << "Investigate: " << metaObject->className(); |
| 233 | − if (QString("Vec3") == metaObject->className()) { | |
| 234 | − printf("Vec3"); | |
| 235 | − } | |
| 236 | 233 | if (QString("ConsoleScriptingInterface") == metaObject->className()) { |
| 237 | 234 | printf("ConsoleScriptingInterface"); |
| 238 | 235 | } |
| @@ -494,6 +491,60 @@ void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> v · 255 unmodified lines | ||
| 494 | 491 | } |
| 495 | 492 | } |
| 496 | 493 | |
| 494 | +void ScriptObjectV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info) { | |
| 495 | + qDebug(scriptengine) << "ScriptObjectV8Proxy::v8GetPropertyNames called"; | |
| 496 | + v8::HandleScope handleScope(info.GetIsolate()); | |
| 497 | + auto context = info.GetIsolate()->GetCurrentContext(); | |
| 498 | + v8::Context::Scope contextScope(context); | |
| 499 | + v8::Local<v8::Value> objectV8 = info.This(); | |
| 500 | + ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(info.GetIsolate(), objectV8); | |
| 501 | + if (!proxy) { | |
| 502 | + qDebug(scriptengine) << "ScriptObjectV8Proxy::v8GetPropertyNames: Proxy object not found when listing"; | |
| 503 | + return; | |
| 504 | + } | |
| 505 | + V8ScriptValue object(proxy->_engine, objectV8); | |
| 506 | + uint id; | |
| 507 | + v8::Local<v8::Array> properties = proxy->getPropertyNames(); | |
| 508 | + v8::Local<v8::Array> objectProperties; | |
| 509 | + uint32_t propertiesLength = properties->Length(); | |
| 510 | + if (info.This()->GetInternalField(2).As<v8::Object>()->GetPropertyNames(context).ToLocal(&objectProperties)) { | |
| 511 | + for (int n = 0; n < objectProperties->Length(); n++) { | |
| 512 | + if(!properties->Set(context, propertiesLength+n, objectProperties->Get(context, n).ToLocalChecked()).FromMaybe(false)) { | |
| 513 | + qDebug(scriptengine) << "ScriptObjectV8Proxy::v8GetPropertyNames: Cannot add member name"; | |
| 514 | + } | |
| 515 | + } | |
| 516 | + } | |
| 517 | + info.GetReturnValue().Set(properties); | |
| 518 | +} | |
| 519 | + | |
| 520 | +v8::Local<v8::Array> ScriptObjectV8Proxy::getPropertyNames() { | |
| 521 | + auto isolate = _engine->getIsolate(); | |
| 522 | + v8::Locker locker(isolate); | |
| 523 | + v8::Isolate::Scope isolateScope(isolate); | |
| 524 | + v8::EscapableHandleScope handleScope(_engine->getIsolate()); | |
| 525 | + auto context = _engine->getContext(); | |
| 526 | + v8::Context::Scope contextScope(_engine->getContext()); | |
| 527 | + | |
| 528 | + v8::Local<v8::Array> properties = v8::Array::New(isolate, _props.size() + _methods.size() + _signals.size()); | |
| 529 | + uint32_t position = 0; | |
| 530 | + for (PropertyDefMap::const_iterator i = _props.begin(); i != _props.end(); i++){ | |
| 531 | + if(!properties->Set(context, position++, i.value().name.constGet()).FromMaybe(false)) { | |
| 532 | + qDebug(scriptengine) << "ScriptObjectV8Proxy::getPropertyNames: Cannot add property member name"; | |
| 533 | + } | |
| 534 | + } | |
| 535 | + for (MethodDefMap::const_iterator i = _methods.begin(); i != _methods.end(); i++){ | |
| 536 | + if(!properties->Set(context, position++, i.value().name.constGet()).FromMaybe(false)) { | |
| 537 | + qDebug(scriptengine) << "ScriptObjectV8Proxy::getPropertyNames: Cannot add property member name"; | |
| 538 | + } | |
| 539 | + } | |
| 540 | + for (SignalDefMap::const_iterator i = _signals.begin(); i != _signals.end(); i++){ | |
| 541 | + if(!properties->Set(context, position++, i.value().name.constGet()).FromMaybe(false)) { | |
| 542 | + qDebug(scriptengine) << "ScriptObjectV8Proxy::getPropertyNames: Cannot add property member name"; | |
| 543 | + } | |
| 544 | + } | |
| 545 | + return handleScope.Escape(properties); | |
| 546 | +} | |
| 547 | + | |
| 497 | 548 | |
| 498 | 549 | V8ScriptValue ScriptObjectV8Proxy::property(const V8ScriptValue& object, const V8ScriptString& name, uint id) { |
| 499 | 550 | auto isolate = _engine->getIsolate(); |
| @@ -840,7 +891,12 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 340 unmodified lines | ||
| 840 | 891 | |
| 841 | 892 | // The Qt MOC engine will automatically call qRegisterMetaType on invokable parameters and properties, but there's |
| 842 | 893 | // nothing in there for return values so these need to be explicitly runtime-registered! |
| 843 | − Q_ASSERT(returnTypeId != QMetaType::UnknownType); | |
| 894 | + if (returnTypeId == QMetaType::UnknownType) { | |
| 895 | + QString methodName = fullName(); | |
| 896 | + qDebug(scriptengine) << "returnTypeId == QMetaType::UnknownType for method " << methodName; | |
| 897 | + _engine->logBacktrace(""); | |
| 898 | + //Q_ASSERT(false); | |
| 899 | + } | |
| 844 | 900 | if (returnTypeId == QMetaType::UnknownType) { |
| 845 | 901 | isolate->ThrowError(v8::String::NewFromUtf8(isolate, QString("Cannot call native function %1, its return value has not been registered with Qt").arg(fullName()).toStdString().c_str()).ToLocalChecked()); |
| 846 | 902 | return; |