Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [[Class]] property of builtin constructors #325

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 0 additions & 99 deletions jerry-core/ecma/operations/ecma-objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,105 +538,6 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */
return LIT_MAGIC_STRING_ARGUMENTS_UL;
}
case ECMA_OBJECT_TYPE_FUNCTION:
{
lit_magic_string_id_t class_name;

if (ecma_get_object_is_builtin (obj_p))
{
ecma_property_t *built_in_id_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_id_prop_p->u.internal_property.value;

switch (builtin_id)
{
case ECMA_BUILTIN_ID_OBJECT:
{
class_name = LIT_MAGIC_STRING_OBJECT_UL;
break;
}
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
case ECMA_BUILTIN_ID_ARRAY:
{
class_name = LIT_MAGIC_STRING_ARRAY_UL;
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
case ECMA_BUILTIN_ID_STRING:
{
class_name = LIT_MAGIC_STRING_STRING_UL;
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
case ECMA_BUILTIN_ID_BOOLEAN:
{
class_name = LIT_MAGIC_STRING_BOOLEAN_UL;
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
case ECMA_BUILTIN_ID_NUMBER:
{
class_name = LIT_MAGIC_STRING_NUMBER_UL;
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
case ECMA_BUILTIN_ID_FUNCTION:
{
class_name = LIT_MAGIC_STRING_FUNCTION_UL;
break;
}
#ifdef CONFIG_ECMA_COMPACT_PROFILE
case ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR:
{
class_name = LIT_MAGIC_STRING_COMPACT_PROFILE_ERROR_UL;
break;
}
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
case ECMA_BUILTIN_ID_ERROR:
case ECMA_BUILTIN_ID_EVAL_ERROR:
case ECMA_BUILTIN_ID_RANGE_ERROR:
case ECMA_BUILTIN_ID_REFERENCE_ERROR:
case ECMA_BUILTIN_ID_SYNTAX_ERROR:
case ECMA_BUILTIN_ID_TYPE_ERROR:
case ECMA_BUILTIN_ID_URI_ERROR:
{
class_name = LIT_MAGIC_STRING_ERROR_UL;
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
case ECMA_BUILTIN_ID_DATE:
{
class_name = LIT_MAGIC_STRING_DATE_UL;
break;
}
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
case ECMA_BUILTIN_ID_REGEXP:
{
class_name = LIT_MAGIC_STRING_REGEXP_UL;
break;
}
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
default:
{
JERRY_ASSERT (builtin_id == ECMA_BUILTIN_ID_TYPE_ERROR_THROWER);

class_name = LIT_MAGIC_STRING_FUNCTION_UL;
break;
}
}
}
else
{
class_name = LIT_MAGIC_STRING_FUNCTION_UL;
}

return class_name;
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
Expand Down
27 changes: 27 additions & 0 deletions tests/jerry/builtin-constructor-class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2015 Samsung Electronics Co., Ltd.
// Copyright 2015 University of Szeged.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Function.prototype.toString = Object.prototype.toString;
assert(Array.toString() === "[object Function]");
assert(Number.toString() === "[object Function]");
assert(String.toString() === "[object Function]");
assert(Boolean.toString() === "[object Function]");
assert(Object.toString() === "[object Function]");
assert(Function.toString() === "[object Function]");
assert(Date.toString() === "[object Function]");
assert(RegExp.toString() === "[object Function]");

assert(Math.toString() === "[object Math]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add tests for RegExp and Date?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

assert(JSON.toString() === "[object JSON]");