OLD | NEW |
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 static void CheckSmi(Isolate* isolate, int value, const char* string) { | 93 static void CheckSmi(Isolate* isolate, int value, const char* string) { |
94 Handle<Object> handle(Smi::FromInt(value), isolate); | 94 Handle<Object> handle(Smi::FromInt(value), isolate); |
95 Object* print_string = | 95 Object* print_string = |
96 *Execution::ToString(isolate, handle).ToHandleChecked(); | 96 *Execution::ToString(isolate, handle).ToHandleChecked(); |
97 CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string))); | 97 CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string))); |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 static void CheckNumber(Isolate* isolate, double value, const char* string) { | 101 static void CheckNumber(Isolate* isolate, double value, const char* string) { |
102 Object* obj = CcTest::heap()->NumberFromDouble(value)->ToObjectChecked(); | 102 Handle<Object> number = isolate->factory()->NewNumber(value); |
103 CHECK(obj->IsNumber()); | 103 CHECK(number->IsNumber()); |
104 Handle<Object> handle(obj, isolate); | 104 Handle<Object> print_string = |
105 Object* print_string = | 105 Execution::ToString(isolate, number).ToHandleChecked(); |
106 *Execution::ToString(isolate, handle).ToHandleChecked(); | 106 CHECK(String::cast(*print_string)->IsUtf8EqualTo(CStrVector(string))); |
107 CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string))); | |
108 } | 107 } |
109 | 108 |
110 | 109 |
111 static void CheckFindCodeObject(Isolate* isolate) { | 110 static void CheckFindCodeObject(Isolate* isolate) { |
112 // Test FindCodeObject | 111 // Test FindCodeObject |
113 #define __ assm. | 112 #define __ assm. |
114 | 113 |
115 Assembler assm(isolate, NULL, 0); | 114 Assembler assm(isolate, NULL, 0); |
116 | 115 |
117 __ nop(); // supported on all architectures | 116 __ nop(); // supported on all architectures |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 154 } |
156 | 155 |
157 | 156 |
158 TEST(HeapObjects) { | 157 TEST(HeapObjects) { |
159 CcTest::InitializeVM(); | 158 CcTest::InitializeVM(); |
160 Isolate* isolate = CcTest::i_isolate(); | 159 Isolate* isolate = CcTest::i_isolate(); |
161 Factory* factory = isolate->factory(); | 160 Factory* factory = isolate->factory(); |
162 Heap* heap = isolate->heap(); | 161 Heap* heap = isolate->heap(); |
163 | 162 |
164 HandleScope sc(isolate); | 163 HandleScope sc(isolate); |
165 Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked(); | 164 Handle<Object> value = factory->NewNumber(1.000123); |
166 CHECK(value->IsHeapNumber()); | 165 CHECK(value->IsHeapNumber()); |
167 CHECK(value->IsNumber()); | 166 CHECK(value->IsNumber()); |
168 CHECK_EQ(1.000123, value->Number()); | 167 CHECK_EQ(1.000123, value->Number()); |
169 | 168 |
170 value = heap->NumberFromDouble(1.0)->ToObjectChecked(); | 169 value = factory->NewNumber(1.0); |
171 CHECK(value->IsSmi()); | 170 CHECK(value->IsSmi()); |
172 CHECK(value->IsNumber()); | 171 CHECK(value->IsNumber()); |
173 CHECK_EQ(1.0, value->Number()); | 172 CHECK_EQ(1.0, value->Number()); |
174 | 173 |
175 value = heap->NumberFromInt32(1024)->ToObjectChecked(); | 174 value = factory->NewNumberFromInt(1024); |
176 CHECK(value->IsSmi()); | 175 CHECK(value->IsSmi()); |
177 CHECK(value->IsNumber()); | 176 CHECK(value->IsNumber()); |
178 CHECK_EQ(1024.0, value->Number()); | 177 CHECK_EQ(1024.0, value->Number()); |
179 | 178 |
180 value = heap->NumberFromInt32(Smi::kMinValue)->ToObjectChecked(); | 179 value = factory->NewNumberFromInt(Smi::kMinValue); |
181 CHECK(value->IsSmi()); | 180 CHECK(value->IsSmi()); |
182 CHECK(value->IsNumber()); | 181 CHECK(value->IsNumber()); |
183 CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value()); | 182 CHECK_EQ(Smi::kMinValue, Handle<Smi>::cast(value)->value()); |
184 | 183 |
185 value = heap->NumberFromInt32(Smi::kMaxValue)->ToObjectChecked(); | 184 value = factory->NewNumberFromInt(Smi::kMaxValue); |
186 CHECK(value->IsSmi()); | 185 CHECK(value->IsSmi()); |
187 CHECK(value->IsNumber()); | 186 CHECK(value->IsNumber()); |
188 CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value()); | 187 CHECK_EQ(Smi::kMaxValue, Handle<Smi>::cast(value)->value()); |
189 | 188 |
190 #if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_ARM64) | 189 #if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_ARM64) |
191 // TODO(lrn): We need a NumberFromIntptr function in order to test this. | 190 // TODO(lrn): We need a NumberFromIntptr function in order to test this. |
192 value = heap->NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked(); | 191 value = factory->NewNumberFromInt(Smi::kMinValue - 1); |
193 CHECK(value->IsHeapNumber()); | 192 CHECK(value->IsHeapNumber()); |
194 CHECK(value->IsNumber()); | 193 CHECK(value->IsNumber()); |
195 CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number()); | 194 CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number()); |
196 #endif | 195 #endif |
197 | 196 |
198 MaybeObject* maybe_value = | 197 value = factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); |
199 heap->NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1); | |
200 value = maybe_value->ToObjectChecked(); | |
201 CHECK(value->IsHeapNumber()); | 198 CHECK(value->IsHeapNumber()); |
202 CHECK(value->IsNumber()); | 199 CHECK(value->IsNumber()); |
203 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1), | 200 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1), |
204 value->Number()); | 201 value->Number()); |
205 | 202 |
206 maybe_value = heap->NumberFromUint32(static_cast<uint32_t>(1) << 31); | 203 value = factory->NewNumberFromUint(static_cast<uint32_t>(1) << 31); |
207 value = maybe_value->ToObjectChecked(); | |
208 CHECK(value->IsHeapNumber()); | 204 CHECK(value->IsHeapNumber()); |
209 CHECK(value->IsNumber()); | 205 CHECK(value->IsNumber()); |
210 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31), | 206 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31), |
211 value->Number()); | 207 value->Number()); |
212 | 208 |
213 // nan oddball checks | 209 // nan oddball checks |
214 CHECK(heap->nan_value()->IsNumber()); | 210 CHECK(factory->nan_value()->IsNumber()); |
215 CHECK(std::isnan(heap->nan_value()->Number())); | 211 CHECK(std::isnan(factory->nan_value()->Number())); |
216 | 212 |
217 Handle<String> s = factory->NewStringFromAscii(CStrVector("fisk hest ")); | 213 Handle<String> s = factory->NewStringFromAscii(CStrVector("fisk hest ")); |
218 CHECK(s->IsString()); | 214 CHECK(s->IsString()); |
219 CHECK_EQ(10, s->length()); | 215 CHECK_EQ(10, s->length()); |
220 | 216 |
221 Handle<String> object_string = Handle<String>::cast(factory->Object_string()); | 217 Handle<String> object_string = Handle<String>::cast(factory->Object_string()); |
222 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); | 218 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); |
223 CHECK(JSReceiver::HasLocalProperty(global, object_string)); | 219 CHECK(JSReceiver::HasLocalProperty(global, object_string)); |
224 | 220 |
225 // Check ToString for oddballs | 221 // Check ToString for oddballs |
(...skipping 3961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4187 v8::Context::Scope cscope(context); | 4183 v8::Context::Scope cscope(context); |
4188 | 4184 |
4189 v8::Local<v8::Value> result = CompileRun( | 4185 v8::Local<v8::Value> result = CompileRun( |
4190 "var locals = '';" | 4186 "var locals = '';" |
4191 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" | 4187 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" |
4192 "eval('function f() {' + locals + 'return function() { return v0; }; }');" | 4188 "eval('function f() {' + locals + 'return function() { return v0; }; }');" |
4193 "interrupt();" // This triggers a fake stack overflow in f. | 4189 "interrupt();" // This triggers a fake stack overflow in f. |
4194 "f()()"); | 4190 "f()()"); |
4195 CHECK_EQ(42.0, result->ToNumber()->Value()); | 4191 CHECK_EQ(42.0, result->ToNumber()->Value()); |
4196 } | 4192 } |
OLD | NEW |