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

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

Issue 6960009: Version 3.3.5 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 7 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 | « test/cctest/cctest.gyp ('k') | test/cctest/test-thread-termination.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <limits.h> 28 #include <limits.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "api.h" 32 #include "api.h"
33 #include "isolate.h"
33 #include "compilation-cache.h" 34 #include "compilation-cache.h"
34 #include "execution.h" 35 #include "execution.h"
35 #include "snapshot.h" 36 #include "snapshot.h"
36 #include "platform.h" 37 #include "platform.h"
37 #include "utils.h" 38 #include "utils.h"
38 #include "cctest.h" 39 #include "cctest.h"
39 #include "parser.h" 40 #include "parser.h"
40 #include "unicode-inl.h" 41 #include "unicode-inl.h"
41 42
42 static const bool kLogThreading = false; 43 static const bool kLogThreading = false;
(...skipping 6696 matching lines...) Expand 10 before | Expand all | Expand 10 after
6739 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 6740 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
6740 templ->SetClassName(v8_str("Fun")); 6741 templ->SetClassName(v8_str("Fun"));
6741 Local<Function> cons = templ->GetFunction(); 6742 Local<Function> cons = templ->GetFunction();
6742 context->Global()->Set(v8_str("Fun"), cons); 6743 context->Global()->Set(v8_str("Fun"), cons);
6743 Local<v8::Object> inst = cons->NewInstance(); 6744 Local<v8::Object> inst = cons->NewInstance();
6744 i::Handle<i::JSObject> obj = v8::Utils::OpenHandle(*inst); 6745 i::Handle<i::JSObject> obj = v8::Utils::OpenHandle(*inst);
6745 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 6746 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
6746 CHECK(value->BooleanValue()); 6747 CHECK(value->BooleanValue());
6747 } 6748 }
6748 6749
6750
6751 static Handle<Value> ConstructorCallback(const Arguments& args) {
6752 ApiTestFuzzer::Fuzz();
6753 Local<Object> This;
6754
6755 if (args.IsConstructCall()) {
6756 Local<Object> Holder = args.Holder();
6757 This = Object::New();
6758 Local<Value> proto = Holder->GetPrototype();
6759 if (proto->IsObject()) {
6760 This->SetPrototype(proto);
6761 }
6762 } else {
6763 This = args.This();
6764 }
6765
6766 This->Set(v8_str("a"), args[0]);
6767 return This;
6768 }
6769
6770
6771 static Handle<Value> FakeConstructorCallback(const Arguments& args) {
6772 ApiTestFuzzer::Fuzz();
6773 return args[0];
6774 }
6775
6776
6777 THREADED_TEST(ConstructorForObject) {
6778 v8::HandleScope handle_scope;
6779 LocalContext context;
6780
6781 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
6782 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
6783 Local<Object> instance = instance_template->NewInstance();
6784 context->Global()->Set(v8_str("obj"), instance);
6785 v8::TryCatch try_catch;
6786 Local<Value> value;
6787 CHECK(!try_catch.HasCaught());
6788
6789 // Call the Object's constructor with a 32-bit signed integer.
6790 value = CompileRun("(function() { var o = new obj(28); return o.a; })()");
6791 CHECK(!try_catch.HasCaught());
6792 CHECK(value->IsInt32());
6793 CHECK_EQ(28, value->Int32Value());
6794
6795 Local<Value> args1[] = { v8_num(28) };
6796 Local<Value> value_obj1 = instance->CallAsConstructor(1, args1);
6797 CHECK(value_obj1->IsObject());
6798 Local<Object> object1 = Local<Object>::Cast(value_obj1);
6799 value = object1->Get(v8_str("a"));
6800 CHECK(value->IsInt32());
6801 CHECK(!try_catch.HasCaught());
6802 CHECK_EQ(28, value->Int32Value());
6803
6804 // Call the Object's constructor with a String.
6805 value = CompileRun(
6806 "(function() { var o = new obj('tipli'); return o.a; })()");
6807 CHECK(!try_catch.HasCaught());
6808 CHECK(value->IsString());
6809 String::AsciiValue string_value1(value->ToString());
6810 CHECK_EQ("tipli", *string_value1);
6811
6812 Local<Value> args2[] = { v8_str("tipli") };
6813 Local<Value> value_obj2 = instance->CallAsConstructor(1, args2);
6814 CHECK(value_obj2->IsObject());
6815 Local<Object> object2 = Local<Object>::Cast(value_obj2);
6816 value = object2->Get(v8_str("a"));
6817 CHECK(!try_catch.HasCaught());
6818 CHECK(value->IsString());
6819 String::AsciiValue string_value2(value->ToString());
6820 CHECK_EQ("tipli", *string_value2);
6821
6822 // Call the Object's constructor with a Boolean.
6823 value = CompileRun("(function() { var o = new obj(true); return o.a; })()");
6824 CHECK(!try_catch.HasCaught());
6825 CHECK(value->IsBoolean());
6826 CHECK_EQ(true, value->BooleanValue());
6827
6828 Handle<Value> args3[] = { v8::Boolean::New(true) };
6829 Local<Value> value_obj3 = instance->CallAsConstructor(1, args3);
6830 CHECK(value_obj3->IsObject());
6831 Local<Object> object3 = Local<Object>::Cast(value_obj3);
6832 value = object3->Get(v8_str("a"));
6833 CHECK(!try_catch.HasCaught());
6834 CHECK(value->IsBoolean());
6835 CHECK_EQ(true, value->BooleanValue());
6836
6837 // Call the Object's constructor with undefined.
6838 Handle<Value> args4[] = { v8::Undefined() };
6839 Local<Value> value_obj4 = instance->CallAsConstructor(1, args4);
6840 CHECK(value_obj4->IsObject());
6841 Local<Object> object4 = Local<Object>::Cast(value_obj4);
6842 value = object4->Get(v8_str("a"));
6843 CHECK(!try_catch.HasCaught());
6844 CHECK(value->IsUndefined());
6845
6846 // Call the Object's constructor with null.
6847 Handle<Value> args5[] = { v8::Null() };
6848 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5);
6849 CHECK(value_obj5->IsObject());
6850 Local<Object> object5 = Local<Object>::Cast(value_obj5);
6851 value = object5->Get(v8_str("a"));
6852 CHECK(!try_catch.HasCaught());
6853 CHECK(value->IsNull());
6854 }
6855
6856 // Check exception handling when there is no constructor set for the Object.
6857 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
6858 Local<Object> instance = instance_template->NewInstance();
6859 context->Global()->Set(v8_str("obj2"), instance);
6860 v8::TryCatch try_catch;
6861 Local<Value> value;
6862 CHECK(!try_catch.HasCaught());
6863
6864 value = CompileRun("new obj2(28)");
6865 CHECK(try_catch.HasCaught());
6866 String::AsciiValue exception_value1(try_catch.Exception());
6867 CHECK_EQ("TypeError: object is not a function", *exception_value1);
6868 try_catch.Reset();
6869
6870 Local<Value> args[] = { v8_num(29) };
6871 value = instance->CallAsConstructor(1, args);
6872 CHECK(try_catch.HasCaught());
6873 String::AsciiValue exception_value2(try_catch.Exception());
6874 CHECK_EQ("TypeError: #<Object> is not a function", *exception_value2);
6875 try_catch.Reset();
6876 }
6877
6878 // Check the case when constructor throws exception.
6879 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
6880 instance_template->SetCallAsFunctionHandler(ThrowValue);
6881 Local<Object> instance = instance_template->NewInstance();
6882 context->Global()->Set(v8_str("obj3"), instance);
6883 v8::TryCatch try_catch;
6884 Local<Value> value;
6885 CHECK(!try_catch.HasCaught());
6886
6887 value = CompileRun("new obj3(22)");
6888 CHECK(try_catch.HasCaught());
6889 String::AsciiValue exception_value1(try_catch.Exception());
6890 CHECK_EQ("22", *exception_value1);
6891 try_catch.Reset();
6892
6893 Local<Value> args[] = { v8_num(23) };
6894 value = instance->CallAsConstructor(1, args);
6895 CHECK(try_catch.HasCaught());
6896 String::AsciiValue exception_value2(try_catch.Exception());
6897 CHECK_EQ("23", *exception_value2);
6898 try_catch.Reset();
6899 }
6900
6901 // Check whether constructor returns with an object or non-object.
6902 { Local<FunctionTemplate> function_template =
6903 FunctionTemplate::New(FakeConstructorCallback);
6904 Local<Function> function = function_template->GetFunction();
6905 Local<Object> instance1 = function;
6906 context->Global()->Set(v8_str("obj4"), instance1);
6907 v8::TryCatch try_catch;
6908 Local<Value> value;
6909 CHECK(!try_catch.HasCaught());
6910
6911 CHECK(instance1->IsObject());
6912 CHECK(instance1->IsFunction());
6913
6914 value = CompileRun("new obj4(28)");
6915 CHECK(!try_catch.HasCaught());
6916 CHECK(value->IsObject());
6917
6918 Local<Value> args1[] = { v8_num(28) };
6919 value = instance1->CallAsConstructor(1, args1);
6920 CHECK(!try_catch.HasCaught());
6921 CHECK(value->IsObject());
6922
6923 Local<ObjectTemplate> instance_template = ObjectTemplate::New();
6924 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback);
6925 Local<Object> instance2 = instance_template->NewInstance();
6926 context->Global()->Set(v8_str("obj5"), instance2);
6927 CHECK(!try_catch.HasCaught());
6928
6929 CHECK(instance2->IsObject());
6930 CHECK(!instance2->IsFunction());
6931
6932 value = CompileRun("new obj5(28)");
6933 CHECK(!try_catch.HasCaught());
6934 CHECK(!value->IsObject());
6935
6936 Local<Value> args2[] = { v8_num(28) };
6937 value = instance2->CallAsConstructor(1, args2);
6938 CHECK(!try_catch.HasCaught());
6939 CHECK(!value->IsObject());
6940 }
6941 }
6942
6943
6749 THREADED_TEST(FunctionDescriptorException) { 6944 THREADED_TEST(FunctionDescriptorException) {
6750 v8::HandleScope handle_scope; 6945 v8::HandleScope handle_scope;
6751 LocalContext context; 6946 LocalContext context;
6752 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 6947 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
6753 templ->SetClassName(v8_str("Fun")); 6948 templ->SetClassName(v8_str("Fun"));
6754 Local<Function> cons = templ->GetFunction(); 6949 Local<Function> cons = templ->GetFunction();
6755 context->Global()->Set(v8_str("Fun"), cons); 6950 context->Global()->Set(v8_str("Fun"), cons);
6756 Local<Value> value = CompileRun( 6951 Local<Value> value = CompileRun(
6757 "function test() {" 6952 "function test() {"
6758 " try {" 6953 " try {"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
6955 } 7150 }
6956 7151
6957 7152
6958 // Test that a call handler can be set for objects which will allow 7153 // Test that a call handler can be set for objects which will allow
6959 // non-function objects created through the API to be called as 7154 // non-function objects created through the API to be called as
6960 // functions. 7155 // functions.
6961 THREADED_TEST(CallAsFunction) { 7156 THREADED_TEST(CallAsFunction) {
6962 v8::HandleScope scope; 7157 v8::HandleScope scope;
6963 LocalContext context; 7158 LocalContext context;
6964 7159
6965 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 7160 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
6966 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 7161 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
6967 instance_template->SetCallAsFunctionHandler(call_as_function); 7162 instance_template->SetCallAsFunctionHandler(call_as_function);
6968 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 7163 Local<v8::Object> instance = t->GetFunction()->NewInstance();
6969 context->Global()->Set(v8_str("obj"), instance); 7164 context->Global()->Set(v8_str("obj"), instance);
6970 v8::TryCatch try_catch; 7165 v8::TryCatch try_catch;
6971 Local<Value> value; 7166 Local<Value> value;
6972 CHECK(!try_catch.HasCaught()); 7167 CHECK(!try_catch.HasCaught());
6973 7168
6974 value = CompileRun("obj(42)"); 7169 value = CompileRun("obj(42)");
6975 CHECK(!try_catch.HasCaught()); 7170 CHECK(!try_catch.HasCaught());
6976 CHECK_EQ(42, value->Int32Value()); 7171 CHECK_EQ(42, value->Int32Value());
6977 7172
6978 value = CompileRun("(function(o){return o(49)})(obj)"); 7173 value = CompileRun("(function(o){return o(49)})(obj)");
6979 CHECK(!try_catch.HasCaught()); 7174 CHECK(!try_catch.HasCaught());
6980 CHECK_EQ(49, value->Int32Value()); 7175 CHECK_EQ(49, value->Int32Value());
6981 7176
6982 // test special case of call as function 7177 // test special case of call as function
6983 value = CompileRun("[obj]['0'](45)"); 7178 value = CompileRun("[obj]['0'](45)");
6984 CHECK(!try_catch.HasCaught()); 7179 CHECK(!try_catch.HasCaught());
6985 CHECK_EQ(45, value->Int32Value()); 7180 CHECK_EQ(45, value->Int32Value());
6986 7181
6987 value = CompileRun("obj.call = Function.prototype.call;" 7182 value = CompileRun("obj.call = Function.prototype.call;"
6988 "obj.call(null, 87)"); 7183 "obj.call(null, 87)");
6989 CHECK(!try_catch.HasCaught()); 7184 CHECK(!try_catch.HasCaught());
6990 CHECK_EQ(87, value->Int32Value()); 7185 CHECK_EQ(87, value->Int32Value());
6991 7186
6992 // Regression tests for bug #1116356: Calling call through call/apply 7187 // Regression tests for bug #1116356: Calling call through call/apply
6993 // must work for non-function receivers. 7188 // must work for non-function receivers.
6994 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])"; 7189 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])";
6995 value = CompileRun(apply_99); 7190 value = CompileRun(apply_99);
6996 CHECK(!try_catch.HasCaught()); 7191 CHECK(!try_catch.HasCaught());
6997 CHECK_EQ(99, value->Int32Value()); 7192 CHECK_EQ(99, value->Int32Value());
6998 7193
6999 const char* call_17 = "Function.prototype.call.call(obj, this, 17)"; 7194 const char* call_17 = "Function.prototype.call.call(obj, this, 17)";
7000 value = CompileRun(call_17); 7195 value = CompileRun(call_17);
7001 CHECK(!try_catch.HasCaught()); 7196 CHECK(!try_catch.HasCaught());
7002 CHECK_EQ(17, value->Int32Value()); 7197 CHECK_EQ(17, value->Int32Value());
7003 7198
7004 // Check that the call-as-function handler can be called through 7199 // Check that the call-as-function handler can be called through
7005 // new. 7200 // new.
7006 value = CompileRun("new obj(43)"); 7201 value = CompileRun("new obj(43)");
7007 CHECK(!try_catch.HasCaught()); 7202 CHECK(!try_catch.HasCaught());
7008 CHECK_EQ(-43, value->Int32Value()); 7203 CHECK_EQ(-43, value->Int32Value());
7204
7205 // Check that the call-as-function handler can be called through
7206 // the API.
7207 v8::Handle<Value> args[] = { v8_num(28) };
7208 value = instance->CallAsFunction(instance, 1, args);
7209 CHECK(!try_catch.HasCaught());
7210 CHECK_EQ(28, value->Int32Value());
7211 }
7212
7213 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
7214 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
7215 Local<v8::Object> instance = t->GetFunction()->NewInstance();
7216 context->Global()->Set(v8_str("obj2"), instance);
7217 v8::TryCatch try_catch;
7218 Local<Value> value;
7219 CHECK(!try_catch.HasCaught());
7220
7221 // Call an object without call-as-function handler through the JS
7222 value = CompileRun("obj2(28)");
7223 CHECK(value.IsEmpty());
7224 CHECK(try_catch.HasCaught());
7225 String::AsciiValue exception_value1(try_catch.Exception());
7226 CHECK_EQ("TypeError: Property 'obj2' of object #<Object> is not a function",
7227 *exception_value1);
7228 try_catch.Reset();
7229
7230 // Call an object without call-as-function handler through the API
7231 value = CompileRun("obj2(28)");
7232 v8::Handle<Value> args[] = { v8_num(28) };
7233 value = instance->CallAsFunction(instance, 1, args);
7234 CHECK(value.IsEmpty());
7235 CHECK(try_catch.HasCaught());
7236 String::AsciiValue exception_value2(try_catch.Exception());
7237 CHECK_EQ("TypeError: [object Object] is not a function", *exception_value2);
7238 try_catch.Reset();
7239 }
7240
7241 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
7242 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
7243 instance_template->SetCallAsFunctionHandler(ThrowValue);
7244 Local<v8::Object> instance = t->GetFunction()->NewInstance();
7245 context->Global()->Set(v8_str("obj3"), instance);
7246 v8::TryCatch try_catch;
7247 Local<Value> value;
7248 CHECK(!try_catch.HasCaught());
7249
7250 // Catch the exception which is thrown by call-as-function handler
7251 value = CompileRun("obj3(22)");
7252 CHECK(try_catch.HasCaught());
7253 String::AsciiValue exception_value1(try_catch.Exception());
7254 CHECK_EQ("22", *exception_value1);
7255 try_catch.Reset();
7256
7257 v8::Handle<Value> args[] = { v8_num(23) };
7258 value = instance->CallAsFunction(instance, 1, args);
7259 CHECK(try_catch.HasCaught());
7260 String::AsciiValue exception_value2(try_catch.Exception());
7261 CHECK_EQ("23", *exception_value2);
7262 try_catch.Reset();
7263 }
7009 } 7264 }
7010 7265
7011 7266
7012 static int CountHandles() { 7267 static int CountHandles() {
7013 return v8::HandleScope::NumberOfHandles(); 7268 return v8::HandleScope::NumberOfHandles();
7014 } 7269 }
7015 7270
7016 7271
7017 static int Recurse(int depth, int iterations) { 7272 static int Recurse(int depth, int iterations) {
7018 v8::HandleScope scope; 7273 v8::HandleScope scope;
(...skipping 1920 matching lines...) Expand 10 before | Expand all | Expand 10 after
8939 } 9194 }
8940 } 9195 }
8941 9196
8942 9197
8943 static unsigned linear_congruential_generator; 9198 static unsigned linear_congruential_generator;
8944 9199
8945 9200
8946 void ApiTestFuzzer::Setup(PartOfTest part) { 9201 void ApiTestFuzzer::Setup(PartOfTest part) {
8947 linear_congruential_generator = i::FLAG_testing_prng_seed; 9202 linear_congruential_generator = i::FLAG_testing_prng_seed;
8948 fuzzing_ = true; 9203 fuzzing_ = true;
8949 int start = (part == FIRST_PART) ? 0 : (RegisterThreadedTest::count() >> 1); 9204 int count = RegisterThreadedTest::count();
8950 int end = (part == FIRST_PART) 9205 int start = count * part / (LAST_PART + 1);
8951 ? (RegisterThreadedTest::count() >> 1) 9206 int end = (count * (part + 1) / (LAST_PART + 1)) - 1;
8952 : RegisterThreadedTest::count(); 9207 active_tests_ = tests_being_run_ = end - start + 1;
8953 active_tests_ = tests_being_run_ = end - start;
8954 for (int i = 0; i < tests_being_run_; i++) { 9208 for (int i = 0; i < tests_being_run_; i++) {
8955 RegisterThreadedTest::nth(i)->fuzzer_ = new ApiTestFuzzer( 9209 RegisterThreadedTest::nth(i)->fuzzer_ = new ApiTestFuzzer(
8956 i::Isolate::Current(), i + start); 9210 i::Isolate::Current(), i + start);
8957 } 9211 }
8958 for (int i = 0; i < active_tests_; i++) { 9212 for (int i = 0; i < active_tests_; i++) {
8959 RegisterThreadedTest::nth(i)->fuzzer_->Start(); 9213 RegisterThreadedTest::nth(i)->fuzzer_->Start();
8960 } 9214 }
8961 } 9215 }
8962 9216
8963 9217
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
9013 ApiTestFuzzer::RunAllTests(); 9267 ApiTestFuzzer::RunAllTests();
9014 ApiTestFuzzer::TearDown(); 9268 ApiTestFuzzer::TearDown();
9015 } 9269 }
9016 9270
9017 TEST(Threading2) { 9271 TEST(Threading2) {
9018 ApiTestFuzzer::Setup(ApiTestFuzzer::SECOND_PART); 9272 ApiTestFuzzer::Setup(ApiTestFuzzer::SECOND_PART);
9019 ApiTestFuzzer::RunAllTests(); 9273 ApiTestFuzzer::RunAllTests();
9020 ApiTestFuzzer::TearDown(); 9274 ApiTestFuzzer::TearDown();
9021 } 9275 }
9022 9276
9277 TEST(Threading3) {
9278 ApiTestFuzzer::Setup(ApiTestFuzzer::THIRD_PART);
9279 ApiTestFuzzer::RunAllTests();
9280 ApiTestFuzzer::TearDown();
9281 }
9282
9283 TEST(Threading4) {
9284 ApiTestFuzzer::Setup(ApiTestFuzzer::FOURTH_PART);
9285 ApiTestFuzzer::RunAllTests();
9286 ApiTestFuzzer::TearDown();
9287 }
9023 9288
9024 void ApiTestFuzzer::CallTest() { 9289 void ApiTestFuzzer::CallTest() {
9025 if (kLogThreading) 9290 if (kLogThreading)
9026 printf("Start test %d\n", test_number_); 9291 printf("Start test %d\n", test_number_);
9027 CallTestNumber(test_number_); 9292 CallTestNumber(test_number_);
9028 if (kLogThreading) 9293 if (kLogThreading)
9029 printf("End test %d\n", test_number_); 9294 printf("End test %d\n", test_number_);
9030 } 9295 }
9031 9296
9032 9297
(...skipping 4348 matching lines...) Expand 10 before | Expand all | Expand 10 after
13381 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number 13646 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number
13382 CHECK_EQ(result1, 10946); 13647 CHECK_EQ(result1, 10946);
13383 CHECK_EQ(result2, 144); 13648 CHECK_EQ(result2, 144);
13384 CHECK_EQ(result1, thread1.result()); 13649 CHECK_EQ(result1, thread1.result());
13385 CHECK_EQ(result2, thread2.result()); 13650 CHECK_EQ(result2, thread2.result());
13386 13651
13387 isolate1->Dispose(); 13652 isolate1->Dispose();
13388 isolate2->Dispose(); 13653 isolate2->Dispose();
13389 } 13654 }
13390 13655
13656 TEST(IsolateDifferentContexts) {
13657 v8::Isolate* isolate = v8::Isolate::New();
13658 Persistent<v8::Context> context;
13659 {
13660 v8::Isolate::Scope isolate_scope(isolate);
13661 v8::HandleScope handle_scope;
13662 context = v8::Context::New();
13663 v8::Context::Scope context_scope(context);
13664 Local<Value> v = CompileRun("2");
13665 CHECK(v->IsNumber());
13666 CHECK_EQ(2, static_cast<int>(v->NumberValue()));
13667 }
13668 {
13669 v8::Isolate::Scope isolate_scope(isolate);
13670 v8::HandleScope handle_scope;
13671 context = v8::Context::New();
13672 v8::Context::Scope context_scope(context);
13673 Local<Value> v = CompileRun("22");
13674 CHECK(v->IsNumber());
13675 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
13676 }
13677 }
13391 13678
13392 class InitDefaultIsolateThread : public v8::internal::Thread { 13679 class InitDefaultIsolateThread : public v8::internal::Thread {
13393 public: 13680 public:
13394 enum TestCase { 13681 enum TestCase {
13395 IgnoreOOM, 13682 IgnoreOOM,
13396 SetResourceConstraints, 13683 SetResourceConstraints,
13397 SetFatalHandler, 13684 SetFatalHandler,
13398 SetCounterFunction, 13685 SetCounterFunction,
13399 SetCreateHistogramFunction, 13686 SetCreateHistogramFunction,
13400 SetAddHistogramSampleFunction 13687 SetAddHistogramSampleFunction
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
14097 14384
14098 // Disallow but setting a global callback that will allow the calls. 14385 // Disallow but setting a global callback that will allow the calls.
14099 context->AllowCodeGenerationFromStrings(false); 14386 context->AllowCodeGenerationFromStrings(false);
14100 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); 14387 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed);
14101 CheckCodeGenerationAllowed(); 14388 CheckCodeGenerationAllowed();
14102 14389
14103 // Set a callback that disallows the code generation. 14390 // Set a callback that disallows the code generation.
14104 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 14391 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
14105 CheckCodeGenerationDisallowed(); 14392 CheckCodeGenerationDisallowed();
14106 } 14393 }
14394
14395
14396 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) {
14397 return v8::Undefined();
14398 }
14399
14400
14401 THREADED_TEST(CallAPIFunctionOnNonObject) {
14402 v8::HandleScope scope;
14403 LocalContext context;
14404 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis);
14405 Handle<Function> function = templ->GetFunction();
14406 context->Global()->Set(v8_str("f"), function);
14407 TryCatch try_catch;
14408 CompileRun("f.call(2)");
14409 CHECK(try_catch.HasCaught());
14410 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/test-thread-termination.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698