@@ -767,6 +767,230 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
767
767
return ret_val ;
768
768
} /* ecma_builtin_typedarray_prototype_set */
769
769
770
+ /**
771
+ * TypedArray.prototype's 'toString' single element operation routine based
772
+ * on the Array.prototype's 'toString' single element operation routine
773
+ *
774
+ * See also:
775
+ * ECMA-262 v5.1, 15.4.4.2
776
+ *
777
+ * @return ecma_value_t value
778
+ * Returned value must be freed with ecma_free_value.
779
+ */
780
+ static ecma_value_t
781
+ ecma_op_typedarray_get_to_string_at_index (ecma_object_t * obj_p , /**< this object */
782
+ uint32_t index ) /**< array index */
783
+ {
784
+ ecma_value_t ret_value = ECMA_VALUE_EMPTY ;
785
+ ecma_string_t * index_string_p = ecma_new_ecma_string_from_uint32 (index );
786
+ ecma_value_t index_value = ecma_op_object_get (obj_p , index_string_p );
787
+
788
+ if (ECMA_IS_VALUE_ERROR (index_value ))
789
+ {
790
+ ecma_deref_ecma_string (index_string_p );
791
+ return index_value ;
792
+ }
793
+
794
+ if (ecma_is_value_undefined (index_value )
795
+ || ecma_is_value_null (index_value ))
796
+ {
797
+ ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY );
798
+ }
799
+ else
800
+ {
801
+ ret_value = ecma_op_to_string (index_value );
802
+ }
803
+
804
+ ecma_free_value (index_value );
805
+ ecma_deref_ecma_string (index_string_p );
806
+ return ret_value ;
807
+ } /* ecma_op_typedarray_get_to_string_at_index */
808
+
809
+ /**
810
+ * The TypedArray.prototype.toString's separator creation routine based on
811
+ * the Array.prototype.toString's separator routine
812
+ *
813
+ * See also:
814
+ * ECMA-262 v5.1, 15.4.4.2 4th step
815
+ *
816
+ * @return ecma value
817
+ * Returned value must be freed with ecma_free_value.
818
+ */
819
+ static ecma_value_t
820
+ ecma_op_typedarray_get_separator_string (ecma_value_t separator ) /**< possible separator */
821
+ {
822
+ if (ecma_is_value_undefined (separator ))
823
+ {
824
+ return ecma_make_magic_string_value (LIT_MAGIC_STRING_COMMA_CHAR );
825
+ }
826
+
827
+ return ecma_op_to_string (separator );
828
+ } /* ecma_op_typedarray_get_separator_string */
829
+
830
+ /**
831
+ * The TypedArray.prototype object's 'join' routine basen on
832
+ * the Array.porottype object's 'join'
833
+ *
834
+ * See also:
835
+ * ECMA-262 v5, 15.4.4.5
836
+ *
837
+ * @return ecma value
838
+ * Returned value must be freed with ecma_free_value.
839
+ */
840
+ static ecma_value_t
841
+ ecma_builtin_typedarray_prototype_join (const ecma_value_t this_arg , /**< this argument */
842
+ const ecma_value_t separator_arg ) /**< separator argument */
843
+ {
844
+ /* 1. */
845
+ ecma_value_t obj_value = ecma_op_to_object (this_arg );
846
+
847
+ if (ECMA_IS_VALUE_ERROR (obj_value ))
848
+ {
849
+ return obj_value ;
850
+ }
851
+ ecma_object_t * obj_p = ecma_get_object_from_value (obj_value );
852
+
853
+ /* 2. */
854
+ ecma_value_t length_value = ecma_op_object_get_by_magic_id (obj_p , LIT_MAGIC_STRING_LENGTH );
855
+
856
+ if (ECMA_IS_VALUE_ERROR (length_value ))
857
+ {
858
+ ecma_free_value (obj_value );
859
+ return length_value ;
860
+ }
861
+
862
+ ecma_value_t ret_value = ECMA_VALUE_EMPTY ;
863
+
864
+ ECMA_OP_TO_NUMBER_TRY_CATCH (length_number ,
865
+ length_value ,
866
+ ret_value );
867
+
868
+ /* 3. */
869
+ uint32_t length = ecma_number_to_uint32 (length_number );
870
+ ECMA_OP_TO_NUMBER_FINALIZE (length_number );
871
+ /* 4-5. */
872
+ ecma_value_t separator_value = ecma_op_typedarray_get_separator_string (separator_arg );
873
+ if (ECMA_IS_VALUE_ERROR (separator_value ))
874
+ {
875
+ ecma_free_value (length_value );
876
+ ecma_free_value (obj_value );
877
+ return separator_value ;
878
+ }
879
+
880
+ if (length == 0 )
881
+ {
882
+ /* 6. */
883
+ ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY );
884
+ }
885
+ else
886
+ {
887
+ ecma_string_t * separator_string_p = ecma_get_string_from_value (separator_value );
888
+
889
+ /* 7-8. */
890
+ ecma_value_t first_value = ecma_op_typedarray_get_to_string_at_index (obj_p , 0 );
891
+ if (ECMA_IS_VALUE_ERROR (first_value ))
892
+ {
893
+ ecma_free_value (separator_value );
894
+ ecma_free_value (length_value );
895
+ ecma_free_value (obj_value );
896
+ return first_value ;
897
+ }
898
+
899
+ ecma_string_t * return_string_p = ecma_get_string_from_value (first_value );
900
+ ecma_ref_ecma_string (return_string_p );
901
+ if (ecma_is_value_empty (ret_value ))
902
+ {
903
+ /* 9-10. */
904
+ for (uint32_t k = 1 ; k < length ; k ++ )
905
+ {
906
+ /* 10.a */
907
+ return_string_p = ecma_concat_ecma_strings (return_string_p , separator_string_p );
908
+
909
+ /* 10.b, 10.c */
910
+ ecma_value_t next_string_value = ecma_op_typedarray_get_to_string_at_index (obj_p , k );
911
+ if (ECMA_IS_VALUE_ERROR (next_string_value ))
912
+ {
913
+ ecma_free_value (first_value );
914
+ ecma_free_value (separator_value );
915
+ ecma_free_value (length_value );
916
+ ecma_free_value (obj_value );
917
+ return next_string_value ;
918
+ }
919
+
920
+ /* 10.d */
921
+ ecma_string_t * next_string_p = ecma_get_string_from_value (next_string_value );
922
+ return_string_p = ecma_concat_ecma_strings (return_string_p , next_string_p );
923
+
924
+ ecma_free_value (next_string_value );
925
+ }
926
+ ret_value = ecma_make_string_value (return_string_p );
927
+ }
928
+ else
929
+ {
930
+ ecma_deref_ecma_string (return_string_p );
931
+ }
932
+
933
+ ecma_free_value (first_value );
934
+ }
935
+
936
+ ecma_free_value (separator_value );
937
+
938
+ ecma_free_value (length_value );
939
+ ecma_free_value (obj_value );
940
+
941
+ return ret_value ;
942
+ } /* ecma_builtin_typedarray_prototype_join */
943
+
944
+ /**
945
+ * The TypedArray.prototype object's 'toString' routine basen on
946
+ * the Array.porottype object's 'toString'
947
+ *
948
+ * See also:
949
+ * ECMA-262 v5, 15.4.4.2
950
+ *
951
+ * @return ecma value
952
+ * Returned value must be freed with ecma_free_value.
953
+ */
954
+ static ecma_value_t
955
+ ecma_builtin_typedarray_prototype_object_to_string (ecma_value_t this_arg ) /**< this argument */
956
+ {
957
+ ecma_value_t ret_value = ECMA_VALUE_EMPTY ;
958
+
959
+ /* 1. */
960
+ ecma_value_t obj_this_value = ecma_op_to_object (this_arg );
961
+ if (ECMA_IS_VALUE_ERROR (obj_this_value ))
962
+ {
963
+ return obj_this_value ;
964
+ }
965
+ ecma_object_t * obj_p = ecma_get_object_from_value (obj_this_value );
966
+
967
+ /* 2. */
968
+ ecma_value_t join_value = ecma_op_object_get_by_magic_id (obj_p , LIT_MAGIC_STRING_JOIN );
969
+ if (ECMA_IS_VALUE_ERROR (join_value ))
970
+ {
971
+ ecma_free_value (obj_this_value );
972
+ return join_value ;
973
+ }
974
+
975
+ if (!ecma_op_is_callable (join_value ))
976
+ {
977
+ /* 3. */
978
+ ret_value = ecma_builtin_helper_object_to_string (this_arg );
979
+ }
980
+ else
981
+ {
982
+ /* 4. */
983
+ ecma_object_t * join_func_obj_p = ecma_get_object_from_value (join_value );
984
+
985
+ ret_value = ecma_op_function_call (join_func_obj_p , this_arg , NULL , 0 );
986
+ }
987
+
988
+ ecma_free_value (join_value );
989
+ ecma_free_value (obj_this_value );
990
+
991
+ return ret_value ;
992
+ } /* ecma_builtin_typedarray_prototype_object_to_string */
993
+
770
994
/**
771
995
* @}
772
996
* @}
0 commit comments