src/script/api/qscriptvalue.cpp
changeset 22 79de32ba3296
parent 19 fcece45ef507
child 30 5dc02b23752f
equal deleted inserted replaced
19:fcece45ef507 22:79de32ba3296
   790         qWarning("QScriptValue::setPrototype() failed: "
   790         qWarning("QScriptValue::setPrototype() failed: "
   791                  "cannot set a prototype created in "
   791                  "cannot set a prototype created in "
   792                  "a different engine");
   792                  "a different engine");
   793         return;
   793         return;
   794     }
   794     }
       
   795     JSC::JSObject *thisObject = JSC::asObject(d->jscValue);
   795     JSC::JSValue other = d->engine->scriptValueToJSCValue(prototype);
   796     JSC::JSValue other = d->engine->scriptValueToJSCValue(prototype);
   796 
   797 
   797     // check for cycle
   798     // check for cycle
   798     JSC::JSValue nextPrototypeValue = other;
   799     JSC::JSValue nextPrototypeValue = other;
   799     while (nextPrototypeValue && nextPrototypeValue.isObject()) {
   800     while (nextPrototypeValue && nextPrototypeValue.isObject()) {
   800         JSC::JSObject *nextPrototype = JSC::asObject(nextPrototypeValue);
   801         JSC::JSObject *nextPrototype = JSC::asObject(nextPrototypeValue);
   801         if (nextPrototype == JSC::asObject(d->jscValue)) {
   802         if (nextPrototype == thisObject) {
   802             qWarning("QScriptValue::setPrototype() failed: cyclic prototype value");
   803             qWarning("QScriptValue::setPrototype() failed: cyclic prototype value");
   803             return;
   804             return;
   804         }
   805         }
   805         nextPrototypeValue = nextPrototype->prototype();
   806         nextPrototypeValue = nextPrototype->prototype();
   806     }
   807     }
   807     JSC::asObject(d->jscValue)->setPrototype(other);
   808 
       
   809     thisObject->setPrototype(other);
       
   810 
       
   811     // Sync the internal Global Object prototype if appropriate.
       
   812     if (((thisObject == d->engine->originalGlobalObjectProxy)
       
   813          && !d->engine->customGlobalObject())
       
   814         || (thisObject == d->engine->customGlobalObject())) {
       
   815         d->engine->originalGlobalObject()->setPrototype(other);
       
   816     }
   808 }
   817 }
   809 
   818 
   810 /*!
   819 /*!
   811   \internal
   820   \internal
   812 */
   821 */