Skip to content

Commit 8544b40

Browse files
ogoffartnierob
authored andcommitted
QScript: Make sure the 'this' is correct
This is to fix the tst_QScriptEngine::nestedEvaluate
1 parent 9ba8b5d commit 8544b40

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/3rdparty/v8/include/v8.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,13 @@ class V8EXPORT Script {
658658
*/
659659
Local<Value> Run();
660660

661+
#ifdef QT_BUILD_SCRIPT_LIB
662+
/**
663+
* Same as Run() but allow to give a different value for the 'this' variable
664+
*/
665+
Local<Value> Run(Handle<Object> receiver);
666+
#endif
667+
661668
/**
662669
* Returns the script id value.
663670
*/

src/3rdparty/v8/src/api.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,36 @@ Local<Value> Script::Run() {
14261426
return Utils::ToLocal(result);
14271427
}
14281428

1429+
#ifdef QT_BUILD_SCRIPT_LIB
1430+
Local<Value> Script::Run(Handle<Object> receiver) {
1431+
i::Isolate* isolate = i::Isolate::Current();
1432+
ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
1433+
LOG_API(isolate, "Script::Run");
1434+
ENTER_V8(isolate);
1435+
i::Object* raw_result = NULL;
1436+
{
1437+
i::HandleScope scope(isolate);
1438+
i::Handle<i::Object> obj = Utils::OpenHandle(this);
1439+
i::Handle<i::JSFunction> fun;
1440+
if (obj->IsSharedFunctionInfo()) {
1441+
i::Handle<i::SharedFunctionInfo>
1442+
function_info(i::SharedFunctionInfo::cast(*obj));
1443+
fun = isolate->factory()->NewFunctionFromSharedFunctionInfo(
1444+
function_info, isolate->global_context());
1445+
} else {
1446+
fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj));
1447+
}
1448+
EXCEPTION_PREAMBLE(isolate);
1449+
i::Handle<i::Object> recv = Utils::OpenHandle(*receiver);
1450+
i::Handle<i::Object> result =
1451+
i::Execution::Call(fun, recv, 0, NULL, &has_pending_exception);
1452+
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
1453+
raw_result = *result;
1454+
}
1455+
i::Handle<i::Object> result(raw_result);
1456+
return Utils::ToLocal(result);
1457+
}
1458+
#endif
14291459

14301460
static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) {
14311461
i::Handle<i::Object> obj = Utils::OpenHandle(script);

0 commit comments

Comments
 (0)