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/regexp_object.cpp

    r28476 r29588  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    3  *  Copyright (C) 2003, 2007 Apple Inc. All Rights Reserved.
     3 *  Copyright (C) 2003, 2007, 2008 Apple Inc. All Rights Reserved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    4040// ------------------------------ RegExpPrototype ---------------------------
    4141
     42static JSValue* regExpProtoFuncTest(ExecState*, JSObject*, const List&);
     43static JSValue* regExpProtoFuncExec(ExecState*, JSObject*, const List&);
     44static JSValue* regExpProtoFuncCompile(ExecState*, JSObject*, const List&);
     45static JSValue* regExpProtoFuncToString(ExecState*, JSObject*, const List&);
     46
    4247// ECMA 15.10.5
    4348
    4449const ClassInfo RegExpPrototype::info = { "RegExpPrototype", 0, 0 };
    4550
    46 RegExpPrototype::RegExpPrototype(ExecState *exec,
    47                                        ObjectPrototype *objProto,
    48                                        FunctionPrototype *funcProto)
    49   : JSObject(objProto)
    50 {
    51   static const Identifier* compilePropertyName = new Identifier("compile");
    52   static const Identifier* execPropertyName = new Identifier("exec");
    53   static const Identifier* testPropertyName = new Identifier("test");
    54 
    55   putDirectFunction(new RegExpProtoFunc(exec, funcProto, RegExpProtoFunc::Compile, 0, *compilePropertyName), DontEnum);
    56   putDirectFunction(new RegExpProtoFunc(exec, funcProto, RegExpProtoFunc::Exec, 0, *execPropertyName), DontEnum);
    57   putDirectFunction(new RegExpProtoFunc(exec, funcProto, RegExpProtoFunc::Test, 0, *testPropertyName), DontEnum);
    58   putDirectFunction(new RegExpProtoFunc(exec, funcProto, RegExpProtoFunc::ToString, 0, exec->propertyNames().toString), DontEnum);
    59 }
    60 
    61 // ------------------------------ RegExpProtoFunc ---------------------------
    62 
    63 RegExpProtoFunc::RegExpProtoFunc(ExecState* exec, FunctionPrototype* funcProto, int i, int len, const Identifier& name)
    64    : InternalFunctionImp(funcProto, name), id(i)
    65 {
    66   putDirect(exec->propertyNames().length, len, DontDelete | ReadOnly | DontEnum);
    67 }
    68 
    69 JSValue *RegExpProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
    70 {
    71   if (!thisObj->inherits(&RegExpImp::info)) {
    72     if (thisObj->inherits(&RegExpPrototype::info)) {
    73       switch (id) {
    74         case ToString: return jsString("//");
    75       }
    76     }
     51RegExpPrototype::RegExpPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)
     52    : JSObject(objectPrototype)
     53{
     54    static const Identifier* compilePropertyName = new Identifier("compile");
     55    static const Identifier* execPropertyName = new Identifier("exec");
     56    static const Identifier* testPropertyName = new Identifier("test");
     57
     58    putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, *compilePropertyName, regExpProtoFuncCompile), DontEnum);
     59    putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, *execPropertyName, regExpProtoFuncExec), DontEnum);
     60    putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, *testPropertyName, regExpProtoFuncTest), DontEnum);
     61    putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, regExpProtoFuncToString), DontEnum);
     62}
     63
     64// ------------------------------ Functions ---------------------------
    7765   
    78     return throwError(exec, TypeError);
    79   }
    80 
    81     switch (id) {
    82         case Test:
    83             return static_cast<RegExpImp*>(thisObj)->test(exec, args);
    84         case Exec:
    85             return static_cast<RegExpImp*>(thisObj)->exec(exec, args);
    86   case Compile:
    87   {
     66JSValue* regExpProtoFuncTest(ExecState* exec, JSObject* thisObj, const List& args)
     67{
     68    if (!thisObj->inherits(&RegExpImp::info))
     69        return throwError(exec, TypeError);
     70
     71    return static_cast<RegExpImp*>(thisObj)->test(exec, args);
     72}
     73
     74JSValue* regExpProtoFuncExec(ExecState* exec, JSObject* thisObj, const List& args)
     75{
     76    if (!thisObj->inherits(&RegExpImp::info))
     77        return throwError(exec, TypeError);
     78
     79    return static_cast<RegExpImp*>(thisObj)->exec(exec, args);
     80}
     81
     82JSValue* regExpProtoFuncCompile(ExecState* exec, JSObject* thisObj, const List& args)
     83{
     84    if (!thisObj->inherits(&RegExpImp::info))
     85        return throwError(exec, TypeError);
     86
    8887    RefPtr<RegExp> regExp;
    8988    JSValue* arg0 = args[0];
     
    9190   
    9291    if (arg0->isObject(&RegExpImp::info)) {
    93       if (!arg1->isUndefined())
    94         return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another.");
    95       regExp = static_cast<RegExpImp*>(arg0)->regExp();
     92        if (!arg1->isUndefined())
     93            return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another.");
     94        regExp = static_cast<RegExpImp*>(arg0)->regExp();
    9695    } else {
    97       UString pattern = args.isEmpty() ? UString("") : arg0->toString(exec);
    98       UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec);
    99       regExp = new RegExp(pattern, flags);
     96        UString pattern = args.isEmpty() ? UString("") : arg0->toString(exec);
     97        UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec);
     98        regExp = new RegExp(pattern, flags);
    10099    }
    101100
    102101    if (!regExp->isValid())
    103       return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
     102        return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
    104103
    105104    static_cast<RegExpImp*>(thisObj)->setRegExp(regExp.release());
    106105    static_cast<RegExpImp*>(thisObj)->put(exec, exec->propertyNames().lastIndex, jsNumber(0), DontDelete|DontEnum);
    107106    return jsUndefined();
    108   }
    109   case ToString:
     107}
     108
     109JSValue* regExpProtoFuncToString(ExecState* exec, JSObject* thisObj, const List&)
     110{
     111    if (!thisObj->inherits(&RegExpImp::info)) {
     112        if (thisObj->inherits(&RegExpPrototype::info))
     113            return jsString("//");
     114        return throwError(exec, TypeError);
     115    }
     116
    110117    UString result = "/" + thisObj->get(exec, exec->propertyNames().source)->toString(exec) + "/";
    111     if (thisObj->get(exec, exec->propertyNames().global)->toBoolean(exec)) {
    112       result += "g";
    113     }
    114     if (thisObj->get(exec, exec->propertyNames().ignoreCase)->toBoolean(exec)) {
    115       result += "i";
    116     }
    117     if (thisObj->get(exec, exec->propertyNames().multiline)->toBoolean(exec)) {
    118       result += "m";
    119     }
     118    if (thisObj->get(exec, exec->propertyNames().global)->toBoolean(exec))
     119        result += "g";
     120    if (thisObj->get(exec, exec->propertyNames().ignoreCase)->toBoolean(exec))
     121        result += "i";
     122    if (thisObj->get(exec, exec->propertyNames().multiline)->toBoolean(exec))
     123        result += "m";
    120124    return jsString(result);
    121   }
    122 
    123   return jsUndefined();
     125
     126    return jsUndefined();
    124127}
    125128
Note: See TracChangeset for help on using the changeset viewer.