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

📄 webscriptobject.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 2 页
字号:
    JSValuePtr result;    JSLock lock(false);        [self _rootObject]->globalObject()->globalData()->timeoutChecker.start();    Completion completion = JSC::evaluate([self _rootObject]->globalObject()->globalExec(), [self _rootObject]->globalObject()->globalScopeChain(), makeSource(String(script)));    [self _rootObject]->globalObject()->globalData()->timeoutChecker.stop();    ComplType type = completion.complType();        if (type == Normal) {        result = completion.value();        if (!result)            result = jsUndefined();    } else        result = jsUndefined();        if (exec->hadException()) {        addExceptionToConsole(exec);        result = jsUndefined();        exec->clearException();    }        id resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];        _didExecute(self);        return resultObj;}- (void)setValue:(id)value forKey:(NSString *)key{    if (![self _isSafeScript])        return;    ExecState* exec = [self _rootObject]->globalObject()->globalExec();    ASSERT(!exec->hadException());    JSLock lock(false);    PutPropertySlot slot;    [self _imp]->put(exec, Identifier(exec, String(key)), convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject]), slot);    if (exec->hadException()) {        addExceptionToConsole(exec);        exec->clearException();    }    _didExecute(self);}- (id)valueForKey:(NSString *)key{    if (![self _isSafeScript])        return nil;    ExecState* exec = [self _rootObject]->globalObject()->globalExec();    ASSERT(!exec->hadException());    id resultObj;    {        // Need to scope this lock to ensure that we release the lock before calling        // [super valueForKey:key] which might throw an exception and bypass the JSLock destructor,        // leaving the lock permanently held        JSLock lock(false);                JSValuePtr result = [self _imp]->get(exec, Identifier(exec, String(key)));                if (exec->hadException()) {            addExceptionToConsole(exec);            result = jsUndefined();            exec->clearException();        }        resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];    }        if ([resultObj isKindOfClass:[WebUndefined class]])        resultObj = [super valueForKey:key];    // defaults to throwing an exception    JSLock lock(false);    _didExecute(self);        return resultObj;}- (void)removeWebScriptKey:(NSString *)key{    if (![self _isSafeScript])        return;    ExecState* exec = [self _rootObject]->globalObject()->globalExec();    ASSERT(!exec->hadException());    JSLock lock(false);    [self _imp]->deleteProperty(exec, Identifier(exec, String(key)));    if (exec->hadException()) {        addExceptionToConsole(exec);        exec->clearException();    }    _didExecute(self);}- (NSString *)stringRepresentation{    if (![self _isSafeScript]) {        // This is a workaround for a gcc 3.3 internal compiler error.        return @"Undefined";    }    JSLock lock(false);    ExecState* exec = [self _rootObject]->globalObject()->globalExec();        id result = convertValueToObjcValue(exec, [self _imp], ObjcObjectType).objectValue;    NSString *description = [result description];    _didExecute(self);    return description;}- (id)webScriptValueAtIndex:(unsigned)index{    if (![self _isSafeScript])        return nil;    ExecState* exec = [self _rootObject]->globalObject()->globalExec();    ASSERT(!exec->hadException());    JSLock lock(false);    JSValuePtr result = [self _imp]->get(exec, index);    if (exec->hadException()) {        addExceptionToConsole(exec);        result = jsUndefined();        exec->clearException();    }    id resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];    _didExecute(self);    return resultObj;}- (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value{    if (![self _isSafeScript])        return;    ExecState* exec = [self _rootObject]->globalObject()->globalExec();    ASSERT(!exec->hadException());    JSLock lock(false);    [self _imp]->put(exec, index, convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject]));    if (exec->hadException()) {        addExceptionToConsole(exec);        exec->clearException();    }    _didExecute(self);}- (void)setException:(NSString *)description{    if (![self _rootObject])        return;    ObjcInstance::setGlobalException(description, [self _rootObject]->globalObject());}- (JSObjectRef)JSObject{    if (![self _isSafeScript])        return NULL;    return toRef([self _imp]);}+ (id)_convertValueToObjcValue:(JSValuePtr)value originRootObject:(RootObject*)originRootObject rootObject:(RootObject*)rootObject{    if (value.isObject()) {        JSObject* object = asObject(value);        ExecState* exec = rootObject->globalObject()->globalExec();        JSLock lock(false);                if (object->classInfo() != &RuntimeObjectImp::s_info) {            JSValuePtr runtimeObject = object->get(exec, Identifier(exec, "__apple_runtime_object"));            if (runtimeObject && runtimeObject.isObject())                object = asObject(runtimeObject);        }        if (object->classInfo() == &RuntimeObjectImp::s_info) {            RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(object);            ObjcInstance *instance = static_cast<ObjcInstance*>(imp->getInternalInstance());            if (instance)                return instance->getObject();            return nil;        }        return [WebScriptObject scriptObjectForJSObject:toRef(object) originRootObject:originRootObject rootObject:rootObject];    }    if (value.isString()) {        const UString& u = asString(value)->value();        return [NSString stringWithCharacters:u.data() length:u.size()];    }    if (value.isNumber())        return [NSNumber numberWithDouble:value.uncheckedGetNumber()];    if (value.isBoolean())        return [NSNumber numberWithBool:value.getBoolean()];    if (value.isUndefined())        return [WebUndefined undefined];    // jsNull is not returned as NSNull because existing applications do not expect    // that return value. Return as nil for compatibility. <rdar://problem/4651318> <rdar://problem/4701626>    // Other types (e.g., UnspecifiedType) also return as nil.    return nil;}@end@interface WebScriptObject (WebKitCocoaBindings)- (id)objectAtIndex:(unsigned)index;@end@implementation WebScriptObject (WebKitCocoaBindings)#if 0 // FIXME: We'd like to add this, but we can't do that until this issue is resolved:// http://bugs.webkit.org/show_bug.cgi?id=13129: presence of 'count' method on// WebScriptObject breaks Democracy player.- (unsigned)count{    id length = [self valueForKey:@"length"];    if (![length respondsToSelector:@selector(intValue)])        return 0;    return [length intValue];}#endif- (id)objectAtIndex:(unsigned)index{    return [self webScriptValueAtIndex:index];}@end@implementation WebUndefined+ (id)allocWithZone:(NSZone *)unusedZone{    UNUSED_PARAM(unusedZone);    static WebUndefined *sharedUndefined = 0;    if (!sharedUndefined)        sharedUndefined = [super allocWithZone:NULL];    return sharedUndefined;}- (NSString *)description{    return @"undefined";}- (id)initWithCoder:(NSCoder *)unusedCoder{    UNUSED_PARAM(unusedCoder);    return self;}- (void)encodeWithCoder:(NSCoder *)unusedCoder{    UNUSED_PARAM(unusedCoder);}- (id)copyWithZone:(NSZone *)unusedZone{    UNUSED_PARAM(unusedZone);    return self;}- (id)retain{    return self;}- (void)release{}- (NSUInteger)retainCount{    return UINT_MAX;}- (id)autorelease{    return self;}- (void)dealloc{    ASSERT(false);    return;    [super dealloc]; // make -Wdealloc-check happy}+ (WebUndefined *)undefined{    return [WebUndefined allocWithZone:NULL];}@end

⌨️ 快捷键说明

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