Changeset 29817 in webkit


Ignore:
Timestamp:
Jan 27, 2008 12:54:25 AM (16 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
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r29815 r29817  
     12008-01-27  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Oliver.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=16498
     6          ''.constructor.toString() gives [function]
     7
     8        Test: fast/js/function-names.html
     9
     10        * kjs/array_object.cpp:
     11        (KJS::ArrayObjectImp::ArrayObjectImp): Use the class name as the constructor's function name.
     12        * kjs/bool_object.cpp:
     13        (KJS::BooleanObjectImp::BooleanObjectImp): Ditto.
     14        * kjs/date_object.cpp:
     15        (KJS::DateObjectImp::DateObjectImp): Ditto.
     16        * kjs/error_object.cpp:
     17        (KJS::ErrorPrototype::ErrorPrototype): Make the error object be an Error.
     18        (KJS::ErrorObjectImp::ErrorObjectImp): Use the class name as the constructor's function name.
     19        (KJS::NativeErrorPrototype::NativeErrorPrototype): Take const UString&.
     20        (KJS::NativeErrorImp::NativeErrorImp): Use the prototype's name as the constructor's function
     21        name.
     22        * kjs/error_object.h: Change ErrorPrototype to inherit from ErrorInstance. Change the
     23        NativeErrorImp constructor to take a NativeErrorPrototype pointer for its prototype.
     24        * kjs/function.h: Removed unneeded constructor for internal functions without names.
     25        We want to avoid those!
     26        * kjs/function_object.cpp:
     27        (KJS::functionProtoFuncToString): Removed code that writes out just [function] for functions
     28        that have no names. There's no reason to do that.
     29        (KJS::FunctionObjectImp::FunctionObjectImp): Use the class name as the constructor's
     30        function name.
     31        * kjs/internal.cpp: Removed the unused constructor.
     32        * kjs/number_object.cpp:
     33        (KJS::fractionalPartToString): Marked static for internal linkage.
     34        (KJS::exponentialPartToString): Ditto.
     35        (KJS::numberProtoFuncToPrecision): Removed an unneeded else.
     36        (KJS::NumberObjectImp::NumberObjectImp): Use the class name as the constructor's
     37        function name.
     38        (KJS::NumberObjectImp::getValueProperty): Tweaked formatting.
     39        * kjs/object_object.cpp:
     40        (KJS::ObjectObjectImp::ObjectObjectImp): Use "Object" for the function name.
     41        * kjs/regexp_object.cpp:
     42        (KJS::RegExpObjectImp::RegExpObjectImp): Use "RegExp" for the function name.
     43        * kjs/string_object.cpp:
     44        (KJS::StringObjectImp::StringObjectImp): Use the class name as the constructor's
     45        function name.
     46
    1472008-01-26  Darin Adler  <darin@apple.com>
    248
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r29508 r29817  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    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 (pmk@post.com)
    55 *  Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
     
    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 (porten@kde.org)
    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 (porten@kde.org)
    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 (cwzwarich@uwaterloo.ca)
    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 (porten@kde.org)
    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 (porten@kde.org)
    33 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    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 (porten@kde.org)
    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 (porten@kde.org)
    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
  • trunk/LayoutTests/ChangeLog

    r29816 r29817  
     12008-01-27  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Oliver.
     4
     5        - test for http://bugs.webkit.org/show_bug.cgi?id=16498
     6          ''.constructor.toString() gives [function]
     7
     8        * fast/js/function-names-expected.txt: Updated for new tests.
     9        * fast/js/kde/resources/function.js: Updated test to expect the format that Gecko uses
     10        for native code, which we now match character for character.
     11        * fast/js/resources/function-names.js: Added tests for the names of all the constructors.
     12
    1132008-01-27  Matt Perry  <mpComplete@gmail.com>
    214
  • trunk/LayoutTests/fast/js/function-names-expected.txt

    r13465 r29817  
    1 This test checks the names of functions constructed two different ways.
     1This test checks the names of all sorts of different functions.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    44
    55
    6 PASS new Function('1').toString().replace(/[ \n]+/g, ' ') is 'function anonymous() { 1; }'
    7 PASS document.documentElement.onclick.toString().replace(/[ \n]+/g, ' ') is 'function onclick(event) { 2; }'
     6PASS new Function('return 1').toString().replace(/[ \n]+/g, ' ') is 'function anonymous() { return 1; }'
     7PASS document.documentElement.onclick.toString().replace(/[ \n]+/g, ' ') is 'function onclick(event) { return 2; }'
     8PASS ''.constructor is String
     9PASS Boolean.toString() is 'function Boolean() {\n    [native code]\n}'
     10PASS Date.toString() is 'function Date() {\n    [native code]\n}'
     11PASS Error.toString() is 'function Error() {\n    [native code]\n}'
     12PASS EvalError.toString() is 'function EvalError() {\n    [native code]\n}'
     13PASS Function.toString() is 'function Function() {\n    [native code]\n}'
     14PASS Number.toString() is 'function Number() {\n    [native code]\n}'
     15PASS Object.toString() is 'function Object() {\n    [native code]\n}'
     16PASS RangeError.toString() is 'function RangeError() {\n    [native code]\n}'
     17PASS ReferenceError.toString() is 'function ReferenceError() {\n    [native code]\n}'
     18PASS RegExp.toString() is 'function RegExp() {\n    [native code]\n}'
     19PASS String.toString() is 'function String() {\n    [native code]\n}'
     20PASS SyntaxError.toString() is 'function SyntaxError() {\n    [native code]\n}'
     21PASS TypeError.toString() is 'function TypeError() {\n    [native code]\n}'
     22PASS URIError.toString() is 'function URIError() {\n    [native code]\n}'
    823PASS successfullyParsed is true
    924
  • trunk/LayoutTests/fast/js/kde/resources/function.js

    r26621 r29817  
    161161shouldBe("groupClone(1, 2)", "9");
    162162
    163 var sinStr = '\nfunction sin() {\n    [native code]\n}\n'
     163var sinStr = 'function sin() {\n    [native code]\n}'
    164164shouldBe("String(Math.sin)", "sinStr");
    165165
  • trunk/LayoutTests/fast/js/resources/function-names.js

    r13465 r29817  
    11description(
    2 "This test checks the names of functions constructed two different ways."
     2"This test checks the names of all sorts of different functions."
    33);
    44
    5 document.documentElement.setAttribute("onclick", "2");
     5document.documentElement.setAttribute("onclick", "return 2");
    66
    7 shouldBe("new Function('1').toString().replace(/[ \\n]+/g, ' ')", "'function anonymous() { 1; }'");
    8 shouldBe("document.documentElement.onclick.toString().replace(/[ \\n]+/g, ' ')", "'function onclick(event) { 2; }'");
     7shouldBe("new Function('return 1').toString().replace(/[ \\n]+/g, ' ')", "'function anonymous() { return 1; }'");
     8shouldBe("document.documentElement.onclick.toString().replace(/[ \\n]+/g, ' ')", "'function onclick(event) { return 2; }'");
     9
     10shouldBe("''.constructor", "String");
     11
     12function checkConstructorName(name)
     13{
     14    shouldBe(name + ".toString()", "'function " + name + "() {\\n    [native code]\\n}'");
     15}
     16
     17checkConstructorName("Boolean");
     18checkConstructorName("Date");
     19checkConstructorName("Error");
     20checkConstructorName("EvalError");
     21checkConstructorName("Function");
     22checkConstructorName("Number");
     23checkConstructorName("Object");
     24checkConstructorName("RangeError");
     25checkConstructorName("ReferenceError");
     26checkConstructorName("RegExp");
     27checkConstructorName("String");
     28checkConstructorName("SyntaxError");
     29checkConstructorName("TypeError");
     30checkConstructorName("URIError");
    931
    1032var successfullyParsed = true;
Note: See TracChangeset for help on using the changeset viewer.