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

Side by Side Diff: src/api.cc

Issue 6241003: Port r6301 to 2.4 branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/2.4/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/version.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 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 3186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3197 "v8::Object::SetInternalField()", 3197 "v8::Object::SetInternalField()",
3198 "Writing internal field out of bounds")) { 3198 "Writing internal field out of bounds")) {
3199 return; 3199 return;
3200 } 3200 }
3201 ENTER_V8; 3201 ENTER_V8;
3202 i::Handle<i::Object> val = Utils::OpenHandle(*value); 3202 i::Handle<i::Object> val = Utils::OpenHandle(*value);
3203 obj->SetInternalField(index, *val); 3203 obj->SetInternalField(index, *val);
3204 } 3204 }
3205 3205
3206 3206
3207 static bool CanBeEncodedAsSmi(void* ptr) {
3208 const intptr_t address = reinterpret_cast<intptr_t>(ptr);
3209 return ((address & i::kEncodablePointerMask) == 0);
3210 }
3211
3212
3213 static i::Smi* EncodeAsSmi(void* ptr) {
3214 ASSERT(CanBeEncodedAsSmi(ptr));
3215 const intptr_t address = reinterpret_cast<intptr_t>(ptr);
3216 i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift);
3217 ASSERT(i::Internals::HasSmiTag(result));
3218 ASSERT_EQ(result, i::Smi::FromInt(result->value()));
3219 ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result));
3220 return result;
3221 }
3222
3223
3207 void v8::Object::SetPointerInInternalField(int index, void* value) { 3224 void v8::Object::SetPointerInInternalField(int index, void* value) {
3208 ENTER_V8; 3225 ENTER_V8;
3209 i::Object* as_object = reinterpret_cast<i::Object*>(value); 3226 if (CanBeEncodedAsSmi(value)) {
3210 if (as_object->IsSmi()) { 3227 Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value));
3211 Utils::OpenHandle(this)->SetInternalField(index, as_object); 3228 } else {
3212 return; 3229 HandleScope scope;
3230 i::Handle<i::Proxy> proxy =
3231 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED);
3232 if (!proxy.is_null())
3233 Utils::OpenHandle(this)->SetInternalField(index, *proxy);
3213 } 3234 }
3214 HandleScope scope; 3235 ASSERT_EQ(value, GetPointerFromInternalField(index));
3215 i::Handle<i::Proxy> proxy =
3216 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED);
3217 if (!proxy.is_null())
3218 Utils::OpenHandle(this)->SetInternalField(index, *proxy);
3219 } 3236 }
3220 3237
3221 3238
3222 // --- E n v i r o n m e n t --- 3239 // --- E n v i r o n m e n t ---
3223 3240
3224 bool v8::V8::Initialize() { 3241 bool v8::V8::Initialize() {
3225 if (i::V8::IsRunning()) return true; 3242 if (i::V8::IsRunning()) return true;
3226 ENTER_V8; 3243 ENTER_V8;
3227 HandleScope scope; 3244 HandleScope scope;
3228 if (i::Snapshot::Initialize()) return true; 3245 if (i::Snapshot::Initialize()) return true;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 static void* ExternalValueImpl(i::Handle<i::Object> obj) { 3504 static void* ExternalValueImpl(i::Handle<i::Object> obj) {
3488 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); 3505 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy());
3489 } 3506 }
3490 3507
3491 3508
3492 Local<Value> v8::External::Wrap(void* data) { 3509 Local<Value> v8::External::Wrap(void* data) {
3493 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); 3510 STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
3494 LOG_API("External::Wrap"); 3511 LOG_API("External::Wrap");
3495 EnsureInitialized("v8::External::Wrap()"); 3512 EnsureInitialized("v8::External::Wrap()");
3496 ENTER_V8; 3513 ENTER_V8;
3497 i::Object* as_object = reinterpret_cast<i::Object*>(data); 3514
3498 if (as_object->IsSmi()) { 3515 v8::Local<v8::Value> result = CanBeEncodedAsSmi(data)
3499 return Utils::ToLocal(i::Handle<i::Object>(as_object)); 3516 ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data)))
3500 } 3517 : v8::Local<v8::Value>(ExternalNewImpl(data));
3501 return ExternalNewImpl(data); 3518
3519 ASSERT_EQ(data, Unwrap(result));
3520 return result;
3502 } 3521 }
3503 3522
3504 3523
3505 void* v8::Object::SlowGetPointerFromInternalField(int index) { 3524 void* v8::Object::SlowGetPointerFromInternalField(int index) {
3506 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3525 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3507 i::Object* value = obj->GetInternalField(index); 3526 i::Object* value = obj->GetInternalField(index);
3508 if (value->IsSmi()) { 3527 if (value->IsSmi()) {
3509 return value; 3528 return i::Internals::GetExternalPointerFromSmi(value);
3510 } else if (value->IsProxy()) { 3529 } else if (value->IsProxy()) {
3511 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); 3530 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy());
3512 } else { 3531 } else {
3513 return NULL; 3532 return NULL;
3514 } 3533 }
3515 } 3534 }
3516 3535
3517 3536
3518 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { 3537 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) {
3519 if (IsDeadCheck("v8::External::Unwrap()")) return 0; 3538 if (IsDeadCheck("v8::External::Unwrap()")) return 0;
3520 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); 3539 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper);
3521 void* result; 3540 void* result;
3522 if (obj->IsSmi()) { 3541 if (obj->IsSmi()) {
3523 // The external value was an aligned pointer. 3542 result = i::Internals::GetExternalPointerFromSmi(*obj);
3524 result = *obj;
3525 } else if (obj->IsProxy()) { 3543 } else if (obj->IsProxy()) {
3526 result = ExternalValueImpl(obj); 3544 result = ExternalValueImpl(obj);
3527 } else { 3545 } else {
3528 result = NULL; 3546 result = NULL;
3529 } 3547 }
3530 ASSERT_EQ(result, QuickUnwrap(wrapper)); 3548 ASSERT_EQ(result, QuickUnwrap(wrapper));
3531 return result; 3549 return result;
3532 } 3550 }
3533 3551
3534 3552
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
4969 4987
4970 4988
4971 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 4989 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
4972 HandleScopeImplementer* thread_local = 4990 HandleScopeImplementer* thread_local =
4973 reinterpret_cast<HandleScopeImplementer*>(storage); 4991 reinterpret_cast<HandleScopeImplementer*>(storage);
4974 thread_local->IterateThis(v); 4992 thread_local->IterateThis(v);
4975 return storage + ArchiveSpacePerThread(); 4993 return storage + ArchiveSpacePerThread();
4976 } 4994 }
4977 4995
4978 } } // namespace v8::internal 4996 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698