diff --git a/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp b/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp index 76db368169..47ff561d87 100644 --- a/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp +++ b/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp @@ -142,7 +142,7 @@ ScriptObjectV8Proxy* ScriptObjectV8Proxy::unwrapProxy(const V8ScriptValue& val) return nullptr; } v8::Local v8Object = v8::Local::Cast(v8Value); - if (v8Object->InternalFieldCount() != 2) { + if (v8Object->InternalFieldCount() != 3) { qDebug(scriptengine) << "Cannot unwrap proxy - wrong number of internal fields"; return nullptr; } @@ -175,7 +175,7 @@ void ScriptObjectV8Proxy::investigate() { v8::Context::Scope contextScope(_engine->getContext()); auto objectTemplate = _v8ObjectTemplate.Get(_engine->getIsolate()); - objectTemplate->SetInternalFieldCount(2); + objectTemplate->SetInternalFieldCount(3); objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set)); const QMetaObject* metaObject = qobject->metaObject(); @@ -295,6 +295,7 @@ void ScriptObjectV8Proxy::investigate() { v8::Local v8Object = objectTemplate->NewInstance(_engine->getContext()).ToLocalChecked(); v8Object->SetAlignedPointerInInternalField(0, const_cast(internalPointsToQObjectProxy)); v8Object->SetAlignedPointerInInternalField(1, reinterpret_cast(this)); + v8Object->SetInternalField(2, v8::Object::New(_engine->getIsolate())); _v8Object.Reset(_engine->getIsolate(), v8Object); } @@ -385,7 +386,12 @@ void ScriptObjectV8Proxy::v8Get(v8::Local name, const v8::PropertyCall V8ScriptValue value = proxy->property(object, nameString, id); info.GetReturnValue().Set(value.get()); } else { - qDebug(scriptengine) << "Value not found: " << *utf8Value; + v8::Local property; + if(info.This()->GetInternalField(2).As()->Get(proxy->_engine->getContext(), name).ToLocal(&property)) { + info.GetReturnValue().Set(property); + } else { + qDebug(scriptengine) << "Value not found: " << *utf8Value; + } } } @@ -407,7 +413,12 @@ void ScriptObjectV8Proxy::v8Set(v8::Local name, v8::Local v proxy->setProperty(object, nameString, id, V8ScriptValue(info.GetIsolate(), value)); info.GetReturnValue().Set(value); } else { - qDebug(scriptengine) << "Value not found: " << *utf8Value; + // V8TODO: Should it be v8::Object or v8::Local? + if (info.This()->GetInternalField(2).As()->Set(proxy->_engine->getContext(), name, value).FromMaybe(false)) { + info.GetReturnValue().Set(value); + } else { + qDebug(scriptengine) << "Set failed: " << *utf8Value; + } } } diff --git a/libraries/script-engine/src/v8/ScriptValueV8Wrapper.cpp b/libraries/script-engine/src/v8/ScriptValueV8Wrapper.cpp index 9eae55aa4c..7ab42d5123 100644 --- a/libraries/script-engine/src/v8/ScriptValueV8Wrapper.cpp +++ b/libraries/script-engine/src/v8/ScriptValueV8Wrapper.cpp @@ -233,7 +233,7 @@ void ScriptValueV8Wrapper::setProperty(const QString& name, const ScriptValue& v v8::Local key = v8::String::NewFromUtf8(isolate, name.toStdString().c_str(),v8::NewStringType::kNormal).ToLocalChecked(); Q_ASSERT(_value.get()->IsObject()); auto object = v8::Local::Cast(_value.get()); - // V8TODO: What if velue context and current context is different? + // V8TODO: What if value context and current context is different? //v8::Maybe retVal = object->Set(_value.getContext(), key, unwrapped.constGet()); //v8::Maybe retVal = object->Set(_engine->getContext(), key, unwrapped.constGet()); v8::Maybe retVal = object->Set(isolate->GetCurrentContext(), key, unwrapped.constGet()); diff --git a/tests/script-engine/src/tests/003_vector_math.js b/tests/script-engine/src/tests/003_vector_math.js index b76b81798d..4be39a91b3 100644 --- a/tests/script-engine/src/tests/003_vector_math.js +++ b/tests/script-engine/src/tests/003_vector_math.js @@ -1,4 +1,8 @@ print(JSON.stringify(this)); -var v1 = { x: 1, y: 0, z: 0 }; -var v2 = { x: 1, y: 0, z: 0 }; +var v1 = { x: 1, y: 0, z: 3 }; +var v2 = { x: 1, y: 0, z: 1 }; print(JSON.stringify(Vec3.sum(v1,v2))); +console.log("Test message"); +print(JSON.stringify(TREE_SCALE)); +print(JSON.stringify(Vec3.sum(v1,v2))); +print(JSON.stringify(TREE_SCALE));