OLD | NEW |
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 7246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7257 v8::Handle<Value> args[] = { v8_num(23) }; | 7257 v8::Handle<Value> args[] = { v8_num(23) }; |
7258 value = instance->CallAsFunction(instance, 1, args); | 7258 value = instance->CallAsFunction(instance, 1, args); |
7259 CHECK(try_catch.HasCaught()); | 7259 CHECK(try_catch.HasCaught()); |
7260 String::AsciiValue exception_value2(try_catch.Exception()); | 7260 String::AsciiValue exception_value2(try_catch.Exception()); |
7261 CHECK_EQ("23", *exception_value2); | 7261 CHECK_EQ("23", *exception_value2); |
7262 try_catch.Reset(); | 7262 try_catch.Reset(); |
7263 } | 7263 } |
7264 } | 7264 } |
7265 | 7265 |
7266 | 7266 |
| 7267 // Check whether a non-function object is callable. |
| 7268 THREADED_TEST(CallableObject) { |
| 7269 v8::HandleScope scope; |
| 7270 LocalContext context; |
| 7271 |
| 7272 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); |
| 7273 instance_template->SetCallAsFunctionHandler(call_as_function); |
| 7274 Local<Object> instance = instance_template->NewInstance(); |
| 7275 v8::TryCatch try_catch; |
| 7276 |
| 7277 CHECK(instance->IsCallable()); |
| 7278 CHECK(!try_catch.HasCaught()); |
| 7279 } |
| 7280 |
| 7281 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); |
| 7282 Local<Object> instance = instance_template->NewInstance(); |
| 7283 v8::TryCatch try_catch; |
| 7284 |
| 7285 CHECK(!instance->IsCallable()); |
| 7286 CHECK(!try_catch.HasCaught()); |
| 7287 } |
| 7288 |
| 7289 { Local<FunctionTemplate> function_template = |
| 7290 FunctionTemplate::New(call_as_function); |
| 7291 Local<Function> function = function_template->GetFunction(); |
| 7292 Local<Object> instance = function; |
| 7293 v8::TryCatch try_catch; |
| 7294 |
| 7295 CHECK(instance->IsCallable()); |
| 7296 CHECK(!try_catch.HasCaught()); |
| 7297 } |
| 7298 |
| 7299 { Local<FunctionTemplate> function_template = FunctionTemplate::New(); |
| 7300 Local<Function> function = function_template->GetFunction(); |
| 7301 Local<Object> instance = function; |
| 7302 v8::TryCatch try_catch; |
| 7303 |
| 7304 CHECK(instance->IsCallable()); |
| 7305 CHECK(!try_catch.HasCaught()); |
| 7306 } |
| 7307 } |
| 7308 |
| 7309 |
7267 static int CountHandles() { | 7310 static int CountHandles() { |
7268 return v8::HandleScope::NumberOfHandles(); | 7311 return v8::HandleScope::NumberOfHandles(); |
7269 } | 7312 } |
7270 | 7313 |
7271 | 7314 |
7272 static int Recurse(int depth, int iterations) { | 7315 static int Recurse(int depth, int iterations) { |
7273 v8::HandleScope scope; | 7316 v8::HandleScope scope; |
7274 if (depth == 0) return CountHandles(); | 7317 if (depth == 0) return CountHandles(); |
7275 for (int i = 0; i < iterations; i++) { | 7318 for (int i = 0; i < iterations; i++) { |
7276 Local<v8::Number> n = v8::Integer::New(42); | 7319 Local<v8::Number> n = v8::Integer::New(42); |
(...skipping 7124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14401 THREADED_TEST(CallAPIFunctionOnNonObject) { | 14444 THREADED_TEST(CallAPIFunctionOnNonObject) { |
14402 v8::HandleScope scope; | 14445 v8::HandleScope scope; |
14403 LocalContext context; | 14446 LocalContext context; |
14404 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); | 14447 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); |
14405 Handle<Function> function = templ->GetFunction(); | 14448 Handle<Function> function = templ->GetFunction(); |
14406 context->Global()->Set(v8_str("f"), function); | 14449 context->Global()->Set(v8_str("f"), function); |
14407 TryCatch try_catch; | 14450 TryCatch try_catch; |
14408 CompileRun("f.call(2)"); | 14451 CompileRun("f.call(2)"); |
14409 CHECK(try_catch.HasCaught()); | 14452 CHECK(try_catch.HasCaught()); |
14410 } | 14453 } |
OLD | NEW |