| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 obj_template->SetInternalFieldCount((internal_field+1)*2 + 7); | 107 obj_template->SetInternalFieldCount((internal_field+1)*2 + 7); |
| 108 context->Global()->Set(v8_str(class_name), constructor->GetFunction()); | 108 context->Global()->Set(v8_str(class_name), constructor->GetFunction()); |
| 109 return obj_template; | 109 return obj_template; |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 static void VerifyRead(v8::Handle<v8::DeclaredAccessorDescriptor> descriptor, | 113 static void VerifyRead(v8::Handle<v8::DeclaredAccessorDescriptor> descriptor, |
| 114 int internal_field, | 114 int internal_field, |
| 115 void* internal_object, | 115 void* internal_object, |
| 116 v8::Handle<v8::Value> expected_value) { | 116 v8::Handle<v8::Value> expected_value) { |
| 117 v8::HandleScope scope; | |
| 118 LocalContext local_context; | 117 LocalContext local_context; |
| 118 v8::HandleScope scope(local_context->GetIsolate()); |
| 119 v8::Handle<v8::Context> context = local_context.local(); | 119 v8::Handle<v8::Context> context = local_context.local(); |
| 120 CreateConstructor(context, "Accessible", internal_field, "x", descriptor); | 120 CreateConstructor(context, "Accessible", internal_field, "x", descriptor); |
| 121 // Setup object. | 121 // Setup object. |
| 122 CompileRun("var accessible = new Accessible();"); | 122 CompileRun("var accessible = new Accessible();"); |
| 123 v8::Local<v8::Object> obj( | 123 v8::Local<v8::Object> obj( |
| 124 v8::Object::Cast(*context->Global()->Get(v8_str("accessible")))); | 124 v8::Object::Cast(*context->Global()->Get(v8_str("accessible")))); |
| 125 obj->SetAlignedPointerInInternalField(internal_field, internal_object); | 125 obj->SetAlignedPointerInInternalField(internal_field, internal_object); |
| 126 bool added_accessor; | 126 bool added_accessor; |
| 127 added_accessor = obj->SetAccessor(v8_str("y"), descriptor); | 127 added_accessor = obj->SetAccessor(v8_str("y"), descriptor); |
| 128 CHECK(added_accessor); | 128 CHECK(added_accessor); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 typedef v8::ObjectOperationDescriptor OOD; | 164 typedef v8::ObjectOperationDescriptor OOD; |
| 165 | 165 |
| 166 template<typename T> | 166 template<typename T> |
| 167 static void TestPrimitiveValue( | 167 static void TestPrimitiveValue( |
| 168 T value, | 168 T value, |
| 169 v8::DeclaredAccessorDescriptorDataType data_type, | 169 v8::DeclaredAccessorDescriptorDataType data_type, |
| 170 DescriptorTestHelper* helper) { | 170 DescriptorTestHelper* helper) { |
| 171 v8::HandleScope handle_scope; | 171 v8::HandleScope handle_scope(helper->isolate_); |
| 172 int index = 17; | 172 int index = 17; |
| 173 int internal_field = 6; | 173 int internal_field = 6; |
| 174 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = | 174 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = |
| 175 OOD::NewInternalFieldDereference(helper->isolate_, internal_field) | 175 OOD::NewInternalFieldDereference(helper->isolate_, internal_field) |
| 176 ->NewRawShift(helper->isolate_, static_cast<uint16_t>(index*sizeof(T))) | 176 ->NewRawShift(helper->isolate_, static_cast<uint16_t>(index*sizeof(T))) |
| 177 ->NewPrimitiveValue(helper->isolate_, data_type, 0); | 177 ->NewPrimitiveValue(helper->isolate_, data_type, 0); |
| 178 v8::Handle<v8::Value> expected = Convert(value, helper->isolate_); | 178 v8::Handle<v8::Value> expected = Convert(value, helper->isolate_); |
| 179 helper->array_->Reset(); | 179 helper->array_->Reset(); |
| 180 helper->array_->As<T*>()[index] = value; | 180 helper->array_->As<T*>()[index] = value; |
| 181 VerifyRead(descriptor, internal_field, *helper->array_, expected); | 181 VerifyRead(descriptor, internal_field, *helper->array_, expected); |
| 182 } | 182 } |
| 183 | 183 |
| 184 | 184 |
| 185 TEST(PrimitiveValueRead) { | 185 TEST(PrimitiveValueRead) { |
| 186 DescriptorTestHelper helper; | 186 DescriptorTestHelper helper; |
| 187 TestPrimitiveValue<int32_t>(203, v8::kDescriptorInt32Type, &helper); | 187 TestPrimitiveValue<int32_t>(203, v8::kDescriptorInt32Type, &helper); |
| 188 TestPrimitiveValue<float>(23.7f, v8::kDescriptorFloatType, &helper); | 188 TestPrimitiveValue<float>(23.7f, v8::kDescriptorFloatType, &helper); |
| 189 TestPrimitiveValue<double>(23.7, v8::kDescriptorDoubleType, &helper); | 189 TestPrimitiveValue<double>(23.7, v8::kDescriptorDoubleType, &helper); |
| 190 } | 190 } |
| 191 | 191 |
| 192 | 192 |
| 193 template<typename T> | 193 template<typename T> |
| 194 static void TestBitmaskCompare(T bitmask, | 194 static void TestBitmaskCompare(T bitmask, |
| 195 T compare_value, | 195 T compare_value, |
| 196 DescriptorTestHelper* helper) { | 196 DescriptorTestHelper* helper) { |
| 197 v8::HandleScope handle_scope; | 197 v8::HandleScope handle_scope(helper->isolate_); |
| 198 int index = 13; | 198 int index = 13; |
| 199 int internal_field = 4; | 199 int internal_field = 4; |
| 200 v8::Handle<v8::RawOperationDescriptor> raw_descriptor = | 200 v8::Handle<v8::RawOperationDescriptor> raw_descriptor = |
| 201 OOD::NewInternalFieldDereference(helper->isolate_, internal_field) | 201 OOD::NewInternalFieldDereference(helper->isolate_, internal_field) |
| 202 ->NewRawShift(helper->isolate_, static_cast<uint16_t>(index*sizeof(T))); | 202 ->NewRawShift(helper->isolate_, static_cast<uint16_t>(index*sizeof(T))); |
| 203 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor; | 203 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor; |
| 204 switch (sizeof(T)) { | 204 switch (sizeof(T)) { |
| 205 case 1: | 205 case 1: |
| 206 descriptor = raw_descriptor->NewBitmaskCompare8( | 206 descriptor = raw_descriptor->NewBitmaskCompare8( |
| 207 helper->isolate_, | 207 helper->isolate_, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 237 TEST(BitmaskCompareRead) { | 237 TEST(BitmaskCompareRead) { |
| 238 DescriptorTestHelper helper; | 238 DescriptorTestHelper helper; |
| 239 TestBitmaskCompare<uint8_t>(0xf3, 0xa8, &helper); | 239 TestBitmaskCompare<uint8_t>(0xf3, 0xa8, &helper); |
| 240 TestBitmaskCompare<uint16_t>(0xfefe, 0x7d42, &helper); | 240 TestBitmaskCompare<uint16_t>(0xfefe, 0x7d42, &helper); |
| 241 TestBitmaskCompare<uint32_t>(0xfefeab18, 0x1234fdec, &helper); | 241 TestBitmaskCompare<uint32_t>(0xfefeab18, 0x1234fdec, &helper); |
| 242 } | 242 } |
| 243 | 243 |
| 244 | 244 |
| 245 TEST(PointerCompareRead) { | 245 TEST(PointerCompareRead) { |
| 246 DescriptorTestHelper helper; | 246 DescriptorTestHelper helper; |
| 247 v8::HandleScope handle_scope; | 247 v8::HandleScope handle_scope(helper.isolate_); |
| 248 int index = 35; | 248 int index = 35; |
| 249 int internal_field = 3; | 249 int internal_field = 3; |
| 250 void* ptr = helper.isolate_; | 250 void* ptr = helper.isolate_; |
| 251 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = | 251 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = |
| 252 OOD::NewInternalFieldDereference(helper.isolate_, internal_field) | 252 OOD::NewInternalFieldDereference(helper.isolate_, internal_field) |
| 253 ->NewRawShift(helper.isolate_, static_cast<uint16_t>(index*sizeof(ptr))) | 253 ->NewRawShift(helper.isolate_, static_cast<uint16_t>(index*sizeof(ptr))) |
| 254 ->NewPointerCompare(helper.isolate_, ptr); | 254 ->NewPointerCompare(helper.isolate_, ptr); |
| 255 AlignedArray* array = *helper.array_; | 255 AlignedArray* array = *helper.array_; |
| 256 VerifyRead(descriptor, internal_field, array, v8::False(helper.isolate_)); | 256 VerifyRead(descriptor, internal_field, array, v8::False(helper.isolate_)); |
| 257 array->As<uintptr_t*>()[index] = reinterpret_cast<uintptr_t>(ptr); | 257 array->As<uintptr_t*>()[index] = reinterpret_cast<uintptr_t>(ptr); |
| 258 VerifyRead(descriptor, internal_field, array, v8::True(helper.isolate_)); | 258 VerifyRead(descriptor, internal_field, array, v8::True(helper.isolate_)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 | 261 |
| 262 TEST(PointerDereferenceRead) { | 262 TEST(PointerDereferenceRead) { |
| 263 DescriptorTestHelper helper; | 263 DescriptorTestHelper helper; |
| 264 v8::HandleScope handle_scope; | 264 v8::HandleScope handle_scope(helper.isolate_); |
| 265 int first_index = 13; | 265 int first_index = 13; |
| 266 int internal_field = 7; | 266 int internal_field = 7; |
| 267 int second_index = 11; | 267 int second_index = 11; |
| 268 int pointed_to_index = 75; | 268 int pointed_to_index = 75; |
| 269 uint16_t expected = 0x1425; | 269 uint16_t expected = 0x1425; |
| 270 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = | 270 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = |
| 271 OOD::NewInternalFieldDereference(helper.isolate_, internal_field) | 271 OOD::NewInternalFieldDereference(helper.isolate_, internal_field) |
| 272 ->NewRawShift(helper.isolate_, first_index*kPointerSize) | 272 ->NewRawShift(helper.isolate_, first_index*kPointerSize) |
| 273 ->NewRawDereference(helper.isolate_) | 273 ->NewRawDereference(helper.isolate_) |
| 274 ->NewRawShift(helper.isolate_, | 274 ->NewRawShift(helper.isolate_, |
| 275 static_cast<uint16_t>(second_index*sizeof(int16_t))) | 275 static_cast<uint16_t>(second_index*sizeof(int16_t))) |
| 276 ->NewPrimitiveValue(helper.isolate_, v8::kDescriptorInt16Type, 0); | 276 ->NewPrimitiveValue(helper.isolate_, v8::kDescriptorInt16Type, 0); |
| 277 AlignedArray* array = *helper.array_; | 277 AlignedArray* array = *helper.array_; |
| 278 array->As<uintptr_t**>()[first_index] = | 278 array->As<uintptr_t**>()[first_index] = |
| 279 &array->As<uintptr_t*>()[pointed_to_index]; | 279 &array->As<uintptr_t*>()[pointed_to_index]; |
| 280 VerifyRead(descriptor, internal_field, array, v8::Integer::New(0)); | 280 VerifyRead(descriptor, internal_field, array, v8::Integer::New(0)); |
| 281 second_index += pointed_to_index*sizeof(uintptr_t)/sizeof(uint16_t); | 281 second_index += pointed_to_index*sizeof(uintptr_t)/sizeof(uint16_t); |
| 282 array->As<uint16_t*>()[second_index] = expected; | 282 array->As<uint16_t*>()[second_index] = expected; |
| 283 VerifyRead(descriptor, internal_field, array, v8::Integer::New(expected)); | 283 VerifyRead(descriptor, internal_field, array, v8::Integer::New(expected)); |
| 284 } | 284 } |
| 285 | 285 |
| 286 | 286 |
| 287 TEST(HandleDereferenceRead) { | 287 TEST(HandleDereferenceRead) { |
| 288 DescriptorTestHelper helper; | 288 DescriptorTestHelper helper; |
| 289 v8::HandleScope handle_scope; | 289 v8::HandleScope handle_scope(helper.isolate_); |
| 290 int index = 13; | 290 int index = 13; |
| 291 int internal_field = 0; | 291 int internal_field = 0; |
| 292 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = | 292 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor = |
| 293 OOD::NewInternalFieldDereference(helper.isolate_, internal_field) | 293 OOD::NewInternalFieldDereference(helper.isolate_, internal_field) |
| 294 ->NewRawShift(helper.isolate_, index*kPointerSize) | 294 ->NewRawShift(helper.isolate_, index*kPointerSize) |
| 295 ->NewHandleDereference(helper.isolate_); | 295 ->NewHandleDereference(helper.isolate_); |
| 296 HandleArray* array = *helper.handle_array_; | 296 HandleArray* array = *helper.handle_array_; |
| 297 v8::Handle<v8::String> expected = v8_str("whatever"); | 297 v8::Handle<v8::String> expected = v8_str("whatever"); |
| 298 array->handles_[index] = v8::Persistent<v8::Value>::New(helper.isolate_, | 298 array->handles_[index] = v8::Persistent<v8::Value>::New(helper.isolate_, |
| 299 expected); | 299 expected); |
| 300 VerifyRead(descriptor, internal_field, array, expected); | 300 VerifyRead(descriptor, internal_field, array, expected); |
| 301 } | 301 } |
| 302 | |
| OLD | NEW |