Skip to content

Commit a125635

Browse files
authored
Inherit toString from Error.prototype (#6391)
1 parent 8d61086 commit a125635

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,14 +2442,13 @@ namespace Js
24422442
} \
24432443
bool JavascriptLibrary::Initialize##error##Prototype(DynamicObject* prototype, DeferredTypeHandlerBase* typeHandler, DeferredInitializeMode mode) \
24442444
{ \
2445-
typeHandler->Convert(prototype, mode, 4); \
2445+
typeHandler->Convert(prototype, mode, 3); \
24462446
JavascriptLibrary* library = prototype->GetLibrary(); \
24472447
library->AddMember(prototype, PropertyIds::constructor, library->Get##error##Constructor()); \
24482448
bool hasNoEnumerableProperties = true; \
24492449
PropertyAttributes prototypeNameMessageAttributes = PropertyConfigurable | PropertyWritable; \
24502450
library->AddMember(prototype, PropertyIds::name, library->CreateStringFromCppLiteral(_u(#errorName)), prototypeNameMessageAttributes); \
24512451
library->AddMember(prototype, PropertyIds::message, library->GetEmptyString(), prototypeNameMessageAttributes); \
2452-
library->AddFunctionToLibraryObject(prototype, PropertyIds::toString, &JavascriptError::EntryInfo::ToString, 0); \
24532452
prototype->SetHasNoEnumerableProperties(hasNoEnumerableProperties); \
24542453
return true; \
24552454
}

test/Error/errorPrototypetoString.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
// Test the fix for https://github.com/microsoft/ChakraCore/issues/6372
7+
8+
9+
function checkObject(object)
10+
{
11+
if (object.prototype.hasOwnProperty('toString'))
12+
{
13+
throw new Error(`${object.name}.prototype should not have own property 'toString'`);
14+
}
15+
if(object.prototype.toString !== Error.prototype.toString)
16+
{
17+
throw new Error(`${object.name}.prototype.toString should === Error.prototype.toString`);
18+
}
19+
}
20+
21+
checkObject(EvalError);
22+
checkObject(RangeError);
23+
checkObject(ReferenceError);
24+
checkObject(SyntaxError);
25+
checkObject(URIError);
26+
27+
if (typeof WebAssembly !== 'undefined')
28+
{
29+
checkObject(WebAssembly.CompileError);
30+
checkObject(WebAssembly.LinkError);
31+
checkObject(WebAssembly.RuntimeError);
32+
}
33+
34+
print('pass');

test/Error/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,9 @@
178178
<compile-flags>-ExtendedErrorStackForTestHost -force:DeferParse</compile-flags>
179179
</default>
180180
</test>
181+
<test>
182+
<default>
183+
<files>errorPrototypetoString.js</files>
184+
</default>
185+
</test>
181186
</regress-exe>

0 commit comments

Comments
 (0)