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