Show
Ignore:
Timestamp:
05/23/06 15:48:06 (3 years ago)
Author:
brmorris
Message:

S60WebKit ... migrated!

Location:
S60/trunk/JavaScriptCore
Files:
16 added
114 modified

Legend:

Unmodified
Added
Removed
  • S60/trunk/JavaScriptCore/bindings/NP_jsobject.cpp

    r14062 r14549  
    7474NPClass *NPScriptObjectClass = &_javascriptClass; 
    7575 
    76 Identifier identiferFromNPIdentifier(const NPUTF8 *name) 
     76static Identifier identifierFromNPIdentifier(const NPUTF8 *name) 
    7777{ 
    7878    NPUTF16 *methodName; 
     
    8686} 
    8787 
    88 NPObject *_NPN_CreateScriptObject (NPP npp, KJS::ObjectImp *imp, KJS::Bindings::RootObject *root) 
     88static bool _isSafeScript(JavaScriptObject *obj) 
     89{ 
     90    if (obj->originExecutionContext) { 
     91        Interpreter *originInterpreter = obj->originExecutionContext->interpreter(); 
     92        if (originInterpreter) { 
     93            return originInterpreter->isSafeScript (obj->executionContext->interpreter()); 
     94        } 
     95    } 
     96    return true; 
     97} 
     98 
     99NPObject *_NPN_CreateScriptObject (NPP npp, KJS::ObjectImp *imp, const KJS::Bindings::RootObject *originExecutionContext, const KJS::Bindings::RootObject *executionContext) 
    89100{ 
    90101    JavaScriptObject *obj = (JavaScriptObject *)_NPN_CreateObject(npp, NPScriptObjectClass); 
    91102 
    92103    obj->imp = imp; 
    93     obj->root = root;     
    94  
    95     addNativeReference (root, imp); 
     104    obj->originExecutionContext = originExecutionContext;     
     105    obj->executionContext = executionContext;     
     106 
     107    addNativeReference (executionContext, imp); 
    96108     
    97109    return (NPObject *)obj; 
     
    118130        JavaScriptObject *obj = (JavaScriptObject *)o;  
    119131         
     132        if (!_isSafeScript(obj)) 
     133            return false; 
     134             
    120135        PrivateIdentifier *i = (PrivateIdentifier *)methodName; 
    121136        if (!i->isString) 
    122137            return false; 
    123138             
    124         // Lookup the function object. 
    125         ExecState *exec = obj->root->interpreter()->globalExec(); 
    126         Interpreter::lock(); 
    127         Value func = obj->imp->get (exec, identiferFromNPIdentifier(i->value.string)); 
    128         Interpreter::unlock(); 
    129  
    130         if (func.isNull()) { 
    131             NPN_InitializeVariantAsNull(result); 
    132             return false; 
    133         } 
    134         else if ( func.type() == UndefinedType) { 
    135             NPN_InitializeVariantAsUndefined(result); 
    136             return false; 
    137         } 
    138         else { 
    139             // Call the function object. 
    140             ObjectImp *funcImp = static_cast<ObjectImp*>(func.imp()); 
    141             Object thisObj = Object(const_cast<ObjectImp*>(obj->imp)); 
    142             List argList = listFromVariantArgs(exec, args, argCount); 
    143             Interpreter::lock(); 
    144             Value resultV = funcImp->call (exec, thisObj, argList); 
    145             Interpreter::unlock(); 
    146  
    147             // Convert and return the result of the function call. 
    148             convertValueToNPVariant(exec, resultV, result); 
    149             return true; 
    150         } 
    151     } 
    152     else { 
    153         if (o->_class->invoke) { 
    154             return o->_class->invoke (o, methodName, args, argCount, result); 
    155         } 
    156     } 
     139        // Special case the "eval" method. 
     140        if (methodName == _NPN_GetStringIdentifier("eval")) { 
     141            if (argCount != 1) 
     142                return false; 
     143            if (args[0].type != NPVariantType_String) 
     144                return false; 
     145             
     146            return _NPN_Evaluate (npp, o, (NPString *)&args[0].value.stringValue, result); 
     147        } 
     148        else { 
     149            // Lookup the function object. 
     150            ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
     151            InterpreterLock lock; 
     152            Value func = obj->imp->get (exec, identifierFromNPIdentifier(i->value.string)); 
     153 
     154            if (func.isNull()) { 
     155                NPN_InitializeVariantAsNull(result); 
     156                return false; 
     157            } else if (func.type() == UndefinedType) { 
     158                NPN_InitializeVariantAsUndefined(result); 
     159                return false; 
     160            } else { 
     161                // Call the function object. 
     162                ObjectImp *funcImp = static_cast<ObjectImp*>(func.imp()); 
     163                Object thisObj = Object(const_cast<ObjectImp*>(obj->imp)); 
     164                List argList = listFromVariantArgs(exec, args, argCount); 
     165                Value resultV = Object(funcImp).call (exec, thisObj, argList); 
     166 
     167                // Convert and return the result of the function call. 
     168                convertValueToNPVariant(exec, resultV, result); 
     169                return true; 
     170            } 
     171        } 
     172    } else if (o->_class->invoke) 
     173        return o->_class->invoke (o, methodName, args, argCount, result); 
    157174     
    158175    return true; 
     
    164181        JavaScriptObject *obj = (JavaScriptObject *)o;  
    165182 
    166         ExecState *exec = obj->root->interpreter()->globalExec(); 
     183        if (!_isSafeScript(obj)) 
     184            return false; 
     185 
     186        ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
    167187        Object thisObj = Object(const_cast<ObjectImp*>(obj->imp)); 
    168188        Value result; 
    169189         
    170         Interpreter::lock(); 
     190        InterpreterLock lock; 
    171191        NPUTF16 *scriptString; 
    172192        unsigned int UTF16Length; 
    173193        convertNPStringToUTF16 (s, &scriptString, &UTF16Length);    // requires free() of returned memory. 
    174         Completion completion = obj->root->interpreter()->evaluate(UString(), 0, UString((const UChar *)scriptString,UTF16Length)); 
     194        Completion completion = obj->executionContext->interpreter()->evaluate(UString(), 0, UString((const UChar *)scriptString,UTF16Length)); 
    175195        ComplType type = completion.complType(); 
    176196         
     
    184204            result = Undefined(); 
    185205             
    186         Interpreter::unlock(); 
    187          
    188206        free ((void *)scriptString); 
    189207         
     
    199217    if (o->_class == NPScriptObjectClass) { 
    200218        JavaScriptObject *obj = (JavaScriptObject *)o;  
    201         ExecState *exec = obj->root->interpreter()->globalExec(); 
     219 
     220        if (!_isSafeScript(obj)) 
     221            return false; 
     222 
     223        ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
    202224 
    203225        PrivateIdentifier *i = (PrivateIdentifier *)propertyName; 
    204226        if (i->isString) { 
    205             if (!obj->imp->hasProperty (exec, identiferFromNPIdentifier(i->value.string))) { 
     227            if (!obj->imp->hasProperty (exec, identifierFromNPIdentifier(i->value.string))) { 
    206228                NPN_InitializeVariantAsNull(variant); 
    207229                return false; 
     
    215237        } 
    216238         
    217         Interpreter::lock(); 
     239        InterpreterLock lock; 
    218240        Value result; 
    219         if (i->isString) { 
    220             result = obj->imp->get (exec, identiferFromNPIdentifier(i->value.string)); 
    221         } 
    222         else { 
     241        if (i->isString) 
     242            result = obj->imp->get (exec, identifierFromNPIdentifier(i->value.string)); 
     243        else 
    223244            result = obj->imp->get (exec, i->value.number); 
    224         } 
    225         Interpreter::unlock(); 
    226  
     245         
    227246        if (result.isNull()) { 
    228247            NPN_InitializeVariantAsNull(variant); 
     
    255274        JavaScriptObject *obj = (JavaScriptObject *)o;  
    256275 
    257         ExecState *exec = obj->root->interpreter()->globalExec(); 
    258         Interpreter::lock(); 
    259         Value result; 
     276        if (!_isSafeScript(obj)) 
     277            return false; 
     278 
     279        ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
     280        InterpreterLock lock; 
     281        PrivateIdentifier *i = (PrivateIdentifier *)propertyName; 
     282        if (i->isString) 
     283            obj->imp->put(exec, identifierFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant)); 
     284        else 
     285            obj->imp->put(exec, i->value.number, convertNPVariantToValue(exec, variant)); 
     286         
     287        return true; 
     288    } else if (o->_class->setProperty) 
     289        return o->_class->setProperty (o, propertyName, variant); 
     290 
     291    return false; 
     292} 
     293 
     294bool _NPN_RemoveProperty (NPP npp, NPObject *o, NPIdentifier propertyName) 
     295{ 
     296    if (o->_class == NPScriptObjectClass) { 
     297        JavaScriptObject *obj = (JavaScriptObject *)o;  
     298 
     299        if (!_isSafeScript(obj)) 
     300            return false; 
     301 
     302        ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
     303 
    260304        PrivateIdentifier *i = (PrivateIdentifier *)propertyName; 
    261305        if (i->isString) { 
    262             obj->imp->put (exec, identiferFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant)); 
    263         } 
    264         else { 
    265             obj->imp->put (exec, i->value.number, convertNPVariantToValue(exec, variant)); 
    266         } 
    267         Interpreter::unlock(); 
    268          
    269         return true; 
    270     } 
    271     else if (o->_class->setProperty) { 
    272         return o->_class->setProperty (o, propertyName, variant); 
    273     } 
    274     return false; 
    275 } 
    276  
    277 bool _NPN_RemoveProperty (NPP npp, NPObject *o, NPIdentifier propertyName) 
    278 { 
    279     if (o->_class == NPScriptObjectClass) { 
    280         JavaScriptObject *obj = (JavaScriptObject *)o;  
    281         ExecState *exec = obj->root->interpreter()->globalExec(); 
    282  
    283         PrivateIdentifier *i = (PrivateIdentifier *)propertyName; 
    284         if (i->isString) { 
    285             if (!obj->imp->hasProperty (exec, identiferFromNPIdentifier(i->value.string))) { 
     306            if (!obj->imp->hasProperty (exec, identifierFromNPIdentifier(i->value.string))) { 
    286307                return false; 
    287308            } 
     
    293314        } 
    294315 
    295         Interpreter::lock(); 
    296         if (i->isString) { 
    297             obj->imp->deleteProperty (exec, identiferFromNPIdentifier(i->value.string)); 
    298         } 
    299         else { 
     316        InterpreterLock lock; 
     317        if (i->isString) 
     318            obj->imp->deleteProperty (exec, identifierFromNPIdentifier(i->value.string)); 
     319        else 
    300320            obj->imp->deleteProperty (exec, i->value.number); 
    301         } 
    302         Interpreter::unlock(); 
    303321         
    304322        return true; 
     
    311329    if (o->_class == NPScriptObjectClass) { 
    312330        JavaScriptObject *obj = (JavaScriptObject *)o;  
    313         ExecState *exec = obj->root->interpreter()->globalExec(); 
     331 
     332        if (!_isSafeScript(obj)) 
     333            return false; 
     334 
     335        ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
    314336 
    315337        PrivateIdentifier *i = (PrivateIdentifier *)propertyName; 
    316         // String identifier? 
    317         if (i->isString) { 
    318             ExecState *exec = obj->root->interpreter()->globalExec(); 
    319             Interpreter::lock(); 
    320             bool result = obj->imp->hasProperty (exec, identiferFromNPIdentifier(i->value.string)); 
    321             Interpreter::unlock(); 
    322             return result; 
    323         } 
    324          
    325         // Numeric identifer 
    326         Interpreter::lock(); 
    327         bool result = obj->imp->hasProperty (exec, i->value.number); 
    328         Interpreter::unlock(); 
    329         return result; 
    330     } 
    331     else if (o->_class->hasProperty) { 
     338        InterpreterLock lock; 
     339 
     340        if (i->isString) 
     341            return obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->value.string)); 
     342         
     343        return obj->imp->hasProperty(exec, i->value.number); 
     344    } else if (o->_class->hasProperty) 
    332345        return o->_class->hasProperty (o, propertyName); 
    333     } 
    334346     
    335347    return false; 
     
    341353        JavaScriptObject *obj = (JavaScriptObject *)o;  
    342354         
     355        if (!_isSafeScript(obj)) 
     356            return false; 
     357 
    343358        PrivateIdentifier *i = (PrivateIdentifier *)methodName; 
    344359        if (!i->isString) 
     
    346361             
    347362        // Lookup the function object. 
    348         ExecState *exec = obj->root->interpreter()->globalExec(); 
    349         Interpreter::lock(); 
    350         Value func = obj->imp->get (exec, identiferFromNPIdentifier(i->value.string)); 
    351         Interpreter::unlock(); 
     363        ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
     364 
     365        InterpreterLock lock; 
     366        Value func = obj->imp->get (exec, identifierFromNPIdentifier(i->value.string)); 
    352367 
    353368        if (func.isNull() || func.type() == UndefinedType) { 
     
    365380} 
    366381 
    367 void _NPN_SetException (NPObject *o, NPString *message) 
    368 { 
    369     if (o->_class == NPScriptObjectClass) { 
    370         JavaScriptObject *obj = (JavaScriptObject *)o;  
    371         ExecState *exec = obj->root->interpreter()->globalExec(); 
    372         Interpreter::lock(); 
    373         char *msg = (char *)malloc (message->UTF8Length + 1); 
    374         strncpy (msg, message->UTF8Characters, message->UTF8Length); 
    375         msg[message->UTF8Length] = 0; 
    376         Object err = Error::create(exec, GeneralError, msg); 
    377         free (msg); 
     382void _NPN_SetException (NPObject *o, const NPUTF8 *message) 
     383{ 
     384    if (o->_class == NPScriptObjectClass) { 
     385        JavaScriptObject *obj = (JavaScriptObject *)o;  
     386        ExecState *exec = obj->executionContext->interpreter()->globalExec(); 
     387        InterpreterLock lock; 
     388        Object err = Error::create(exec, GeneralError, message); 
    378389        exec->setException (err); 
    379         Interpreter::unlock(); 
    380     } 
    381 } 
     390    } 
     391} 
  • S60/trunk/JavaScriptCore/bindings/NP_jsobject.h

    r14062 r14549  
    4242    NPObject object; 
    4343    KJS::ObjectImp *imp; 
    44     KJS::Bindings::RootObject *root; 
     44    const KJS::Bindings::RootObject *originExecutionContext; 
     45    const KJS::Bindings::RootObject *executionContext; 
    4546} JavaScriptObject; 
    4647 
    47 NPObject *_NPN_CreateScriptObject (NPP npp, KJS::ObjectImp *imp, KJS::Bindings::RootObject *root); 
     48NPObject *_NPN_CreateScriptObject (NPP npp, KJS::ObjectImp *imp, const KJS::Bindings::RootObject *originExecutionContext, const KJS::Bindings::RootObject *executionContext); 
    4849 
    4950#ifdef __cplusplus 
  • S60/trunk/JavaScriptCore/bindings/c/c_instance.cpp

    r14062 r14549  
    4747    _object = _NPN_RetainObject (o); 
    4848    _class = 0; 
     49    setExecutionContext (0); 
    4950}; 
    5051 
     
    6061    _object = _NPN_RetainObject (other._object); 
    6162    _class = 0; 
     63    setExecutionContext (other.executionContext()); 
    6264}; 
    6365 
     
    204206KJS::Value CInstance::stringValue() const 
    205207{ 
    206     // FIXME:  Implement something sensible, like calling toString... 
    207     KJS::String v(""); 
     208    char buf[1024]; 
     209    snprintf (buf, 1024, "NPObject %p, NPClass %p", _object, _object->_class); 
     210    KJS::String v(buf); 
    208211    return v; 
    209212} 
  • S60/trunk/JavaScriptCore/bindings/c/c_instance.h

    r14062 r14549  
    6464    NPObject *getObject() const { return _object; } 
    6565 
    66     void setExecutionContext (RootObject *r) { _root = r; } 
    67     const RootObject *executionContext() const { return _root; } 
    68      
    6966private: 
    7067    mutable CClass *_class; 
    7168    NPObject *_object; 
    72     RootObject *_root; 
    7369}; 
    7470 
  • S60/trunk/JavaScriptCore/bindings/c/c_utility.cpp

    r14062 r14549