OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #include "src/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 3046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 // 15. Set O's [[ByteLength]] internal slot to viewByteLength. | 3057 // 15. Set O's [[ByteLength]] internal slot to viewByteLength. |
3058 Handle<JSDataView>::cast(result)->set_byte_length(*view_byte_length); | 3058 Handle<JSDataView>::cast(result)->set_byte_length(*view_byte_length); |
3059 | 3059 |
3060 // 16. Set O's [[ByteOffset]] internal slot to offset. | 3060 // 16. Set O's [[ByteOffset]] internal slot to offset. |
3061 Handle<JSDataView>::cast(result)->set_byte_offset(*offset); | 3061 Handle<JSDataView>::cast(result)->set_byte_offset(*offset); |
3062 | 3062 |
3063 // 17. Return O. | 3063 // 17. Return O. |
3064 return *result; | 3064 return *result; |
3065 } | 3065 } |
3066 | 3066 |
| 3067 // ES6 section 24.2.4.1 get DataView.prototype.buffer |
| 3068 BUILTIN(DataViewPrototypeGetBuffer) { |
| 3069 HandleScope scope(isolate); |
| 3070 CHECK_RECEIVER(JSDataView, data_view, "get DataView.prototype.buffer"); |
| 3071 return data_view->buffer(); |
| 3072 } |
| 3073 |
| 3074 // ES6 section 24.2.4.2 get DataView.prototype.byteLength |
| 3075 BUILTIN(DataViewPrototypeGetByteLength) { |
| 3076 HandleScope scope(isolate); |
| 3077 CHECK_RECEIVER(JSDataView, data_view, "get DataView.prototype.byteLength"); |
| 3078 // TODO(bmeurer): According to the ES6 spec, we should throw a TypeError |
| 3079 // here if the JSArrayBuffer of the {data_view} was neutered. |
| 3080 return data_view->byte_length(); |
| 3081 } |
| 3082 |
| 3083 // ES6 section 24.2.4.3 get DataView.prototype.byteOffset |
| 3084 BUILTIN(DataViewPrototypeGetByteOffset) { |
| 3085 HandleScope scope(isolate); |
| 3086 CHECK_RECEIVER(JSDataView, data_view, "get DataView.prototype.byteOffset"); |
| 3087 // TODO(bmeurer): According to the ES6 spec, we should throw a TypeError |
| 3088 // here if the JSArrayBuffer of the {data_view} was neutered. |
| 3089 return data_view->byte_offset(); |
| 3090 } |
| 3091 |
| 3092 // ----------------------------------------------------------------------------- |
| 3093 // ES6 section 22.2 TypedArray Objects |
| 3094 |
| 3095 // ES6 section 22.2.3.1 get %TypedArray%.prototype.buffer |
| 3096 BUILTIN(TypedArrayPrototypeBuffer) { |
| 3097 HandleScope scope(isolate); |
| 3098 CHECK_RECEIVER(JSTypedArray, typed_array, "get TypedArray.prototype.buffer"); |
| 3099 return *typed_array->GetBuffer(); |
| 3100 } |
| 3101 |
| 3102 namespace { |
| 3103 |
| 3104 void Generate_TypedArrayProtoypeGetter(CodeStubAssembler* assembler, |
| 3105 const char* method_name, |
| 3106 int object_offset) { |
| 3107 typedef CodeStubAssembler::Label Label; |
| 3108 typedef compiler::Node Node; |
| 3109 |
| 3110 Node* receiver = assembler->Parameter(0); |
| 3111 Node* context = assembler->Parameter(3); |
| 3112 |
| 3113 // Check if the {receiver} is actually a JSTypedArray. |
| 3114 Label if_receiverisincompatible(assembler, Label::kDeferred); |
| 3115 assembler->GotoIf(assembler->WordIsSmi(receiver), &if_receiverisincompatible); |
| 3116 Node* receiver_instance_type = assembler->LoadInstanceType(receiver); |
| 3117 assembler->GotoUnless( |
| 3118 assembler->Word32Equal(receiver_instance_type, |
| 3119 assembler->Int32Constant(JS_TYPED_ARRAY_TYPE)), |
| 3120 &if_receiverisincompatible); |
| 3121 |
| 3122 // Check if the {receiver}'s JSArrayBuffer was neutered. |
| 3123 Node* receiver_buffer = |
| 3124 assembler->LoadObjectField(receiver, JSTypedArray::kBufferOffset); |
| 3125 Node* receiver_buffer_bit_field = assembler->LoadObjectField( |
| 3126 receiver_buffer, JSArrayBuffer::kBitFieldOffset, MachineType::Int8()); |
| 3127 Label if_receiverisneutered(assembler, Label::kDeferred); |
| 3128 assembler->GotoUnless( |
| 3129 assembler->Word32Equal( |
| 3130 assembler->Word32And( |
| 3131 receiver_buffer_bit_field, |
| 3132 assembler->Int32Constant(JSArrayBuffer::WasNeutered::kMask)), |
| 3133 assembler->Int32Constant(0)), |
| 3134 &if_receiverisneutered); |
| 3135 assembler->Return(assembler->LoadObjectField(receiver, object_offset)); |
| 3136 |
| 3137 assembler->Bind(&if_receiverisneutered); |
| 3138 { |
| 3139 // The {receiver}s buffer was neutered, default to zero. |
| 3140 assembler->Return(assembler->SmiConstant(0)); |
| 3141 } |
| 3142 |
| 3143 assembler->Bind(&if_receiverisincompatible); |
| 3144 { |
| 3145 // The {receiver} is not a valid JSGeneratorObject. |
| 3146 Node* result = assembler->CallRuntime( |
| 3147 Runtime::kThrowIncompatibleMethodReceiver, context, |
| 3148 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( |
| 3149 method_name, TENURED)), |
| 3150 receiver); |
| 3151 assembler->Return(result); // Never reached. |
| 3152 } |
| 3153 } |
| 3154 |
| 3155 } // namespace |
| 3156 |
| 3157 // ES6 section 22.2.3.2 get %TypedArray%.prototype.byteLength |
| 3158 void Builtins::Generate_TypedArrayPrototypeByteLength( |
| 3159 CodeStubAssembler* assembler) { |
| 3160 Generate_TypedArrayProtoypeGetter(assembler, |
| 3161 "get TypedArray.prototype.byteLength", |
| 3162 JSTypedArray::kByteLengthOffset); |
| 3163 } |
| 3164 |
| 3165 // ES6 section 22.2.3.3 get %TypedArray%.prototype.byteOffset |
| 3166 void Builtins::Generate_TypedArrayPrototypeByteOffset( |
| 3167 CodeStubAssembler* assembler) { |
| 3168 Generate_TypedArrayProtoypeGetter(assembler, |
| 3169 "get TypedArray.prototype.byteOffset", |
| 3170 JSTypedArray::kByteOffsetOffset); |
| 3171 } |
| 3172 |
| 3173 // ES6 section 22.2.3.18 get %TypedArray%.prototype.length |
| 3174 void Builtins::Generate_TypedArrayPrototypeLength( |
| 3175 CodeStubAssembler* assembler) { |
| 3176 Generate_TypedArrayProtoypeGetter(assembler, |
| 3177 "get TypedArray.prototype.length", |
| 3178 JSTypedArray::kLengthOffset); |
| 3179 } |
3067 | 3180 |
3068 // ----------------------------------------------------------------------------- | 3181 // ----------------------------------------------------------------------------- |
3069 // ES6 section 20.3 Date Objects | 3182 // ES6 section 20.3 Date Objects |
3070 | 3183 |
3071 | 3184 |
3072 namespace { | 3185 namespace { |
3073 | 3186 |
3074 // ES6 section 20.3.1.1 Time Values and Time Range | 3187 // ES6 section 20.3.1.1 Time Values and Time Range |
3075 const double kMinYear = -1000000.0; | 3188 const double kMinYear = -1000000.0; |
3076 const double kMaxYear = -kMinYear; | 3189 const double kMaxYear = -kMinYear; |
(...skipping 2730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5807 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5920 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5808 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5921 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5809 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5922 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5810 #undef DEFINE_BUILTIN_ACCESSOR_C | 5923 #undef DEFINE_BUILTIN_ACCESSOR_C |
5811 #undef DEFINE_BUILTIN_ACCESSOR_A | 5924 #undef DEFINE_BUILTIN_ACCESSOR_A |
5812 #undef DEFINE_BUILTIN_ACCESSOR_T | 5925 #undef DEFINE_BUILTIN_ACCESSOR_T |
5813 #undef DEFINE_BUILTIN_ACCESSOR_H | 5926 #undef DEFINE_BUILTIN_ACCESSOR_H |
5814 | 5927 |
5815 } // namespace internal | 5928 } // namespace internal |
5816 } // namespace v8 | 5929 } // namespace v8 |
OLD | NEW |