Ignore:
Timestamp:
Jan 17, 2008, 11:27:33 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Fix for http://bugs.webkit.org/show_bug.cgi?id=16901
Convert remaining JS function objects to use the new PrototypeFunction class

  • Moves Boolean, Function, RegExp, Number, Object and Global functions to their own static function implementations so that they can be used with the PrototypeFunction class. SunSpider says this is 1.003x as fast.
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::reset):
  • kjs/array_object.h:
  • kjs/bool_object.cpp: (KJS::BooleanInstance::BooleanInstance): (KJS::BooleanPrototype::BooleanPrototype): (KJS::booleanProtoFuncToString): (KJS::booleanProtoFuncValueOf): (KJS::BooleanObjectImp::BooleanObjectImp): (KJS::BooleanObjectImp::implementsConstruct): (KJS::BooleanObjectImp::construct): (KJS::BooleanObjectImp::callAsFunction):
  • kjs/bool_object.h: (KJS::BooleanInstance::classInfo):
  • kjs/error_object.cpp: (KJS::ErrorPrototype::ErrorPrototype): (KJS::errorProtoFuncToString):
  • kjs/error_object.h:
  • kjs/function.cpp: (KJS::globalFuncEval): (KJS::globalFuncParseInt): (KJS::globalFuncParseFloat): (KJS::globalFuncIsNaN): (KJS::globalFuncIsFinite): (KJS::globalFuncDecodeURI): (KJS::globalFuncDecodeURIComponent): (KJS::globalFuncEncodeURI): (KJS::globalFuncEncodeURIComponent): (KJS::globalFuncEscape): (KJS::globalFuncUnEscape): (KJS::globalFuncKJSPrint): (KJS::PrototypeFunction::PrototypeFunction):
  • kjs/function.h:
  • kjs/function_object.cpp: (KJS::FunctionPrototype::FunctionPrototype): (KJS::functionProtoFuncToString): (KJS::functionProtoFuncApply): (KJS::functionProtoFuncCall):
  • kjs/function_object.h:
  • kjs/number_object.cpp: (KJS::NumberPrototype::NumberPrototype): (KJS::numberProtoFuncToString): (KJS::numberProtoFuncToLocaleString): (KJS::numberProtoFuncValueOf): (KJS::numberProtoFuncToFixed): (KJS::numberProtoFuncToExponential): (KJS::numberProtoFuncToPrecision):
  • kjs/number_object.h: (KJS::NumberInstance::classInfo): (KJS::NumberObjectImp::classInfo): (KJS::NumberObjectImp::):
  • kjs/object_object.cpp: (KJS::ObjectPrototype::ObjectPrototype): (KJS::objectProtoFuncValueOf): (KJS::objectProtoFuncHasOwnProperty): (KJS::objectProtoFuncIsPrototypeOf): (KJS::objectProtoFuncDefineGetter): (KJS::objectProtoFuncDefineSetter): (KJS::objectProtoFuncLookupGetter): (KJS::objectProtoFuncLookupSetter): (KJS::objectProtoFuncPropertyIsEnumerable): (KJS::objectProtoFuncToLocaleString): (KJS::objectProtoFuncToString):
  • kjs/object_object.h:
  • kjs/regexp_object.cpp: (KJS::RegExpPrototype::RegExpPrototype): (KJS::regExpProtoFuncTest): (KJS::regExpProtoFuncExec): (KJS::regExpProtoFuncCompile): (KJS::regExpProtoFuncToString):
  • kjs/regexp_object.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/bool_object.cpp

    r28469 r29588  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    3  *  This file is part of the KDE libraries
    42 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    5  *  Copyright (C) 2003 Apple Computer, Inc.
     3 *  Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
    64 *
    75 *  This library is free software; you can redistribute it and/or
     
    2927#include <wtf/Assertions.h>
    3028
    31 using namespace KJS;
     29namespace KJS {
    3230
    3331// ------------------------------ BooleanInstance ---------------------------
    3432
    35 const ClassInfo BooleanInstance::info = {"Boolean", 0, 0};
     33const ClassInfo BooleanInstance::info = { "Boolean", 0, 0 };
    3634
    37 BooleanInstance::BooleanInstance(JSObject *proto)
    38   : JSWrapperObject(proto)
     35BooleanInstance::BooleanInstance(JSObject* proto)
     36    : JSWrapperObject(proto)
    3937{
    4038}
     
    4240// ------------------------------ BooleanPrototype --------------------------
    4341
     42// Functions
     43static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, const List&);
     44static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, const List&);
     45
    4446// ECMA 15.6.4
    4547
    46 BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectProto, FunctionPrototype* funcProto)
    47   : BooleanInstance(objectProto)
     48BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)
     49    : BooleanInstance(objectPrototype)
    4850{
    49   putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ToString, 0, exec->propertyNames().toString), DontEnum);
    50   putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ValueOf, 0, exec->propertyNames().valueOf),  DontEnum);
    51   setInternalValue(jsBoolean(false));
     51    setInternalValue(jsBoolean(false));
     52
     53    putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, booleanProtoFuncToString), DontEnum);
     54    putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().valueOf, booleanProtoFuncValueOf), DontEnum);
    5255}
    5356
    5457
    55 // ------------------------------ BooleanProtoFunc --------------------------
    56 
    57 BooleanProtoFunc::BooleanProtoFunc(ExecState* exec, FunctionPrototype* funcProto, int i, int len, const Identifier& name)
    58   : InternalFunctionImp(funcProto, name)
    59   , id(i)
    60 {
    61   putDirect(exec->propertyNames().length, len, DontDelete|ReadOnly|DontEnum);
    62 }
    63 
     58// ------------------------------ Functions --------------------------
    6459
    6560// ECMA 15.6.4.2 + 15.6.4.3
    66 JSValue *BooleanProtoFunc::callAsFunction(ExecState* exec, JSObject *thisObj, const List &/*args*/)
     61
     62JSValue* booleanProtoFuncToString(ExecState* exec, JSObject* thisObj, const List&)
    6763{
    68   // no generic function. "this" has to be a Boolean object
    69   if (!thisObj->inherits(&BooleanInstance::info))
    70     return throwError(exec, TypeError);
     64    if (!thisObj->inherits(&BooleanInstance::info))
     65        return throwError(exec, TypeError);
    7166
    72   // execute "toString()" or "valueOf()", respectively
     67    JSValue* v = static_cast<BooleanInstance*>(thisObj)->internalValue();
     68    ASSERT(v);
    7369
    74   JSValue *v = static_cast<BooleanInstance*>(thisObj)->internalValue();
    75   ASSERT(v);
     70    return jsString(v->toString(exec));
     71}
     72JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const List&)
     73{
     74    if (!thisObj->inherits(&BooleanInstance::info))
     75        return throwError(exec, TypeError);
    7676
    77   if (id == ToString)
    78     return jsString(v->toString(exec));
    79   return jsBoolean(v->toBoolean(exec)); /* TODO: optimize for bool case */
     77    JSValue* v = static_cast<BooleanInstance*>(thisObj)->internalValue();
     78    ASSERT(v);
     79
     80    // TODO: optimize for bool case
     81    return jsBoolean(v->toBoolean(exec));
    8082}
    8183
     
    8385
    8486
    85 BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* funcProto, BooleanPrototype* booleanProto)
    86   : InternalFunctionImp(funcProto)
     87BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype)
     88    : InternalFunctionImp(functionPrototype)
    8789{
    88   putDirect(exec->propertyNames().prototype, booleanProto, DontEnum|DontDelete|ReadOnly);
     90    putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);
    8991
    90   // no. of arguments for constructor
    91   putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
     92    // no. of arguments for constructor
     93    putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum);
    9294}
    9395
     
    9597bool BooleanObjectImp::implementsConstruct() const
    9698{
    97   return true;
     99    return true;
    98100}
    99101
    100102// ECMA 15.6.2
    101 JSObject *BooleanObjectImp::construct(ExecState *exec, const List &args)
     103JSObject* BooleanObjectImp::construct(ExecState* exec, const List& args)
    102104{
    103   BooleanInstance *obj(new BooleanInstance(exec->lexicalGlobalObject()->booleanPrototype()));
    104 
    105   bool b;
    106   if (args.size() > 0)
    107     b = args[0]->toBoolean(exec);
    108   else
    109     b = false;
    110 
    111   obj->setInternalValue(jsBoolean(b));
    112 
    113   return obj;
     105    BooleanInstance* obj(new BooleanInstance(exec->lexicalGlobalObject()->booleanPrototype()));
     106    obj->setInternalValue(jsBoolean(args[0]->toBoolean(exec)));
     107    return obj;
    114108}
    115109
    116110// ECMA 15.6.1
    117 JSValue *BooleanObjectImp::callAsFunction(ExecState *exec, JSObject *, const List &args)
     111JSValue* BooleanObjectImp::callAsFunction(ExecState* exec, JSObject*, const List& args)
    118112{
    119   if (args.isEmpty())
    120     return jsBoolean(false);
    121   else
    122     return jsBoolean(args[0]->toBoolean(exec)); /* TODO: optimize for bool case */
     113    // TODO: optimize for bool case
     114    return jsBoolean(args[0]->toBoolean(exec));
    123115}
    124116
     117} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.