From: dcarney@chromium.org Date: Mon, 27 May 2013 11:50:08 +0000 (+0000) Subject: make isolate accessible from returnvalue X-Git-Tag: upstream/4.7.83~14114 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81e5778718f9c9714c4f377d3862541b82f4e996;p=platform%2Fupstream%2Fv8.git make isolate accessible from returnvalue R=svenpanne@chromium.org BUG= Review URL: https://codereview.chromium.org/16021010 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14819 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/include/v8.h b/include/v8.h index 7dfc918..b5c780a 100644 --- a/include/v8.h +++ b/include/v8.h @@ -2782,16 +2782,16 @@ class ReturnValue { V8_INLINE(void Set(const Persistent& handle)); V8_INLINE(void Set(const Handle handle)); // Fast primitive setters - V8_INLINE(void Set(Isolate* isolate, bool value)); - V8_INLINE(void Set(Isolate* isolate, double i)); - V8_INLINE(void Set(Isolate* isolate, int32_t i)); - V8_INLINE(void Set(Isolate* isolate, uint32_t i)); + V8_INLINE(void Set(bool value)); + V8_INLINE(void Set(double i)); + V8_INLINE(void Set(int32_t i)); + V8_INLINE(void Set(uint32_t i)); // Fast JS primitive setters - V8_INLINE(void SetNull(Isolate* isolate)); - V8_INLINE(void SetUndefined(Isolate* isolate)); + V8_INLINE(void SetNull()); + V8_INLINE(void SetUndefined()); + // Convenience getter for Isolate + V8_INLINE(Isolate* GetIsolate()); private: - V8_INLINE(void SetTrue(Isolate* isolate)); - V8_INLINE(void SetFalse(Isolate* isolate)); internal::Object** value_; }; @@ -2868,8 +2868,8 @@ class PropertyCallbackInfo { static const int kThisIndex = 0; static const int kHolderIndex = -1; static const int kDataIndex = -2; - static const int kIsolateIndex = -3; - static const int kReturnValueIndex = -4; + static const int kReturnValueIndex = -3; + static const int kIsolateIndex = -4; V8_INLINE(PropertyCallbackInfo(internal::Object** args)) : args_(args) { } @@ -5694,61 +5694,58 @@ void ReturnValue::Set(const Handle handle) { } template -void ReturnValue::Set(Isolate* isolate, double i) { - Set(Number::New(isolate, i)); +void ReturnValue::Set(double i) { + Set(Number::New(GetIsolate(), i)); } template -void ReturnValue::Set(Isolate* isolate, int32_t i) { +void ReturnValue::Set(int32_t i) { typedef internal::Internals I; if (V8_LIKELY(I::IsValidSmi(i))) { *value_ = I::IntToSmi(i); return; } - Set(Integer::New(i, isolate)); + Set(Integer::New(i, GetIsolate())); } template -void ReturnValue::Set(Isolate* isolate, uint32_t i) { +void ReturnValue::Set(uint32_t i) { typedef internal::Internals I; if (V8_LIKELY(I::IsValidSmi(i))) { *value_ = I::IntToSmi(i); return; } - Set(Integer::NewFromUnsigned(i, isolate)); + Set(Integer::NewFromUnsigned(i, GetIsolate())); } template -void ReturnValue::Set(Isolate* isolate, bool value) { +void ReturnValue::Set(bool value) { + typedef internal::Internals I; + int root_index; if (value) { - SetTrue(isolate); + root_index = I::kTrueValueRootIndex; } else { - SetFalse(isolate); + root_index = I::kFalseValueRootIndex; } + *value_ = *I::GetRoot(GetIsolate(), root_index); } template -void ReturnValue::SetTrue(Isolate* isolate) { - typedef internal::Internals I; - *value_ = *I::GetRoot(isolate, I::kTrueValueRootIndex); -} - -template -void ReturnValue::SetFalse(Isolate* isolate) { +void ReturnValue::SetNull() { typedef internal::Internals I; - *value_ = *I::GetRoot(isolate, I::kFalseValueRootIndex); + *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); } template -void ReturnValue::SetNull(Isolate* isolate) { +void ReturnValue::SetUndefined() { typedef internal::Internals I; - *value_ = *I::GetRoot(isolate, I::kNullValueRootIndex); + *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); } template -void ReturnValue::SetUndefined(Isolate* isolate) { - typedef internal::Internals I; - *value_ = *I::GetRoot(isolate, I::kUndefinedValueRootIndex); +Isolate* ReturnValue::GetIsolate() { + // Isolate is always the pointer below value_ on the stack. + return *reinterpret_cast(&value_[-1]); } diff --git a/src/arm/stub-cache-arm.cc b/src/arm/stub-cache-arm.cc index 1ede12c..912caed 100644 --- a/src/arm/stub-cache-arm.cc +++ b/src/arm/stub-cache-arm.cc @@ -1433,9 +1433,9 @@ void BaseLoadStubCompiler::GenerateLoadCallback( __ Move(scratch3(), Handle(callback->data(), isolate())); } __ Push(reg, scratch3()); - __ mov(scratch3(), + __ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex); + __ mov(scratch4(), Operand(ExternalReference::isolate_address(isolate()))); - __ LoadRoot(scratch4(), Heap::kUndefinedValueRootIndex); __ Push(scratch3(), scratch4(), name()); __ mov(r0, sp); // r0 = Handle @@ -1462,7 +1462,7 @@ void BaseLoadStubCompiler::GenerateLoadCallback( __ CallApiFunctionAndReturn(ref, kStackUnwindSpace, returns_handle, - 3); + 4); } diff --git a/src/ia32/stub-cache-ia32.cc b/src/ia32/stub-cache-ia32.cc index e1db7cd..7cb7811 100644 --- a/src/ia32/stub-cache-ia32.cc +++ b/src/ia32/stub-cache-ia32.cc @@ -1386,8 +1386,8 @@ void BaseLoadStubCompiler::GenerateLoadCallback( } else { __ push(Immediate(Handle(callback->data(), isolate()))); } - __ push(Immediate(reinterpret_cast(isolate()))); __ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue + __ push(Immediate(reinterpret_cast(isolate()))); // Save a pointer to where we pushed the arguments pointer. This will be // passed as the const ExecutableAccessorInfo& to the C++ callback. @@ -1420,7 +1420,7 @@ void BaseLoadStubCompiler::GenerateLoadCallback( __ CallApiFunctionAndReturn(getter_address, kStackSpace, returns_handle, - 4); + 5); } diff --git a/src/x64/stub-cache-x64.cc b/src/x64/stub-cache-x64.cc index 36fcb84..c1cab8f 100644 --- a/src/x64/stub-cache-x64.cc +++ b/src/x64/stub-cache-x64.cc @@ -1303,9 +1303,9 @@ void BaseLoadStubCompiler::GenerateLoadCallback( } else { __ Push(Handle(callback->data(), isolate())); } - __ PushAddress(ExternalReference::isolate_address(isolate())); __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); __ push(kScratchRegister); // return value + __ PushAddress(ExternalReference::isolate_address(isolate())); __ push(name()); // name // Save a pointer to where we pushed the arguments pointer. This will be // passed as the const ExecutableAccessorInfo& to the C++ callback. @@ -1350,7 +1350,7 @@ void BaseLoadStubCompiler::GenerateLoadCallback( __ CallApiFunctionAndReturn(getter_address, kStackSpace, returns_handle, - 3); + 4); } diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 2e5cce6..9097039 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -810,7 +810,8 @@ template static void CheckReturnValue(const T& t) { v8::ReturnValue rv = t.GetReturnValue(); i::Object** o = *reinterpret_cast(&rv); - CHECK_EQ(t.GetIsolate(), v8::Isolate::GetCurrent()); + CHECK_EQ(v8::Isolate::GetCurrent(), t.GetIsolate()); + CHECK_EQ(t.GetIsolate(), rv.GetIsolate()); CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); } @@ -927,7 +928,7 @@ static void TestFunctionTemplateInitializer(Handler handler, LocalContext env; v8::HandleScope scope(env->GetIsolate()); Local fun_templ = v8::FunctionTemplate::New(); - fun_templ->SetCallHandler(handler); + fun_templ->SetCallHandler(handler_2); Local fun = fun_templ->GetFunction(); env->Global()->Set(v8_str("obj"), fun); Local