-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
- Loading branch information
Showing
6 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* 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. | ||
*/ | ||
|
||
#include "ecma-array-prototype.h" | ||
|
||
#include "ecma-builtins.h" | ||
#include "ecma-conversion.h" | ||
#include "ecma-function-object.h" | ||
#include "ecma-exceptions.h" | ||
#include "ecma-helpers.h" | ||
#include "ecma-objects.h" | ||
#include "ecma-try-catch-macro.h" | ||
|
||
/** \addtogroup ecma ECMA | ||
* @{ | ||
* | ||
* \addtogroup ecmabuiltins | ||
* @{ | ||
* | ||
* \addtogroup arrayprototype ECMA Array.prototype object built-in operations | ||
* @{ | ||
*/ | ||
|
||
|
||
/** | ||
* The Array.prototype's 'toString' single element operation routine | ||
* | ||
* See also: | ||
* ECMA-262 v5.1, 15.4.4.2 | ||
* | ||
* @return ecma_completion_value_t value | ||
* Returned value must be freed with ecma_free_completion_value. | ||
*/ | ||
ecma_completion_value_t | ||
ecma_op_array_get_to_string_at_index (ecma_object_t *obj_p, /** < this object */ | ||
uint32_t index) /** < array index */ | ||
{ | ||
ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index); | ||
ecma_completion_value_t index_prop_ret = ecma_op_object_get (obj_p, index_string_p); | ||
ecma_deref_ecma_string (index_string_p); | ||
|
||
if (!ecma_is_completion_value_normal (index_prop_ret)) | ||
{ | ||
return index_prop_ret; | ||
} | ||
|
||
ecma_value_t index_prop_value = ecma_get_completion_value_value (index_prop_ret); | ||
|
||
ecma_completion_value_t return_string_completion; | ||
if (ecma_is_value_undefined (index_prop_value) | ||
|| ecma_is_value_null (index_prop_value)) | ||
{ | ||
ecma_string_t *empty_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING__EMPTY); | ||
return_string_completion = ecma_make_normal_completion_value (ecma_make_string_value (empty_string_p)); | ||
ecma_deref_ecma_string (empty_string_p); | ||
} | ||
else | ||
{ | ||
return_string_completion = ecma_op_to_string (index_prop_value); | ||
} | ||
|
||
ecma_free_completion_value (index_prop_ret); | ||
|
||
return return_string_completion; | ||
} /* ecma_op_array_get_to_string_at_index */ | ||
|
||
/** | ||
* @} | ||
* @} | ||
* @} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* 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. | ||
*/ | ||
|
||
#ifndef ECMA_ARRAY_PROTOTYPE_H | ||
#define ECMA_ARRAY_PROTOTYPE_H | ||
|
||
#include "ecma-globals.h" | ||
|
||
/** \addtogroup ecma ECMA | ||
* @{ | ||
* | ||
* \addtogroup ecmaarrayprototypeops ECMA array prototype's operations | ||
* @{ | ||
*/ | ||
|
||
extern ecma_completion_value_t ecma_op_array_get_to_string_at_index (ecma_object_t *obj_p, uint32_t index); | ||
|
||
/** | ||
* @} | ||
* @} | ||
*/ | ||
|
||
#endif /* !ECMA_ARRAY_PROPERTY_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
assert ([].join() === ""); | ||
assert ([1].join() === "1"); | ||
assert ([1, 2].join() === "1,2"); | ||
|
||
|
||
assert ([].join('--') === ""); | ||
assert ([1].join("--") === "1"); | ||
assert ([1, 2].join('--') === "1--2"); | ||
|
||
assert ([1,2,3].join({toString: function() { return "--"; }}) === "1--2--3"); | ||
|
||
|
||
// Join should use 'length' to as the number of elements int the array. | ||
var lst = [1,2,3,4]; | ||
lst.length = 3; | ||
assert (lst.join() === [1,2,3].join()); | ||
|
||
// Checking behavior when unable to get length. | ||
var obj = {}; | ||
Object.defineProperty(obj, 'length', { 'get' : function () {throw new ReferenceError ("foo"); } }); | ||
obj.join = Array.prototype.join; | ||
|
||
try { | ||
obj.join(); | ||
// Should not be reached. | ||
assert (false); | ||
} catch (e) { | ||
assert (e.message === "foo"); | ||
assert (e instanceof ReferenceError); | ||
} | ||
|
||
// Check join argument fail. | ||
try { | ||
[1,2,3].join({toString: function() { throw new ReferenceError ("foo"); }}); | ||
// Should not be reached. | ||
assert (false); | ||
} catch (e) { | ||
assert (e.message === "foo"); | ||
assert (e instanceof ReferenceError); | ||
} | ||
|
||
// Check single join element fail. | ||
try { | ||
[1, 2, {toString: function() { throw new ReferenceError ("foo"); }}, 4].join(); | ||
// Should not be reached. | ||
assert (false); | ||
} catch (e) { | ||
assert (e.message === "foo"); | ||
assert (e instanceof ReferenceError); | ||
} | ||
|
||
// Check join on different object. | ||
var obj_2 = {}; | ||
obj_2.length = 3; | ||
obj_2[0] = 1; | ||
obj_2[1] = 2; | ||
obj_2[2] = 3; | ||
obj_2[3] = 4; | ||
|
||
obj_2.join = Array.prototype.join; | ||
|
||
assert (obj_2.join() === "1,2,3"); |