Commit c90e697a authored by dcarney@chromium.org's avatar dcarney@chromium.org

make empty string returnable by ReturnValue

R=svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/16621004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15054 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1d4c6459
...@@ -2845,6 +2845,7 @@ class ReturnValue { ...@@ -2845,6 +2845,7 @@ class ReturnValue {
// Fast JS primitive setters // Fast JS primitive setters
V8_INLINE(void SetNull()); V8_INLINE(void SetNull());
V8_INLINE(void SetUndefined()); V8_INLINE(void SetUndefined());
V8_INLINE(void SetEmptyString());
// Convenience getter for Isolate // Convenience getter for Isolate
V8_INLINE(Isolate* GetIsolate()); V8_INLINE(Isolate* GetIsolate());
...@@ -5729,6 +5730,12 @@ void ReturnValue<T>::SetUndefined() { ...@@ -5729,6 +5730,12 @@ void ReturnValue<T>::SetUndefined() {
*value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
} }
template<typename T>
void ReturnValue<T>::SetEmptyString() {
typedef internal::Internals I;
*value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
}
template<typename T> template<typename T>
Isolate* ReturnValue<T>::GetIsolate() { Isolate* ReturnValue<T>::GetIsolate() {
// Isolate is always the pointer below the default value on the stack. // Isolate is always the pointer below the default value on the stack.
......
...@@ -1037,7 +1037,12 @@ static uint32_t fast_return_value_uint32 = 571; ...@@ -1037,7 +1037,12 @@ static uint32_t fast_return_value_uint32 = 571;
static const double kFastReturnValueDouble = 2.7; static const double kFastReturnValueDouble = 2.7;
// variable return values // variable return values
static bool fast_return_value_bool = false; static bool fast_return_value_bool = false;
static bool fast_return_value_void_is_null = false; enum ReturnValueOddball {
kNullReturnValue,
kUndefinedReturnValue,
kEmptyStringReturnValue
};
static ReturnValueOddball fast_return_value_void;
static bool fast_return_value_object_is_empty = false; static bool fast_return_value_object_is_empty = false;
template<> template<>
...@@ -1072,10 +1077,16 @@ template<> ...@@ -1072,10 +1077,16 @@ template<>
void FastReturnValueCallback<void>( void FastReturnValueCallback<void>(
const v8::FunctionCallbackInfo<v8::Value>& info) { const v8::FunctionCallbackInfo<v8::Value>& info) {
CheckReturnValue(info); CheckReturnValue(info);
if (fast_return_value_void_is_null) { switch (fast_return_value_void) {
info.GetReturnValue().SetNull(); case kNullReturnValue:
} else { info.GetReturnValue().SetNull();
info.GetReturnValue().SetUndefined(); break;
case kUndefinedReturnValue:
info.GetReturnValue().SetUndefined();
break;
case kEmptyStringReturnValue:
info.GetReturnValue().SetEmptyString();
break;
} }
} }
...@@ -1135,13 +1146,25 @@ THREADED_TEST(FastReturnValues) { ...@@ -1135,13 +1146,25 @@ THREADED_TEST(FastReturnValues) {
CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value()); CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value());
} }
// check oddballs // check oddballs
for (int i = 0; i < 2; i++) { ReturnValueOddball oddballs[] = {
fast_return_value_void_is_null = i == 0; kNullReturnValue,
kUndefinedReturnValue,
kEmptyStringReturnValue
};
for (size_t i = 0; i < ARRAY_SIZE(oddballs); i++) {
fast_return_value_void = oddballs[i];
value = TestFastReturnValues<void>(); value = TestFastReturnValues<void>();
if (fast_return_value_void_is_null) { switch (fast_return_value_void) {
CHECK(value->IsNull()); case kNullReturnValue:
} else { CHECK(value->IsNull());
CHECK(value->IsUndefined()); break;
case kUndefinedReturnValue:
CHECK(value->IsUndefined());
break;
case kEmptyStringReturnValue:
CHECK(value->IsString());
CHECK_EQ(0, v8::String::Cast(*value)->Length());
break;
} }
} }
// check handles // check handles
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment