[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kjs-frostbyte/kjs
From:       Maks Orlovich <maksim () kde ! org>
Date:       2008-02-27 17:07:37
Message-ID: 1204132057.971705.10997.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 779972 by orlovich:

- Fix reversed result in !==
- Implement delete

 M  +40 -1     bytecode/codes.def  
 M  +10 -1     nodes.h  
 M  +55 -0     nodes2bytecode.cpp  


--- branches/work/kjs-frostbyte/kjs/bytecode/codes.def #779971:779972
@@ -669,6 +669,45 @@
     ]]
 }
 
+operation SymDeleteKnownObject {
+    impl bool(value scope, ident name) [[
+        ASSERT(scope->isObject());
+        $$ = static_cast<JSObject*>(scope)->deleteProperty(exec, *name);
+    ]]
+}
+
+operation SymDelete {
+    impl bool(value scope, ident name) [[
+        JSObject* o = scope->toObject(exec);
+        if (pc == localPC) // No exception!
+            $$ = o->deleteProperty(exec, *name);
+    ]]
+}
+
+operation BracketDelete {
+    impl bool(value v1, value v2) [[
+        uint32_t i;
+        JSObject *o = v1->toObject(exec);
+        if (pc != localPC)
+            break;
+
+        if (v2->getUInt32(i))
+            $$ = o->deleteProperty(exec, i);
+        else
+            $$ = o->deleteProperty(exec, Identifier(v2->toString(exec)));
+    ]]
+}
+
+operation IndexDelete {
+    impl bool(value v1, int32 i) [[
+        JSObject *o = v1->toObject(exec);
+        if (pc != localPC)
+            break;
+
+        $$ = o->deleteProperty(exec, (uint32_t)i);
+    ]]
+}
+
 /**
  Making things..
 */
@@ -881,7 +920,7 @@
 operation StrNEq {
     impl bool(value v1, value v2) [[
         // operator !==
-        $$ = strictEqual(exec,v1, v2);
+        $$ = !strictEqual(exec,v1, v2);
     ]]
 }
 
--- branches/work/kjs-frostbyte/kjs/nodes.h #779971:779972
@@ -213,11 +213,16 @@
                            // generateRefBegin, try to combine them if possible.
     };
 
+
     virtual CompileReference* generateRefBegin (CompileState*, CodeBlock& block, int flags = 0) = 0;
     virtual OpValue generateRefBase(CompileState*, CodeBlock& block, CompileReference* ref) = 0;
     virtual OpValue generateRefRead(CompileState*, CodeBlock& block, CompileReference* ref) = 0;
     virtual void generateRefWrite  (CompileState*, CodeBlock& block,
                                     CompileReference* ref, OpValue& valToStore) = 0;
+
+    // The location nodes also handle deletes themselves. Note that this is called
+    // w/o generateRefBegin
+    virtual OpValue generateRefDelete(CompileState*, CodeBlock& block) = 0;
   };
 
   class StatementNode : public Node {
@@ -326,6 +331,7 @@
     virtual OpValue generateRefBase(CompileState* comp, CodeBlock& block, CompileReference* ref);
     virtual void generateRefWrite(CompileState*, CodeBlock& block,
                                         CompileReference* ref, OpValue& valToStore);
+    virtual OpValue generateRefDelete(CompileState*, CodeBlock& block);
 
     // Returns the ID this variable should be accessed as, or
     // missingSymbolMarker(). maybeLocal will be set if the symbol
@@ -452,6 +458,7 @@
     virtual OpValue generateRefRead(CompileState*, CodeBlock& block, CompileReference* ref);
     virtual void generateRefWrite  (CompileState*, CodeBlock& block,
                                     CompileReference* ref, OpValue& valToStore);
+    virtual OpValue generateRefDelete(CompileState*, CodeBlock& block);
 
     Node *base() { return expr1.get(); }
     Node *subscript() { return expr2.get(); }
@@ -477,8 +484,8 @@
     virtual OpValue generateRefBase(CompileState* comp, CodeBlock& block, CompileReference* ref);
     virtual void generateRefWrite(CompileState*, CodeBlock& block,
                                         CompileReference* ref, OpValue& valToStore);
+    virtual OpValue generateRefDelete(CompileState*, CodeBlock& block);
 
-
     Node *base() const { return expr.get(); }
     const Identifier& identifier() const { return ident; }
 
@@ -625,6 +632,7 @@
     JSValue* evaluate(ExecState*);
     void streamTo(SourceStream&) const;
     void recurseVisit(NodeVisitor * visitor);
+    virtual OpValue generateEvalCode(CompileState* comp, CodeBlock& block);
   private:
     RefPtr<LocationNode> loc;
   };
@@ -635,6 +643,7 @@
     JSValue* evaluate(ExecState*);
     virtual void streamTo(SourceStream&) const;
     virtual void recurseVisit(NodeVisitor *visitor);
+    virtual OpValue generateEvalCode(CompileState* comp, CodeBlock& block);
   private:
     RefPtr<Node> m_expr;
   };
--- branches/work/kjs-frostbyte/kjs/nodes2bytecode.cpp #779971:779972
@@ -248,6 +248,29 @@
     }
 }
 
+OpValue VarAccessNode::generateRefDelete(CompileState* comp, CodeBlock& block)
+{
+    bool dynamicLocal;
+    size_t index = localID(comp, dynamicLocal);
+
+    if (index == missingSymbolMarker()) {
+        // Fetch the scope...
+        OpValue base;
+        OpValue varName = OpValue::immIdent(&ident);
+        OpValue silent  = OpValue::immNode(0);
+        CodeGen::emitOp(comp, block, dynamicLocal ? Op_ScopeLookup : Op_NonLocalScopeLookup,
+                        &base, &varName, &silent);
+
+        // Remove the property..
+        OpValue out;
+        CodeGen::emitOp(comp, block, Op_SymDeleteKnownObject, &out, &base, &varName);
+        return out;
+    } else {
+        // Normal locals are DontDelete, so this always fails.
+        return OpValue::immBool(false);
+    }
+}
+
 // ------------------------------ GroupNode----------------------------------------
 
 OpValue GroupNode::generateEvalCode(CompileState* comp, CodeBlock& block)
@@ -372,6 +395,19 @@
         CodeGen::emitOp(comp, block, Op_BracketPut, 0, &ref->baseVal, &index, &valToStore);
 }
 
+OpValue BracketAccessorNode::generateRefDelete(CompileState* comp, CodeBlock& block)
+{
+    OpValue base  = expr1->generateEvalCode(comp, block);
+    OpValue index = expr2->generateEvalCode(comp, block);
+
+    OpValue out;
+    if (index.type == OpType_int32)
+        CodeGen::emitOp(comp, block, Op_IndexDelete, &out, &base, &index);
+    else
+        CodeGen::emitOp(comp, block, Op_BracketDelete, &out, &base, &index);
+    return out;
+}
+
 // ------------------------------ DotAccessorNode --------------------------------
 
 // ECMA 11.2.1b
@@ -412,6 +448,15 @@
     CodeGen::emitOp(comp, block, Op_SymPut, 0, &ref->baseVal, &varName, &valToStore);
 }
 
+OpValue DotAccessorNode::generateRefDelete(CompileState* comp, CodeBlock& block)
+{
+    OpValue base = expr->generateEvalCode(comp, block);
+    OpValue varName = OpValue::immIdent(&ident);
+    OpValue out;
+    CodeGen::emitOp(comp, block, Op_SymDelete, &out, &base, &varName);
+    return out;
+}
+
 // ------------------ ........
 
 void ArgumentsNode::generateEvalArguments(CompileState* comp, CodeBlock& block)
@@ -509,6 +554,16 @@
     return curV;
 }
 
+OpValue DeleteReferenceNode::generateEvalCode(CompileState* comp, CodeBlock& block)
+{
+    return loc->generateRefDelete(comp, block);
+}
+
+OpValue DeleteValueNode::generateEvalCode(CompileState* comp, CodeBlock& block)
+{
+    return OpValue::immBool(true);
+}
+
 OpValue VoidNode::generateEvalCode(CompileState* comp, CodeBlock& block)
 {
     (void)expr->generateEvalCode(comp, block);
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic