⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jscallbackobjectfunctions.h

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 H
📖 第 1 页 / 共 2 页
字号:
            constructData.native.function = construct;            return ConstructTypeHost;        }    }    return ConstructTypeNone;}template <class Base>JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args){    JSContextRef execRef = toRef(exec);    JSObjectRef constructorRef = toRef(constructor);        for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {        if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {            int argumentCount = static_cast<int>(args.size());            Vector<JSValueRef, 16> arguments(argumentCount);            for (int i = 0; i < argumentCount; i++)                arguments[i] = toRef(args.at(exec, i));            JSLock::DropAllLocks dropAllLocks(exec);            return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));        }    }        ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here    return 0;}template <class Base>bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValuePtr value, JSValuePtr){    JSContextRef execRef = toRef(exec);    JSObjectRef thisRef = toRef(this);        for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {        if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {            JSLock::DropAllLocks dropAllLocks(exec);            return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));        }    }    return false;}template <class Base>CallType JSCallbackObject<Base>::getCallData(CallData& callData){    for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {        if (jsClass->callAsFunction) {            callData.native.function = call;            return CallTypeHost;        }    }    return CallTypeNone;}template <class Base>JSValuePtr JSCallbackObject<Base>::call(ExecState* exec, JSObject* functionObject, JSValuePtr thisValue, const ArgList& args){    JSContextRef execRef = toRef(exec);    JSObjectRef functionRef = toRef(functionObject);    JSObjectRef thisObjRef = toRef(thisValue.toThisObject(exec));        for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(functionObject)->classRef(); jsClass; jsClass = jsClass->parentClass) {        if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {            int argumentCount = static_cast<int>(args.size());            Vector<JSValueRef, 16> arguments(argumentCount);            for (int i = 0; i < argumentCount; i++)                arguments[i] = toRef(args.at(exec, i));            JSLock::DropAllLocks dropAllLocks(exec);            return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));        }    }        ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here    return noValue();}template <class Base>void JSCallbackObject<Base>::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames){    JSContextRef execRef = toRef(exec);    JSObjectRef thisRef = toRef(this);        for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {        if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {            JSLock::DropAllLocks dropAllLocks(exec);            getPropertyNames(execRef, thisRef, toRef(&propertyNames));        }                if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {            typedef OpaqueJSClassStaticValuesTable::const_iterator iterator;            iterator end = staticValues->end();            for (iterator it = staticValues->begin(); it != end; ++it) {                UString::Rep* name = it->first.get();                StaticValueEntry* entry = it->second;                if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum))                    propertyNames.add(Identifier(exec, name));            }        }                if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {            typedef OpaqueJSClassStaticFunctionsTable::const_iterator iterator;            iterator end = staticFunctions->end();            for (iterator it = staticFunctions->begin(); it != end; ++it) {                UString::Rep* name = it->first.get();                StaticFunctionEntry* entry = it->second;                if (!(entry->attributes & kJSPropertyAttributeDontEnum))                    propertyNames.add(Identifier(exec, name));            }        }    }        Base::getPropertyNames(exec, propertyNames);}template <class Base>double JSCallbackObject<Base>::toNumber(ExecState* exec) const{    // We need this check to guard against the case where this object is rhs of    // a binary expression where lhs threw an exception in its conversion to    // primitive    if (exec->hadException())        return NaN;    JSContextRef ctx = toRef(exec);    JSObjectRef thisRef = toRef(this);        for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)        if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {            JSLock::DropAllLocks dropAllLocks(exec);            if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot()))) {                double dValue;                return toJS(value).getNumber(dValue) ? dValue : NaN;            }        }                return Base::toNumber(exec);}template <class Base>UString JSCallbackObject<Base>::toString(ExecState* exec) const{    JSContextRef ctx = toRef(exec);    JSObjectRef thisRef = toRef(this);        for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)        if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {            JSValueRef value;            {                JSLock::DropAllLocks dropAllLocks(exec);                value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot()));            }            if (value)                return toJS(value).getString();        }                return Base::toString(exec);}template <class Base>void JSCallbackObject<Base>::setPrivate(void* data){    m_callbackObjectData->privateData = data;}template <class Base>void* JSCallbackObject<Base>::getPrivate(){    return m_callbackObjectData->privateData;}template <class Base>bool JSCallbackObject<Base>::inherits(JSClassRef c) const{    for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)        if (jsClass == c)            return true;        return false;}template <class Base>JSValuePtr JSCallbackObject<Base>::staticValueGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot){    JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());        JSObjectRef thisRef = toRef(thisObj);    RefPtr<OpaqueJSString> propertyNameRef;        for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)        if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec))            if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))                if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {                    if (!propertyNameRef)                        propertyNameRef = OpaqueJSString::create(propertyName.ustring());                    JSLock::DropAllLocks dropAllLocks(exec);                    if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))                        return toJS(value);                }                        return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");}template <class Base>JSValuePtr JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot){    JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());        // Check for cached or override property.    PropertySlot slot2(thisObj);    if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2))        return slot2.getValue(exec, propertyName);        for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {        if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {            if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {                if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {                    JSObject* o = new (exec) JSCallbackFunction(exec, callAsFunction, propertyName);                    thisObj->putDirect(propertyName, o, entry->attributes);                    return o;                }            }        }    }        return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");}template <class Base>JSValuePtr JSCallbackObject<Base>::callbackGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot){    JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());        JSObjectRef thisRef = toRef(thisObj);    RefPtr<OpaqueJSString> propertyNameRef;        for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)        if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {            if (!propertyNameRef)                propertyNameRef = OpaqueJSString::create(propertyName.ustring());            JSLock::DropAllLocks dropAllLocks(exec);            if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))                return toJS(value);        }                return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");}} // namespace JSC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -