make isolate accessible from returnvalue
authordcarney@chromium.org <dcarney@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 27 May 2013 11:50:08 +0000 (11:50 +0000)
committerdcarney@chromium.org <dcarney@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 27 May 2013 11:50:08 +0000 (11:50 +0000)
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

include/v8.h
src/arm/stub-cache-arm.cc
src/ia32/stub-cache-ia32.cc
src/x64/stub-cache-x64.cc
test/cctest/test-api.cc

index 7dfc918..b5c780a 100644 (file)
@@ -2782,16 +2782,16 @@ class ReturnValue {
   V8_INLINE(void Set(const Persistent<T>& handle));
   V8_INLINE(void Set(const Handle<T> 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<T>::Set(const Handle<T> handle) {
 }
 
 template<typename T>
-void ReturnValue<T>::Set(Isolate* isolate, double i) {
-  Set(Number::New(isolate, i));
+void ReturnValue<T>::Set(double i) {
+  Set(Number::New(GetIsolate(), i));
 }
 
 template<typename T>
-void ReturnValue<T>::Set(Isolate* isolate, int32_t i) {
+void ReturnValue<T>::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<typename T>
-void ReturnValue<T>::Set(Isolate* isolate, uint32_t i) {
+void ReturnValue<T>::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<typename T>
-void ReturnValue<T>::Set(Isolate* isolate, bool value) {
+void ReturnValue<T>::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<typename T>
-void ReturnValue<T>::SetTrue(Isolate* isolate) {
-  typedef internal::Internals I;
-  *value_ = *I::GetRoot(isolate, I::kTrueValueRootIndex);
-}
-
-template<typename T>
-void ReturnValue<T>::SetFalse(Isolate* isolate) {
+void ReturnValue<T>::SetNull() {
   typedef internal::Internals I;
-  *value_ = *I::GetRoot(isolate, I::kFalseValueRootIndex);
+  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
 }
 
 template<typename T>
-void ReturnValue<T>::SetNull(Isolate* isolate) {
+void ReturnValue<T>::SetUndefined() {
   typedef internal::Internals I;
-  *value_ = *I::GetRoot(isolate, I::kNullValueRootIndex);
+  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
 }
 
 template<typename T>
-void ReturnValue<T>::SetUndefined(Isolate* isolate) {
-  typedef internal::Internals I;
-  *value_ = *I::GetRoot(isolate, I::kUndefinedValueRootIndex);
+Isolate* ReturnValue<T>::GetIsolate() {
+  // Isolate is always the pointer below value_ on the stack.
+  return *reinterpret_cast<Isolate**>(&value_[-1]);
 }
 
 
index 1ede12c..912caed 100644 (file)
@@ -1433,9 +1433,9 @@ void BaseLoadStubCompiler::GenerateLoadCallback(
     __ Move(scratch3(), Handle<Object>(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<Name>
 
@@ -1462,7 +1462,7 @@ void BaseLoadStubCompiler::GenerateLoadCallback(
   __ CallApiFunctionAndReturn(ref,
                               kStackUnwindSpace,
                               returns_handle,
-                              3);
+                              4);
 }
 
 
index e1db7cd..7cb7811 100644 (file)
@@ -1386,8 +1386,8 @@ void BaseLoadStubCompiler::GenerateLoadCallback(
   } else {
     __ push(Immediate(Handle<Object>(callback->data(), isolate())));
   }
-  __ push(Immediate(reinterpret_cast<int>(isolate())));
   __ push(Immediate(isolate()->factory()->undefined_value()));  // ReturnValue
+  __ push(Immediate(reinterpret_cast<int>(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);
 }
 
 
index 36fcb84..c1cab8f 100644 (file)
@@ -1303,9 +1303,9 @@ void BaseLoadStubCompiler::GenerateLoadCallback(
   } else {
     __ Push(Handle<Object>(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);
 }
 
 
index 2e5cce6..9097039 100644 (file)
@@ -810,7 +810,8 @@ template<typename T>
 static void CheckReturnValue(const T& t) {
   v8::ReturnValue<v8::Value> rv = t.GetReturnValue();
   i::Object** o = *reinterpret_cast<i::Object***>(&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<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
-    fun_templ->SetCallHandler(handler);
+    fun_templ->SetCallHandler(handler_2);
     Local<Function> fun = fun_templ->GetFunction();
     env->Global()->Set(v8_str("obj"), fun);
     Local<Script> script = v8_compile("obj()");
@@ -1037,34 +1038,39 @@ static bool fast_return_value_void_is_null = false;
 template<>
 void FastReturnValueCallback<int32_t>(
     const v8::FunctionCallbackInfo<v8::Value>& info) {
-  info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueInt32);
+  CheckReturnValue(info);
+  info.GetReturnValue().Set(kFastReturnValueInt32);
 }
 
 template<>
 void FastReturnValueCallback<uint32_t>(
     const v8::FunctionCallbackInfo<v8::Value>& info) {
-  info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueUint32);
+  CheckReturnValue(info);
+  info.GetReturnValue().Set(kFastReturnValueUint32);
 }
 
 template<>
 void FastReturnValueCallback<double>(
     const v8::FunctionCallbackInfo<v8::Value>& info) {
-  info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueDouble);
+  CheckReturnValue(info);
+  info.GetReturnValue().Set(kFastReturnValueDouble);
 }
 
 template<>
 void FastReturnValueCallback<bool>(
     const v8::FunctionCallbackInfo<v8::Value>& info) {
-  info.GetReturnValue().Set(info.GetIsolate(), fast_return_value_bool);
+  CheckReturnValue(info);
+  info.GetReturnValue().Set(fast_return_value_bool);
 }
 
 template<>
 void FastReturnValueCallback<void>(
     const v8::FunctionCallbackInfo<v8::Value>& info) {
+  CheckReturnValue(info);
   if (fast_return_value_void_is_null) {
-    info.GetReturnValue().SetNull(info.GetIsolate());
+    info.GetReturnValue().SetNull();
   } else {
-    info.GetReturnValue().SetUndefined(info.GetIsolate());
+    info.GetReturnValue().SetUndefined();
   }
 }