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

Side by Side Diff: src/api.cc

Issue 6597029: [Isolates] Merge r 6300:6500 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « src/SConscript ('k') | src/arm/assembler-arm.h » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 3217 matching lines...) Expand 10 before | Expand all | Expand 10 after
3228 "v8::Object::SetInternalField()", 3228 "v8::Object::SetInternalField()",
3229 "Writing internal field out of bounds")) { 3229 "Writing internal field out of bounds")) {
3230 return; 3230 return;
3231 } 3231 }
3232 ENTER_V8; 3232 ENTER_V8;
3233 i::Handle<i::Object> val = Utils::OpenHandle(*value); 3233 i::Handle<i::Object> val = Utils::OpenHandle(*value);
3234 obj->SetInternalField(index, *val); 3234 obj->SetInternalField(index, *val);
3235 } 3235 }
3236 3236
3237 3237
3238 static bool CanBeEncodedAsSmi(void* ptr) {
3239 const uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
3240 return ((address & i::kEncodablePointerMask) == 0);
3241 }
3242
3243
3244 static i::Smi* EncodeAsSmi(void* ptr) {
3245 ASSERT(CanBeEncodedAsSmi(ptr));
3246 const uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
3247 i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift);
3248 ASSERT(i::Internals::HasSmiTag(result));
3249 ASSERT_EQ(result, i::Smi::FromInt(result->value()));
3250 ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result));
3251 return result;
3252 }
3253
3254
3238 void v8::Object::SetPointerInInternalField(int index, void* value) { 3255 void v8::Object::SetPointerInInternalField(int index, void* value) {
3239 ENTER_V8; 3256 ENTER_V8;
3240 i::Object* as_object = reinterpret_cast<i::Object*>(value); 3257 if (CanBeEncodedAsSmi(value)) {
3241 if (as_object->IsSmi()) { 3258 Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value));
3242 Utils::OpenHandle(this)->SetInternalField(index, as_object); 3259 } else {
3243 return; 3260 HandleScope scope;
3261 i::Handle<i::Proxy> proxy =
3262 FACTORY->NewProxy(reinterpret_cast<i::Address>(value), i::TENURED);
3263 if (!proxy.is_null())
3264 Utils::OpenHandle(this)->SetInternalField(index, *proxy);
3244 } 3265 }
3245 HandleScope scope; 3266 ASSERT_EQ(value, GetPointerFromInternalField(index));
3246 i::Handle<i::Proxy> proxy =
3247 FACTORY->NewProxy(reinterpret_cast<i::Address>(value), i::TENURED);
3248 if (!proxy.is_null())
3249 Utils::OpenHandle(this)->SetInternalField(index, *proxy);
3250 } 3267 }
3251 3268
3252 3269
3253 // --- E n v i r o n m e n t --- 3270 // --- E n v i r o n m e n t ---
3254 3271
3255 3272
3256 bool v8::V8::Initialize() { 3273 bool v8::V8::Initialize() {
3257 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); 3274 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
3258 if (isolate != NULL && isolate->IsInitialized()) { 3275 if (isolate != NULL && isolate->IsInitialized()) {
3259 return true; 3276 return true;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
3534 static void* ExternalValueImpl(i::Handle<i::Object> obj) { 3551 static void* ExternalValueImpl(i::Handle<i::Object> obj) {
3535 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); 3552 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy());
3536 } 3553 }
3537 3554
3538 3555
3539 Local<Value> v8::External::Wrap(void* data) { 3556 Local<Value> v8::External::Wrap(void* data) {
3540 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); 3557 STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
3541 LOG_API("External::Wrap"); 3558 LOG_API("External::Wrap");
3542 EnsureInitialized("v8::External::Wrap()"); 3559 EnsureInitialized("v8::External::Wrap()");
3543 ENTER_V8; 3560 ENTER_V8;
3544 i::Object* as_object = reinterpret_cast<i::Object*>(data); 3561
3545 if (as_object->IsSmi()) { 3562 v8::Local<v8::Value> result = CanBeEncodedAsSmi(data)
3546 return Utils::ToLocal(i::Handle<i::Object>(as_object)); 3563 ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data)))
3547 } 3564 : v8::Local<v8::Value>(ExternalNewImpl(data));
3548 return ExternalNewImpl(data); 3565
3566 ASSERT_EQ(data, Unwrap(result));
3567 return result;
3549 } 3568 }
3550 3569
3551 3570
3552 void* v8::Object::SlowGetPointerFromInternalField(int index) { 3571 void* v8::Object::SlowGetPointerFromInternalField(int index) {
3553 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3572 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3554 i::Object* value = obj->GetInternalField(index); 3573 i::Object* value = obj->GetInternalField(index);
3555 if (value->IsSmi()) { 3574 if (value->IsSmi()) {
3556 return value; 3575 return i::Internals::GetExternalPointerFromSmi(value);
3557 } else if (value->IsProxy()) { 3576 } else if (value->IsProxy()) {
3558 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); 3577 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy());
3559 } else { 3578 } else {
3560 return NULL; 3579 return NULL;
3561 } 3580 }
3562 } 3581 }
3563 3582
3564 3583
3565 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { 3584 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) {
3566 if (IsDeadCheck("v8::External::Unwrap()")) return 0; 3585 if (IsDeadCheck("v8::External::Unwrap()")) return 0;
3567 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); 3586 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper);
3568 void* result; 3587 void* result;
3569 if (obj->IsSmi()) { 3588 if (obj->IsSmi()) {
3570 // The external value was an aligned pointer. 3589 result = i::Internals::GetExternalPointerFromSmi(*obj);
3571 result = *obj;
3572 } else if (obj->IsProxy()) { 3590 } else if (obj->IsProxy()) {
3573 result = ExternalValueImpl(obj); 3591 result = ExternalValueImpl(obj);
3574 } else { 3592 } else {
3575 result = NULL; 3593 result = NULL;
3576 } 3594 }
3577 ASSERT_EQ(result, QuickUnwrap(wrapper)); 3595 ASSERT_EQ(result, QuickUnwrap(wrapper));
3578 return result; 3596 return result;
3579 } 3597 }
3580 3598
3581 3599
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after
5160 5178
5161 5179
5162 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 5180 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
5163 HandleScopeImplementer* thread_local = 5181 HandleScopeImplementer* thread_local =
5164 reinterpret_cast<HandleScopeImplementer*>(storage); 5182 reinterpret_cast<HandleScopeImplementer*>(storage);
5165 thread_local->IterateThis(v); 5183 thread_local->IterateThis(v);
5166 return storage + ArchiveSpacePerThread(); 5184 return storage + ArchiveSpacePerThread();
5167 } 5185 }
5168 5186
5169 } } // namespace v8::internal 5187 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/SConscript ('k') | src/arm/assembler-arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698