Fix attributes of length property for builtin functions (#3689)
fix length property of builtin functions to be configurable (ECMA-262 v6, 19.2.4.1) JerryScript-DCO-1.0-Signed-off-by: HyukWoo Park hyukwoo.park@samsung.com
This commit is contained in:
@@ -650,17 +650,32 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Lazy instantiation of 'length' property
|
* Lazy instantiation of 'length' property
|
||||||
*
|
|
||||||
* Note:
|
|
||||||
* We don't need to mark that the property was already lazy instantiated,
|
|
||||||
* as it is non-configurable and so can't be deleted
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ecma_property_t *len_prop_p;
|
ecma_property_t *len_prop_p;
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||||
|
uint32_t *bitset_p = ext_func_p->u.built_in.instantiated_bitset;
|
||||||
|
if (*bitset_p & (1u << 0))
|
||||||
|
{
|
||||||
|
/* length property was already instantiated */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* We mark that the property was lazily instantiated,
|
||||||
|
* as it is configurable and so can be deleted (ECMA-262 v6, 19.2.4.1) */
|
||||||
|
*bitset_p |= (1u << 0);
|
||||||
|
ecma_property_value_t *len_prop_value_p = ecma_create_named_data_property (object_p,
|
||||||
|
string_p,
|
||||||
|
ECMA_PROPERTY_FLAG_CONFIGURABLE,
|
||||||
|
&len_prop_p);
|
||||||
|
#else /* !ENABLED (JERRY_ES2015) */
|
||||||
|
/* We don't need to mark that the property was already lazy instantiated,
|
||||||
|
* as it is non-configurable and so can't be deleted (ECMA-262 v5, 13.2.5) */
|
||||||
ecma_property_value_t *len_prop_value_p = ecma_create_named_data_property (object_p,
|
ecma_property_value_t *len_prop_value_p = ecma_create_named_data_property (object_p,
|
||||||
string_p,
|
string_p,
|
||||||
ECMA_PROPERTY_FIXED,
|
ECMA_PROPERTY_FIXED,
|
||||||
&len_prop_p);
|
&len_prop_p);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
|
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
|
||||||
|
|
||||||
@@ -949,8 +964,17 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
|||||||
|
|
||||||
if (!is_array_indices_only)
|
if (!is_array_indices_only)
|
||||||
{
|
{
|
||||||
|
#if ENABLED (JERRY_ES2015)
|
||||||
|
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||||
|
if (!(ext_func_p->u.built_in.instantiated_bitset[0] & (1u << 0)))
|
||||||
|
{
|
||||||
|
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
|
||||||
|
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||||
|
}
|
||||||
|
#else /* !ENABLED (JERRY_ES2015) */
|
||||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||||
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
assert(Function.prototype.toString.hasOwnProperty('length'));
|
||||||
|
assert(delete Function.prototype.toString.length);
|
||||||
|
assert(!Function.prototype.toString.hasOwnProperty('length'));
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
assert(Function.prototype.toString.hasOwnProperty('length'));
|
||||||
|
assert(delete Function.prototype.toString.length);
|
||||||
|
assert(!Function.prototype.toString.hasOwnProperty('length'));
|
||||||
@@ -39,8 +39,6 @@ var builtin_objects = [
|
|||||||
WeakSet,
|
WeakSet,
|
||||||
];
|
];
|
||||||
|
|
||||||
var builtin_prototypes = [Function.prototype]
|
|
||||||
|
|
||||||
var builtin_typedArrays = [
|
var builtin_typedArrays = [
|
||||||
Float32Array,
|
Float32Array,
|
||||||
Float64Array,
|
Float64Array,
|
||||||
@@ -65,13 +63,6 @@ var builtin_typedArrays = [
|
|||||||
assert(desc.configurable === true);
|
assert(desc.configurable === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (proto of builtin_prototypes) {
|
|
||||||
desc = Object.getOwnPropertyDescriptor(proto, 'length');
|
|
||||||
assert(desc.writable === false);
|
|
||||||
assert(desc.enumerable === false);
|
|
||||||
assert(desc.configurable === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ta of builtin_typedArrays) {
|
for (ta of builtin_typedArrays) {
|
||||||
desc = Object.getOwnPropertyDescriptor(ta, 'length');
|
desc = Object.getOwnPropertyDescriptor(ta, 'length');
|
||||||
assert(desc.writable === false);
|
assert(desc.writable === false);
|
||||||
@@ -88,12 +79,6 @@ var builtin_typedArrays = [
|
|||||||
assert(obj.hasOwnProperty('length') === false);
|
assert(obj.hasOwnProperty('length') === false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (proto of builtin_prototypes) {
|
|
||||||
assert(proto.hasOwnProperty('length') === true);
|
|
||||||
assert(delete proto.length);
|
|
||||||
assert(proto.hasOwnProperty('length') === false);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ta of builtin_typedArrays) {
|
for (ta of builtin_typedArrays) {
|
||||||
assert(ta.hasOwnProperty('length') === true);
|
assert(ta.hasOwnProperty('length') === true);
|
||||||
assert(delete ta.length);
|
assert(delete ta.length);
|
||||||
@@ -101,6 +86,26 @@ var builtin_typedArrays = [
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
/* test length property of builtin function */
|
||||||
|
for (obj of builtin_objects) {
|
||||||
|
var property_names = Object.getOwnPropertyNames(obj);
|
||||||
|
for (var name of property_names) {
|
||||||
|
if (typeof obj[name] == 'function') {
|
||||||
|
var func = obj[name];
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(func, 'length');
|
||||||
|
assert(desc.writable === false);
|
||||||
|
assert(desc.enumerable === false);
|
||||||
|
assert(desc.configurable === true);
|
||||||
|
|
||||||
|
assert(func.hasOwnProperty('length') === true);
|
||||||
|
assert(delete func.length);
|
||||||
|
assert(func.hasOwnProperty('length') === false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
/* test length property of function objects */
|
/* test length property of function objects */
|
||||||
var normal_func = function () {};
|
var normal_func = function () {};
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.charAt, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.charAt, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.charAt, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.charAt, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.charCodeAt, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.charCodeAt, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.charCodeAt, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.charCodeAt, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.concat, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.concat, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.concat, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.concat, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.indexOf, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.indexOf, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.indexOf, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.indexOf, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.lastIndexOf, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.lastIndexOf, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.lastIndexOf, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.lastIndexOf, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.match, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.match, 'length').configurable === length_configurable());
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.match, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.match, 'length').enumerable === false);
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.match, 'length').writable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.match, 'length').writable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.substr, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.substr, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.substr, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.substr, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.substring, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.substring, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.substring, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.substring, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// check properties
|
// check properties
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.trim, 'length').configurable === false);
|
|
||||||
|
function length_configurable()
|
||||||
|
{
|
||||||
|
function is_es51() {
|
||||||
|
return (typeof g === "function");
|
||||||
|
{ function g() {} }
|
||||||
|
}
|
||||||
|
return is_es51() ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Object.getOwnPropertyDescriptor(String.prototype.trim, 'length').configurable === length_configurable());
|
||||||
|
|
||||||
assert(Object.getOwnPropertyDescriptor(String.prototype.trim, 'length').enumerable === false);
|
assert(Object.getOwnPropertyDescriptor(String.prototype.trim, 'length').enumerable === false);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user