Bug 607751 - Compile JSOP_DEFCONST, JSOP_SETCONST (r=dvander)

This commit is contained in:
Bill McCloskey 2010-11-11 17:17:16 -08:00
parent 7670250f20
commit a06ec9a237
3 changed files with 50 additions and 9 deletions

View File

@ -1718,16 +1718,34 @@ mjit::Compiler::generateMethod()
END_CASE(JSOP_DEFFUN)
BEGIN_CASE(JSOP_DEFVAR)
BEGIN_CASE(JSOP_DEFCONST)
{
uint32 index = fullAtomIndex(PC);
JSAtom *atom = script->getAtom(index);
prepareStubCall(Uses(0));
masm.move(ImmPtr(atom), Registers::ArgReg1);
INLINE_STUBCALL(stubs::DefVar);
INLINE_STUBCALL(stubs::DefVarOrConst);
}
END_CASE(JSOP_DEFVAR)
BEGIN_CASE(JSOP_SETCONST)
{
uint32 index = fullAtomIndex(PC);
JSAtom *atom = script->getAtom(index);
if (fun) {
JSLocalKind localKind = fun->lookupLocal(cx, atom, NULL);
if (localKind != JSLOCAL_NONE)
frame.syncAndForgetEverything();
}
prepareStubCall(Uses(1));
masm.move(ImmPtr(atom), Registers::ArgReg1);
INLINE_STUBCALL(stubs::SetConst);
}
END_CASE(JSOP_SETCONST)
BEGIN_CASE(JSOP_DEFLOCALFUN_FC)
{
uint32 slot = GET_SLOTNO(PC);

View File

@ -2647,7 +2647,7 @@ stubs::DelElem(VMFrame &f)
}
void JS_FASTCALL
stubs::DefVar(VMFrame &f, JSAtom *atom)
stubs::DefVarOrConst(VMFrame &f, JSAtom *atom)
{
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
@ -2657,18 +2657,25 @@ stubs::DefVar(VMFrame &f, JSAtom *atom)
uintN attrs = JSPROP_ENUMERATE;
if (!fp->isEvalFrame())
attrs |= JSPROP_PERMANENT;
if (JSOp(*f.regs.pc) == JSOP_DEFCONST)
attrs |= JSPROP_READONLY;
/* Lookup id in order to check for redeclaration problems. */
jsid id = ATOM_TO_JSID(atom);
JSProperty *prop = NULL;
JSObject *obj2;
/*
* Redundant declaration of a |var|, even one for a non-writable
* property like |undefined| in ES5, does nothing.
*/
if (!obj->lookupProperty(cx, id, &obj2, &prop))
THROW();
if (JSOp(*f.regs.pc) == JSOP_DEFVAR) {
/*
* Redundant declaration of a |var|, even one for a non-writable
* property like |undefined| in ES5, does nothing.
*/
if (!obj->lookupProperty(cx, id, &obj2, &prop))
THROW();
} else {
if (!CheckRedeclaration(cx, obj, id, attrs, &obj2, &prop))
THROW();
}
/* Bind a variable only if it's not yet defined. */
if (!prop) {
@ -2681,6 +2688,21 @@ stubs::DefVar(VMFrame &f, JSAtom *atom)
}
}
void JS_FASTCALL
stubs::SetConst(VMFrame &f, JSAtom *atom)
{
JSContext *cx = f.cx;
JSStackFrame *fp = f.fp();
JSObject *obj = &fp->varobj(cx);
const Value &ref = f.regs.sp[-1];
if (!obj->defineProperty(cx, ATOM_TO_JSID(atom), ref,
PropertyStub, PropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY)) {
THROW();
}
}
JSBool JS_FASTCALL
stubs::In(VMFrame &f)
{

View File

@ -154,7 +154,8 @@ template <JSBool strict> void JS_FASTCALL DelElem(VMFrame &f);
void JS_FASTCALL DelName(VMFrame &f, JSAtom *atom);
JSBool JS_FASTCALL In(VMFrame &f);
void JS_FASTCALL DefVar(VMFrame &f, JSAtom *atom);
void JS_FASTCALL DefVarOrConst(VMFrame &f, JSAtom *atom);
void JS_FASTCALL SetConst(VMFrame &f, JSAtom *atom);
template<JSBool strict> void JS_FASTCALL DefFun(VMFrame &f, JSFunction *fun);
JSObject * JS_FASTCALL DefLocalFun(VMFrame &f, JSFunction *fun);
JSObject * JS_FASTCALL DefLocalFun_FC(VMFrame &f, JSFunction *fun);