Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: src/objects.cc

Issue 834443004: remove declarative accessors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <sstream> 5 #include <sstream>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/allocation-site-scopes.h" 10 #include "src/allocation-site-scopes.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 for (Object* type = fun->shared()->function_data(); 227 for (Object* type = fun->shared()->function_data();
228 type->IsFunctionTemplateInfo(); 228 type->IsFunctionTemplateInfo();
229 type = FunctionTemplateInfo::cast(type)->parent_template()) { 229 type = FunctionTemplateInfo::cast(type)->parent_template()) {
230 if (type == this) return true; 230 if (type == this) return true;
231 } 231 }
232 // Didn't find the required type in the inheritance chain. 232 // Didn't find the required type in the inheritance chain.
233 return false; 233 return false;
234 } 234 }
235 235
236 236
237 template<typename To>
238 static inline To* CheckedCast(void *from) {
239 uintptr_t temp = reinterpret_cast<uintptr_t>(from);
240 DCHECK(temp % sizeof(To) == 0);
241 return reinterpret_cast<To*>(temp);
242 }
243
244
245 static Handle<Object> PerformCompare(const BitmaskCompareDescriptor& descriptor,
246 char* ptr,
247 Isolate* isolate) {
248 uint32_t bitmask = descriptor.bitmask;
249 uint32_t compare_value = descriptor.compare_value;
250 uint32_t value;
251 switch (descriptor.size) {
252 case 1:
253 value = static_cast<uint32_t>(*CheckedCast<uint8_t>(ptr));
254 compare_value &= 0xff;
255 bitmask &= 0xff;
256 break;
257 case 2:
258 value = static_cast<uint32_t>(*CheckedCast<uint16_t>(ptr));
259 compare_value &= 0xffff;
260 bitmask &= 0xffff;
261 break;
262 case 4:
263 value = *CheckedCast<uint32_t>(ptr);
264 break;
265 default:
266 UNREACHABLE();
267 return isolate->factory()->undefined_value();
268 }
269 return isolate->factory()->ToBoolean(
270 (bitmask & value) == (bitmask & compare_value));
271 }
272
273
274 static Handle<Object> PerformCompare(const PointerCompareDescriptor& descriptor,
275 char* ptr,
276 Isolate* isolate) {
277 uintptr_t compare_value =
278 reinterpret_cast<uintptr_t>(descriptor.compare_value);
279 uintptr_t value = *CheckedCast<uintptr_t>(ptr);
280 return isolate->factory()->ToBoolean(compare_value == value);
281 }
282
283
284 static Handle<Object> GetPrimitiveValue(
285 const PrimitiveValueDescriptor& descriptor,
286 char* ptr,
287 Isolate* isolate) {
288 int32_t int32_value = 0;
289 switch (descriptor.data_type) {
290 case kDescriptorInt8Type:
291 int32_value = *CheckedCast<int8_t>(ptr);
292 break;
293 case kDescriptorUint8Type:
294 int32_value = *CheckedCast<uint8_t>(ptr);
295 break;
296 case kDescriptorInt16Type:
297 int32_value = *CheckedCast<int16_t>(ptr);
298 break;
299 case kDescriptorUint16Type:
300 int32_value = *CheckedCast<uint16_t>(ptr);
301 break;
302 case kDescriptorInt32Type:
303 int32_value = *CheckedCast<int32_t>(ptr);
304 break;
305 case kDescriptorUint32Type: {
306 uint32_t value = *CheckedCast<uint32_t>(ptr);
307 AllowHeapAllocation allow_gc;
308 return isolate->factory()->NewNumberFromUint(value);
309 }
310 case kDescriptorBoolType: {
311 uint8_t byte = *CheckedCast<uint8_t>(ptr);
312 return isolate->factory()->ToBoolean(
313 byte & (0x1 << descriptor.bool_offset));
314 }
315 case kDescriptorFloatType: {
316 float value = *CheckedCast<float>(ptr);
317 AllowHeapAllocation allow_gc;
318 return isolate->factory()->NewNumber(value);
319 }
320 case kDescriptorDoubleType: {
321 double value = *CheckedCast<double>(ptr);
322 AllowHeapAllocation allow_gc;
323 return isolate->factory()->NewNumber(value);
324 }
325 }
326 AllowHeapAllocation allow_gc;
327 return isolate->factory()->NewNumberFromInt(int32_value);
328 }
329
330
331 static Handle<Object> GetDeclaredAccessorProperty(
332 Handle<Object> receiver,
333 Handle<DeclaredAccessorInfo> info,
334 Isolate* isolate) {
335 DisallowHeapAllocation no_gc;
336 char* current = reinterpret_cast<char*>(*receiver);
337 DeclaredAccessorDescriptorIterator iterator(info->descriptor());
338 while (true) {
339 const DeclaredAccessorDescriptorData* data = iterator.Next();
340 switch (data->type) {
341 case kDescriptorReturnObject: {
342 DCHECK(iterator.Complete());
343 current = *CheckedCast<char*>(current);
344 return handle(*CheckedCast<Object*>(current), isolate);
345 }
346 case kDescriptorPointerDereference:
347 DCHECK(!iterator.Complete());
348 current = *reinterpret_cast<char**>(current);
349 break;
350 case kDescriptorPointerShift:
351 DCHECK(!iterator.Complete());
352 current += data->pointer_shift_descriptor.byte_offset;
353 break;
354 case kDescriptorObjectDereference: {
355 DCHECK(!iterator.Complete());
356 Object* object = CheckedCast<Object>(current);
357 int field = data->object_dereference_descriptor.internal_field;
358 Object* smi = JSObject::cast(object)->GetInternalField(field);
359 DCHECK(smi->IsSmi());
360 current = reinterpret_cast<char*>(smi);
361 break;
362 }
363 case kDescriptorBitmaskCompare:
364 DCHECK(iterator.Complete());
365 return PerformCompare(data->bitmask_compare_descriptor,
366 current,
367 isolate);
368 case kDescriptorPointerCompare:
369 DCHECK(iterator.Complete());
370 return PerformCompare(data->pointer_compare_descriptor,
371 current,
372 isolate);
373 case kDescriptorPrimitiveValue:
374 DCHECK(iterator.Complete());
375 return GetPrimitiveValue(data->primitive_value_descriptor,
376 current,
377 isolate);
378 }
379 }
380 UNREACHABLE();
381 return isolate->factory()->undefined_value();
382 }
383
384
385 Handle<FixedArray> JSObject::EnsureWritableFastElements( 237 Handle<FixedArray> JSObject::EnsureWritableFastElements(
386 Handle<JSObject> object) { 238 Handle<JSObject> object) {
387 DCHECK(object->HasFastSmiOrObjectElements()); 239 DCHECK(object->HasFastSmiOrObjectElements());
388 Isolate* isolate = object->GetIsolate(); 240 Isolate* isolate = object->GetIsolate();
389 Handle<FixedArray> elems(FixedArray::cast(object->elements()), isolate); 241 Handle<FixedArray> elems(FixedArray::cast(object->elements()), isolate);
390 if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; 242 if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems;
391 Handle<FixedArray> writable_elems = isolate->factory()->CopyFixedArrayWithMap( 243 Handle<FixedArray> writable_elems = isolate->factory()->CopyFixedArrayWithMap(
392 elems, isolate->factory()->fixed_array_map()); 244 elems, isolate->factory()->fixed_array_map());
393 object->set_elements(*writable_elems); 245 object->set_elements(*writable_elems);
394 isolate->counters()->cow_arrays_converted()->Increment(); 246 isolate->counters()->cow_arrays_converted()->Increment();
(...skipping 24 matching lines...) Expand all
419 // api style callbacks. 271 // api style callbacks.
420 if (structure->IsAccessorInfo()) { 272 if (structure->IsAccessorInfo()) {
421 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); 273 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure);
422 if (!info->IsCompatibleReceiver(*receiver)) { 274 if (!info->IsCompatibleReceiver(*receiver)) {
423 Handle<Object> args[2] = { name, receiver }; 275 Handle<Object> args[2] = { name, receiver };
424 THROW_NEW_ERROR(isolate, 276 THROW_NEW_ERROR(isolate,
425 NewTypeError("incompatible_method_receiver", 277 NewTypeError("incompatible_method_receiver",
426 HandleVector(args, arraysize(args))), 278 HandleVector(args, arraysize(args))),
427 Object); 279 Object);
428 } 280 }
429 if (structure->IsDeclaredAccessorInfo()) {
430 return GetDeclaredAccessorProperty(
431 receiver,
432 Handle<DeclaredAccessorInfo>::cast(structure),
433 isolate);
434 }
435 281
436 Handle<ExecutableAccessorInfo> data = 282 Handle<ExecutableAccessorInfo> data =
437 Handle<ExecutableAccessorInfo>::cast(structure); 283 Handle<ExecutableAccessorInfo>::cast(structure);
438 v8::AccessorNameGetterCallback call_fun = 284 v8::AccessorNameGetterCallback call_fun =
439 v8::ToCData<v8::AccessorNameGetterCallback>(data->getter()); 285 v8::ToCData<v8::AccessorNameGetterCallback>(data->getter());
440 if (call_fun == NULL) return isolate->factory()->undefined_value(); 286 if (call_fun == NULL) return isolate->factory()->undefined_value();
441 287
442 LOG(isolate, ApiNamedPropertyAccess("load", *holder, *name)); 288 LOG(isolate, ApiNamedPropertyAccess("load", *holder, *name));
443 PropertyCallbackArguments args(isolate, data->data(), *receiver, *holder); 289 PropertyCallbackArguments args(isolate, data->data(), *receiver, *holder);
444 v8::Handle<v8::Value> result = 290 v8::Handle<v8::Value> result =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 receiver, Handle<JSReceiver>::cast(setter), value); 364 receiver, Handle<JSReceiver>::cast(setter), value);
519 } else { 365 } else {
520 if (strict_mode == SLOPPY) return value; 366 if (strict_mode == SLOPPY) return value;
521 Handle<Object> args[2] = { name, holder }; 367 Handle<Object> args[2] = { name, holder };
522 THROW_NEW_ERROR( 368 THROW_NEW_ERROR(
523 isolate, NewTypeError("no_setter_in_callback", HandleVector(args, 2)), 369 isolate, NewTypeError("no_setter_in_callback", HandleVector(args, 2)),
524 Object); 370 Object);
525 } 371 }
526 } 372 }
527 373
528 // TODO(dcarney): Handle correctly.
529 if (structure->IsDeclaredAccessorInfo()) {
530 return value;
531 }
532
533 UNREACHABLE(); 374 UNREACHABLE();
534 return MaybeHandle<Object>(); 375 return MaybeHandle<Object>();
535 } 376 }
536 377
537 378
538 MaybeHandle<Object> Object::GetPropertyWithDefinedGetter( 379 MaybeHandle<Object> Object::GetPropertyWithDefinedGetter(
539 Handle<Object> receiver, 380 Handle<Object> receiver,
540 Handle<JSReceiver> getter) { 381 Handle<JSReceiver> getter) {
541 Isolate* isolate = getter->GetIsolate(); 382 Isolate* isolate = getter->GetIsolate();
542 Debug* debug = isolate->debug(); 383 Debug* debug = isolate->debug();
(...skipping 2452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2995 if (done && (maybe_attributes.value & READ_ONLY) != 0) { 2836 if (done && (maybe_attributes.value & READ_ONLY) != 0) {
2996 return WriteToReadOnlyProperty(it, value, strict_mode); 2837 return WriteToReadOnlyProperty(it, value, strict_mode);
2997 } 2838 }
2998 } 2839 }
2999 break; 2840 break;
3000 2841
3001 case LookupIterator::ACCESSOR: 2842 case LookupIterator::ACCESSOR:
3002 if (it->property_details().IsReadOnly()) { 2843 if (it->property_details().IsReadOnly()) {
3003 return WriteToReadOnlyProperty(it, value, strict_mode); 2844 return WriteToReadOnlyProperty(it, value, strict_mode);
3004 } 2845 }
3005 if (it->HolderIsReceiverOrHiddenPrototype() || 2846 return SetPropertyWithAccessor(it->GetReceiver(), it->name(), value,
3006 !it->GetAccessors()->IsDeclaredAccessorInfo()) { 2847 it->GetHolder<JSObject>(),
3007 return SetPropertyWithAccessor(it->GetReceiver(), it->name(), value, 2848 it->GetAccessors(), strict_mode);
3008 it->GetHolder<JSObject>(),
3009 it->GetAccessors(), strict_mode);
3010 }
3011 done = true;
3012 break;
3013 2849
3014 case LookupIterator::DATA: 2850 case LookupIterator::DATA:
3015 if (it->property_details().IsReadOnly()) { 2851 if (it->property_details().IsReadOnly()) {
3016 return WriteToReadOnlyProperty(it, value, strict_mode); 2852 return WriteToReadOnlyProperty(it, value, strict_mode);
3017 } 2853 }
3018 if (it->HolderIsReceiverOrHiddenPrototype()) { 2854 if (it->HolderIsReceiverOrHiddenPrototype()) {
3019 return SetDataProperty(it, value); 2855 return SetDataProperty(it, value);
3020 } 2856 }
3021 done = true; 2857 done = true;
3022 break; 2858 break;
(...skipping 9332 matching lines...) Expand 10 before | Expand all | Expand 10 after
12355 isolate); 12191 isolate);
12356 if (getter->IsSpecFunction()) { 12192 if (getter->IsSpecFunction()) {
12357 // TODO(rossberg): nicer would be to cast to some JSCallable here... 12193 // TODO(rossberg): nicer would be to cast to some JSCallable here...
12358 return GetPropertyWithDefinedGetter( 12194 return GetPropertyWithDefinedGetter(
12359 receiver, Handle<JSReceiver>::cast(getter)); 12195 receiver, Handle<JSReceiver>::cast(getter));
12360 } 12196 }
12361 // Getter is not a function. 12197 // Getter is not a function.
12362 return isolate->factory()->undefined_value(); 12198 return isolate->factory()->undefined_value();
12363 } 12199 }
12364 12200
12365 if (structure->IsDeclaredAccessorInfo()) {
12366 return GetDeclaredAccessorProperty(
12367 receiver, Handle<DeclaredAccessorInfo>::cast(structure), isolate);
12368 }
12369
12370 UNREACHABLE(); 12201 UNREACHABLE();
12371 return MaybeHandle<Object>(); 12202 return MaybeHandle<Object>();
12372 } 12203 }
12373 12204
12374 12205
12375 MaybeHandle<Object> JSObject::SetElementWithCallback( 12206 MaybeHandle<Object> JSObject::SetElementWithCallback(
12376 Handle<Object> object, Handle<Object> structure, uint32_t index, 12207 Handle<Object> object, Handle<Object> structure, uint32_t index,
12377 Handle<Object> value, Handle<JSObject> holder, StrictMode strict_mode) { 12208 Handle<Object> value, Handle<JSObject> holder, StrictMode strict_mode) {
12378 Isolate* isolate = holder->GetIsolate(); 12209 Isolate* isolate = holder->GetIsolate();
12379 12210
(...skipping 30 matching lines...) Expand all
12410 } else { 12241 } else {
12411 if (strict_mode == SLOPPY) return value; 12242 if (strict_mode == SLOPPY) return value;
12412 Handle<Object> key(isolate->factory()->NewNumberFromUint(index)); 12243 Handle<Object> key(isolate->factory()->NewNumberFromUint(index));
12413 Handle<Object> args[2] = { key, holder }; 12244 Handle<Object> args[2] = { key, holder };
12414 THROW_NEW_ERROR( 12245 THROW_NEW_ERROR(
12415 isolate, NewTypeError("no_setter_in_callback", HandleVector(args, 2)), 12246 isolate, NewTypeError("no_setter_in_callback", HandleVector(args, 2)),
12416 Object); 12247 Object);
12417 } 12248 }
12418 } 12249 }
12419 12250
12420 // TODO(dcarney): Handle correctly.
12421 if (structure->IsDeclaredAccessorInfo()) return value;
12422
12423 UNREACHABLE(); 12251 UNREACHABLE();
12424 return MaybeHandle<Object>(); 12252 return MaybeHandle<Object>();
12425 } 12253 }
12426 12254
12427 12255
12428 bool JSObject::HasFastArgumentsElements() { 12256 bool JSObject::HasFastArgumentsElements() {
12429 Heap* heap = GetHeap(); 12257 Heap* heap = GetHeap();
12430 if (!elements()->IsFixedArray()) return false; 12258 if (!elements()->IsFixedArray()) return false;
12431 FixedArray* elements = FixedArray::cast(this->elements()); 12259 FixedArray* elements = FixedArray::cast(this->elements());
12432 if (elements->map() != heap->sloppy_arguments_elements_map()) { 12260 if (elements->map() != heap->sloppy_arguments_elements_map()) {
(...skipping 4036 matching lines...) Expand 10 before | Expand all | Expand 10 after
16469 template void 16297 template void
16470 OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::MoveNext(); 16298 OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::MoveNext();
16471 16299
16472 template Object* 16300 template Object*
16473 OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::CurrentKey(); 16301 OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::CurrentKey();
16474 16302
16475 template void 16303 template void
16476 OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::Transition(); 16304 OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::Transition();
16477 16305
16478 16306
16479 DeclaredAccessorDescriptorIterator::DeclaredAccessorDescriptorIterator(
16480 DeclaredAccessorDescriptor* descriptor)
16481 : array_(descriptor->serialized_data()->GetDataStartAddress()),
16482 length_(descriptor->serialized_data()->length()),
16483 offset_(0) {
16484 }
16485
16486
16487 const DeclaredAccessorDescriptorData*
16488 DeclaredAccessorDescriptorIterator::Next() {
16489 DCHECK(offset_ < length_);
16490 uint8_t* ptr = &array_[offset_];
16491 DCHECK(reinterpret_cast<uintptr_t>(ptr) % sizeof(uintptr_t) == 0);
16492 const DeclaredAccessorDescriptorData* data =
16493 reinterpret_cast<const DeclaredAccessorDescriptorData*>(ptr);
16494 offset_ += sizeof(*data);
16495 DCHECK(offset_ <= length_);
16496 return data;
16497 }
16498
16499
16500 Handle<DeclaredAccessorDescriptor> DeclaredAccessorDescriptor::Create(
16501 Isolate* isolate,
16502 const DeclaredAccessorDescriptorData& descriptor,
16503 Handle<DeclaredAccessorDescriptor> previous) {
16504 int previous_length =
16505 previous.is_null() ? 0 : previous->serialized_data()->length();
16506 int length = sizeof(descriptor) + previous_length;
16507 Handle<ByteArray> serialized_descriptor =
16508 isolate->factory()->NewByteArray(length);
16509 Handle<DeclaredAccessorDescriptor> value =
16510 isolate->factory()->NewDeclaredAccessorDescriptor();
16511 value->set_serialized_data(*serialized_descriptor);
16512 // Copy in the data.
16513 {
16514 DisallowHeapAllocation no_allocation;
16515 uint8_t* array = serialized_descriptor->GetDataStartAddress();
16516 if (previous_length != 0) {
16517 uint8_t* previous_array =
16518 previous->serialized_data()->GetDataStartAddress();
16519 MemCopy(array, previous_array, previous_length);
16520 array += previous_length;
16521 }
16522 DCHECK(reinterpret_cast<uintptr_t>(array) % sizeof(uintptr_t) == 0);
16523 DeclaredAccessorDescriptorData* data =
16524 reinterpret_cast<DeclaredAccessorDescriptorData*>(array);
16525 *data = descriptor;
16526 }
16527 return value;
16528 }
16529
16530
16531 // Check if there is a break point at this code position. 16307 // Check if there is a break point at this code position.
16532 bool DebugInfo::HasBreakPoint(int code_position) { 16308 bool DebugInfo::HasBreakPoint(int code_position) {
16533 // Get the break point info object for this code position. 16309 // Get the break point info object for this code position.
16534 Object* break_point_info = GetBreakPointInfo(code_position); 16310 Object* break_point_info = GetBreakPointInfo(code_position);
16535 16311
16536 // If there is no break point info object or no break points in the break 16312 // If there is no break point info object or no break points in the break
16537 // point info object there is no break point at this code position. 16313 // point info object there is no break point at this code position.
16538 if (break_point_info->IsUndefined()) return false; 16314 if (break_point_info->IsUndefined()) return false;
16539 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; 16315 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0;
16540 } 16316 }
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
17057 Handle<DependentCode> codes = 16833 Handle<DependentCode> codes =
17058 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), 16834 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()),
17059 DependentCode::kPropertyCellChangedGroup, 16835 DependentCode::kPropertyCellChangedGroup,
17060 info->object_wrapper()); 16836 info->object_wrapper());
17061 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); 16837 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes);
17062 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( 16838 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add(
17063 cell, info->zone()); 16839 cell, info->zone());
17064 } 16840 }
17065 16841
17066 } } // namespace v8::internal 16842 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698