-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJSFunction.cpp
More file actions
33 lines (31 loc) · 1023 Bytes
/
JSFunction.cpp
File metadata and controls
33 lines (31 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "pch.h"
#include "JSFunction.h"
#include "JSVM.h"
#include "ByteCode.h"
JSValue Function::callFromC(JSValue* argsBegin, JSValue* argsEnd) {
JSValue r;
auto vm = JSVM::instance();
auto frame = vm->topFrame();
JSValue *ret = vm->pushStack(argsBegin, argsEnd);
callFromVM(ret, ret + (argsEnd - argsBegin));
execute(frame);
r = *ret;
vm->popStack(int(argsEnd - argsBegin));
return r;
}
void Function::callFromVM(JSValue *argsBegin, JSValue* argsEnd) {
if (funcType == FT_C) {
auto cfunc = static_cast<CFunction*>(this);
if (cfunc->func(argsBegin, argsEnd) == 0) {
*argsBegin = JSValue::NIL;
}
} else {
ASSERT(funcType == FT_JS);
auto jsFunc = static_cast<JSFunction*>(this);
int paramCount = (int)(argsEnd - argsBegin);
for (; paramCount < jsFunc->meta->argCount; ++paramCount) {
argsBegin[paramCount] = JSValue::NIL;
}
JSVM::instance()->pushFrame(jsFunc, argsBegin);
}
}