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

Side by Side Diff: src/api.cc

Issue 2185963002: [api] Add v8::Object::SetAlignedPointerInInternalFields (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: adding fast paths Created 4 years, 4 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
OLDNEW
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/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 5530 matching lines...) Expand 10 before | Expand all | Expand 10 after
5541 5541
5542 5542
5543 void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { 5543 void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
5544 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 5544 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
5545 const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; 5545 const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
5546 if (!InternalFieldOK(obj, index, location)) return NULL; 5546 if (!InternalFieldOK(obj, index, location)) return NULL;
5547 return DecodeSmiToAligned( 5547 return DecodeSmiToAligned(
5548 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), location); 5548 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), location);
5549 } 5549 }
5550 5550
5551 5551 void v8::Object::SlowSetAlignedPointerInInternalField(int index, void* value) {
5552 void v8::Object::SetAlignedPointerInInternalField(int index, void* value) {
5553 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 5552 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
5554 const char* location = "v8::Object::SetAlignedPointerInInternalField()"; 5553 const char* location = "v8::Object::SetAlignedPointerInInternalField()";
5555 if (!InternalFieldOK(obj, index, location)) return; 5554 if (!InternalFieldOK(obj, index, location)) return;
5556 i::Handle<i::JSObject>::cast(obj) 5555 i::Handle<i::JSObject>::cast(obj)
5557 ->SetInternalField(index, EncodeAlignedAsSmi(value, location)); 5556 ->SetInternalField(index, EncodeAlignedAsSmi(value, location));
5558 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); 5557 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
5559 } 5558 }
5560 5559
5560 void v8::Object::SlowSetAlignedPointerInInternalFields(int argc, int indices[],
5561 void* values[]) {
5562 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
5563 const char* location = "v8::Object::SetAlignedPointerInInternalFields()";
5564 i::DisallowHeapAllocation no_gc;
5565 i::JSObject* object = i::JSObject::cast(*obj);
5566 int nof_internal_fields = object->GetInternalFieldCount();
5567 for (int i = 0; i < argc; i++) {
5568 int index = indices[i];
5569 if (!Utils::ApiCheck(index < nof_internal_fields, location,
5570 "Internal field out of bounds")) {
5571 return;
5572 }
5573 void* value = values[i];
5574 object->SetInternalField(index, EncodeAlignedAsSmi(value, location));
5575 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
5576 }
5577 }
5561 5578
5562 static void* ExternalValue(i::Object* obj) { 5579 static void* ExternalValue(i::Object* obj) {
5563 // Obscure semantics for undefined, but somehow checked in our unit tests... 5580 // Obscure semantics for undefined, but somehow checked in our unit tests...
5564 if (!obj->IsSmi() && 5581 if (!obj->IsSmi() &&
5565 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) { 5582 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) {
5566 return NULL; 5583 return NULL;
5567 } 5584 }
5568 i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); 5585 i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0);
5569 return i::Foreign::cast(foreign)->foreign_address(); 5586 return i::Foreign::cast(foreign)->foreign_address();
5570 } 5587 }
(...skipping 3471 matching lines...) Expand 10 before | Expand all | Expand 10 after
9042 Address callback_address = 9059 Address callback_address =
9043 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9060 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9044 VMState<EXTERNAL> state(isolate); 9061 VMState<EXTERNAL> state(isolate);
9045 ExternalCallbackScope call_scope(isolate, callback_address); 9062 ExternalCallbackScope call_scope(isolate, callback_address);
9046 callback(info); 9063 callback(info);
9047 } 9064 }
9048 9065
9049 9066
9050 } // namespace internal 9067 } // namespace internal
9051 } // namespace v8 9068 } // namespace v8
OLDNEW
« include/v8.h ('K') | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698