OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 <stdlib.h> | |
29 | |
30 #include "v8.h" | 28 #include "v8.h" |
31 | 29 |
32 #include "api.h" | 30 #include "api.h" |
33 #include "compilation-cache.h" | 31 #include "compilation-cache.h" |
34 #include "execution.h" | 32 #include "execution.h" |
35 #include "snapshot.h" | 33 #include "snapshot.h" |
36 #include "platform.h" | 34 #include "platform.h" |
37 #include "top.h" | 35 #include "top.h" |
38 #include "cctest.h" | 36 #include "cctest.h" |
39 | 37 |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 LocalContext env; | 693 LocalContext env; |
696 Local<Function> fun = fun_templ->GetFunction(); | 694 Local<Function> fun = fun_templ->GetFunction(); |
697 env->Global()->Set(v8_str("Fun"), fun); | 695 env->Global()->Set(v8_str("Fun"), fun); |
698 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;"); | 696 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;"); |
699 CHECK_EQ(900, getter->Run()->Int32Value()); | 697 CHECK_EQ(900, getter->Run()->Int32Value()); |
700 Local<Script> setter = v8_compile("obj.foo = 901;"); | 698 Local<Script> setter = v8_compile("obj.foo = 901;"); |
701 CHECK_EQ(901, setter->Run()->Int32Value()); | 699 CHECK_EQ(901, setter->Run()->Int32Value()); |
702 } | 700 } |
703 | 701 |
704 | 702 |
| 703 THREADED_TEST(TinyInteger) { |
| 704 v8::HandleScope scope; |
| 705 LocalContext env; |
| 706 int32_t value = 239; |
| 707 Local<v8::Integer> value_obj = v8::Integer::New(value); |
| 708 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
| 709 } |
| 710 |
| 711 |
| 712 THREADED_TEST(BigSmiInteger) { |
| 713 v8::HandleScope scope; |
| 714 LocalContext env; |
| 715 int32_t value = i::Smi::kMaxValue; |
| 716 CHECK(i::Smi::IsValid(value)); |
| 717 CHECK(!i::Smi::IsValid(value + 1)); |
| 718 Local<v8::Integer> value_obj = v8::Integer::New(value); |
| 719 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
| 720 } |
| 721 |
| 722 |
| 723 THREADED_TEST(BigInteger) { |
| 724 v8::HandleScope scope; |
| 725 LocalContext env; |
| 726 int32_t value = i::Smi::kMaxValue + 1; |
| 727 CHECK(value > i::Smi::kMaxValue); |
| 728 CHECK(!i::Smi::IsValid(value)); |
| 729 Local<v8::Integer> value_obj = v8::Integer::New(value); |
| 730 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
| 731 } |
| 732 |
| 733 |
| 734 THREADED_TEST(TinyUnsignedInteger) { |
| 735 v8::HandleScope scope; |
| 736 LocalContext env; |
| 737 uint32_t value = 239; |
| 738 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); |
| 739 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
| 740 } |
| 741 |
| 742 |
| 743 THREADED_TEST(BigUnsignedSmiInteger) { |
| 744 v8::HandleScope scope; |
| 745 LocalContext env; |
| 746 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue); |
| 747 CHECK(i::Smi::IsValid(value)); |
| 748 CHECK(!i::Smi::IsValid(value + 1)); |
| 749 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); |
| 750 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
| 751 } |
| 752 |
| 753 |
| 754 THREADED_TEST(BigUnsignedInteger) { |
| 755 v8::HandleScope scope; |
| 756 LocalContext env; |
| 757 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1; |
| 758 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue)); |
| 759 CHECK(!i::Smi::IsValid(value)); |
| 760 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); |
| 761 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
| 762 } |
| 763 |
| 764 |
| 765 THREADED_TEST(OutOfSignedRangeUnsignedInteger) { |
| 766 v8::HandleScope scope; |
| 767 LocalContext env; |
| 768 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1; |
| 769 uint32_t value = INT32_MAX_AS_UINT + 1; |
| 770 CHECK(value > INT32_MAX_AS_UINT); // No overflow. |
| 771 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); |
| 772 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
| 773 } |
| 774 |
| 775 |
705 THREADED_TEST(Number) { | 776 THREADED_TEST(Number) { |
706 v8::HandleScope scope; | 777 v8::HandleScope scope; |
707 LocalContext env; | 778 LocalContext env; |
708 double PI = 3.1415926; | 779 double PI = 3.1415926; |
709 Local<v8::Number> pi_obj = v8::Number::New(PI); | 780 Local<v8::Number> pi_obj = v8::Number::New(PI); |
710 CHECK_EQ(PI, pi_obj->NumberValue()); | 781 CHECK_EQ(PI, pi_obj->NumberValue()); |
711 } | 782 } |
712 | 783 |
713 | 784 |
714 THREADED_TEST(ToNumber) { | 785 THREADED_TEST(ToNumber) { |
(...skipping 7275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7990 env->Global()->Set(v8_str("get_stack_limit"), fun); | 8061 env->Global()->Set(v8_str("get_stack_limit"), fun); |
7991 CompileRun("get_stack_limit();"); | 8062 CompileRun("get_stack_limit();"); |
7992 | 8063 |
7993 CHECK(stack_limit == set_limit); | 8064 CHECK(stack_limit == set_limit); |
7994 } | 8065 } |
7995 { | 8066 { |
7996 v8::Locker locker; | 8067 v8::Locker locker; |
7997 CHECK(stack_limit == set_limit); | 8068 CHECK(stack_limit == set_limit); |
7998 } | 8069 } |
7999 } | 8070 } |
OLD | NEW |