Changeset 29817 in webkit
- Timestamp:
- Jan 27, 2008, 12:54:25 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r29815 r29817 1 2008-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 1 47 2008-01-26 Darin Adler <darin@apple.com> 2 48 -
trunk/JavaScriptCore/kjs/array_object.cpp
r29508 r29817 1 1 /* 2 2 * 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. 4 4 * Copyright (C) 2003 Peter Kelly (pmk@post.com) 5 5 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) … … 721 721 // ------------------------------ ArrayObjectImp ------------------------------- 722 722 723 ArrayObjectImp::ArrayObjectImp(ExecState* exec, 724 FunctionPrototype* funcProto, 725 ArrayPrototype* arrayProto) 726 : InternalFunctionImp(funcProto) 723 ArrayObjectImp::ArrayObjectImp(ExecState* exec, FunctionPrototype* funcProto, ArrayPrototype* arrayProto) 724 : InternalFunctionImp(funcProto, arrayProto->classInfo()->className) 727 725 { 728 726 // ECMA 15.4.3.1 Array.prototype -
trunk/JavaScriptCore/kjs/bool_object.cpp
r29588 r29817 86 86 87 87 BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype) 88 : InternalFunctionImp(functionPrototype )88 : InternalFunctionImp(functionPrototype, booleanPrototype->classInfo()->className) 89 89 { 90 90 putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly); -
trunk/JavaScriptCore/kjs/date_object.cpp
r29508 r29817 1 1 /* 2 2 * 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. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 440 440 // TODO: MakeTime (15.9.11.1) etc. ? 441 441 442 DateObjectImp::DateObjectImp(ExecState *exec, 443 FunctionPrototype *funcProto, 444 DatePrototype *dateProto) 445 : InternalFunctionImp(funcProto) 442 DateObjectImp::DateObjectImp(ExecState* exec, FunctionPrototype* funcProto, DatePrototype* dateProto) 443 : InternalFunctionImp(funcProto, dateProto->classInfo()->className) 446 444 { 447 445 static const Identifier* parsePropertyName = new Identifier("parse"); -
trunk/JavaScriptCore/kjs/error_object.cpp
r29588 r29817 43 43 // ECMA 15.9.4 44 44 ErrorPrototype::ErrorPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype) 45 : JSObject(objectPrototype)45 : ErrorInstance(objectPrototype) 46 46 { 47 47 // The constructor will be added later in ErrorObjectImp's constructor … … 72 72 73 73 ErrorObjectImp::ErrorObjectImp(ExecState* exec, FunctionPrototype* funcProto, ErrorPrototype* errorProto) 74 : InternalFunctionImp(funcProto )74 : InternalFunctionImp(funcProto, errorProto->classInfo()->className) 75 75 { 76 76 // ECMA 15.11.3.1 Error.prototype 77 77 putDirect(exec->propertyNames().prototype, errorProto, DontEnum|DontDelete|ReadOnly); 78 78 putDirect(exec->propertyNames().length, jsNumber(1), DontDelete|ReadOnly|DontEnum); 79 //putDirect(namePropertyName, jsString(n));80 79 } 81 80 … … 107 106 // ------------------------------ NativeErrorPrototype ---------------------- 108 107 109 NativeErrorPrototype::NativeErrorPrototype(ExecState* exec, ErrorPrototype* errorProto, UString name, UStringmessage)108 NativeErrorPrototype::NativeErrorPrototype(ExecState* exec, ErrorPrototype* errorProto, const UString& name, const UString& message) 110 109 : JSObject(errorProto) 111 110 { … … 118 117 const ClassInfo NativeErrorImp::info = { "Function", &InternalFunctionImp::info, 0 }; 119 118 120 NativeErrorImp::NativeErrorImp(ExecState* exec, FunctionPrototype* funcProto, JSObject* prot)121 : InternalFunctionImp(funcProto )119 NativeErrorImp::NativeErrorImp(ExecState* exec, FunctionPrototype* funcProto, NativeErrorPrototype* prot) 120 : InternalFunctionImp(funcProto, Identifier(prot->getDirect(exec->propertyNames().name)->getString())) 122 121 , proto(prot) 123 122 { -
trunk/JavaScriptCore/kjs/error_object.h
r29588 r29817 34 34 }; 35 35 36 class ErrorPrototype : public JSObject{36 class ErrorPrototype : public ErrorInstance { 37 37 public: 38 38 ErrorPrototype(ExecState*, ObjectPrototype*, FunctionPrototype*); … … 53 53 class NativeErrorPrototype : public JSObject { 54 54 public: 55 NativeErrorPrototype(ExecState*, ErrorPrototype*, UString name, UStringmessage);55 NativeErrorPrototype(ExecState*, ErrorPrototype*, const UString& name, const UString& message); 56 56 }; 57 57 58 58 class NativeErrorImp : public InternalFunctionImp { 59 59 public: 60 NativeErrorImp(ExecState*, FunctionPrototype*, JSObject*);60 NativeErrorImp(ExecState*, FunctionPrototype*, NativeErrorPrototype*); 61 61 62 62 virtual bool implementsConstruct() const; -
trunk/JavaScriptCore/kjs/function.h
r29588 r29817 2 2 /* 3 3 * 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. 5 5 * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca) 6 6 * Copyright (C) 2007 Maks Orlovich … … 42 42 public: 43 43 InternalFunctionImp(); 44 InternalFunctionImp(FunctionPrototype*);45 44 InternalFunctionImp(FunctionPrototype*, const Identifier&); 46 45 -
trunk/JavaScriptCore/kjs/function_object.cpp
r29588 r29817 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 * This file is part of the KDE libraries4 2 * 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. 6 4 * 7 5 * This library is free software; you can redistribute it and/or … … 79 77 } 80 78 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}"); 85 80 } 86 81 … … 137 132 138 133 FunctionObjectImp::FunctionObjectImp(ExecState* exec, FunctionPrototype* functionPrototype) 139 : InternalFunctionImp(functionPrototype )134 : InternalFunctionImp(functionPrototype, functionPrototype->classInfo()->className) 140 135 { 141 136 putDirect(exec->propertyNames().prototype, functionPrototype, DontEnum | DontDelete | ReadOnly); -
trunk/JavaScriptCore/kjs/internal.cpp
r28468 r29817 2 2 * Copyright (C) 1999-2002 Harri Porten (porten@kde.org) 3 3 * 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. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 227 227 } 228 228 229 InternalFunctionImp::InternalFunctionImp(FunctionPrototype* funcProto)230 : JSObject(funcProto)231 {232 }233 234 229 InternalFunctionImp::InternalFunctionImp(FunctionPrototype* funcProto, const Identifier& name) 235 230 : JSObject(funcProto) -
trunk/JavaScriptCore/kjs/number_object.cpp
r29588 r29817 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * 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. 5 4 * 6 5 * This library is free software; you can redistribute it and/or … … 275 274 } 276 275 277 void fractionalPartToString(char* buf, int& i, const char* result, int resultLength, int fractionalDigits)276 static void fractionalPartToString(char* buf, int& i, const char* result, int resultLength, int fractionalDigits) 278 277 { 279 278 if (fractionalDigits <= 0) … … 296 295 } 297 296 298 void exponentialPartToString(char* buf, int& i, int decimalPoint)297 static void exponentialPartToString(char* buf, int& i, int decimalPoint) 299 298 { 300 299 buf[i++] = 'e'; … … 442 441 if (e == precision - 1) 443 442 return jsString(s + m); 444 elseif (e >= 0) {443 if (e >= 0) { 445 444 if (e + 1 < m.size()) 446 445 return jsString(s + m.substr(0, e + 1) + "." + m.substr(e + 1)); … … 464 463 */ 465 464 NumberObjectImp::NumberObjectImp(ExecState* exec, FunctionPrototype* funcProto, NumberPrototype* numberProto) 466 : InternalFunctionImp(funcProto )465 : InternalFunctionImp(funcProto, numberProto->classInfo()->className) 467 466 { 468 467 // Number.Prototype … … 482 481 // ECMA 15.7.3 483 482 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(); 495 495 return jsNull(); 496 496 } … … 507 507 NumberInstance* obj = new NumberInstance(proto); 508 508 509 // FIXME: Check args[0]->isUndefined() instead of args.isEmpty()? 509 510 double n = args.isEmpty() ? 0 : args[0]->toNumber(exec); 510 511 obj->setInternalValue(jsNumber(n)); … … 515 516 JSValue* NumberObjectImp::callAsFunction(ExecState* exec, JSObject*, const List& args) 516 517 { 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)); 519 520 } 520 521 -
trunk/JavaScriptCore/kjs/object_object.cpp
r29588 r29817 177 177 178 178 ObjectObjectImp::ObjectObjectImp(ExecState* exec, ObjectPrototype* objProto, FunctionPrototype* funcProto) 179 : InternalFunctionImp(funcProto )179 : InternalFunctionImp(funcProto, "Object") 180 180 { 181 181 // ECMA 15.2.3.1 -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r29592 r29817 286 286 287 287 RegExpObjectImp::RegExpObjectImp(ExecState* exec, FunctionPrototype* funcProto, RegExpPrototype* regProto) 288 : InternalFunctionImp(funcProto )288 : InternalFunctionImp(funcProto, "RegExp") 289 289 , d(new RegExpObjectImpPrivate) 290 290 { -
trunk/JavaScriptCore/kjs/string_object.cpp
r29537 r29817 2 2 /* 3 3 * 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. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 988 988 // ------------------------------ StringObjectImp ------------------------------ 989 989 990 StringObjectImp::StringObjectImp(ExecState* exec, 991 FunctionPrototype* funcProto, 992 StringPrototype* stringProto) 993 : InternalFunctionImp(funcProto) 990 StringObjectImp::StringObjectImp(ExecState* exec, FunctionPrototype* funcProto, StringPrototype* stringProto) 991 : InternalFunctionImp(funcProto, stringProto->classInfo()->className) 994 992 { 995 993 // ECMA 15.5.3.1 String.prototype -
trunk/LayoutTests/ChangeLog
r29816 r29817 1 2008-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 1 13 2008-01-27 Matt Perry <mpComplete@gmail.com> 2 14 -
trunk/LayoutTests/fast/js/function-names-expected.txt
r13465 r29817 1 This test checks the names of functions constructed two different ways.1 This test checks the names of all sorts of different functions. 2 2 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 4 5 5 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; }' 6 PASS new Function('return 1').toString().replace(/[ \n]+/g, ' ') is 'function anonymous() { return 1; }' 7 PASS document.documentElement.onclick.toString().replace(/[ \n]+/g, ' ') is 'function onclick(event) { return 2; }' 8 PASS ''.constructor is String 9 PASS Boolean.toString() is 'function Boolean() {\n [native code]\n}' 10 PASS Date.toString() is 'function Date() {\n [native code]\n}' 11 PASS Error.toString() is 'function Error() {\n [native code]\n}' 12 PASS EvalError.toString() is 'function EvalError() {\n [native code]\n}' 13 PASS Function.toString() is 'function Function() {\n [native code]\n}' 14 PASS Number.toString() is 'function Number() {\n [native code]\n}' 15 PASS Object.toString() is 'function Object() {\n [native code]\n}' 16 PASS RangeError.toString() is 'function RangeError() {\n [native code]\n}' 17 PASS ReferenceError.toString() is 'function ReferenceError() {\n [native code]\n}' 18 PASS RegExp.toString() is 'function RegExp() {\n [native code]\n}' 19 PASS String.toString() is 'function String() {\n [native code]\n}' 20 PASS SyntaxError.toString() is 'function SyntaxError() {\n [native code]\n}' 21 PASS TypeError.toString() is 'function TypeError() {\n [native code]\n}' 22 PASS URIError.toString() is 'function URIError() {\n [native code]\n}' 8 23 PASS successfullyParsed is true 9 24 -
trunk/LayoutTests/fast/js/kde/resources/function.js
r26621 r29817 161 161 shouldBe("groupClone(1, 2)", "9"); 162 162 163 var sinStr = ' \nfunction sin() {\n [native code]\n}\n'163 var sinStr = 'function sin() {\n [native code]\n}' 164 164 shouldBe("String(Math.sin)", "sinStr"); 165 165 -
trunk/LayoutTests/fast/js/resources/function-names.js
r13465 r29817 1 1 description( 2 "This test checks the names of functions constructed two different ways."2 "This test checks the names of all sorts of different functions." 3 3 ); 4 4 5 document.documentElement.setAttribute("onclick", " 2");5 document.documentElement.setAttribute("onclick", "return 2"); 6 6 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; }'"); 7 shouldBe("new Function('return 1').toString().replace(/[ \\n]+/g, ' ')", "'function anonymous() { return 1; }'"); 8 shouldBe("document.documentElement.onclick.toString().replace(/[ \\n]+/g, ' ')", "'function onclick(event) { return 2; }'"); 9 10 shouldBe("''.constructor", "String"); 11 12 function checkConstructorName(name) 13 { 14 shouldBe(name + ".toString()", "'function " + name + "() {\\n [native code]\\n}'"); 15 } 16 17 checkConstructorName("Boolean"); 18 checkConstructorName("Date"); 19 checkConstructorName("Error"); 20 checkConstructorName("EvalError"); 21 checkConstructorName("Function"); 22 checkConstructorName("Number"); 23 checkConstructorName("Object"); 24 checkConstructorName("RangeError"); 25 checkConstructorName("ReferenceError"); 26 checkConstructorName("RegExp"); 27 checkConstructorName("String"); 28 checkConstructorName("SyntaxError"); 29 checkConstructorName("TypeError"); 30 checkConstructorName("URIError"); 9 31 10 32 var successfullyParsed = true;
Note:
See TracChangeset
for help on using the changeset viewer.