2000-04-21 04:04:14 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the JavaScript 2 Prototype.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of the GNU Public License (the "GPL"), in which case the
|
|
|
|
* provisions of the GPL are applicable instead of those above.
|
|
|
|
* If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of the GPL and not to allow others to use your
|
|
|
|
* version of this file under the NPL, indicate your decision by
|
|
|
|
* deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this
|
|
|
|
* file under either the NPL or the GPL.
|
|
|
|
*/
|
2000-04-05 10:05:57 +04:00
|
|
|
|
|
|
|
#include "interpreter.h"
|
2000-06-24 03:49:48 +04:00
|
|
|
#include "jsclasses.h"
|
2000-04-06 00:33:41 +04:00
|
|
|
#include "world.h"
|
2000-08-05 00:28:35 +04:00
|
|
|
#include "parser.h"
|
2000-07-21 05:16:49 +04:00
|
|
|
#include "jsmath.h"
|
2000-04-05 10:05:57 +04:00
|
|
|
|
2000-04-29 04:29:56 +04:00
|
|
|
#include <assert.h>
|
|
|
|
|
2000-04-05 10:10:53 +04:00
|
|
|
namespace JavaScript {
|
2000-04-26 09:35:07 +04:00
|
|
|
namespace Interpreter {
|
|
|
|
|
|
|
|
// operand access macros.
|
2000-04-18 04:17:34 +04:00
|
|
|
#define op1(i) (i->o1())
|
|
|
|
#define op2(i) (i->o2())
|
|
|
|
#define op3(i) (i->o3())
|
2000-05-11 04:35:06 +04:00
|
|
|
#define op4(i) (i->o4())
|
2000-04-05 10:05:57 +04:00
|
|
|
|
2000-04-26 09:35:07 +04:00
|
|
|
// mnemonic names for operands.
|
2000-04-18 04:17:34 +04:00
|
|
|
#define dst(i) op1(i)
|
2000-04-11 07:11:00 +04:00
|
|
|
#define src1(i) op2(i)
|
|
|
|
#define src2(i) op3(i)
|
2000-04-18 04:17:34 +04:00
|
|
|
#define ofs(i) (i->getOffset())
|
2000-07-13 04:14:54 +04:00
|
|
|
#define val2(i) op2(i)
|
2000-05-11 04:35:06 +04:00
|
|
|
#define val3(i) op3(i)
|
|
|
|
#define val4(i) op4(i)
|
2000-04-11 07:11:00 +04:00
|
|
|
|
2000-04-26 09:35:07 +04:00
|
|
|
using namespace ICG;
|
|
|
|
using namespace JSTypes;
|
2000-06-24 04:50:59 +04:00
|
|
|
using namespace JSClasses;
|
2000-07-21 05:16:49 +04:00
|
|
|
using namespace JSMathClass;
|
2000-04-21 04:37:51 +04:00
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
// These classes are private to the JS interpreter.
|
|
|
|
|
2000-04-27 05:27:09 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct Handler: public gc_base {
|
|
|
|
Handler(Label *catchLabel, Label *finallyLabel)
|
|
|
|
: catchTarget(catchLabel), finallyTarget(finallyLabel) {}
|
|
|
|
Label *catchTarget;
|
|
|
|
Label *finallyTarget;
|
|
|
|
};
|
|
|
|
typedef std::vector<Handler *> CatchStack;
|
|
|
|
|
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
/**
|
|
|
|
* Represents the current function's invocation state.
|
|
|
|
*/
|
2000-04-26 09:35:07 +04:00
|
|
|
struct Activation : public gc_base {
|
2000-04-26 05:42:00 +04:00
|
|
|
JSValues mRegisters;
|
2000-04-26 09:35:07 +04:00
|
|
|
ICodeModule* mICode;
|
2000-04-27 05:27:09 +04:00
|
|
|
CatchStack catchStack;
|
2000-04-26 05:42:00 +04:00
|
|
|
|
2000-04-26 09:35:07 +04:00
|
|
|
Activation(ICodeModule* iCode, const JSValues& args)
|
|
|
|
: mRegisters(iCode->itsMaxRegister + 1), mICode(iCode)
|
2000-04-19 01:51:45 +04:00
|
|
|
{
|
2000-04-26 05:42:00 +04:00
|
|
|
// copy arg list to initial registers.
|
|
|
|
JSValues::iterator dest = mRegisters.begin();
|
|
|
|
for (JSValues::const_iterator src = args.begin(),
|
|
|
|
end = args.end(); src != end; ++src, ++dest) {
|
|
|
|
*dest = *src;
|
|
|
|
}
|
|
|
|
}
|
2000-04-08 07:23:44 +04:00
|
|
|
|
2000-06-22 02:32:21 +04:00
|
|
|
Activation(ICodeModule* iCode, Activation* caller, const JSValue thisArg,
|
2000-09-02 05:01:04 +04:00
|
|
|
const ArgumentList& list)
|
2000-04-26 09:35:07 +04:00
|
|
|
: mRegisters(iCode->itsMaxRegister + 1), mICode(iCode)
|
2000-04-26 05:42:00 +04:00
|
|
|
{
|
|
|
|
// copy caller's parameter list to initial registers.
|
|
|
|
JSValues::iterator dest = mRegisters.begin();
|
2000-06-22 02:32:21 +04:00
|
|
|
*dest++ = thisArg;
|
2000-04-26 05:42:00 +04:00
|
|
|
const JSValues& params = caller->mRegisters;
|
2000-09-02 05:01:04 +04:00
|
|
|
for (ArgumentList::const_iterator src = list.begin(),
|
2000-04-26 05:42:00 +04:00
|
|
|
end = list.end(); src != end; ++src, ++dest) {
|
2000-09-07 23:22:13 +04:00
|
|
|
Register r = (*src).first.first;
|
|
|
|
if (r != NotARegister)
|
|
|
|
*dest = params[r];
|
|
|
|
else
|
|
|
|
*dest = JSValue(JSValue::uninitialized_tag);
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-19 21:41:10 +04:00
|
|
|
|
2000-09-12 02:10:44 +04:00
|
|
|
// calling a binary operator, no 'this'
|
2000-05-19 21:41:10 +04:00
|
|
|
Activation(ICodeModule* iCode, const JSValue arg1, const JSValue arg2)
|
|
|
|
: mRegisters(iCode->itsMaxRegister + 1), mICode(iCode)
|
|
|
|
{
|
2000-09-12 02:10:44 +04:00
|
|
|
mRegisters[1] = arg1;
|
|
|
|
mRegisters[2] = arg2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calling a getter function, no arguments
|
|
|
|
Activation(ICodeModule* iCode)
|
|
|
|
: mRegisters(iCode->itsMaxRegister + 1), mICode(iCode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// calling a setter function, 1 argument
|
|
|
|
Activation(ICodeModule* iCode, const JSValue arg)
|
|
|
|
: mRegisters(iCode->itsMaxRegister + 1), mICode(iCode)
|
|
|
|
{
|
|
|
|
mRegisters[1] = arg;
|
2000-05-19 21:41:10 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
};
|
2000-04-11 04:32:17 +04:00
|
|
|
|
2000-07-13 05:35:57 +04:00
|
|
|
/**
|
|
|
|
* exception-safe class to save off values.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
class autosaver {
|
|
|
|
T& mRef;
|
|
|
|
T mOld;
|
|
|
|
public:
|
|
|
|
autosaver(T& ref, T val = T()) : mRef(ref), mOld(ref) { ref = val; }
|
|
|
|
~autosaver() { mRef = mOld; }
|
|
|
|
};
|
2000-07-12 03:49:20 +04:00
|
|
|
|
2000-08-05 00:28:35 +04:00
|
|
|
ICodeModule* Context::compileFunction(const String &source)
|
2000-07-26 05:56:47 +04:00
|
|
|
{
|
|
|
|
Arena a;
|
|
|
|
String filename = widenCString("Some source source");
|
|
|
|
Parser p(getWorld(), a, source, filename);
|
2000-08-05 00:28:35 +04:00
|
|
|
ExprNode* e = p.parseExpression(false);
|
|
|
|
ICodeGenerator icg(&getWorld(), getGlobalObject());
|
|
|
|
ASSERT(e->getKind() == ExprNode::functionLiteral);
|
|
|
|
FunctionExprNode* f = static_cast<FunctionExprNode*>(e);
|
|
|
|
icg.allocateParameter(getWorld().identifiers["this"]); // always parameter #0
|
|
|
|
VariableBinding* v = f->function.parameters;
|
|
|
|
while (v) {
|
|
|
|
if (v->name && (v->name->getKind() == ExprNode::identifier))
|
|
|
|
icg.allocateParameter((static_cast<IdentifierExprNode*>(v->name))->name);
|
|
|
|
v = v->next;
|
|
|
|
}
|
|
|
|
icg.genStmt(f->function.body);
|
|
|
|
ICodeModule* result = icg.complete();
|
|
|
|
result->setFileName(filename);
|
|
|
|
return result;
|
2000-07-26 05:56:47 +04:00
|
|
|
}
|
|
|
|
|
2000-07-12 03:49:20 +04:00
|
|
|
JSValue Context::readEvalFile(FILE* in, const String& fileName)
|
|
|
|
{
|
|
|
|
String buffer;
|
|
|
|
string line;
|
|
|
|
LineReader inReader(in);
|
|
|
|
JSValues emptyArgs;
|
|
|
|
JSValue result;
|
|
|
|
|
2000-07-13 05:35:57 +04:00
|
|
|
// save off important member variables, to enable recursive call to interpret.
|
|
|
|
// this is a little stinky, but should be exception-safe.
|
|
|
|
autosaver<Activation*> activation(mActivation, 0);
|
|
|
|
autosaver<Linkage*> linkage(mLinkage, 0);
|
|
|
|
autosaver<InstructionIterator> pc(mPC);
|
|
|
|
|
2000-07-12 03:49:20 +04:00
|
|
|
while (inReader.readLine(line) != 0) {
|
|
|
|
appendChars(buffer, line.data(), line.size());
|
|
|
|
try {
|
|
|
|
Arena a;
|
|
|
|
Parser p(getWorld(), a, buffer, fileName);
|
|
|
|
StmtNode *parsedStatements = p.parseProgram();
|
|
|
|
ASSERT(p.lexer.peek(true).hasKind(Token::end));
|
|
|
|
{
|
|
|
|
PrettyPrinter f(stdOut, 30);
|
|
|
|
{
|
|
|
|
PrettyPrinter::Block b(f, 2);
|
|
|
|
f << "Program =";
|
|
|
|
f.linearBreak(1);
|
|
|
|
StmtNode::printStatements(f, parsedStatements);
|
|
|
|
}
|
|
|
|
f.end();
|
|
|
|
}
|
|
|
|
stdOut << '\n';
|
|
|
|
|
2000-07-26 05:56:47 +04:00
|
|
|
// Generate code for parsedStatements, which is a linked
|
2000-07-12 03:49:20 +04:00
|
|
|
// list of zero or more statements
|
|
|
|
ICodeModule* icm = genCode(parsedStatements, fileName);
|
|
|
|
if (icm) {
|
2000-07-13 05:35:57 +04:00
|
|
|
result = interpret(icm, emptyArgs);
|
2000-07-12 03:49:20 +04:00
|
|
|
delete icm;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear(buffer);
|
|
|
|
} catch (Exception &e) {
|
|
|
|
/* If we got a syntax error on the end of input,
|
|
|
|
* then wait for a continuation
|
|
|
|
* of input rather than printing the error message. */
|
|
|
|
if (!(e.hasKind(Exception::syntaxError) &&
|
|
|
|
e.lineNum && e.pos == buffer.size() &&
|
|
|
|
e.sourceFile == fileName)) {
|
|
|
|
stdOut << '\n' << e.fullMessage();
|
|
|
|
clear(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ICodeModule* Context::genCode(StmtNode *p, const String &fileName)
|
|
|
|
{
|
|
|
|
ICodeGenerator icg(&getWorld(), getGlobalObject());
|
|
|
|
|
|
|
|
TypedRegister ret(NotARegister, &None_Type);
|
|
|
|
while (p) {
|
|
|
|
ret = icg.genStmt(p);
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
icg.returnStmt(ret);
|
|
|
|
|
|
|
|
ICodeModule *icm = icg.complete();
|
|
|
|
icm->setFileName (fileName);
|
|
|
|
return icm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-29 18:43:36 +04:00
|
|
|
JSValues& Context::getRegisters() { return mActivation->mRegisters; }
|
|
|
|
ICodeModule* Context::getICode() { return mActivation->mICode; }
|
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
/**
|
|
|
|
* Stores saved state from the *previous* activation, the current
|
|
|
|
* activation is alive and well in locals of the interpreter loop.
|
|
|
|
*/
|
2000-04-28 06:23:08 +04:00
|
|
|
struct Linkage : public Context::Frame, public gc_base {
|
2000-04-26 09:35:07 +04:00
|
|
|
Linkage* mNext; // next linkage in linkage stack.
|
2000-04-26 05:42:00 +04:00
|
|
|
InstructionIterator mReturnPC;
|
2000-04-26 09:35:07 +04:00
|
|
|
Activation* mActivation; // caller's activation.
|
2000-06-27 06:39:32 +04:00
|
|
|
JSScope* mScope;
|
2000-06-21 02:45:45 +04:00
|
|
|
TypedRegister mResult; // the desired target register for the return value
|
2000-04-11 04:32:17 +04:00
|
|
|
|
2000-05-19 21:41:10 +04:00
|
|
|
Linkage(Linkage* linkage, InstructionIterator returnPC,
|
2000-06-27 06:39:32 +04:00
|
|
|
Activation* activation, JSScope* scope, TypedRegister result)
|
2000-05-19 21:41:10 +04:00
|
|
|
: mNext(linkage), mReturnPC(returnPC),
|
2000-06-27 06:39:32 +04:00
|
|
|
mActivation(activation), mScope(scope), mResult(result)
|
2000-04-26 05:42:00 +04:00
|
|
|
{
|
|
|
|
}
|
2000-04-26 09:35:07 +04:00
|
|
|
|
2000-06-27 06:39:32 +04:00
|
|
|
Context::Frame* getNext() { return mNext; }
|
2000-04-26 09:35:07 +04:00
|
|
|
|
2000-06-27 06:39:32 +04:00
|
|
|
void getState(InstructionIterator& pc, JSValues*& registers, ICodeModule*& iCode)
|
2000-04-26 09:35:07 +04:00
|
|
|
{
|
|
|
|
pc = mReturnPC;
|
|
|
|
registers = &mActivation->mRegisters;
|
|
|
|
iCode = mActivation->mICode;
|
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
};
|
2000-05-23 04:08:29 +04:00
|
|
|
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue shiftLeft_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-19 21:41:10 +04:00
|
|
|
{
|
2000-05-23 04:08:29 +04:00
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toUInt32());
|
|
|
|
return JSValue(num1.i32 << (num2.u32 & 0x1F));
|
2000-05-19 21:41:10 +04:00
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue shiftRight_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toUInt32());
|
|
|
|
return JSValue(num1.i32 >> (num2.u32 & 0x1F));
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue UshiftRight_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toUInt32());
|
|
|
|
JSValue num2(r2.toUInt32());
|
|
|
|
return JSValue(num1.u32 >> (num2.u32 & 0x1F));
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue and_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toInt32());
|
|
|
|
return JSValue(num1.i32 & num2.i32);
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue or_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toInt32());
|
|
|
|
return JSValue(num1.i32 | num2.i32);
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue xor_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toInt32());
|
|
|
|
return JSValue(num1.i32 ^ num2.i32);
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue add_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// could also handle these as separate entries in the override table for add
|
|
|
|
// by specifying add(String, Any), add(Any, String), add(String, String)
|
|
|
|
//
|
|
|
|
if (r1.isString() || r2.isString()) {
|
2000-06-26 21:09:27 +04:00
|
|
|
JSString& str1 = *r1.toString().string;
|
2000-05-23 04:08:29 +04:00
|
|
|
JSString& str2 = *r2.toString().string;
|
2000-06-26 21:25:25 +04:00
|
|
|
return JSValue(new JSString(str1 + str2));
|
2000-05-23 04:08:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
JSValue num1(r1.toNumber());
|
|
|
|
JSValue num2(r2.toNumber());
|
|
|
|
return JSValue(num1.f64 + num2.f64);
|
|
|
|
}
|
|
|
|
}
|
2000-07-12 03:08:03 +04:00
|
|
|
|
|
|
|
/*
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue add_String1(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toNumber());
|
|
|
|
JSValue num2(r2.toNumber());
|
|
|
|
return JSValue(num1.f64 + num2.f64);
|
|
|
|
}
|
2000-07-12 03:08:03 +04:00
|
|
|
*/
|
|
|
|
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue subtract_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toNumber());
|
|
|
|
JSValue num2(r2.toNumber());
|
|
|
|
return JSValue(num1.f64 - num2.f64);
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue multiply_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-19 21:41:10 +04:00
|
|
|
{
|
2000-05-23 04:08:29 +04:00
|
|
|
JSValue num1(r1.toNumber());
|
|
|
|
JSValue num2(r2.toNumber());
|
2000-05-19 21:41:10 +04:00
|
|
|
return JSValue(num1.f64 * num2.f64);
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue divide_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toNumber());
|
|
|
|
JSValue num2(r2.toNumber());
|
|
|
|
return JSValue(num1.f64 / num2.f64);
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue remainder_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue num1(r1.toNumber());
|
|
|
|
JSValue num2(r2.toNumber());
|
|
|
|
return JSValue(fmod(num1.f64, num2.f64));
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue less_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue lv = r1.toPrimitive(JSValue::Number);
|
|
|
|
JSValue rv = r2.toPrimitive(JSValue::Number);
|
|
|
|
if (lv.isString() && rv.isString()) {
|
2000-06-28 22:41:30 +04:00
|
|
|
return JSValue(bool(lv.string->compare(*rv.string) < 0));
|
2000-05-23 04:08:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lv = lv.toNumber();
|
|
|
|
rv = rv.toNumber();
|
|
|
|
if (lv.isNaN() || rv.isNaN())
|
|
|
|
return JSValue();
|
|
|
|
else
|
|
|
|
return JSValue(lv.f64 < rv.f64);
|
|
|
|
}
|
|
|
|
}
|
2000-07-12 03:49:20 +04:00
|
|
|
static JSValue lessOrEqual_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue lv = r1.toPrimitive(JSValue::Number);
|
|
|
|
JSValue rv = r2.toPrimitive(JSValue::Number);
|
|
|
|
if (lv.isString() && rv.isString()) {
|
2000-06-28 22:41:30 +04:00
|
|
|
return JSValue(bool(lv.string->compare(*rv.string) <= 0));
|
2000-05-23 04:08:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lv = lv.toNumber();
|
|
|
|
rv = rv.toNumber();
|
|
|
|
if (lv.isNaN() || rv.isNaN())
|
|
|
|
return JSValue();
|
|
|
|
else
|
|
|
|
return JSValue(lv.f64 <= rv.f64);
|
|
|
|
}
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue equal_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
JSValue lv = r1.toPrimitive(JSValue::Number);
|
|
|
|
JSValue rv = r2.toPrimitive(JSValue::Number);
|
|
|
|
if (lv.isString() && rv.isString()) {
|
2000-06-28 22:41:30 +04:00
|
|
|
return JSValue(bool(lv.string->compare(*rv.string) == 0));
|
2000-05-23 04:08:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lv = lv.toNumber();
|
|
|
|
rv = rv.toNumber();
|
|
|
|
if (lv.isNaN() || rv.isNaN())
|
|
|
|
return JSValue();
|
|
|
|
else
|
|
|
|
return JSValue(lv.f64 == rv.f64);
|
|
|
|
}
|
|
|
|
}
|
2000-05-24 04:54:40 +04:00
|
|
|
static JSValue identical_Default(const JSValue& r1, const JSValue& r2)
|
2000-05-23 04:08:29 +04:00
|
|
|
{
|
|
|
|
if (r1.getType() != r2.getType())
|
2000-06-27 06:39:32 +04:00
|
|
|
return kFalseValue;
|
2000-05-23 04:08:29 +04:00
|
|
|
if (r1.isUndefined() )
|
2000-06-27 06:39:32 +04:00
|
|
|
return kTrueValue;
|
2000-05-23 04:08:29 +04:00
|
|
|
if (r1.isNull())
|
2000-06-27 06:39:32 +04:00
|
|
|
return kTrueValue;
|
2000-05-23 04:08:29 +04:00
|
|
|
if (r1.isNumber()) {
|
|
|
|
if (r1.isNaN())
|
2000-06-27 06:39:32 +04:00
|
|
|
return kFalseValue;
|
2000-05-23 04:08:29 +04:00
|
|
|
if (r2.isNaN())
|
2000-06-27 06:39:32 +04:00
|
|
|
return kFalseValue;
|
2000-05-23 04:08:29 +04:00
|
|
|
return JSValue(r1.f64 == r2.f64);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (r1.isString())
|
2000-07-13 05:35:57 +04:00
|
|
|
return JSValue(bool(r1.string->compare(*r2.string) == 0));
|
2000-05-23 04:08:29 +04:00
|
|
|
if (r1.isBoolean())
|
2000-07-13 05:35:57 +04:00
|
|
|
return JSValue(bool(r1.boolean == r2.boolean));
|
2000-05-23 04:08:29 +04:00
|
|
|
if (r1.isObject())
|
2000-07-13 05:35:57 +04:00
|
|
|
return JSValue(bool(r1.object == r2.object));
|
2000-06-27 06:39:32 +04:00
|
|
|
return kFalseValue;
|
2000-05-23 04:08:29 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-19 21:41:10 +04:00
|
|
|
|
|
|
|
|
2000-07-13 04:14:54 +04:00
|
|
|
static JSValue defineAdd(Context *cx, const JSValues& argv)
|
2000-06-16 05:36:59 +04:00
|
|
|
{
|
|
|
|
// should be three args, first two are types, third is a function.
|
|
|
|
ASSERT(argv[0].isType());
|
|
|
|
ASSERT(argv[1].isType());
|
|
|
|
ASSERT(argv[2].isFunction());
|
|
|
|
|
|
|
|
// XXX need to prove that argv[2].function takes T1 and T2 as args and returns Boolean for the relational operators ?
|
|
|
|
|
2000-07-13 04:14:54 +04:00
|
|
|
cx->addBinaryOperator(BinaryOperator::Add, new BinaryOperator(argv[0].type, argv[1].type, argv[2].function));
|
2000-06-16 05:36:59 +04:00
|
|
|
|
|
|
|
return kUndefinedValue;
|
|
|
|
}
|
|
|
|
|
2000-07-12 03:49:20 +04:00
|
|
|
#define DEFINE_OBO(NAME) \
|
2000-07-13 04:14:54 +04:00
|
|
|
static JSValue define##NAME(Context *cx, const JSValues& argv) \
|
2000-07-12 03:49:20 +04:00
|
|
|
{ \
|
|
|
|
ASSERT(argv[0].isType()); \
|
|
|
|
ASSERT(argv[1].isType()); \
|
|
|
|
ASSERT(argv[2].isFunction()); \
|
2000-07-13 04:14:54 +04:00
|
|
|
cx->addBinaryOperator(BinaryOperator::##NAME, \
|
2000-07-12 03:49:20 +04:00
|
|
|
new BinaryOperator(argv[0].type, argv[1].type, argv[2].function)); \
|
|
|
|
return kUndefinedValue; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
DEFINE_OBO(Subtract)
|
|
|
|
DEFINE_OBO(Multiply)
|
|
|
|
DEFINE_OBO(Divide)
|
|
|
|
DEFINE_OBO(Remainder)
|
|
|
|
DEFINE_OBO(LeftShift)
|
|
|
|
DEFINE_OBO(RightShift)
|
|
|
|
DEFINE_OBO(LogicalRightShift)
|
|
|
|
DEFINE_OBO(BitwiseOr)
|
|
|
|
DEFINE_OBO(BitwiseXor)
|
|
|
|
DEFINE_OBO(BitwiseAnd)
|
|
|
|
DEFINE_OBO(Less)
|
|
|
|
DEFINE_OBO(LessOrEqual)
|
|
|
|
DEFINE_OBO(Equal)
|
|
|
|
DEFINE_OBO(Identical)
|
|
|
|
|
2000-07-13 04:14:54 +04:00
|
|
|
void Context::initOperatorsPackage()
|
|
|
|
{
|
|
|
|
// hack - the following should be available only after importing the 'Operators' package
|
|
|
|
// (hmm, how will that work - the import needs to connect the functions into this mechanism
|
|
|
|
// do we watch for the specific package name???)
|
|
|
|
|
|
|
|
struct OBO {
|
|
|
|
char *name;
|
|
|
|
JSNativeFunction::JSCode fun;
|
|
|
|
} OBOs[] = {
|
|
|
|
{ "defineAdd", defineAdd },
|
|
|
|
{ "defineSubtract", defineSubtract },
|
|
|
|
{ "defineMultiply", defineMultiply },
|
|
|
|
{ "defineDivide", defineDivide },
|
|
|
|
{ "defineRemainder", defineRemainder },
|
|
|
|
{ "defineLeftShift", defineLeftShift },
|
|
|
|
{ "defineRightShift", defineRightShift },
|
|
|
|
{ "defineLogicalRightShift",defineLogicalRightShift },
|
|
|
|
{ "defineBitwiseOr", defineBitwiseOr },
|
|
|
|
{ "defineBitwiseXor", defineBitwiseXor },
|
|
|
|
{ "defineBitwiseAnd", defineBitwiseAnd },
|
|
|
|
{ "defineLess", defineLess },
|
|
|
|
{ "defineLessOrEqual", defineLessOrEqual },
|
|
|
|
{ "defineEqual", defineEqual },
|
|
|
|
{ "defineIdentical", defineIdentical },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < sizeof(OBOs) / sizeof(struct OBO); i++)
|
|
|
|
mGlobal->defineNativeFunction(mWorld.identifiers[widenCString(OBOs[i].name)], OBOs[i].fun);
|
|
|
|
|
|
|
|
mHasOperatorsPackageLoaded = true;
|
|
|
|
}
|
|
|
|
|
2000-06-16 05:36:59 +04:00
|
|
|
void Context::initContext()
|
|
|
|
{
|
2000-06-23 09:10:46 +04:00
|
|
|
// if global has a parent, assume it's been initialized already.
|
|
|
|
if (mGlobal->getParent())
|
|
|
|
return;
|
|
|
|
|
2000-07-12 03:49:20 +04:00
|
|
|
// predefine the umm, predefined types;
|
|
|
|
struct PDT {
|
|
|
|
char *name;
|
|
|
|
JSType *type;
|
|
|
|
} PDTs[] = {
|
|
|
|
{ "any", &Any_Type },
|
|
|
|
{ "Integer", &Integer_Type },
|
|
|
|
{ "Number", &Number_Type },
|
|
|
|
{ "Character", &Character_Type },
|
|
|
|
{ "String", &String_Type },
|
|
|
|
{ "Function", &Function_Type },
|
|
|
|
{ "Array", &Array_Type },
|
|
|
|
{ "Type", &Type_Type },
|
|
|
|
{ "Boolean", &Boolean_Type },
|
|
|
|
{ "Null", &Null_Type },
|
|
|
|
{ "Void", &Void_Type },
|
|
|
|
{ "none", &None_Type }
|
|
|
|
};
|
2000-06-16 05:36:59 +04:00
|
|
|
|
2000-07-12 03:49:20 +04:00
|
|
|
for (int i = 0; i < sizeof(PDTs) / sizeof(struct PDT); i++)
|
|
|
|
mGlobal->defineVariable(widenCString(PDTs[i].name), &Type_Type, JSValue(PDTs[i].type));
|
2000-06-16 05:36:59 +04:00
|
|
|
|
2000-07-21 05:16:49 +04:00
|
|
|
// set up the correct [[Class]] for the global object (matching SpiderMonkey)
|
|
|
|
mGlobal->setClass(new JSString("global"));
|
|
|
|
|
2000-07-26 02:58:04 +04:00
|
|
|
|
2000-07-21 05:16:49 +04:00
|
|
|
// add (XXX some) of the global object properties
|
|
|
|
mGlobal->setProperty(widenCString("NaN"), kNaNValue);
|
|
|
|
mGlobal->setProperty(widenCString("undefined"), kUndefinedValue);
|
|
|
|
|
2000-07-26 02:58:04 +04:00
|
|
|
|
2000-07-21 05:16:49 +04:00
|
|
|
// 'Object', 'Date', 'RegExp', 'Array' etc are all (constructor) properties of the global object
|
2000-08-05 00:28:35 +04:00
|
|
|
// Some of these overlap with the predefined types above. The way we handle this is to set a
|
|
|
|
// 'constructor' function for types. When new <typename> is encountered, the type is queried for
|
|
|
|
// a 'constructor' function to be invoked.
|
2000-07-26 02:58:04 +04:00
|
|
|
JSObject::initObjectObject(mGlobal);
|
2000-08-05 00:28:35 +04:00
|
|
|
|
2000-07-26 05:56:47 +04:00
|
|
|
JSFunction::initFunctionObject(mGlobal);
|
2000-08-05 00:28:35 +04:00
|
|
|
JSBoolean::initBooleanObject(mGlobal);
|
2000-07-26 02:58:04 +04:00
|
|
|
|
|
|
|
// the 'Math' object just has some useful properties
|
|
|
|
JSMath::initMathObject(mGlobal);
|
2000-07-21 05:16:49 +04:00
|
|
|
|
|
|
|
|
|
|
|
// This initializes the state of the binary operator overload mechanism.
|
|
|
|
// One could argue that it is unneccessary to do this until the 'Operators'
|
|
|
|
// package is loaded and that all (un-typed) binary operators should use a
|
|
|
|
// form of icode that performed the inline operation instead.
|
2000-07-13 04:14:54 +04:00
|
|
|
JSBinaryOperator::JSBinaryCode defaultFunction[] = {
|
|
|
|
add_Default,
|
|
|
|
subtract_Default,
|
|
|
|
multiply_Default,
|
|
|
|
divide_Default,
|
|
|
|
remainder_Default,
|
|
|
|
shiftLeft_Default,
|
|
|
|
shiftRight_Default,
|
|
|
|
UshiftRight_Default,
|
|
|
|
or_Default,
|
|
|
|
xor_Default,
|
|
|
|
and_Default,
|
|
|
|
less_Default,
|
|
|
|
lessOrEqual_Default,
|
|
|
|
equal_Default,
|
|
|
|
identical_Default
|
2000-07-12 03:49:20 +04:00
|
|
|
};
|
|
|
|
|
2000-07-13 04:14:54 +04:00
|
|
|
for (BinaryOperator::BinaryOp b = BinaryOperator::BinaryOperatorFirst;
|
|
|
|
b < BinaryOperator::BinaryOperatorCount;
|
|
|
|
b = (BinaryOperator::BinaryOp)(b + 1) )
|
|
|
|
addBinaryOperator(b, new BinaryOperator(&Any_Type, &Any_Type, new JSBinaryOperator(defaultFunction[b])));
|
|
|
|
|
2000-06-16 05:36:59 +04:00
|
|
|
}
|
2000-05-19 21:41:10 +04:00
|
|
|
|
2000-07-13 04:14:54 +04:00
|
|
|
const JSValue Context::findBinaryOverride(JSValue &operand1, JSValue &operand2, BinaryOperator::BinaryOp op)
|
2000-05-19 21:41:10 +04:00
|
|
|
{
|
|
|
|
int32 bestDist1 = JSType::NoRelation;
|
|
|
|
int32 bestDist2 = JSType::NoRelation;
|
|
|
|
BinaryOperatorList::iterator candidate = NULL;
|
|
|
|
|
2000-07-13 04:14:54 +04:00
|
|
|
for (BinaryOperatorList::iterator i = mBinaryOperators[op].begin();
|
|
|
|
i != mBinaryOperators[op].end(); i++)
|
2000-05-19 21:41:10 +04:00
|
|
|
{
|
|
|
|
int32 dist1 = operand1.getType()->distance((*i)->t1);
|
|
|
|
int32 dist2 = operand2.getType()->distance((*i)->t2);
|
|
|
|
|
|
|
|
if ((dist1 < bestDist1) && (dist2 < bestDist2)) {
|
|
|
|
bestDist1 = dist1;
|
|
|
|
bestDist2 = dist2;
|
|
|
|
candidate = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(candidate);
|
|
|
|
return JSValue((*candidate)->function);
|
|
|
|
}
|
2000-04-21 04:04:14 +04:00
|
|
|
|
2000-09-02 05:01:04 +04:00
|
|
|
|
|
|
|
bool Context::hasNamedArguments(ArgumentList &args)
|
|
|
|
{
|
|
|
|
Argument* e = args.end();
|
|
|
|
for (ArgumentList::iterator r = args.begin(); r != e; r++) {
|
|
|
|
if ((*r).second) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
JSValue Context::interpret(ICodeModule* iCode, const JSValues& args)
|
|
|
|
{
|
2000-04-29 04:23:06 +04:00
|
|
|
assert(mActivation == 0); /* recursion == bad */
|
|
|
|
|
|
|
|
JSValue rv;
|
2000-05-19 21:41:10 +04:00
|
|
|
|
2000-07-21 05:16:49 +04:00
|
|
|
// when invoked with empty args, make sure that 'this' is
|
|
|
|
// going to be the global object.
|
|
|
|
|
2000-04-29 04:23:06 +04:00
|
|
|
mActivation = new Activation(iCode, args);
|
|
|
|
JSValues* registers = &mActivation->mRegisters;
|
2000-07-21 05:16:49 +04:00
|
|
|
if (args.size() == 0) (*registers)[0] = mGlobal;
|
2000-04-21 04:04:14 +04:00
|
|
|
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin();
|
2000-06-23 10:10:14 +04:00
|
|
|
InstructionIterator endPC = mActivation->mICode->its_iCode->end();
|
2000-04-26 05:42:00 +04:00
|
|
|
|
2000-04-27 05:27:09 +04:00
|
|
|
// stack of all catch/finally handlers available for the current activation
|
2000-04-29 04:23:06 +04:00
|
|
|
// to implement jsr/rts for finally code
|
|
|
|
std::stack<InstructionIterator> subroutineStack;
|
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
while (true) {
|
|
|
|
try {
|
2000-04-26 09:35:07 +04:00
|
|
|
// tell any listeners about the current execution state.
|
|
|
|
// XXX should only do this if we're single stepping/tracing.
|
2000-04-29 04:23:06 +04:00
|
|
|
if (mListeners.size())
|
2000-05-12 05:19:39 +04:00
|
|
|
broadcast(EV_STEP);
|
2000-04-29 04:23:06 +04:00
|
|
|
|
2000-06-23 10:10:14 +04:00
|
|
|
assert(mPC != endPC);
|
2000-04-29 18:43:36 +04:00
|
|
|
Instruction* instruction = *mPC;
|
2000-04-26 05:42:00 +04:00
|
|
|
switch (instruction->op()) {
|
2000-07-11 03:18:07 +04:00
|
|
|
case CAST:
|
|
|
|
{
|
|
|
|
Cast* c = static_cast<Cast*>(instruction);
|
|
|
|
JSType *toType = op3(c);
|
2000-07-12 00:54:06 +04:00
|
|
|
(*registers)[dst(c).first] = (*registers)[src1(c).first].convert(toType);
|
2000-07-11 03:18:07 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-07-08 05:08:29 +04:00
|
|
|
case SUPER:
|
|
|
|
{
|
|
|
|
Super* su = static_cast<Super*>(instruction);
|
|
|
|
ASSERT((*registers)[0].isObject()); // should be scope of current class
|
|
|
|
JSScope *s = static_cast<JSScope *>((*registers)[0].object->getPrototype());
|
|
|
|
(*registers)[dst(su).first] = s;
|
|
|
|
}
|
|
|
|
break;
|
2000-06-22 02:32:21 +04:00
|
|
|
|
2000-07-19 00:53:03 +04:00
|
|
|
case GET_METHOD:
|
2000-06-28 22:41:30 +04:00
|
|
|
{
|
2000-07-19 00:53:03 +04:00
|
|
|
GetMethod* gm = static_cast<GetMethod*>(instruction);
|
|
|
|
JSValue base = (*registers)[src1(gm).first];
|
|
|
|
ASSERT(base.isObject()); // XXX runtime error
|
|
|
|
JSClass *theClass = dynamic_cast<JSClass*>(base.object->getType());
|
|
|
|
ASSERT(theClass);
|
|
|
|
(*registers)[dst(gm).first] = theClass->getMethod(src2(gm));
|
2000-07-08 05:08:29 +04:00
|
|
|
}
|
2000-07-19 00:53:03 +04:00
|
|
|
break;
|
2000-07-08 05:08:29 +04:00
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
case CALL:
|
|
|
|
{
|
|
|
|
Call* call = static_cast<Call*>(instruction);
|
2000-08-05 00:28:35 +04:00
|
|
|
JSValue v = (*registers)[op2(call).first];
|
|
|
|
JSFunction *target = NULL;
|
|
|
|
if (v.isFunction())
|
|
|
|
target = v.function;
|
|
|
|
else
|
|
|
|
if (v.isObject()) {
|
|
|
|
JSType *t = dynamic_cast<JSType*>(v.object);
|
|
|
|
if (t)
|
|
|
|
target = t->getInvokor();
|
|
|
|
}
|
|
|
|
if (!target)
|
|
|
|
throw new JSException("Call to non callable object");
|
2000-05-09 02:59:42 +04:00
|
|
|
if (target->isNative()) {
|
2000-09-02 05:01:04 +04:00
|
|
|
ArgumentList ¶ms = op4(call);
|
2000-06-22 02:32:21 +04:00
|
|
|
JSValues argv(params.size() + 1);
|
2000-07-19 00:53:03 +04:00
|
|
|
argv[0] = (*registers)[op3(call).first];
|
2000-06-22 02:32:21 +04:00
|
|
|
JSValues::size_type i = 1;
|
2000-09-02 05:01:04 +04:00
|
|
|
for (ArgumentList::const_iterator src = params.begin(), end = params.end();
|
2000-05-09 02:59:42 +04:00
|
|
|
src != end; ++src, ++i) {
|
2000-09-02 05:01:04 +04:00
|
|
|
argv[i] = (*registers)[src->first.first];
|
2000-05-09 02:59:42 +04:00
|
|
|
}
|
2000-07-13 04:14:54 +04:00
|
|
|
JSValue result = static_cast<JSNativeFunction*>(target)->mCode(this, argv);
|
2000-06-22 02:32:21 +04:00
|
|
|
if (op1(call).first != NotARegister)
|
|
|
|
(*registers)[op1(call).first] = result;
|
2000-05-09 02:59:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2000-09-02 05:01:04 +04:00
|
|
|
ICodeModule *icm = target->getICode();
|
|
|
|
ArgumentList &args = op4(call);
|
|
|
|
|
2000-09-07 23:22:13 +04:00
|
|
|
// mParameterCount includes 'this' and also 1 for a named rest parameter
|
|
|
|
//
|
|
|
|
uint32 pCount = icm->mParameterCount - 1;
|
|
|
|
ArgumentList callArgs(pCount, Argument(TypedRegister(NotARegister, &Null_Type), NULL));
|
|
|
|
if (icm->mHasNamedRestParameter) pCount--;
|
|
|
|
|
|
|
|
|
|
|
|
// walk along the given arguments, handling each.
|
|
|
|
// might be good to optimize the case of calls without named arguments and/or rest parameters
|
|
|
|
JSArray *restArg = NULL;
|
|
|
|
uint32 restIndex = 0;
|
|
|
|
uint32 i;
|
|
|
|
for (i = 0; i < args.size(); i++) {
|
|
|
|
if (args[i].second) { // a named argument
|
2000-09-12 02:10:44 +04:00
|
|
|
TypedRegister r = icm->itsVariables->findVariable(*(args[i].second));
|
2000-09-07 23:22:13 +04:00
|
|
|
bool isParameter = false;
|
2000-09-12 02:10:44 +04:00
|
|
|
if (r.first != NotABanana) { // we found the name in the target's list of variables
|
2000-09-07 23:22:13 +04:00
|
|
|
if (r.first < icm->mParameterCount) { // make sure we didn't match a local var
|
|
|
|
ASSERT(r.first <= callArgs.size());
|
|
|
|
// the named argument is arriving in slot i, but needs to be r instead
|
|
|
|
// r.first is the intended target register, we subtract 1 since the callArgs array doesn't include 'this'
|
|
|
|
// here's where we could detect over-writing a positional arg with a named one if that is illegal
|
|
|
|
// if (callArgs[r.first - 1].first.first != NotARegister)...
|
2000-09-12 02:10:44 +04:00
|
|
|
(*registers)[args[i].first.first] = (*registers)[args[i].first.first].convert(r.second);
|
2000-09-07 23:22:13 +04:00
|
|
|
callArgs[r.first - 1] = Argument(args[i].first, NULL); // no need to copy the name through?
|
|
|
|
isParameter = true;
|
2000-09-02 05:01:04 +04:00
|
|
|
}
|
|
|
|
}
|
2000-09-07 23:22:13 +04:00
|
|
|
if (!isParameter) { // wasn't a parameter, make it a property of the rest parameter (if there is one)
|
|
|
|
if (icm->mHasRestParameter) {
|
|
|
|
if (icm->mHasNamedRestParameter) {
|
|
|
|
if (restArg == NULL) {
|
|
|
|
restArg = new JSArray();
|
|
|
|
restArg->setProperty(*args[i].second, (*registers)[args[i].first.first]);
|
|
|
|
(*registers)[args[i].first.first] = restArg;
|
|
|
|
callArgs[pCount] = Argument(TypedRegister(args[i].first.first, &Array_Type), NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
restArg->setProperty(*args[i].second, (*registers)[args[i].first.first]);
|
|
|
|
|
|
|
|
}
|
|
|
|
// else just throw it away
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new JSException("Named argument doesn't match parameter name in call with no rest parameter");
|
|
|
|
// what about matching the named rest parameter ? aaarrggh!
|
2000-09-02 05:01:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-09-07 23:22:13 +04:00
|
|
|
if (i >= pCount) { // more args than expected
|
|
|
|
if (icm->mHasRestParameter) {
|
|
|
|
if (icm->mHasNamedRestParameter) {
|
|
|
|
if (restArg == NULL) {
|
|
|
|
restArg = new JSArray();
|
|
|
|
(*restArg)[restIndex++] = (*registers)[args[i].first.first];
|
|
|
|
(*registers)[args[i].first.first] = restArg;
|
|
|
|
callArgs[pCount] = Argument(TypedRegister(args[i].first.first, &Array_Type), NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(*restArg)[restIndex++] = (*registers)[args[i].first.first];
|
|
|
|
}
|
|
|
|
// else just throw it away
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new JSException("Too many arguments in call");
|
|
|
|
}
|
2000-09-12 02:10:44 +04:00
|
|
|
else {
|
|
|
|
TypedRegister r = icm->itsVariables->getRegister(i + 1); // the variable list includes 'this'
|
|
|
|
(*registers)[args[i].first.first] = (*registers)[args[i].first.first].convert(r.second);
|
|
|
|
callArgs[i] = args[i]; // it's a positional, just slap it in place
|
|
|
|
}
|
2000-09-02 05:01:04 +04:00
|
|
|
}
|
|
|
|
}
|
2000-09-07 23:22:13 +04:00
|
|
|
uint32 contiguousArgs = 0;
|
|
|
|
for (i = 0; i < args.size(); i++) {
|
|
|
|
Argument &arg = args[i];
|
|
|
|
if (arg.first.first == NotARegister) break;
|
|
|
|
contiguousArgs++;
|
2000-09-02 05:01:04 +04:00
|
|
|
}
|
2000-09-07 23:22:13 +04:00
|
|
|
if ((contiguousArgs + 1) < icm->mNonOptionalParameterCount) // there's always a 'this' in R0 (even though it might be null)
|
|
|
|
throw new JSException("Too few arguments in call");
|
|
|
|
|
2000-09-02 05:01:04 +04:00
|
|
|
mLinkage = new Linkage(mLinkage, ++mPC, mActivation, mGlobal, op1(call));
|
2000-09-07 23:22:13 +04:00
|
|
|
mActivation = new Activation(icm, mActivation, (*registers)[op3(call).first], callArgs);
|
2000-05-09 02:59:42 +04:00
|
|
|
registers = &mActivation->mRegisters;
|
2000-09-07 23:22:13 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin();
|
2000-06-23 10:10:14 +04:00
|
|
|
endPC = mActivation->mICode->its_iCode->end();
|
2000-05-19 21:41:10 +04:00
|
|
|
continue;
|
2000-05-09 02:59:42 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
|
2000-08-05 00:28:35 +04:00
|
|
|
case DIRECT_CALL:
|
|
|
|
{
|
|
|
|
DirectCall* call = static_cast<DirectCall*>(instruction);
|
|
|
|
JSFunction *target = op2(call);
|
|
|
|
if (target->isNative()) {
|
2000-09-02 05:01:04 +04:00
|
|
|
ArgumentList ¶ms = op3(call);
|
2000-08-05 00:28:35 +04:00
|
|
|
JSValues argv(params.size() + 1);
|
|
|
|
JSValues::size_type i = 1;
|
2000-09-02 05:01:04 +04:00
|
|
|
for (ArgumentList::const_iterator src = params.begin(), end = params.end();
|
2000-08-05 00:28:35 +04:00
|
|
|
src != end; ++src, ++i) {
|
2000-09-02 05:01:04 +04:00
|
|
|
argv[i] = (*registers)[src->first.first];
|
2000-08-05 00:28:35 +04:00
|
|
|
}
|
|
|
|
JSValue result = static_cast<JSNativeFunction*>(target)->mCode(this, argv);
|
|
|
|
if (op1(call).first != NotARegister)
|
|
|
|
(*registers)[op1(call).first] = result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLinkage = new Linkage(mLinkage, ++mPC,
|
|
|
|
mActivation, mGlobal, op1(call));
|
|
|
|
mActivation = new Activation(target->getICode(), mActivation, kNullValue, op3(call));
|
|
|
|
registers = &mActivation->mRegisters;
|
|
|
|
mPC = mActivation->mICode->its_iCode->begin();
|
|
|
|
endPC = mActivation->mICode->its_iCode->end();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
case RETURN_VOID:
|
|
|
|
{
|
2000-04-26 09:35:07 +04:00
|
|
|
Linkage *linkage = mLinkage;
|
2000-04-26 05:42:00 +04:00
|
|
|
if (!linkage)
|
2000-04-29 04:23:06 +04:00
|
|
|
{
|
2000-04-29 18:43:36 +04:00
|
|
|
// let the garbage collector free activations.
|
|
|
|
mActivation = 0;
|
2000-06-26 19:06:36 +04:00
|
|
|
return kUndefinedValue;
|
2000-04-29 04:23:06 +04:00
|
|
|
}
|
2000-04-26 09:35:07 +04:00
|
|
|
mLinkage = linkage->mNext;
|
2000-04-29 04:23:06 +04:00
|
|
|
mActivation = linkage->mActivation;
|
2000-06-27 06:39:32 +04:00
|
|
|
mGlobal = linkage->mScope;
|
2000-04-29 04:23:06 +04:00
|
|
|
registers = &mActivation->mRegisters;
|
2000-06-24 06:50:23 +04:00
|
|
|
if (linkage->mResult.first != NotARegister)
|
2000-06-26 19:06:36 +04:00
|
|
|
(*registers)[linkage->mResult.first] = kUndefinedValue;
|
2000-04-29 18:43:36 +04:00
|
|
|
mPC = linkage->mReturnPC;
|
2000-06-23 10:10:14 +04:00
|
|
|
endPC = mActivation->mICode->its_iCode->end();
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case RETURN:
|
|
|
|
{
|
|
|
|
Return* ret = static_cast<Return*>(instruction);
|
2000-04-28 09:43:33 +04:00
|
|
|
JSValue result;
|
2000-06-21 02:45:45 +04:00
|
|
|
if (op1(ret).first != NotARegister)
|
|
|
|
result = (*registers)[op1(ret).first];
|
2000-04-26 09:35:07 +04:00
|
|
|
Linkage* linkage = mLinkage;
|
2000-04-26 05:42:00 +04:00
|
|
|
if (!linkage)
|
2000-04-29 04:23:06 +04:00
|
|
|
{
|
2000-04-29 18:43:36 +04:00
|
|
|
// let the garbage collector free activations.
|
|
|
|
mActivation = 0;
|
|
|
|
return result;
|
2000-04-29 04:23:06 +04:00
|
|
|
}
|
2000-04-26 09:35:07 +04:00
|
|
|
mLinkage = linkage->mNext;
|
2000-04-29 04:23:06 +04:00
|
|
|
mActivation = linkage->mActivation;
|
2000-06-27 06:39:32 +04:00
|
|
|
mGlobal = linkage->mScope;
|
2000-04-29 04:23:06 +04:00
|
|
|
registers = &mActivation->mRegisters;
|
2000-06-24 06:50:23 +04:00
|
|
|
if (linkage->mResult.first != NotARegister)
|
|
|
|
(*registers)[linkage->mResult.first] = result;
|
2000-04-29 18:43:36 +04:00
|
|
|
mPC = linkage->mReturnPC;
|
2000-06-23 10:10:14 +04:00
|
|
|
endPC = mActivation->mICode->its_iCode->end();
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case MOVE:
|
|
|
|
{
|
|
|
|
Move* mov = static_cast<Move*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
(*registers)[dst(mov).first] = (*registers)[src1(mov).first];
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOAD_NAME:
|
|
|
|
{
|
2000-09-12 02:10:44 +04:00
|
|
|
LoadName* ln = static_cast<LoadName*>(instruction);
|
|
|
|
JSFunction *getter = mGlobal->getter(*src1(ln));
|
|
|
|
if (getter) {
|
|
|
|
ASSERT(!getter->isNative());
|
|
|
|
mLinkage = new Linkage(mLinkage, ++mPC, mActivation, mGlobal, dst(ln));
|
|
|
|
mActivation = new Activation(getter->getICode());
|
|
|
|
registers = &mActivation->mRegisters;
|
|
|
|
mPC = mActivation->mICode->its_iCode->begin();
|
|
|
|
endPC = mActivation->mICode->its_iCode->end();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(*registers)[dst(ln).first] = mGlobal->getVariable(*src1(ln));
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SAVE_NAME:
|
|
|
|
{
|
|
|
|
SaveName* sn = static_cast<SaveName*>(instruction);
|
2000-09-12 02:10:44 +04:00
|
|
|
JSFunction *setter = mGlobal->setter(*dst(sn));
|
|
|
|
if (setter) {
|
|
|
|
ASSERT(!setter->isNative());
|
|
|
|
mLinkage = new Linkage(mLinkage, ++mPC, mActivation, mGlobal, TypedRegister(NotARegister, &Null_Type));
|
|
|
|
mActivation = new Activation(setter->getICode(), (*registers)[src1(sn).first]);
|
|
|
|
registers = &mActivation->mRegisters;
|
|
|
|
mPC = mActivation->mICode->its_iCode->begin();
|
|
|
|
endPC = mActivation->mICode->its_iCode->end();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mGlobal->setVariable(*dst(sn), (*registers)[src1(sn).first]);
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NEW_OBJECT:
|
|
|
|
{
|
|
|
|
NewObject* no = static_cast<NewObject*>(instruction);
|
2000-07-26 02:58:04 +04:00
|
|
|
if (src1(no).first != NotARegister)
|
|
|
|
(*registers)[dst(no).first] = new JSObject((*registers)[src1(no).first]);
|
|
|
|
else
|
|
|
|
(*registers)[dst(no).first] = new JSObject();
|
2000-06-24 03:49:48 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NEW_CLASS:
|
|
|
|
{
|
|
|
|
NewClass* nc = static_cast<NewClass*>(instruction);
|
2000-07-08 05:08:29 +04:00
|
|
|
JSClass* thisClass = src1(nc);
|
|
|
|
JSInstance* thisInstance = new(thisClass) JSInstance(thisClass);
|
|
|
|
(*registers)[dst(nc).first] = thisInstance;
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-06-22 02:32:21 +04:00
|
|
|
case NEW_FUNCTION:
|
|
|
|
{
|
|
|
|
NewFunction* nf = static_cast<NewFunction*>(instruction);
|
2000-09-12 02:10:44 +04:00
|
|
|
(*registers)[dst(nf).first] = new JSFunction(src1(nf));
|
2000-06-22 02:32:21 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-04-26 05:42:00 +04:00
|
|
|
case NEW_ARRAY:
|
|
|
|
{
|
|
|
|
NewArray* na = static_cast<NewArray*>(instruction);
|
2000-06-27 06:39:32 +04:00
|
|
|
(*registers)[dst(na).first] = new JSArray();
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-06-29 22:13:46 +04:00
|
|
|
case DELETE_PROP:
|
|
|
|
{
|
|
|
|
DeleteProp* dp = static_cast<DeleteProp*>(instruction);
|
|
|
|
JSValue& value = (*registers)[src1(dp).first];
|
|
|
|
if (value.isObject() && !value.isType()) {
|
|
|
|
(*registers)[dst(dp).first] = value.object->deleteProperty(*src2(dp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-04-26 05:42:00 +04:00
|
|
|
case GET_PROP:
|
|
|
|
{
|
|
|
|
GetProp* gp = static_cast<GetProp*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& value = (*registers)[src1(gp).first];
|
2000-06-24 02:53:09 +04:00
|
|
|
if (value.isObject()) {
|
2000-06-27 06:39:32 +04:00
|
|
|
if (value.isType()) {
|
2000-06-28 20:15:06 +04:00
|
|
|
// REVISIT: should signal error if slot doesn't exist.
|
2000-09-12 02:10:44 +04:00
|
|
|
NOT_REACHED("tell me I'm wrong");
|
2000-06-28 20:15:06 +04:00
|
|
|
JSClass* thisClass = dynamic_cast<JSClass*>(value.type);
|
|
|
|
if (thisClass && thisClass->hasStatic(*src2(gp))) {
|
2000-06-28 20:32:52 +04:00
|
|
|
const JSSlot& slot = thisClass->getStatic(*src2(gp));
|
2000-06-28 20:15:06 +04:00
|
|
|
(*registers)[dst(gp).first] = (*thisClass)[slot.mIndex];
|
|
|
|
}
|
2000-08-05 00:28:35 +04:00
|
|
|
else
|
|
|
|
(*registers)[dst(gp).first] = value.object->getProperty(*src2(gp));
|
2000-06-28 20:15:06 +04:00
|
|
|
} else {
|
|
|
|
(*registers)[dst(gp).first] = value.object->getProperty(*src2(gp));
|
2000-06-27 06:39:32 +04:00
|
|
|
}
|
2000-04-28 09:43:33 +04:00
|
|
|
}
|
2000-06-22 02:32:21 +04:00
|
|
|
// XXX runtime error
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SET_PROP:
|
|
|
|
{
|
|
|
|
SetProp* sp = static_cast<SetProp*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& value = (*registers)[dst(sp).first];
|
2000-06-24 02:53:09 +04:00
|
|
|
if (value.isObject()) {
|
2000-06-27 06:39:32 +04:00
|
|
|
if (value.isType()) {
|
2000-06-28 20:15:06 +04:00
|
|
|
// REVISIT: should signal error if slot doesn't exist.
|
2000-09-12 02:10:44 +04:00
|
|
|
NOT_REACHED("tell me I'm wrong");
|
2000-06-28 20:15:06 +04:00
|
|
|
JSClass* thisClass = dynamic_cast<JSClass*>(value.object);
|
|
|
|
if (thisClass && thisClass->hasStatic(*src1(sp))) {
|
2000-06-28 20:32:52 +04:00
|
|
|
const JSSlot& slot = thisClass->getStatic(*src1(sp));
|
2000-06-28 20:15:06 +04:00
|
|
|
(*thisClass)[slot.mIndex] = (*registers)[src2(sp).first];
|
|
|
|
}
|
2000-08-05 00:28:35 +04:00
|
|
|
else
|
|
|
|
value.object->setProperty(*src1(sp), (*registers)[src2(sp).first]);
|
2000-06-28 20:15:06 +04:00
|
|
|
} else {
|
|
|
|
value.object->setProperty(*src1(sp), (*registers)[src2(sp).first]);
|
2000-06-27 06:39:32 +04:00
|
|
|
}
|
2000-04-28 09:43:33 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-06-27 06:39:32 +04:00
|
|
|
case GET_STATIC:
|
|
|
|
{
|
|
|
|
GetStatic* gs = static_cast<GetStatic*>(instruction);
|
|
|
|
JSClass* c = src1(gs);
|
2000-06-28 20:15:06 +04:00
|
|
|
(*registers)[dst(gs).first] = (*c)[src2(gs)];
|
2000-06-27 06:39:32 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SET_STATIC:
|
|
|
|
{
|
|
|
|
SetStatic* ss = static_cast<SetStatic*>(instruction);
|
|
|
|
JSClass* c = dst(ss);
|
2000-06-28 20:15:06 +04:00
|
|
|
(*c)[src1(ss)] = (*registers)[src2(ss).first];
|
2000-06-27 06:39:32 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
/*
|
2000-05-19 21:41:10 +04:00
|
|
|
In 1.5, there is no 'array' type really, the index operation
|
|
|
|
turns into a get_property call like this, only we need to be
|
|
|
|
using JSString throughout.
|
2000-05-18 04:03:23 +04:00
|
|
|
case GET_ELEMENT:
|
|
|
|
{
|
|
|
|
GetElement* ge = static_cast<GetElement*>(instruction);
|
|
|
|
JSValue& base = (*registers)[src1(ge)];
|
|
|
|
JSValue index = (*registers)[src2(ge)].toString();
|
|
|
|
if (base.tag == JSValue::object_tag) {
|
|
|
|
JSObject* object = base.object;
|
|
|
|
(*registers)[dst(ge)] = object->getProperty(*index.string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
2000-04-26 05:42:00 +04:00
|
|
|
case GET_ELEMENT:
|
|
|
|
{
|
|
|
|
GetElement* ge = static_cast<GetElement*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& value = (*registers)[src1(ge).first];
|
2000-04-28 09:43:33 +04:00
|
|
|
if (value.tag == JSValue::array_tag) {
|
|
|
|
JSArray* array = value.array;
|
2000-06-21 02:45:45 +04:00
|
|
|
(*registers)[dst(ge).first] = (*array)[(*registers)[src2(ge).first]];
|
2000-04-28 09:43:33 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SET_ELEMENT:
|
|
|
|
{
|
|
|
|
SetElement* se = static_cast<SetElement*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& value = (*registers)[dst(se).first];
|
2000-04-28 09:43:33 +04:00
|
|
|
if (value.tag == JSValue::array_tag) {
|
|
|
|
JSArray* array = value.array;
|
2000-06-21 02:45:45 +04:00
|
|
|
(*array)[(*registers)[src1(se).first]] = (*registers)[src2(se).first];
|
2000-04-28 09:43:33 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
|
2000-06-24 04:50:59 +04:00
|
|
|
case GET_SLOT:
|
|
|
|
{
|
|
|
|
GetSlot* gs = static_cast<GetSlot*>(instruction);
|
|
|
|
JSValue& value = (*registers)[src1(gs).first];
|
|
|
|
if (value.isObject()) {
|
|
|
|
JSInstance* inst = static_cast<JSInstance *>(value.object);
|
|
|
|
(*registers)[dst(gs).first] = (*inst)[src2(gs)];
|
|
|
|
}
|
|
|
|
// XXX runtime error
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SET_SLOT:
|
|
|
|
{
|
|
|
|
SetSlot* ss = static_cast<SetSlot*>(instruction);
|
|
|
|
JSValue& value = (*registers)[dst(ss).first];
|
|
|
|
if (value.isObject()) {
|
|
|
|
JSInstance* inst = static_cast<JSInstance *>(value.object);
|
|
|
|
(*inst)[src1(ss)] = (*registers)[src2(ss).first];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
case LOAD_IMMEDIATE:
|
|
|
|
{
|
|
|
|
LoadImmediate* li = static_cast<LoadImmediate*>(instruction);
|
2000-06-27 06:39:32 +04:00
|
|
|
(*registers)[dst(li).first] = src1(li);
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-09 02:59:42 +04:00
|
|
|
case LOAD_STRING:
|
|
|
|
{
|
|
|
|
LoadString* ls = static_cast<LoadString*>(instruction);
|
2000-06-27 06:39:32 +04:00
|
|
|
(*registers)[dst(ls).first] = src1(ls);
|
2000-05-09 02:59:42 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-06-21 02:45:45 +04:00
|
|
|
case LOAD_BOOLEAN:
|
2000-05-18 04:03:23 +04:00
|
|
|
{
|
2000-06-21 02:45:45 +04:00
|
|
|
LoadBoolean* lb = static_cast<LoadBoolean*>(instruction);
|
2000-06-27 06:39:32 +04:00
|
|
|
(*registers)[dst(lb).first] = src1(lb);
|
2000-05-18 04:03:23 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-04-26 05:42:00 +04:00
|
|
|
case BRANCH:
|
|
|
|
{
|
|
|
|
GenericBranch* bra =
|
|
|
|
static_cast<GenericBranch*>(instruction);
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + ofs(bra);
|
2000-04-08 07:23:44 +04:00
|
|
|
continue;
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-19 21:41:10 +04:00
|
|
|
case BRANCH_TRUE:
|
2000-04-26 05:42:00 +04:00
|
|
|
{
|
|
|
|
GenericBranch* bc =
|
|
|
|
static_cast<GenericBranch*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
ASSERT((*registers)[src1(bc).first].isBoolean());
|
|
|
|
if ((*registers)[src1(bc).first].boolean) {
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + ofs(bc);
|
2000-04-26 05:42:00 +04:00
|
|
|
continue;
|
2000-04-22 02:52:52 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-19 21:41:10 +04:00
|
|
|
case BRANCH_FALSE:
|
2000-04-26 05:42:00 +04:00
|
|
|
{
|
|
|
|
GenericBranch* bc =
|
|
|
|
static_cast<GenericBranch*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
ASSERT((*registers)[src1(bc).first].isBoolean());
|
|
|
|
if (!(*registers)[src1(bc).first].boolean) {
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + ofs(bc);
|
2000-04-26 05:42:00 +04:00
|
|
|
continue;
|
2000-04-22 02:52:52 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-09-07 23:22:13 +04:00
|
|
|
case BRANCH_INITIALIZED:
|
|
|
|
{
|
|
|
|
GenericBranch* bc =
|
|
|
|
static_cast<GenericBranch*>(instruction);
|
|
|
|
if ((*registers)[src1(bc).first].isInitialized()) {
|
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + ofs(bc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-07-13 04:14:54 +04:00
|
|
|
case GENERIC_BINARY_OP:
|
|
|
|
{
|
|
|
|
GenericBinaryOP* gbo = static_cast<GenericBinaryOP*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(gbo).first];
|
|
|
|
JSValue& r1 = (*registers)[val3(gbo).first];
|
|
|
|
JSValue& r2 = (*registers)[val4(gbo).first];
|
|
|
|
const JSValue ovr = findBinaryOverride(r1, r2, val2(gbo));
|
|
|
|
JSFunction *target = ovr.function;
|
|
|
|
if (target->isNative()) {
|
|
|
|
JSValues argv(2);
|
|
|
|
argv[0] = r1;
|
|
|
|
argv[1] = r2;
|
|
|
|
dest = static_cast<JSBinaryOperator*>(target)->mCode(r1, r2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLinkage = new Linkage(mLinkage, ++mPC,
|
|
|
|
mActivation, mGlobal, dst(gbo));
|
|
|
|
mActivation = new Activation(target->getICode(), r1, r2);
|
|
|
|
registers = &mActivation->mRegisters;
|
|
|
|
mPC = mActivation->mICode->its_iCode->begin();
|
|
|
|
endPC = mActivation->mICode->its_iCode->end();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-07-14 05:00:53 +04:00
|
|
|
|
2000-05-18 04:03:23 +04:00
|
|
|
case SHIFTLEFT:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toUInt32());
|
|
|
|
dest = JSValue(num1.i32 << (num2.u32 & 0x1F));
|
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
case SHIFTRIGHT:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toUInt32());
|
|
|
|
dest = JSValue(num1.i32 >> (num2.u32 & 0x1F));
|
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
case USHIFTRIGHT:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
JSValue num1(r1.toUInt32());
|
|
|
|
JSValue num2(r2.toUInt32());
|
|
|
|
dest = JSValue(num1.u32 >> (num2.u32 & 0x1F));
|
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
case AND:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toInt32());
|
|
|
|
dest = JSValue(num1.i32 & num2.i32);
|
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
case OR:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toInt32());
|
|
|
|
dest = JSValue(num1.i32 | num2.i32);
|
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
case XOR:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
JSValue num1(r1.toInt32());
|
|
|
|
JSValue num2(r2.toInt32());
|
|
|
|
dest = JSValue(num1.i32 ^ num2.i32);
|
|
|
|
}
|
|
|
|
break;
|
2000-04-26 05:42:00 +04:00
|
|
|
case ADD:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
dest = JSValue(r1.f64 + r2.f64);
|
|
|
|
}
|
|
|
|
break;
|
2000-04-26 05:42:00 +04:00
|
|
|
case SUBTRACT:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
dest = JSValue(r1.f64 - r2.f64);
|
|
|
|
}
|
|
|
|
break;
|
2000-04-26 05:42:00 +04:00
|
|
|
case MULTIPLY:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
dest = JSValue(r1.f64 * r2.f64);
|
|
|
|
}
|
|
|
|
break;
|
2000-05-23 04:08:29 +04:00
|
|
|
case DIVIDE:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
dest = JSValue(r1.f64 / r2.f64);
|
|
|
|
}
|
|
|
|
break;
|
2000-05-23 04:08:29 +04:00
|
|
|
case REMAINDER:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
dest = JSValue(fmod(r1.f64, r2.f64));
|
|
|
|
}
|
|
|
|
break;
|
2000-05-23 04:08:29 +04:00
|
|
|
case COMPARE_LT:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
if (r1.isNaN() || r2.isNaN())
|
|
|
|
dest = JSValue();
|
|
|
|
else
|
|
|
|
dest = JSValue(r1.f64 < r2.f64);
|
|
|
|
}
|
|
|
|
break;
|
2000-05-23 04:08:29 +04:00
|
|
|
case COMPARE_LE:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
if (r1.isNaN() || r2.isNaN())
|
|
|
|
dest = JSValue();
|
|
|
|
else
|
|
|
|
dest = JSValue(r1.f64 <= r2.f64);
|
|
|
|
}
|
|
|
|
break;
|
2000-05-23 04:08:29 +04:00
|
|
|
case COMPARE_EQ:
|
2000-07-14 05:00:53 +04:00
|
|
|
{
|
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
if (r1.isNaN() || r2.isNaN())
|
|
|
|
dest = JSValue();
|
|
|
|
else
|
|
|
|
dest = JSValue(r1.f64 == r2.f64);
|
|
|
|
}
|
|
|
|
break;
|
2000-05-23 04:08:29 +04:00
|
|
|
case STRICT_EQ:
|
2000-04-26 05:42:00 +04:00
|
|
|
{
|
2000-07-13 04:14:54 +04:00
|
|
|
Arithmetic* a = static_cast<Arithmetic*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(a).first];
|
|
|
|
JSValue& r1 = (*registers)[src1(a).first];
|
|
|
|
JSValue& r2 = (*registers)[src2(a).first];
|
2000-07-14 05:00:53 +04:00
|
|
|
ASSERT(r1.isNumber());
|
|
|
|
ASSERT(r2.isNumber());
|
|
|
|
if (r1.isNaN() || r2.isNaN())
|
|
|
|
dest = kFalseValue;
|
|
|
|
else
|
|
|
|
dest = JSValue(r1.f64 == r2.f64);
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-11 04:35:06 +04:00
|
|
|
|
2000-06-15 03:26:15 +04:00
|
|
|
case VAR_XCR:
|
|
|
|
{
|
|
|
|
VarXcr *vx = static_cast<VarXcr*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& dest = (*registers)[dst(vx).first];
|
|
|
|
JSValue r = (*registers)[src1(vx).first].toNumber();
|
2000-06-15 03:26:15 +04:00
|
|
|
dest = r;
|
|
|
|
r.f64 += val3(vx);
|
2000-06-21 02:45:45 +04:00
|
|
|
(*registers)[src1(vx).first] = r;
|
2000-06-15 03:26:15 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-05-11 04:35:06 +04:00
|
|
|
case PROP_XCR:
|
|
|
|
{
|
|
|
|
PropXcr *px = static_cast<PropXcr*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& dest = (*registers)[dst(px).first];
|
|
|
|
JSValue& base = (*registers)[src1(px).first];
|
2000-05-11 04:35:06 +04:00
|
|
|
JSObject *object = base.object;
|
|
|
|
JSValue r = object->getProperty(*src2(px)).toNumber();
|
|
|
|
dest = r;
|
|
|
|
r.f64 += val4(px);
|
|
|
|
object->setProperty(*src2(px), r);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-06-24 04:50:59 +04:00
|
|
|
case SLOT_XCR:
|
|
|
|
{
|
|
|
|
SlotXcr *sx = static_cast<SlotXcr*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(sx).first];
|
|
|
|
JSValue& base = (*registers)[src1(sx).first];
|
|
|
|
JSInstance *inst = static_cast<JSInstance*>(base.object);
|
|
|
|
JSValue r = (*inst)[src2(sx)].toNumber();
|
|
|
|
dest = r;
|
|
|
|
r.f64 += val4(sx);
|
|
|
|
(*inst)[src2(sx)] = r;
|
|
|
|
}
|
|
|
|
break;
|
2000-06-28 20:15:06 +04:00
|
|
|
|
|
|
|
case STATIC_XCR:
|
|
|
|
{
|
|
|
|
StaticXcr *sx = static_cast<StaticXcr*>(instruction);
|
|
|
|
JSValue& dest = (*registers)[dst(sx).first];
|
|
|
|
JSClass* thisClass = src1(sx);
|
|
|
|
JSValue r = (*thisClass)[src2(sx)].toNumber();
|
|
|
|
dest = r;
|
|
|
|
r.f64 += val4(sx);
|
|
|
|
(*thisClass)[src2(sx)] = r;
|
|
|
|
}
|
|
|
|
break;
|
2000-06-24 04:50:59 +04:00
|
|
|
|
2000-05-11 04:35:06 +04:00
|
|
|
case NAME_XCR:
|
|
|
|
{
|
|
|
|
NameXcr *nx = static_cast<NameXcr*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& dest = (*registers)[dst(nx).first];
|
2000-05-11 04:35:06 +04:00
|
|
|
JSValue r = mGlobal->getVariable(*src1(nx)).toNumber();
|
|
|
|
dest = r;
|
|
|
|
r.f64 += val3(nx);
|
2000-05-18 04:03:23 +04:00
|
|
|
mGlobal->setVariable(*src1(nx), r);
|
2000-05-11 04:35:06 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-05-18 04:03:23 +04:00
|
|
|
case TEST:
|
|
|
|
{
|
|
|
|
Test* tst = static_cast<Test*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
(*registers)[dst(tst).first] = (*registers)[src1(tst).first].toBoolean();
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-09 02:59:42 +04:00
|
|
|
case NEGATE:
|
|
|
|
{
|
|
|
|
Negate* neg = static_cast<Negate*>(instruction);
|
2000-06-27 06:39:32 +04:00
|
|
|
(*registers)[dst(neg).first] = -(*registers)[src1(neg).first].toNumber().f64;
|
2000-05-09 02:59:42 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case POSATE:
|
|
|
|
{
|
|
|
|
Posate* pos = static_cast<Posate*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
(*registers)[dst(pos).first] = (*registers)[src1(pos).first].toNumber();
|
2000-05-09 02:59:42 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-18 04:03:23 +04:00
|
|
|
case BITNOT:
|
|
|
|
{
|
|
|
|
Bitnot* bn = static_cast<Bitnot*>(instruction);
|
2000-06-27 06:39:32 +04:00
|
|
|
(*registers)[dst(bn).first] = ~(*registers)[src1(bn).first].toInt32().i32;
|
2000-05-18 04:03:23 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-06-22 02:32:21 +04:00
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
case NOT:
|
|
|
|
{
|
|
|
|
Not* nt = static_cast<Not*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
ASSERT((*registers)[src1(nt).first].isBoolean());
|
2000-06-27 06:39:32 +04:00
|
|
|
(*registers)[dst(nt).first] = !(*registers)[src1(nt).first].boolean;
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-06-22 02:32:21 +04:00
|
|
|
|
2000-04-29 18:43:36 +04:00
|
|
|
case THROW:
|
2000-04-26 05:42:00 +04:00
|
|
|
{
|
2000-04-27 05:27:09 +04:00
|
|
|
Throw* thrw = static_cast<Throw*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
throw new JSException((*registers)[op1(thrw).first]);
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
2000-04-22 02:52:52 +04:00
|
|
|
|
2000-05-06 01:38:16 +04:00
|
|
|
case TRYIN:
|
2000-04-26 05:42:00 +04:00
|
|
|
{ // push the catch handler address onto the try stack
|
2000-05-06 01:38:16 +04:00
|
|
|
Tryin* tri = static_cast<Tryin*>(instruction);
|
2000-04-29 04:23:06 +04:00
|
|
|
mActivation->catchStack.push_back(new Handler(op1(tri),
|
|
|
|
op2(tri)));
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-05-06 01:38:16 +04:00
|
|
|
case TRYOUT:
|
2000-04-26 05:42:00 +04:00
|
|
|
{
|
2000-04-29 04:23:06 +04:00
|
|
|
Handler *h = mActivation->catchStack.back();
|
|
|
|
mActivation->catchStack.pop_back();
|
2000-04-27 05:27:09 +04:00
|
|
|
delete h;
|
2000-04-08 07:23:44 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
break;
|
2000-04-29 18:43:36 +04:00
|
|
|
case JSR:
|
2000-04-27 05:27:09 +04:00
|
|
|
{
|
2000-04-29 18:43:36 +04:00
|
|
|
subroutineStack.push(++mPC);
|
2000-04-27 05:27:09 +04:00
|
|
|
Jsr* jsr = static_cast<Jsr*>(instruction);
|
|
|
|
uint32 offset = ofs(jsr);
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + offset;
|
2000-04-27 05:27:09 +04:00
|
|
|
continue;
|
|
|
|
}
|
2000-04-29 18:43:36 +04:00
|
|
|
case RTS:
|
2000-04-27 05:27:09 +04:00
|
|
|
{
|
|
|
|
ASSERT(!subroutineStack.empty());
|
2000-04-29 18:43:36 +04:00
|
|
|
mPC = subroutineStack.top();
|
2000-04-27 05:27:09 +04:00
|
|
|
subroutineStack.pop();
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-29 18:43:36 +04:00
|
|
|
case WITHIN:
|
|
|
|
{
|
|
|
|
Within* within = static_cast<Within*>(instruction);
|
2000-06-21 02:45:45 +04:00
|
|
|
JSValue& value = (*registers)[op1(within).first];
|
2000-04-29 18:43:36 +04:00
|
|
|
assert(value.tag == JSValue::object_tag);
|
|
|
|
mGlobal = new JSScope(mGlobal, value.object);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WITHOUT:
|
|
|
|
{
|
2000-05-01 21:18:49 +04:00
|
|
|
// Without* without = static_cast<Without*>(instruction);
|
2000-04-29 18:43:36 +04:00
|
|
|
mGlobal = mGlobal->getParent();
|
|
|
|
}
|
|
|
|
break;
|
2000-06-24 02:27:17 +04:00
|
|
|
case DEBUGGER:
|
|
|
|
{
|
|
|
|
if (mListeners.size())
|
|
|
|
broadcast(EV_DEBUG);
|
|
|
|
break;
|
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
default:
|
|
|
|
NOT_REACHED("bad opcode");
|
|
|
|
break;
|
2000-04-22 02:52:52 +04:00
|
|
|
}
|
2000-04-26 05:42:00 +04:00
|
|
|
|
|
|
|
// increment the program counter.
|
2000-04-29 18:43:36 +04:00
|
|
|
++mPC;
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
2000-07-12 00:54:06 +04:00
|
|
|
catch (JSException *x) {
|
2000-04-27 05:27:09 +04:00
|
|
|
if (mLinkage) {
|
2000-04-29 04:23:06 +04:00
|
|
|
if (mActivation->catchStack.empty()) {
|
2000-04-27 05:27:09 +04:00
|
|
|
Linkage *pLinkage = mLinkage;
|
|
|
|
for (; pLinkage != NULL; pLinkage = pLinkage->mNext) {
|
|
|
|
if (!pLinkage->mActivation->catchStack.empty()) {
|
2000-04-29 04:23:06 +04:00
|
|
|
mActivation = pLinkage->mActivation;
|
|
|
|
Handler *h = mActivation->catchStack.back();
|
|
|
|
registers = &mActivation->mRegisters;
|
2000-04-27 05:27:09 +04:00
|
|
|
if (h->catchTarget) {
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + h->catchTarget->mOffset;
|
2000-04-27 05:27:09 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ASSERT(h->finallyTarget);
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + h->finallyTarget->mOffset;
|
2000-04-27 05:27:09 +04:00
|
|
|
}
|
|
|
|
mLinkage = pLinkage;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pLinkage)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
2000-04-29 04:23:06 +04:00
|
|
|
Handler *h = mActivation->catchStack.back();
|
2000-04-27 05:27:09 +04:00
|
|
|
if (h->catchTarget) {
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + h->catchTarget->mOffset;
|
2000-04-27 05:27:09 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ASSERT(h->finallyTarget);
|
2000-05-19 21:41:10 +04:00
|
|
|
mPC = mActivation->mICode->its_iCode->begin() + h->finallyTarget->mOffset;
|
2000-04-27 05:27:09 +04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2000-07-12 00:54:06 +04:00
|
|
|
rv = x->value;
|
|
|
|
break;
|
2000-04-19 01:51:45 +04:00
|
|
|
}
|
2000-06-24 02:27:17 +04:00
|
|
|
|
2000-04-26 05:42:00 +04:00
|
|
|
}
|
2000-09-02 05:01:04 +04:00
|
|
|
mActivation = 0;
|
2000-04-29 04:23:06 +04:00
|
|
|
return rv;
|
2000-04-26 05:42:00 +04:00
|
|
|
} /* interpret */
|
2000-04-05 10:05:57 +04:00
|
|
|
|
2000-04-26 09:35:07 +04:00
|
|
|
void Context::addListener(Listener* listener)
|
|
|
|
{
|
|
|
|
mListeners.push_back(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::removeListener(Listener* listener)
|
2000-05-12 05:19:39 +04:00
|
|
|
{
|
|
|
|
ListenerIterator e = mListeners.end();
|
2000-05-18 04:03:23 +04:00
|
|
|
ListenerIterator l = std::find(mListeners.begin(), e, listener);
|
2000-05-12 05:19:39 +04:00
|
|
|
if (l != e) mListeners.erase(l);
|
2000-04-26 09:35:07 +04:00
|
|
|
}
|
|
|
|
|
2000-05-12 05:19:39 +04:00
|
|
|
void Context::broadcast(Event event)
|
2000-04-26 09:35:07 +04:00
|
|
|
{
|
2000-04-29 04:23:06 +04:00
|
|
|
for (ListenerIterator i = mListeners.begin(), e = mListeners.end();
|
|
|
|
i != e; ++i) {
|
2000-04-26 09:35:07 +04:00
|
|
|
Listener* listener = *i;
|
2000-05-12 05:19:39 +04:00
|
|
|
listener->listen(this, event);
|
2000-04-26 09:35:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context::Frame* Context::getFrames()
|
|
|
|
{
|
|
|
|
return mLinkage;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace Interpreter */
|
2000-04-18 11:14:49 +04:00
|
|
|
} /* namespace JavaScript */
|