OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 READ_ONLY | DONT_ENUM | DONT_DELETE); | 840 READ_ONLY | DONT_ENUM | DONT_DELETE); |
841 // TODO(littledan): Remove this performance workaround BUG(chromium:579905) | 841 // TODO(littledan): Remove this performance workaround BUG(chromium:579905) |
842 utils.InstallGetter(GlobalNAME.prototype, "length", NAME_GetLength, | 842 utils.InstallGetter(GlobalNAME.prototype, "length", NAME_GetLength, |
843 DONT_ENUM | DONT_DELETE); | 843 DONT_ENUM | DONT_DELETE); |
844 endmacro | 844 endmacro |
845 | 845 |
846 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 846 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
847 | 847 |
848 // --------------------------- DataView ----------------------------- | 848 // --------------------------- DataView ----------------------------- |
849 | 849 |
850 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | |
851 if (IS_UNDEFINED(new.target)) { | |
852 throw MakeTypeError(kConstructorNotFunction, "DataView"); | |
853 } | |
854 | |
855 // TODO(binji): support SharedArrayBuffers? | |
856 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer); | |
857 if (!IS_UNDEFINED(byteOffset)) { | |
858 byteOffset = ToPositiveInteger(byteOffset, kInvalidDataViewOffset); | |
859 } | |
860 if (!IS_UNDEFINED(byteLength)) { | |
861 byteLength = TO_INTEGER(byteLength); | |
862 } | |
863 | |
864 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); | |
865 | |
866 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; | |
867 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset); | |
868 | |
869 var length = IS_UNDEFINED(byteLength) | |
870 ? bufferByteLength - offset | |
871 : byteLength; | |
872 if (length < 0 || offset + length > bufferByteLength) { | |
873 throw new MakeRangeError(kInvalidDataViewLength); | |
874 } | |
875 var result = %NewObject(GlobalDataView, new.target); | |
876 %_DataViewInitialize(result, buffer, offset, length); | |
877 return result; | |
878 } | |
879 | |
880 function DataViewGetBufferJS() { | 850 function DataViewGetBufferJS() { |
881 if (!IS_DATAVIEW(this)) { | 851 if (!IS_DATAVIEW(this)) { |
882 throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this); | 852 throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this); |
883 } | 853 } |
884 return %DataViewGetBuffer(this); | 854 return %DataViewGetBuffer(this); |
885 } | 855 } |
886 | 856 |
887 function DataViewGetByteOffset() { | 857 function DataViewGetByteOffset() { |
888 if (!IS_DATAVIEW(this)) { | 858 if (!IS_DATAVIEW(this)) { |
889 throw MakeTypeError(kIncompatibleMethodReceiver, | 859 throw MakeTypeError(kIncompatibleMethodReceiver, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 if (arguments.length < 2) throw MakeTypeError(kInvalidArgument); | 902 if (arguments.length < 2) throw MakeTypeError(kInvalidArgument); |
933 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); | 903 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
934 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); | 904 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); |
935 } | 905 } |
936 %FunctionSetLength(DataViewSetTYPENAMEJS, 2); | 906 %FunctionSetLength(DataViewSetTYPENAMEJS, 2); |
937 endmacro | 907 endmacro |
938 | 908 |
939 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) | 909 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
940 | 910 |
941 // Setup the DataView constructor. | 911 // Setup the DataView constructor. |
942 %SetCode(GlobalDataView, DataViewConstructor); | |
943 %FunctionSetPrototype(GlobalDataView, new GlobalObject); | 912 %FunctionSetPrototype(GlobalDataView, new GlobalObject); |
944 | 913 |
945 // Set up constructor property on the DataView prototype. | 914 // Set up constructor property on the DataView prototype. |
946 %AddNamedProperty(GlobalDataView.prototype, "constructor", GlobalDataView, | 915 %AddNamedProperty(GlobalDataView.prototype, "constructor", GlobalDataView, |
947 DONT_ENUM); | 916 DONT_ENUM); |
948 %AddNamedProperty(GlobalDataView.prototype, toStringTagSymbol, "DataView", | 917 %AddNamedProperty(GlobalDataView.prototype, toStringTagSymbol, "DataView", |
949 READ_ONLY|DONT_ENUM); | 918 READ_ONLY|DONT_ENUM); |
950 | 919 |
951 utils.InstallGetter(GlobalDataView.prototype, "buffer", DataViewGetBufferJS); | 920 utils.InstallGetter(GlobalDataView.prototype, "buffer", DataViewGetBufferJS); |
952 utils.InstallGetter(GlobalDataView.prototype, "byteOffset", | 921 utils.InstallGetter(GlobalDataView.prototype, "byteOffset", |
(...skipping 21 matching lines...) Expand all Loading... |
974 "setUint32", DataViewSetUint32JS, | 943 "setUint32", DataViewSetUint32JS, |
975 | 944 |
976 "getFloat32", DataViewGetFloat32JS, | 945 "getFloat32", DataViewGetFloat32JS, |
977 "setFloat32", DataViewSetFloat32JS, | 946 "setFloat32", DataViewSetFloat32JS, |
978 | 947 |
979 "getFloat64", DataViewGetFloat64JS, | 948 "getFloat64", DataViewGetFloat64JS, |
980 "setFloat64", DataViewSetFloat64JS | 949 "setFloat64", DataViewSetFloat64JS |
981 ]); | 950 ]); |
982 | 951 |
983 }) | 952 }) |
OLD | NEW |