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

📄 jsobjectref.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */#include "config.h"#include "JSObjectRef.h"#include "APICast.h"#include "DateConstructor.h"#include "ErrorConstructor.h"#include "FunctionConstructor.h"#include "Identifier.h"#include "InitializeThreading.h"#include "JSArray.h"#include "JSCallbackConstructor.h"#include "JSCallbackFunction.h"#include "JSCallbackObject.h"#include "JSClassRef.h"#include "JSFunction.h"#include "JSGlobalObject.h"#include "JSObject.h"#include "JSRetainPtr.h"#include "JSString.h"#include "JSValueRef.h"#include "ObjectPrototype.h"#include "PropertyNameArray.h"#include "RegExpConstructor.h"#include <wtf/Platform.h>using namespace JSC;JSClassRef JSClassCreate(const JSClassDefinition* definition){    initializeThreading();    RefPtr<OpaqueJSClass> jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype)        ? OpaqueJSClass::createNoAutomaticPrototype(definition)        : OpaqueJSClass::create(definition);        return jsClass.release().releaseRef();}JSClassRef JSClassRetain(JSClassRef jsClass){    jsClass->ref();    return jsClass;}void JSClassRelease(JSClassRef jsClass){    jsClass->deref();}JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    if (!jsClass)        return toRef(new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure())); // slightly more efficient    JSCallbackObject<JSObject>* object = new (exec) JSCallbackObject<JSObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);    if (JSObject* prototype = jsClass->prototype(exec))        object->setPrototype(prototype);    return toRef(object);}JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");        return toRef(new (exec) JSCallbackFunction(exec, callAsFunction, nameID));}JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    JSValuePtr jsPrototype = jsClass         ? jsClass->prototype(exec)        : exec->lexicalGlobalObject()->objectPrototype();        JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor);    constructor->putDirect(exec->propertyNames().prototype, jsPrototype, DontEnum | DontDelete | ReadOnly);    return toRef(constructor);}JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");        ArgList args;    for (unsigned i = 0; i < parameterCount; i++)        args.append(jsString(exec, parameterNames[i]->ustring()));    args.append(jsString(exec, body->ustring()));    JSObject* result = constructFunction(exec, args, nameID, sourceURL->ustring(), startingLineNumber);    if (exec->hadException()) {        if (exception)            *exception = toRef(exec->exception());        exec->clearException();        result = 0;    }    return toRef(result);}JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[],  JSValueRef* exception){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    JSObject* result;    if (argumentCount) {        ArgList argList;        for (size_t i = 0; i < argumentCount; ++i)            argList.append(toJS(arguments[i]));        result = constructArray(exec, argList);    } else        result = constructEmptyArray(exec);    if (exec->hadException()) {        if (exception)            *exception = toRef(exec->exception());        exec->clearException();        result = 0;    }    return toRef(result);}JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[],  JSValueRef* exception){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    ArgList argList;    for (size_t i = 0; i < argumentCount; ++i)        argList.append(toJS(arguments[i]));    JSObject* result = constructDate(exec, argList);    if (exec->hadException()) {        if (exception)            *exception = toRef(exec->exception());        exec->clearException();        result = 0;    }    return toRef(result);}JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[],  JSValueRef* exception){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    ArgList argList;    for (size_t i = 0; i < argumentCount; ++i)        argList.append(toJS(arguments[i]));    JSObject* result = constructError(exec, argList);    if (exec->hadException()) {        if (exception)            *exception = toRef(exec->exception());        exec->clearException();        result = 0;    }    return toRef(result);}JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[],  JSValueRef* exception){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    ArgList argList;    for (size_t i = 0; i < argumentCount; ++i)        argList.append(toJS(arguments[i]));    JSObject* result = constructRegExp(exec, argList);    if (exec->hadException()) {        if (exception)            *exception = toRef(exec->exception());        exec->clearException();        result = 0;    }        return toRef(result);}JSValueRef JSObjectGetPrototype(JSContextRef, JSObjectRef object){    JSObject* jsObject = toJS(object);    return toRef(jsObject->prototype());}void JSObjectSetPrototype(JSContextRef, JSObjectRef object, JSValueRef value){    JSObject* jsObject = toJS(object);    JSValuePtr jsValue = toJS(value);    jsObject->setPrototype(jsValue.isObject() ? jsValue : jsNull());}bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName){    ExecState* exec = toJS(ctx);    exec->globalData().heap.registerThread();    JSLock lock(exec);    JSObject* jsObject = toJS(object);        return jsObject->hasProperty(exec, propertyName->identifier(&exec->globalData()));}JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception){

⌨️ 快捷键说明

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