82 void calledAsConstructor(); |
82 void calledAsConstructor(); |
83 void argumentsObjectInNative(); |
83 void argumentsObjectInNative(); |
84 void jsActivationObject(); |
84 void jsActivationObject(); |
85 void qobjectAsActivationObject(); |
85 void qobjectAsActivationObject(); |
86 void parentContextCallee_QT2270(); |
86 void parentContextCallee_QT2270(); |
|
87 void popNativeContextScope(); |
87 }; |
88 }; |
88 |
89 |
89 tst_QScriptContext::tst_QScriptContext() |
90 tst_QScriptContext::tst_QScriptContext() |
90 { |
91 { |
91 } |
92 } |
537 QCOMPARE(eng.currentContext(), ctx5); |
538 QCOMPARE(eng.currentContext(), ctx5); |
538 eng.popContext(); |
539 eng.popContext(); |
539 } |
540 } |
540 } |
541 } |
541 |
542 |
|
543 void tst_QScriptContext::popNativeContextScope() |
|
544 { |
|
545 QScriptEngine eng; |
|
546 QScriptContext *ctx = eng.pushContext(); |
|
547 QVERIFY(ctx->popScope().isObject()); // the activation object |
|
548 |
|
549 QCOMPARE(ctx->scopeChain().size(), 1); |
|
550 QVERIFY(ctx->scopeChain().at(0).strictlyEquals(eng.globalObject())); |
|
551 // This was different in 4.5: scope and activation were decoupled |
|
552 QVERIFY(ctx->activationObject().strictlyEquals(eng.globalObject())); |
|
553 |
|
554 QVERIFY(!eng.evaluate("var foo = 123; function bar() {}").isError()); |
|
555 QVERIFY(eng.globalObject().property("foo").isNumber()); |
|
556 QVERIFY(eng.globalObject().property("bar").isFunction()); |
|
557 |
|
558 QScriptValue customScope = eng.newObject(); |
|
559 ctx->pushScope(customScope); |
|
560 QCOMPARE(ctx->scopeChain().size(), 2); |
|
561 QVERIFY(ctx->scopeChain().at(0).strictlyEquals(customScope)); |
|
562 QVERIFY(ctx->scopeChain().at(1).strictlyEquals(eng.globalObject())); |
|
563 QVERIFY(ctx->activationObject().strictlyEquals(eng.globalObject())); |
|
564 ctx->setActivationObject(customScope); |
|
565 QVERIFY(ctx->activationObject().strictlyEquals(customScope)); |
|
566 QCOMPARE(ctx->scopeChain().size(), 2); |
|
567 QVERIFY(ctx->scopeChain().at(0).strictlyEquals(customScope)); |
|
568 QEXPECT_FAIL("", "QTBUG-11012", Continue); |
|
569 QVERIFY(ctx->scopeChain().at(1).strictlyEquals(eng.globalObject())); |
|
570 |
|
571 QVERIFY(!eng.evaluate("baz = 456; var foo = 789; function barbar() {}").isError()); |
|
572 QEXPECT_FAIL("", "QTBUG-11012", Continue); |
|
573 QVERIFY(eng.globalObject().property("baz").isNumber()); |
|
574 QVERIFY(customScope.property("foo").isNumber()); |
|
575 QVERIFY(customScope.property("barbar").isFunction()); |
|
576 |
|
577 QVERIFY(ctx->popScope().strictlyEquals(customScope)); |
|
578 QCOMPARE(ctx->scopeChain().size(), 1); |
|
579 QEXPECT_FAIL("", "QTBUG-11012", Continue); |
|
580 QVERIFY(ctx->scopeChain().at(0).strictlyEquals(eng.globalObject())); |
|
581 |
|
582 // Need to push another object, otherwise we crash in popContext() (QTBUG-11012) |
|
583 ctx->pushScope(customScope); |
|
584 eng.popContext(); |
|
585 } |
|
586 |
542 void tst_QScriptContext::lineNumber() |
587 void tst_QScriptContext::lineNumber() |
543 { |
588 { |
544 QScriptEngine eng; |
589 QScriptEngine eng; |
545 |
590 |
546 QScriptValue result = eng.evaluate("try { eval(\"foo = 123;\\n this[is{a{syntax|error@#$%@#% \"); } catch (e) { e.lineNumber; }", "foo.qs", 123); |
591 QScriptValue result = eng.evaluate("try { eval(\"foo = 123;\\n this[is{a{syntax|error@#$%@#% \"); } catch (e) { e.lineNumber; }", "foo.qs", 123); |