Showing the changes to libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp (1 of 2 files). Show all
Unified · Split
| @@ -275,7 +275,8 @@ void ScriptObjectV8Proxy::investigate() { · 274 unmodified lines | |||
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | auto v8Name = v8::String::NewFromUtf8(_engine->getIsolate(), prop.name()).ToLocalChecked(); | 277 | auto v8Name = v8::String::NewFromUtf8(_engine->getIsolate(), prop.name()).ToLocalChecked(); |
| 278 | PropertyDef& propDef = _props.insert(idx, PropertyDef(_engine, v8Name)).value(); | 278 | PropertyDef& propDef = _props.insert(idx, PropertyDef(_engine, v8Name, idx)).value(); |
| 279 | _propNameMap.insert(V8ScriptString(_engine, v8Name), &propDef); | ||
| 279 | propDef.flags = ScriptValue::Undeletable | ScriptValue::PropertyGetter | ScriptValue::PropertySetter | | 280 | propDef.flags = ScriptValue::Undeletable | ScriptValue::PropertyGetter | ScriptValue::PropertySetter | |
| 280 | ScriptValue::QObjectMember; | 281 | ScriptValue::QObjectMember; |
| 281 | if (prop.isConstant()) propDef.flags |= ScriptValue::ReadOnly; | 282 | if (prop.isConstant()) propDef.flags |= ScriptValue::ReadOnly; |
| @@ -318,9 +319,10 @@ void ScriptObjectV8Proxy::investigate() { · 36 unmodified lines | |||
| 318 | auto nameLookup = methodNames.find(name); | 319 | auto nameLookup = methodNames.find(name); |
| 319 | if (isSignal) { | 320 | if (isSignal) { |
| 320 | if (nameLookup == methodNames.end()) { | 321 | if (nameLookup == methodNames.end()) { |
| 321 | SignalDef& signalDef = _signals.insert(idx, SignalDef(_engine, name.get())).value(); | 322 | SignalDef& signalDef = _signals.insert(idx, SignalDef(_engine, name.get(), idx)).value(); |
| 322 | signalDef.name = name; | 323 | signalDef.name = name; |
| 323 | signalDef.signal = method; | 324 | signalDef.signal = method; |
| 325 | _signalNameMap.insert(name, &signalDef); | ||
| 324 | //qCDebug(scriptengine_v8) << "Utf8Value 1: " << QString(*v8::String::Utf8Value(const_cast<v8::Isolate*>(_engine->getIsolate()), nameString)); | 326 | //qCDebug(scriptengine_v8) << "Utf8Value 1: " << QString(*v8::String::Utf8Value(const_cast<v8::Isolate*>(_engine->getIsolate()), nameString)); |
| 325 | //qCDebug(scriptengine_v8) << "Utf8Value 2: " << QString(*v8::String::Utf8Value(const_cast<v8::Isolate*>(_engine->getIsolate()), name.constGet())); | 327 | //qCDebug(scriptengine_v8) << "Utf8Value 2: " << QString(*v8::String::Utf8Value(const_cast<v8::Isolate*>(_engine->getIsolate()), name.constGet())); |
| 326 | //qCDebug(scriptengine_v8) << "toQString: " << name.toQString(); | 328 | //qCDebug(scriptengine_v8) << "toQString: " << name.toQString(); |
| @@ -346,10 +348,11 @@ void ScriptObjectV8Proxy::investigate() { · 19 unmodified lines | |||
| 346 | } | 348 | } |
| 347 | } | 349 | } |
| 348 | if (nameLookup == methodNames.end()) { | 350 | if (nameLookup == methodNames.end()) { |
| 349 | MethodDef& methodDef = _methods.insert(idx, MethodDef(_engine, name.get())).value(); | 351 | MethodDef& methodDef = _methods.insert(idx, MethodDef(_engine, name.get(), idx)).value(); |
| 350 | methodDef.name = name; | 352 | methodDef.name = name; |
| 351 | methodDef.numMaxParms = parameterCount; | 353 | methodDef.numMaxParms = parameterCount; |
| 352 | methodDef.methods.append(method); | 354 | methodDef.methods.append(method); |
| 355 | _methodNameMap.insert(name, &methodDef); | ||
| 353 | methodNames.insert(name, idx); | 356 | methodNames.insert(name, idx); |
| 354 | } else { | 357 | } else { |
| 355 | int originalMethodId = nameLookup.value(); | 358 | int originalMethodId = nameLookup.value(); |
| @@ -403,20 +406,34 @@ ScriptObjectV8Proxy::QueryFlags ScriptObjectV8Proxy::queryProperty(const V8Scrip · 47 unmodified lines | |||
| 403 | v8::String::Utf8Value nameStr(isolate, name.constGet()); | 406 | v8::String::Utf8Value nameStr(isolate, name.constGet()); |
| 404 | 407 | ||
| 405 | // check for methods | 408 | // check for methods |
| 406 | for (MethodDefMap::const_iterator trans = _methods.cbegin(); trans != _methods.cend(); ++trans) { | 409 | /*for (MethodDefMap::const_iterator trans = _methods.cbegin(); trans != _methods.cend(); ++trans) { |
| 407 | v8::String::Utf8Value methodNameStr(isolate, trans.value().name.constGet()); | 410 | v8::String::Utf8Value methodNameStr(isolate, trans.value().name.constGet()); |
| 408 | //qCDebug(scriptengine_v8) << "queryProperty : " << *nameStr << " method: " << *methodNameStr; | 411 | //qCDebug(scriptengine_v8) << "queryProperty : " << *nameStr << " method: " << *methodNameStr; |
| 409 | if (!(trans.value().name == name)) continue; | 412 | if (!(trans.value().name == name)) continue; |
| 410 | *id = trans.key() | METHOD_TYPE; | 413 | *id = trans.key() | METHOD_TYPE; |
| 411 | return flags & (HandlesReadAccess | HandlesWriteAccess); | 414 | return flags & (HandlesReadAccess | HandlesWriteAccess); |
| 415 | }*/ | ||
| 416 | MethodNameMap::const_iterator method = _methodNameMap.find(name); | ||
| 417 | if (method != _methodNameMap.cend()) { | ||
| 418 | //v8::String::Utf8Value methodNameStr(isolate, trans.value().name.constGet()); | ||
| 419 | //qCDebug(scriptengine_v8) << "queryProperty : " << *nameStr << " method: " << *methodNameStr; | ||
| 420 | const MethodDef* methodDef = method.value(); | ||
| 421 | *id = methodDef->_id | METHOD_TYPE; | ||
| 422 | return flags & (HandlesReadAccess | HandlesWriteAccess); | ||
| 412 | } | 423 | } |
| 413 | 424 | ||
| 414 | // check for properties | 425 | // check for properties |
| 415 | for (PropertyDefMap::const_iterator trans = _props.cbegin(); trans != _props.cend(); ++trans) { | 426 | /*for (PropertyDefMap::const_iterator trans = _props.cbegin(); trans != _props.cend(); ++trans) { |
| 416 | const PropertyDef& propDef = trans.value(); | 427 | const PropertyDef& propDef = trans.value(); |
| 417 | if (!(propDef.name == name)) continue; | 428 | if (!(propDef.name == name)) continue; |
| 418 | *id = trans.key() | PROPERTY_TYPE; | 429 | *id = trans.key() | PROPERTY_TYPE; |
| 419 | return flags & (HandlesReadAccess | HandlesWriteAccess); | 430 | return flags & (HandlesReadAccess | HandlesWriteAccess); |
| 431 | }*/ | ||
| 432 | PropertyNameMap::const_iterator prop = _propNameMap.find(name); | ||
| 433 | if (prop != _propNameMap.cend()) { | ||
| 434 | const PropertyDef* propDef = prop.value(); | ||
| 435 | *id = propDef->_id | PROPERTY_TYPE; | ||
| 436 | return flags & (HandlesReadAccess | HandlesWriteAccess); | ||
| 420 | } | 437 | } |
| 421 | 438 | ||
| 422 | // check for signals | 439 | // check for signals |
| @@ -585,6 +602,7 @@ v8::Local<v8::Array> ScriptObjectV8Proxy::getPropertyNames() { · 162 unmodified lines | |||
| 585 | auto context = _engine->getContext(); | 602 | auto context = _engine->getContext(); |
| 586 | v8::Context::Scope contextScope(_engine->getContext()); | 603 | v8::Context::Scope contextScope(_engine->getContext()); |
| 587 | 604 | ||
| 605 | //V8TODO: this is really slow. It could be cached if this is called often. | ||
| 588 | v8::Local<v8::Array> properties = v8::Array::New(isolate, _props.size() + _methods.size() + _signals.size()); | 606 | v8::Local<v8::Array> properties = v8::Array::New(isolate, _props.size() + _methods.size() + _signals.size()); |
| 589 | uint32_t position = 0; | 607 | uint32_t position = 0; |
| 590 | for (PropertyDefMap::const_iterator i = _props.begin(); i != _props.end(); i++){ | 608 | for (PropertyDefMap::const_iterator i = _props.begin(); i != _props.end(); i++){ |