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