Showing the changes to libraries/script-engine/src/v8/ScriptValueV8Wrapper.cpp (1 of 8 files). Show all
Unified · Split
| @@ -61,7 +61,8 @@ V8ScriptValue ScriptValueV8Wrapper::fullUnwrap(ScriptEngineV8* engine, const Scr · 60 unmodified lines | ||
| 61 | 61 | |
| 62 | 62 | ScriptValue ScriptValueV8Wrapper::call(const ScriptValue& thisObject, const ScriptValueList& args) { |
| 63 | 63 | auto isolate = _engine->getIsolate(); |
| 64 | − Q_ASSERT(isolate->IsCurrent()); | |
| 64 | + v8::Locker locker(isolate); | |
| 65 | + v8::Isolate::Scope isolateScope(isolate); | |
| 65 | 66 | v8::HandleScope handleScope(isolate); |
| 66 | 67 | v8::Context::Scope contextScope(_engine->getContext()); |
| 67 | 68 | V8ScriptValue v8This = fullUnwrap(thisObject); |
| @@ -89,7 +90,8 @@ ScriptValue ScriptValueV8Wrapper::call(const ScriptValue& thisObject, const Scri · 21 unmodified lines | ||
| 89 | 90 | |
| 90 | 91 | ScriptValue ScriptValueV8Wrapper::call(const ScriptValue& thisObject, const ScriptValue& arguments) { |
| 91 | 92 | auto isolate = _engine->getIsolate(); |
| 92 | − Q_ASSERT(isolate->IsCurrent()); | |
| 93 | + v8::Locker locker(isolate); | |
| 94 | + v8::Isolate::Scope isolateScope(isolate); | |
| 93 | 95 | v8::HandleScope handleScope(isolate); |
| 94 | 96 | v8::Context::Scope contextScope(_engine->getContext()); |
| 95 | 97 | V8ScriptValue v8This = fullUnwrap(thisObject); |
| @@ -113,7 +115,8 @@ ScriptValue ScriptValueV8Wrapper::call(const ScriptValue& thisObject, const Scri · 17 unmodified lines | ||
| 113 | 115 | |
| 114 | 116 | ScriptValue ScriptValueV8Wrapper::construct(const ScriptValueList& args) { |
| 115 | 117 | auto isolate = _engine->getIsolate(); |
| 116 | − Q_ASSERT(isolate->IsCurrent()); | |
| 118 | + v8::Locker locker(isolate); | |
| 119 | + v8::Isolate::Scope isolateScope(isolate); | |
| 117 | 120 | v8::HandleScope handleScope(isolate); |
| 118 | 121 | v8::Context::Scope contextScope(_engine->getContext()); |
| 119 | 122 | Q_ASSERT(args.length() <= Q_METAMETHOD_INVOKE_MAX_ARGS); |
| @@ -139,7 +142,8 @@ ScriptValue ScriptValueV8Wrapper::construct(const ScriptValueList& args) { · 19 unmodified lines | ||
| 139 | 142 | |
| 140 | 143 | ScriptValue ScriptValueV8Wrapper::construct(const ScriptValue& arguments) { |
| 141 | 144 | auto isolate = _engine->getIsolate(); |
| 142 | − Q_ASSERT(isolate->IsCurrent()); | |
| 145 | + v8::Locker locker(isolate); | |
| 146 | + v8::Isolate::Scope isolateScope(isolate); | |
| 143 | 147 | v8::HandleScope handleScope(isolate); |
| 144 | 148 | v8::Context::Scope contextScope(_engine->getContext()); |
| 145 | 149 | // V8TODO I'm not sure in what format arguments are yet, backtrace will show how it is used |
| @@ -170,7 +174,8 @@ ScriptValueIteratorPointer ScriptValueV8Wrapper::newIterator() const { · 24 unmodified lines | ||
| 170 | 174 | |
| 171 | 175 | ScriptValue ScriptValueV8Wrapper::property(const QString& name, const ScriptValue::ResolveFlags &mode) const { |
| 172 | 176 | auto isolate = _engine->getIsolate(); |
| 173 | − Q_ASSERT(isolate->IsCurrent()); | |
| 177 | + v8::Locker locker(_engine->getIsolate()); | |
| 178 | + v8::Isolate::Scope isolateScope(_engine->getIsolate()); | |
| 174 | 179 | v8::HandleScope handleScope(isolate); |
| 175 | 180 | v8::Context::Scope contextScope(_engine->getContext()); |
| 176 | 181 | if (_value.constGet()->IsObject()) { |
| @@ -181,6 +186,13 @@ ScriptValue ScriptValueV8Wrapper::property(const QString& name, const ScriptValu · 4 unmodified lines | ||
| 181 | 186 | if (object->Get(_value.constGetContext(), key).ToLocal(&resultLocal)) { |
| 182 | 187 | V8ScriptValue result(_engine->getIsolate(), resultLocal); |
| 183 | 188 | return ScriptValue(new ScriptValueV8Wrapper(_engine, std::move(result))); |
| 189 | + } else { | |
| 190 | + QString parentValueQString(""); | |
| 191 | + v8::Local<v8::String> parentValueString; | |
| 192 | + if (_value.constGet()->ToDetailString(_engine->getContext()).ToLocal(&parentValueString)) { | |
| 193 | + QString(*v8::String::Utf8Value(isolate, parentValueString)); | |
| 194 | + } | |
| 195 | + qDebug() << "Failed to get property, parent of value: " << name << ", parent type: " << QString(*v8::String::Utf8Value(isolate, _value.constGet()->TypeOf(isolate))) << " parent value: " << parentValueQString; | |
| 184 | 196 | } |
| 185 | 197 | } |
| 186 | 198 | qDebug() << "Failed to get property, parent of value: " << name << " is not a V8 object, reported type: " << QString(*v8::String::Utf8Value(isolate, _value.constGet()->TypeOf(isolate))); |
| @@ -194,7 +206,8 @@ ScriptValue ScriptValueV8Wrapper::property(const QString& name, const ScriptValu · 7 unmodified lines | ||
| 194 | 206 | |
| 195 | 207 | ScriptValue ScriptValueV8Wrapper::property(quint32 arrayIndex, const ScriptValue::ResolveFlags& mode) const { |
| 196 | 208 | auto isolate = _engine->getIsolate(); |
| 197 | − Q_ASSERT(isolate->IsCurrent()); | |
| 209 | + v8::Locker locker(isolate); | |
| 210 | + v8::Isolate::Scope isolateScope(isolate); | |
| 198 | 211 | v8::HandleScope handleScope(isolate); |
| 199 | 212 | v8::Context::Scope contextScope(_engine->getContext()); |
| 200 | 213 | if (_value.constGet()->IsObject()) { |
| @@ -215,7 +228,8 @@ ScriptValue ScriptValueV8Wrapper::property(quint32 arrayIndex, const ScriptValue · 14 unmodified lines | ||
| 215 | 228 | |
| 216 | 229 | void ScriptValueV8Wrapper::setData(const ScriptValue& value) { |
| 217 | 230 | auto isolate = _engine->getIsolate(); |
| 218 | − Q_ASSERT(isolate->IsCurrent()); | |
| 231 | + v8::Locker locker(isolate); | |
| 232 | + v8::Isolate::Scope isolateScope(isolate); | |
| 219 | 233 | v8::HandleScope handleScope(isolate); |
| 220 | 234 | v8::Context::Scope contextScope(_engine->getContext()); |
| 221 | 235 | V8ScriptValue unwrapped = fullUnwrap(value); |
| @@ -225,7 +239,8 @@ void ScriptValueV8Wrapper::setData(const ScriptValue& value) { · 3 unmodified lines | ||
| 225 | 239 | void ScriptValueV8Wrapper::setProperty(const QString& name, const ScriptValue& value, const ScriptValue::PropertyFlags& flags) { |
| 226 | 240 | Q_ASSERT(flags != ScriptValue::PropertyGetter || flags != ScriptValue::PropertySetter); |
| 227 | 241 | auto isolate = _engine->getIsolate(); |
| 228 | − Q_ASSERT(isolate->IsCurrent()); | |
| 242 | + v8::Locker locker(_engine->getIsolate()); | |
| 243 | + v8::Isolate::Scope isolateScope(_engine->getIsolate()); | |
| 229 | 244 | v8::HandleScope handleScope(isolate); |
| 230 | 245 | v8::Context::Scope contextScope(_engine->getContext()); |
| 231 | 246 | V8ScriptValue unwrapped = fullUnwrap(value); |
| @@ -256,7 +271,8 @@ void ScriptValueV8Wrapper::setProperty(const QString& name, const ScriptValue& v · 24 unmodified lines | ||
| 256 | 271 | |
| 257 | 272 | void ScriptValueV8Wrapper::setProperty(quint32 arrayIndex, const ScriptValue& value, const ScriptValue::PropertyFlags& flags) { |
| 258 | 273 | auto isolate = _engine->getIsolate(); |
| 259 | − Q_ASSERT(isolate->IsCurrent()); | |
| 274 | + v8::Locker locker(isolate); | |
| 275 | + v8::Isolate::Scope isolateScope(isolate); | |
| 260 | 276 | v8::HandleScope handleScope(isolate); |
| 261 | 277 | v8::Context::Scope contextScope(_engine->getContext()); |
| 262 | 278 | V8ScriptValue unwrapped = fullUnwrap(value); |
| @@ -275,7 +291,8 @@ void ScriptValueV8Wrapper::setProperty(quint32 arrayIndex, const ScriptValue& va · 12 unmodified lines | ||
| 275 | 291 | |
| 276 | 292 | void ScriptValueV8Wrapper::setPrototype(const ScriptValue& prototype) { |
| 277 | 293 | auto isolate = _engine->getIsolate(); |
| 278 | − Q_ASSERT(isolate->IsCurrent()); | |
| 294 | + v8::Locker locker(isolate); | |
| 295 | + v8::Isolate::Scope isolateScope(isolate); | |
| 279 | 296 | v8::HandleScope handleScope(isolate); |
| 280 | 297 | v8::Context::Scope contextScope(_engine->getContext()); |
| 281 | 298 | ScriptValueV8Wrapper* unwrappedPrototype = unwrap(prototype); |
| @@ -294,7 +311,8 @@ void ScriptValueV8Wrapper::setPrototype(const ScriptValue& prototype) { · 12 unmodified lines | ||
| 294 | 311 | |
| 295 | 312 | bool ScriptValueV8Wrapper::strictlyEquals(const ScriptValue& other) const { |
| 296 | 313 | auto isolate = _engine->getIsolate(); |
| 297 | − Q_ASSERT(isolate->IsCurrent()); | |
| 314 | + v8::Locker locker(isolate); | |
| 315 | + v8::Isolate::Scope isolateScope(isolate); | |
| 298 | 316 | v8::HandleScope handleScope(isolate); |
| 299 | 317 | v8::Context::Scope contextScope(_engine->getContext()); |
| 300 | 318 | ScriptValueV8Wrapper* unwrappedOther = unwrap(other); |
| @@ -303,7 +321,8 @@ bool ScriptValueV8Wrapper::strictlyEquals(const ScriptValue& other) const { · 2 unmodified lines | ||
| 303 | 321 | |
| 304 | 322 | bool ScriptValueV8Wrapper::toBool() const { |
| 305 | 323 | auto isolate = _engine->getIsolate(); |
| 306 | − Q_ASSERT(isolate->IsCurrent()); | |
| 324 | + v8::Locker locker(isolate); | |
| 325 | + v8::Isolate::Scope isolateScope(isolate); | |
| 307 | 326 | v8::HandleScope handleScope(isolate); |
| 308 | 327 | v8::Context::Scope contextScope(_engine->getContext()); |
| 309 | 328 | return _value.constGet()->ToBoolean(_engine->getIsolate())->Value(); |
| @@ -311,7 +330,8 @@ bool ScriptValueV8Wrapper::toBool() const { · 1 unmodified line | ||
| 311 | 330 | |
| 312 | 331 | qint32 ScriptValueV8Wrapper::toInt32() const { |
| 313 | 332 | auto isolate = _engine->getIsolate(); |
| 314 | − Q_ASSERT(isolate->IsCurrent()); | |
| 333 | + v8::Locker locker(isolate); | |
| 334 | + v8::Isolate::Scope isolateScope(isolate); | |
| 315 | 335 | v8::HandleScope handleScope(isolate); |
| 316 | 336 | v8::Context::Scope contextScope(_engine->getContext()); |
| 317 | 337 | v8::Local<v8::Integer> integer; |
| @@ -323,7 +343,8 @@ qint32 ScriptValueV8Wrapper::toInt32() const { · 5 unmodified lines | ||
| 323 | 343 | |
| 324 | 344 | double ScriptValueV8Wrapper::toInteger() const { |
| 325 | 345 | auto isolate = _engine->getIsolate(); |
| 326 | − Q_ASSERT(isolate->IsCurrent()); | |
| 346 | + v8::Locker locker(isolate); | |
| 347 | + v8::Isolate::Scope isolateScope(isolate); | |
| 327 | 348 | v8::HandleScope handleScope(isolate); |
| 328 | 349 | v8::Context::Scope contextScope(_engine->getContext()); |
| 329 | 350 | v8::Local<v8::Integer> integer; |
| @@ -335,7 +356,8 @@ double ScriptValueV8Wrapper::toInteger() const { · 5 unmodified lines | ||
| 335 | 356 | |
| 336 | 357 | double ScriptValueV8Wrapper::toNumber() const { |
| 337 | 358 | auto isolate = _engine->getIsolate(); |
| 338 | − Q_ASSERT(isolate->IsCurrent()); | |
| 359 | + v8::Locker locker(isolate); | |
| 360 | + v8::Isolate::Scope isolateScope(isolate); | |
| 339 | 361 | v8::HandleScope handleScope(isolate); |
| 340 | 362 | v8::Context::Scope contextScope(_engine->getContext()); |
| 341 | 363 | v8::Local<v8::Number> number; |
| @@ -347,7 +369,8 @@ double ScriptValueV8Wrapper::toNumber() const { · 5 unmodified lines | ||
| 347 | 369 | |
| 348 | 370 | QString ScriptValueV8Wrapper::toString() const { |
| 349 | 371 | auto isolate = _engine->getIsolate(); |
| 350 | − Q_ASSERT(isolate->IsCurrent()); | |
| 372 | + v8::Locker locker(isolate); | |
| 373 | + v8::Isolate::Scope isolateScope(isolate); | |
| 351 | 374 | v8::HandleScope handleScope(isolate); |
| 352 | 375 | v8::Context::Scope contextScope(_engine->getContext()); |
| 353 | 376 | v8::String::Utf8Value string(_engine->getIsolate(), _value.constGet()); |
| @@ -357,7 +380,8 @@ QString ScriptValueV8Wrapper::toString() const { · 3 unmodified lines | ||
| 357 | 380 | |
| 358 | 381 | quint16 ScriptValueV8Wrapper::toUInt16() const { |
| 359 | 382 | auto isolate = _engine->getIsolate(); |
| 360 | − Q_ASSERT(isolate->IsCurrent()); | |
| 383 | + v8::Locker locker(isolate); | |
| 384 | + v8::Isolate::Scope isolateScope(isolate); | |
| 361 | 385 | v8::HandleScope handleScope(isolate); |
| 362 | 386 | v8::Context::Scope contextScope(_engine->getContext()); |
| 363 | 387 | v8::Local<v8::Uint32> integer; |
| @@ -369,7 +393,8 @@ quint16 ScriptValueV8Wrapper::toUInt16() const { · 5 unmodified lines | ||
| 369 | 393 | |
| 370 | 394 | quint32 ScriptValueV8Wrapper::toUInt32() const { |
| 371 | 395 | auto isolate = _engine->getIsolate(); |
| 372 | − Q_ASSERT(isolate->IsCurrent()); | |
| 396 | + v8::Locker locker(isolate); | |
| 397 | + v8::Isolate::Scope isolateScope(isolate); | |
| 373 | 398 | v8::HandleScope handleScope(isolate); |
| 374 | 399 | v8::Context::Scope contextScope(_engine->getContext()); |
| 375 | 400 | v8::Local<v8::Uint32> integer; |
| @@ -401,7 +426,8 @@ QObject* ScriptValueV8Wrapper::toQObject() const { · 25 unmodified lines | ||
| 401 | 426 | |
| 402 | 427 | bool ScriptValueV8Wrapper::equals(const ScriptValue& other) const { |
| 403 | 428 | auto isolate = _engine->getIsolate(); |
| 404 | − Q_ASSERT(isolate->IsCurrent()); | |
| 429 | + v8::Locker locker(isolate); | |
| 430 | + v8::Isolate::Scope isolateScope(isolate); | |
| 405 | 431 | v8::HandleScope handleScope(isolate); |
| 406 | 432 | v8::Context::Scope contextScope(_engine->getContext()); |
| 407 | 433 | ScriptValueV8Wrapper* unwrappedOther = unwrap(other); |
| @@ -420,7 +446,8 @@ bool ScriptValueV8Wrapper::equals(const ScriptValue& other) const { · 12 unmodified lines | ||
| 420 | 446 | |
| 421 | 447 | bool ScriptValueV8Wrapper::isArray() const { |
| 422 | 448 | auto isolate = _engine->getIsolate(); |
| 423 | − Q_ASSERT(isolate->IsCurrent()); | |
| 449 | + v8::Locker locker(isolate); | |
| 450 | + v8::Isolate::Scope isolateScope(isolate); | |
| 424 | 451 | v8::HandleScope handleScope(isolate); |
| 425 | 452 | v8::Context::Scope contextScope(_engine->getContext()); |
| 426 | 453 | return _value.constGet()->IsArray(); |
| @@ -428,7 +455,8 @@ bool ScriptValueV8Wrapper::isArray() const { · 1 unmodified line | ||
| 428 | 455 | |
| 429 | 456 | bool ScriptValueV8Wrapper::isBool() const { |
| 430 | 457 | auto isolate = _engine->getIsolate(); |
| 431 | − Q_ASSERT(isolate->IsCurrent()); | |
| 458 | + v8::Locker locker(isolate); | |
| 459 | + v8::Isolate::Scope isolateScope(isolate); | |
| 432 | 460 | v8::HandleScope handleScope(isolate); |
| 433 | 461 | v8::Context::Scope contextScope(_engine->getContext()); |
| 434 | 462 | return _value.constGet()->IsBoolean(); |
| @@ -446,7 +474,8 @@ bool ScriptValueV8Wrapper::isError() const { · 11 unmodified lines | ||
| 446 | 474 | |
| 447 | 475 | bool ScriptValueV8Wrapper::isFunction() const { |
| 448 | 476 | auto isolate = _engine->getIsolate(); |
| 449 | − Q_ASSERT(isolate->IsCurrent()); | |
| 477 | + v8::Locker locker(isolate); | |
| 478 | + v8::Isolate::Scope isolateScope(isolate); | |
| 450 | 479 | v8::HandleScope handleScope(isolate); |
| 451 | 480 | v8::Context::Scope contextScope(_engine->getContext()); |
| 452 | 481 | return _value.constGet()->IsFunction(); |
| @@ -454,7 +483,8 @@ bool ScriptValueV8Wrapper::isFunction() const { · 1 unmodified line | ||
| 454 | 483 | |
| 455 | 484 | bool ScriptValueV8Wrapper::isNumber() const { |
| 456 | 485 | auto isolate = _engine->getIsolate(); |
| 457 | − Q_ASSERT(isolate->IsCurrent()); | |
| 486 | + v8::Locker locker(isolate); | |
| 487 | + v8::Isolate::Scope isolateScope(isolate); | |
| 458 | 488 | v8::HandleScope handleScope(isolate); |
| 459 | 489 | v8::Context::Scope contextScope(_engine->getContext()); |
| 460 | 490 | return _value.constGet()->IsNumber(); |
| @@ -462,7 +492,8 @@ bool ScriptValueV8Wrapper::isNumber() const { · 1 unmodified line | ||
| 462 | 492 | |
| 463 | 493 | bool ScriptValueV8Wrapper::isNull() const { |
| 464 | 494 | auto isolate = _engine->getIsolate(); |
| 465 | − Q_ASSERT(isolate->IsCurrent()); | |
| 495 | + v8::Locker locker(isolate); | |
| 496 | + v8::Isolate::Scope isolateScope(isolate); | |
| 466 | 497 | v8::HandleScope handleScope(isolate); |
| 467 | 498 | v8::Context::Scope contextScope(_engine->getContext()); |
| 468 | 499 | return _value.constGet()->IsNull(); |
| @@ -470,7 +501,8 @@ bool ScriptValueV8Wrapper::isNull() const { · 1 unmodified line | ||
| 470 | 501 | |
| 471 | 502 | bool ScriptValueV8Wrapper::isObject() const { |
| 472 | 503 | auto isolate = _engine->getIsolate(); |
| 473 | − Q_ASSERT(isolate->IsCurrent()); | |
| 504 | + v8::Locker locker(isolate); | |
| 505 | + v8::Isolate::Scope isolateScope(isolate); | |
| 474 | 506 | v8::HandleScope handleScope(isolate); |
| 475 | 507 | v8::Context::Scope contextScope(_engine->getContext()); |
| 476 | 508 | return _value.constGet()->IsObject(); |
| @@ -478,7 +510,8 @@ bool ScriptValueV8Wrapper::isObject() const { · 1 unmodified line | ||
| 478 | 510 | |
| 479 | 511 | bool ScriptValueV8Wrapper::isString() const { |
| 480 | 512 | auto isolate = _engine->getIsolate(); |
| 481 | − Q_ASSERT(isolate->IsCurrent()); | |
| 513 | + v8::Locker locker(isolate); | |
| 514 | + v8::Isolate::Scope isolateScope(isolate); | |
| 482 | 515 | v8::HandleScope handleScope(isolate); |
| 483 | 516 | v8::Context::Scope contextScope(_engine->getContext()); |
| 484 | 517 | return _value.constGet()->IsString(); |
| @@ -486,26 +519,30 @@ bool ScriptValueV8Wrapper::isString() const { · 1 unmodified line | ||
| 486 | 519 | |
| 487 | 520 | bool ScriptValueV8Wrapper::isUndefined() const { |
| 488 | 521 | auto isolate = _engine->getIsolate(); |
| 489 | − Q_ASSERT(isolate->IsCurrent()); | |
| 522 | + v8::Locker locker(isolate); | |
| 523 | + v8::Isolate::Scope isolateScope(isolate); | |
| 490 | 524 | v8::HandleScope handleScope(isolate); |
| 491 | 525 | v8::Context::Scope contextScope(_engine->getContext()); |
| 492 | 526 | return _value.constGet()->IsUndefined(); |
| 493 | 527 | } |
| 494 | 528 | |
| 495 | 529 | bool ScriptValueV8Wrapper::isValid() const { |
| 496 | − //V8TODO | |
| 497 | 530 | auto isolate = _engine->getIsolate(); |
| 498 | − Q_ASSERT(isolate->IsCurrent()); | |
| 531 | + v8::Locker locker(isolate); | |
| 532 | + v8::Isolate::Scope isolateScope(isolate); | |
| 499 | 533 | v8::HandleScope handleScope(isolate); |
| 500 | 534 | v8::Context::Scope contextScope(_engine->getContext()); |
| 535 | + if (_value.constGet()->IsNullOrUndefined()) { | |
| 536 | + return false; | |
| 537 | + } | |
| 501 | 538 | return true; |
| 502 | − //return _value.constGet()->IsValid(); | |
| 503 | 539 | } |
| 504 | 540 | |
| 505 | 541 | bool ScriptValueV8Wrapper::isVariant() const { |
| 506 | 542 | //V8TODO |
| 507 | 543 | auto isolate = _engine->getIsolate(); |
| 508 | − Q_ASSERT(isolate->IsCurrent()); | |
| 544 | + v8::Locker locker(isolate); | |
| 545 | + v8::Isolate::Scope isolateScope(isolate); | |
| 509 | 546 | v8::HandleScope handleScope(isolate); |
| 510 | 547 | v8::Context::Scope contextScope(_engine->getContext()); |
| 511 | 548 | return false; |