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

Side by Side Diff: test/cctest/test-api.cc

Issue 16073010: ReturnValue::Set needs to check for empty handles (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 template<typename T> 1022 template<typename T>
1023 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); 1023 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info);
1024 1024
1025 // constant return values 1025 // constant return values
1026 static const int32_t kFastReturnValueInt32 = 471; 1026 static const int32_t kFastReturnValueInt32 = 471;
1027 static const uint32_t kFastReturnValueUint32 = 571; 1027 static const uint32_t kFastReturnValueUint32 = 571;
1028 static const double kFastReturnValueDouble = 2.7; 1028 static const double kFastReturnValueDouble = 2.7;
1029 // variable return values 1029 // variable return values
1030 static bool fast_return_value_bool = false; 1030 static bool fast_return_value_bool = false;
1031 static bool fast_return_value_void_is_null = false; 1031 static bool fast_return_value_void_is_null = false;
1032 static bool fast_return_value_object_is_empty = false;
1032 1033
1033 template<> 1034 template<>
1034 void FastReturnValueCallback<int32_t>( 1035 void FastReturnValueCallback<int32_t>(
1035 const v8::FunctionCallbackInfo<v8::Value>& info) { 1036 const v8::FunctionCallbackInfo<v8::Value>& info) {
1036 CheckReturnValue(info); 1037 CheckReturnValue(info);
1037 info.GetReturnValue().Set(kFastReturnValueInt32); 1038 info.GetReturnValue().Set(kFastReturnValueInt32);
1038 } 1039 }
1039 1040
1040 template<> 1041 template<>
1041 void FastReturnValueCallback<uint32_t>( 1042 void FastReturnValueCallback<uint32_t>(
(...skipping 23 matching lines...) Expand all
1065 if (fast_return_value_void_is_null) { 1066 if (fast_return_value_void_is_null) {
1066 info.GetReturnValue().SetNull(); 1067 info.GetReturnValue().SetNull();
1067 } else { 1068 } else {
1068 info.GetReturnValue().SetUndefined(); 1069 info.GetReturnValue().SetUndefined();
1069 } 1070 }
1070 } 1071 }
1071 1072
1072 template<> 1073 template<>
1073 void FastReturnValueCallback<Object>( 1074 void FastReturnValueCallback<Object>(
1074 const v8::FunctionCallbackInfo<v8::Value>& info) { 1075 const v8::FunctionCallbackInfo<v8::Value>& info) {
1075 info.GetReturnValue().Set(Object::New()); 1076 v8::Handle<v8::Object> object;
1077 if (!fast_return_value_object_is_empty) object = Object::New();
1078 info.GetReturnValue().Set(object);
1076 } 1079 }
1077 1080
1078 template<typename T> 1081 template<typename T>
1079 Handle<Value> TestFastReturnValues() { 1082 Handle<Value> TestFastReturnValues() {
1080 LocalContext env; 1083 LocalContext env;
1081 v8::HandleScope scope(env->GetIsolate()); 1084 v8::HandleScope scope(env->GetIsolate());
1082 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1085 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1083 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1086 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1084 object_template->Set("callback", v8::FunctionTemplate::New(callback)); 1087 object_template->Set("callback", v8::FunctionTemplate::New(callback));
1085 v8::Local<v8::Object> object = object_template->NewInstance(); 1088 v8::Local<v8::Object> object = object_template->NewInstance();
(...skipping 26 matching lines...) Expand all
1112 // check oddballs 1115 // check oddballs
1113 for (int i = 0; i < 2; i++) { 1116 for (int i = 0; i < 2; i++) {
1114 fast_return_value_void_is_null = i == 0; 1117 fast_return_value_void_is_null = i == 0;
1115 value = TestFastReturnValues<void>(); 1118 value = TestFastReturnValues<void>();
1116 if (fast_return_value_void_is_null) { 1119 if (fast_return_value_void_is_null) {
1117 CHECK(value->IsNull()); 1120 CHECK(value->IsNull());
1118 } else { 1121 } else {
1119 CHECK(value->IsUndefined()); 1122 CHECK(value->IsUndefined());
1120 } 1123 }
1121 } 1124 }
1125 // check handles
1126 fast_return_value_object_is_empty = false;
1122 value = TestFastReturnValues<Object>(); 1127 value = TestFastReturnValues<Object>();
1123 CHECK(value->IsObject()); 1128 CHECK(value->IsObject());
1129 fast_return_value_object_is_empty = true;
1130 value = TestFastReturnValues<Object>();
1131 CHECK(value->IsUndefined());
1124 } 1132 }
1125 1133
1126 1134
1127 THREADED_TEST(FunctionTemplateSetLength) { 1135 THREADED_TEST(FunctionTemplateSetLength) {
1128 LocalContext env; 1136 LocalContext env;
1129 v8::HandleScope scope(env->GetIsolate()); 1137 v8::HandleScope scope(env->GetIsolate());
1130 { 1138 {
1131 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( 1139 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(
1132 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23); 1140 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23);
1133 Local<Function> fun = fun_templ->GetFunction(); 1141 Local<Function> fun = fun_templ->GetFunction();
(...skipping 17941 matching lines...) Expand 10 before | Expand all | Expand 10 after
19075 i::Semaphore* sem_; 19083 i::Semaphore* sem_;
19076 volatile int sem_value_; 19084 volatile int sem_value_;
19077 }; 19085 };
19078 19086
19079 19087
19080 THREADED_TEST(SemaphoreInterruption) { 19088 THREADED_TEST(SemaphoreInterruption) {
19081 ThreadInterruptTest().RunTest(); 19089 ThreadInterruptTest().RunTest();
19082 } 19090 }
19083 19091
19084 #endif // WIN32 19092 #endif // WIN32
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698