Changeset 29817 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Jan 27, 2008, 12:54:25 AM (17 years ago)
Author:
Darin Adler
Message:

JavaScriptCore:

Reviewed by Oliver.

Test: fast/js/function-names.html

  • kjs/array_object.cpp: (KJS::ArrayObjectImp::ArrayObjectImp): Use the class name as the constructor's function name.
  • kjs/bool_object.cpp: (KJS::BooleanObjectImp::BooleanObjectImp): Ditto.
  • kjs/date_object.cpp: (KJS::DateObjectImp::DateObjectImp): Ditto.
  • kjs/error_object.cpp: (KJS::ErrorPrototype::ErrorPrototype): Make the error object be an Error. (KJS::ErrorObjectImp::ErrorObjectImp): Use the class name as the constructor's function name. (KJS::NativeErrorPrototype::NativeErrorPrototype): Take const UString&. (KJS::NativeErrorImp::NativeErrorImp): Use the prototype's name as the constructor's function name.
  • kjs/error_object.h: Change ErrorPrototype to inherit from ErrorInstance. Change the NativeErrorImp constructor to take a NativeErrorPrototype pointer for its prototype.
  • kjs/function.h: Removed unneeded constructor for internal functions without names. We want to avoid those!
  • kjs/function_object.cpp: (KJS::functionProtoFuncToString): Removed code that writes out just [function] for functions that have no names. There's no reason to do that. (KJS::FunctionObjectImp::FunctionObjectImp): Use the class name as the constructor's function name.
  • kjs/internal.cpp: Removed the unused constructor.
  • kjs/number_object.cpp: (KJS::fractionalPartToString): Marked static for internal linkage. (KJS::exponentialPartToString): Ditto. (KJS::numberProtoFuncToPrecision): Removed an unneeded else. (KJS::NumberObjectImp::NumberObjectImp): Use the class name as the constructor's function name. (KJS::NumberObjectImp::getValueProperty): Tweaked formatting.
  • kjs/object_object.cpp: (KJS::ObjectObjectImp::ObjectObjectImp): Use "Object" for the function name.
  • kjs/regexp_object.cpp: (KJS::RegExpObjectImp::RegExpObjectImp): Use "RegExp" for the function name.
  • kjs/string_object.cpp: (KJS::StringObjectImp::StringObjectImp): Use the class name as the constructor's function name.

LayoutTests:

Reviewed by Oliver.

  • fast/js/function-names-expected.txt: Updated for new tests.
  • fast/js/kde/resources/function.js: Updated test to expect the format that Gecko uses for native code, which we now match character for character.
  • fast/js/resources/function-names.js: Added tests for the names of all the constructors.
Location:
trunk/JavaScriptCore/kjs
Files:
12 edited

Legend:

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

    r29508 r29817  
    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 *  Copyright (C) 2003 Peter Kelly ([email protected])
    55 *  Copyright (C) 2006 Alexey Proskuryakov ([email protected])
     
    721721// ------------------------------ ArrayObjectImp -------------------------------
    722722
    723 ArrayObjectImp::ArrayObjectImp(ExecState* exec,
    724                                FunctionPrototype* funcProto,
    725                                ArrayPrototype* arrayProto)
    726         : InternalFunctionImp(funcProto)
     723ArrayObjectImp::ArrayObjectImp(ExecState* exec, FunctionPrototype* funcProto, ArrayPrototype* arrayProto)
     724    : InternalFunctionImp(funcProto, arrayProto->classInfo()->className)
    727725{
    728726    // ECMA 15.4.3.1 Array.prototype
  • trunk/JavaScriptCore/kjs/bool_object.cpp

    r29588 r29817  
    8686
    8787BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype)
    88     : InternalFunctionImp(functionPrototype)
     88    : InternalFunctionImp(functionPrototype, booleanPrototype->classInfo()->className)
    8989{
    9090    putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);
  • trunk/JavaScriptCore/kjs/date_object.cpp

    r29508 r29817  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    3  *  Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    440440// TODO: MakeTime (15.9.11.1) etc. ?
    441441
    442 DateObjectImp::DateObjectImp(ExecState *exec,
    443                              FunctionPrototype *funcProto,
    444                              DatePrototype *dateProto)
    445   : InternalFunctionImp(funcProto)
     442DateObjectImp::DateObjectImp(ExecState* exec, FunctionPrototype* funcProto, DatePrototype* dateProto)
     443  : InternalFunctionImp(funcProto, dateProto->classInfo()->className)
    446444{
    447445  static const Identifier* parsePropertyName = new Identifier("parse");
  • trunk/JavaScriptCore/kjs/error_object.cpp

    r29588 r29817  
    4343// ECMA 15.9.4
    4444ErrorPrototype::ErrorPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)
    45     : JSObject(objectPrototype)
     45    : ErrorInstance(objectPrototype)
    4646{
    4747    // The constructor will be added later in ErrorObjectImp's constructor
     
    7272
    7373ErrorObjectImp::ErrorObjectImp(ExecState* exec, FunctionPrototype* funcProto, ErrorPrototype* errorProto)
    74     : InternalFunctionImp(funcProto)
     74    : InternalFunctionImp(funcProto, errorProto->classInfo()->className)
    7575{
    7676    // ECMA 15.11.3.1 Error.prototype
    7777    putDirect(exec->propertyNames().prototype, errorProto, DontEnum|DontDelete|ReadOnly);
    7878    putDirect(exec->propertyNames().length, jsNumber(1), DontDelete|ReadOnly|DontEnum);
    79     //putDirect(namePropertyName, jsString(n));
    8079}
    8180
     
    107106// ------------------------------ NativeErrorPrototype ----------------------
    108107
    109 NativeErrorPrototype::NativeErrorPrototype(ExecState* exec, ErrorPrototype* errorProto, UString name, UString message)
     108NativeErrorPrototype::NativeErrorPrototype(ExecState* exec, ErrorPrototype* errorProto, const UString& name, const UString& message)
    110109    : JSObject(errorProto)
    111110{
     
    118117const ClassInfo NativeErrorImp::info = { "Function", &InternalFunctionImp::info, 0 };
    119118
    120 NativeErrorImp::NativeErrorImp(ExecState* exec, FunctionPrototype* funcProto, JSObject* prot)
    121     : InternalFunctionImp(funcProto)
     119NativeErrorImp::NativeErrorImp(ExecState* exec, FunctionPrototype* funcProto, NativeErrorPrototype* prot)
     120    : InternalFunctionImp(funcProto, Identifier(prot->getDirect(exec->propertyNames().name)->getString()))
    122121    , proto(prot)
    123122{
  • trunk/JavaScriptCore/kjs/error_object.h

    r29588 r29817  
    3434    };
    3535
    36     class ErrorPrototype : public JSObject {
     36    class ErrorPrototype : public ErrorInstance {
    3737    public:
    3838        ErrorPrototype(ExecState*, ObjectPrototype*, FunctionPrototype*);
     
    5353    class NativeErrorPrototype : public JSObject {
    5454    public:
    55         NativeErrorPrototype(ExecState*, ErrorPrototype*, UString name, UString message);
     55        NativeErrorPrototype(ExecState*, ErrorPrototype*, const UString& name, const UString& message);
    5656    };
    5757
    5858    class NativeErrorImp : public InternalFunctionImp {
    5959    public:
    60         NativeErrorImp(ExecState*, FunctionPrototype*, JSObject*);
     60        NativeErrorImp(ExecState*, FunctionPrototype*, NativeErrorPrototype*);
    6161
    6262        virtual bool implementsConstruct() const;
  • trunk/JavaScriptCore/kjs/function.h

    r29588 r29817  
    22/*
    33 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    4  *  Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
    55 *  Copyright (C) 2007 Cameron Zwarich ([email protected])
    66 *  Copyright (C) 2007 Maks Orlovich
     
    4242  public:
    4343    InternalFunctionImp();
    44     InternalFunctionImp(FunctionPrototype*);
    4544    InternalFunctionImp(FunctionPrototype*, const Identifier&);
    4645
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r29588 r29817  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    3  *  This file is part of the KDE libraries
    42 *  Copyright (C) 1999-2001 Harri Porten ([email protected])
    5  *  Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
     3 *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
    64 *
    75 *  This library is free software; you can redistribute it and/or
     
    7977    }
    8078
    81     if (thisObj->inherits(&InternalFunctionImp::info) && !static_cast<InternalFunctionImp*>(thisObj)->functionName().isNull())
    82         return jsString("\nfunction " + static_cast<InternalFunctionImp*>(thisObj)->functionName().ustring() + "() {\n    [native code]\n}\n");
    83 
    84     return jsString("[function]");
     79    return jsString("function " + static_cast<InternalFunctionImp*>(thisObj)->functionName().ustring() + "() {\n    [native code]\n}");
    8580}
    8681
     
    137132
    138133FunctionObjectImp::FunctionObjectImp(ExecState* exec, FunctionPrototype* functionPrototype)
    139     : InternalFunctionImp(functionPrototype)
     134    : InternalFunctionImp(functionPrototype, functionPrototype->classInfo()->className)
    140135{
    141136    putDirect(exec->propertyNames().prototype, functionPrototype, DontEnum | DontDelete | ReadOnly);
  • trunk/JavaScriptCore/kjs/internal.cpp

    r28468 r29817  
    22 *  Copyright (C) 1999-2002 Harri Porten ([email protected])
    33 *  Copyright (C) 2001 Peter Kelly ([email protected])
    4  *  Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2004, 2007, 2008 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    227227}
    228228
    229 InternalFunctionImp::InternalFunctionImp(FunctionPrototype* funcProto)
    230   : JSObject(funcProto)
    231 {
    232 }
    233 
    234229InternalFunctionImp::InternalFunctionImp(FunctionPrototype* funcProto, const Identifier& name)
    235230  : JSObject(funcProto)
  • trunk/JavaScriptCore/kjs/number_object.cpp

    r29588 r29817  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    32 *  Copyright (C) 1999-2000,2003 Harri Porten ([email protected])
    4  *  Copyright (C) 2007 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
    54 *
    65 *  This library is free software; you can redistribute it and/or
     
    275274}
    276275
    277 void fractionalPartToString(char* buf, int& i, const char* result, int resultLength, int fractionalDigits)
     276static void fractionalPartToString(char* buf, int& i, const char* result, int resultLength, int fractionalDigits)
    278277{
    279278    if (fractionalDigits <= 0)
     
    296295}
    297296
    298 void exponentialPartToString(char* buf, int& i, int decimalPoint)
     297static void exponentialPartToString(char* buf, int& i, int decimalPoint)
    299298{
    300299    buf[i++] = 'e';
     
    442441    if (e == precision - 1)
    443442        return jsString(s + m);
    444     else if (e >= 0) {
     443    if (e >= 0) {
    445444        if (e + 1 < m.size())
    446445            return jsString(s + m.substr(0, e + 1) + "." + m.substr(e + 1));
     
    464463*/
    465464NumberObjectImp::NumberObjectImp(ExecState* exec, FunctionPrototype* funcProto, NumberPrototype* numberProto)
    466     : InternalFunctionImp(funcProto)
     465    : InternalFunctionImp(funcProto, numberProto->classInfo()->className)
    467466{
    468467    // Number.Prototype
     
    482481    // ECMA 15.7.3
    483482    switch (token) {
    484     case NaNValue:
    485         return jsNaN();
    486     case NegInfinity:
    487         return jsNumberCell(-Inf);
    488     case PosInfinity:
    489         return jsNumberCell(Inf);
    490     case MaxValue:
    491         return jsNumberCell(1.7976931348623157E+308);
    492     case MinValue:
    493         return jsNumberCell(5E-324);
    494     }
     483        case NaNValue:
     484            return jsNaN();
     485        case NegInfinity:
     486            return jsNumberCell(-Inf);
     487        case PosInfinity:
     488            return jsNumberCell(Inf);
     489        case MaxValue:
     490            return jsNumberCell(1.7976931348623157E+308);
     491        case MinValue:
     492            return jsNumberCell(5E-324);
     493    }
     494    ASSERT_NOT_REACHED();
    495495    return jsNull();
    496496}
     
    507507    NumberInstance* obj = new NumberInstance(proto);
    508508
     509    // FIXME: Check args[0]->isUndefined() instead of args.isEmpty()?
    509510    double n = args.isEmpty() ? 0 : args[0]->toNumber(exec);
    510511    obj->setInternalValue(jsNumber(n));
     
    515516JSValue* NumberObjectImp::callAsFunction(ExecState* exec, JSObject*, const List& args)
    516517{
    517     double n = args.isEmpty() ? 0 : args[0]->toNumber(exec);
    518     return jsNumber(n);
     518    // FIXME: Check args[0]->isUndefined() instead of args.isEmpty()?
     519    return jsNumber(args.isEmpty() ? 0 : args[0]->toNumber(exec));
    519520}
    520521
  • trunk/JavaScriptCore/kjs/object_object.cpp

    r29588 r29817  
    177177
    178178ObjectObjectImp::ObjectObjectImp(ExecState* exec, ObjectPrototype* objProto, FunctionPrototype* funcProto)
    179   : InternalFunctionImp(funcProto)
     179  : InternalFunctionImp(funcProto, "Object")
    180180{
    181181  // ECMA 15.2.3.1
  • trunk/JavaScriptCore/kjs/regexp_object.cpp

    r29592 r29817  
    286286
    287287RegExpObjectImp::RegExpObjectImp(ExecState* exec, FunctionPrototype* funcProto, RegExpPrototype* regProto)
    288   : InternalFunctionImp(funcProto)
     288  : InternalFunctionImp(funcProto, "RegExp")
    289289  , d(new RegExpObjectImpPrivate)
    290290{
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r29537 r29817  
    22/*
    33 *  Copyright (C) 1999-2001 Harri Porten ([email protected])
    4  *  Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    988988// ------------------------------ StringObjectImp ------------------------------
    989989
    990 StringObjectImp::StringObjectImp(ExecState* exec,
    991                                  FunctionPrototype* funcProto,
    992                                  StringPrototype* stringProto)
    993   : InternalFunctionImp(funcProto)
     990StringObjectImp::StringObjectImp(ExecState* exec, FunctionPrototype* funcProto, StringPrototype* stringProto)
     991  : InternalFunctionImp(funcProto, stringProto->classInfo()->className)
    994992{
    995993  // ECMA 15.5.3.1 String.prototype
Note: See TracChangeset for help on using the changeset viewer.