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

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

Issue 10832365: Rename Context::global to Context::global_object, (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Michael's comments. Created 8 years, 4 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/test-compiler.cc ('k') | test/cctest/test-mark-compact.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 2
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "execution.h" 7 #include "execution.h"
8 #include "factory.h" 8 #include "factory.h"
9 #include "macro-assembler.h" 9 #include "macro-assembler.h"
10 #include "global-handles.h" 10 #include "global-handles.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // nan oddball checks 150 // nan oddball checks
151 CHECK(HEAP->nan_value()->IsNumber()); 151 CHECK(HEAP->nan_value()->IsNumber());
152 CHECK(isnan(HEAP->nan_value()->Number())); 152 CHECK(isnan(HEAP->nan_value()->Number()));
153 153
154 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector("fisk hest ")); 154 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector("fisk hest "));
155 CHECK(s->IsString()); 155 CHECK(s->IsString());
156 CHECK_EQ(10, s->length()); 156 CHECK_EQ(10, s->length());
157 157
158 String* object_symbol = String::cast(HEAP->Object_symbol()); 158 String* object_symbol = String::cast(HEAP->Object_symbol());
159 CHECK( 159 CHECK(
160 Isolate::Current()->context()->global()->HasLocalProperty(object_symbol)); 160 Isolate::Current()->context()->global_object()->HasLocalProperty(
161 object_symbol));
161 162
162 // Check ToString for oddballs 163 // Check ToString for oddballs
163 CheckOddball(HEAP->true_value(), "true"); 164 CheckOddball(HEAP->true_value(), "true");
164 CheckOddball(HEAP->false_value(), "false"); 165 CheckOddball(HEAP->false_value(), "false");
165 CheckOddball(HEAP->null_value(), "null"); 166 CheckOddball(HEAP->null_value(), "null");
166 CheckOddball(HEAP->undefined_value(), "undefined"); 167 CheckOddball(HEAP->undefined_value(), "undefined");
167 168
168 // Check ToString for Smis 169 // Check ToString for Smis
169 CheckSmi(0, "0"); 170 CheckSmi(0, "0");
170 CheckSmi(42, "42"); 171 CheckSmi(42, "42");
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 Handle<String> obj_name = FACTORY->LookupAsciiSymbol("theObject"); 207 Handle<String> obj_name = FACTORY->LookupAsciiSymbol("theObject");
207 208
208 { 209 {
209 v8::HandleScope inner_scope; 210 v8::HandleScope inner_scope;
210 // Allocate a function and keep it in global object's property. 211 // Allocate a function and keep it in global object's property.
211 Handle<JSFunction> function = 212 Handle<JSFunction> function =
212 FACTORY->NewFunction(name, FACTORY->undefined_value()); 213 FACTORY->NewFunction(name, FACTORY->undefined_value());
213 Handle<Map> initial_map = 214 Handle<Map> initial_map =
214 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 215 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
215 function->set_initial_map(*initial_map); 216 function->set_initial_map(*initial_map);
216 Isolate::Current()->context()->global()->SetProperty( 217 Isolate::Current()->context()->global_object()->SetProperty(
217 *name, *function, NONE, kNonStrictMode)->ToObjectChecked(); 218 *name, *function, NONE, kNonStrictMode)->ToObjectChecked();
218 // Allocate an object. Unrooted after leaving the scope. 219 // Allocate an object. Unrooted after leaving the scope.
219 Handle<JSObject> obj = FACTORY->NewJSObject(function); 220 Handle<JSObject> obj = FACTORY->NewJSObject(function);
220 obj->SetProperty( 221 obj->SetProperty(
221 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 222 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
222 obj->SetProperty( 223 obj->SetProperty(
223 *prop_namex, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); 224 *prop_namex, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked();
224 225
225 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 226 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
226 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); 227 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
227 } 228 }
228 229
229 HEAP->CollectGarbage(NEW_SPACE); 230 HEAP->CollectGarbage(NEW_SPACE);
230 231
231 // Function should be alive. 232 // Function should be alive.
232 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*name)); 233 CHECK(Isolate::Current()->context()->global_object()->
234 HasLocalProperty(*name));
233 // Check function is retained. 235 // Check function is retained.
234 Object* func_value = Isolate::Current()->context()->global()-> 236 Object* func_value = Isolate::Current()->context()->global_object()->
235 GetProperty(*name)->ToObjectChecked(); 237 GetProperty(*name)->ToObjectChecked();
236 CHECK(func_value->IsJSFunction()); 238 CHECK(func_value->IsJSFunction());
237 Handle<JSFunction> function(JSFunction::cast(func_value)); 239 Handle<JSFunction> function(JSFunction::cast(func_value));
238 240
239 { 241 {
240 HandleScope inner_scope; 242 HandleScope inner_scope;
241 // Allocate another object, make it reachable from global. 243 // Allocate another object, make it reachable from global.
242 Handle<JSObject> obj = FACTORY->NewJSObject(function); 244 Handle<JSObject> obj = FACTORY->NewJSObject(function);
243 Isolate::Current()->context()->global()->SetProperty( 245 Isolate::Current()->context()->global_object()->SetProperty(
244 *obj_name, *obj, NONE, kNonStrictMode)->ToObjectChecked(); 246 *obj_name, *obj, NONE, kNonStrictMode)->ToObjectChecked();
245 obj->SetProperty( 247 obj->SetProperty(
246 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 248 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
247 } 249 }
248 250
249 // After gc, it should survive. 251 // After gc, it should survive.
250 HEAP->CollectGarbage(NEW_SPACE); 252 HEAP->CollectGarbage(NEW_SPACE);
251 253
252 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*obj_name)); 254 CHECK(Isolate::Current()->context()->global_object()->
253 CHECK(Isolate::Current()->context()->global()-> 255 HasLocalProperty(*obj_name));
256 CHECK(Isolate::Current()->context()->global_object()->
254 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); 257 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject());
255 Object* obj = Isolate::Current()->context()->global()-> 258 Object* obj = Isolate::Current()->context()->global_object()->
256 GetProperty(*obj_name)->ToObjectChecked(); 259 GetProperty(*obj_name)->ToObjectChecked();
257 JSObject* js_obj = JSObject::cast(obj); 260 JSObject* js_obj = JSObject::cast(obj);
258 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name)); 261 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name));
259 } 262 }
260 263
261 264
262 static void VerifyStringAllocation(const char* string) { 265 static void VerifyStringAllocation(const char* string) {
263 v8::HandleScope scope; 266 v8::HandleScope scope;
264 Handle<String> s = FACTORY->NewStringFromUtf8(CStrVector(string)); 267 Handle<String> s = FACTORY->NewStringFromUtf8(CStrVector(string));
265 CHECK_EQ(StrLength(string), s->length()); 268 CHECK_EQ(StrLength(string), s->length());
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); 559 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked();
557 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 560 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
558 } 561 }
559 562
560 563
561 TEST(ObjectProperties) { 564 TEST(ObjectProperties) {
562 InitializeVM(); 565 InitializeVM();
563 566
564 v8::HandleScope sc; 567 v8::HandleScope sc;
565 String* object_symbol = String::cast(HEAP->Object_symbol()); 568 String* object_symbol = String::cast(HEAP->Object_symbol());
566 Object* raw_object = Isolate::Current()->context()->global()-> 569 Object* raw_object = Isolate::Current()->context()->global_object()->
567 GetProperty(object_symbol)->ToObjectChecked(); 570 GetProperty(object_symbol)->ToObjectChecked();
568 JSFunction* object_function = JSFunction::cast(raw_object); 571 JSFunction* object_function = JSFunction::cast(raw_object);
569 Handle<JSFunction> constructor(object_function); 572 Handle<JSFunction> constructor(object_function);
570 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); 573 Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
571 Handle<String> first = FACTORY->LookupAsciiSymbol("first"); 574 Handle<String> first = FACTORY->LookupAsciiSymbol("first");
572 Handle<String> second = FACTORY->LookupAsciiSymbol("second"); 575 Handle<String> second = FACTORY->LookupAsciiSymbol("second");
573 576
574 // check for empty 577 // check for empty
575 CHECK(!obj->HasLocalProperty(*first)); 578 CHECK(!obj->HasLocalProperty(*first));
576 579
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // Check the map has changed 656 // Check the map has changed
654 CHECK(*initial_map != obj->map()); 657 CHECK(*initial_map != obj->map());
655 } 658 }
656 659
657 660
658 TEST(JSArray) { 661 TEST(JSArray) {
659 InitializeVM(); 662 InitializeVM();
660 663
661 v8::HandleScope sc; 664 v8::HandleScope sc;
662 Handle<String> name = FACTORY->LookupAsciiSymbol("Array"); 665 Handle<String> name = FACTORY->LookupAsciiSymbol("Array");
663 Object* raw_object = Isolate::Current()->context()->global()-> 666 Object* raw_object = Isolate::Current()->context()->global_object()->
664 GetProperty(*name)->ToObjectChecked(); 667 GetProperty(*name)->ToObjectChecked();
665 Handle<JSFunction> function = Handle<JSFunction>( 668 Handle<JSFunction> function = Handle<JSFunction>(
666 JSFunction::cast(raw_object)); 669 JSFunction::cast(raw_object));
667 670
668 // Allocate the object. 671 // Allocate the object.
669 Handle<JSObject> object = FACTORY->NewJSObject(function); 672 Handle<JSObject> object = FACTORY->NewJSObject(function);
670 Handle<JSArray> array = Handle<JSArray>::cast(object); 673 Handle<JSArray> array = Handle<JSArray>::cast(object);
671 // We just initialized the VM, no heap allocation failure yet. 674 // We just initialized the VM, no heap allocation failure yet.
672 array->Initialize(0)->ToObjectChecked(); 675 array->Initialize(0)->ToObjectChecked();
673 676
(...skipping 26 matching lines...) Expand all
700 CHECK_EQ(array->GetElement(int_length), *name); 703 CHECK_EQ(array->GetElement(int_length), *name);
701 CHECK_EQ(array->GetElement(0), *name); 704 CHECK_EQ(array->GetElement(0), *name);
702 } 705 }
703 706
704 707
705 TEST(JSObjectCopy) { 708 TEST(JSObjectCopy) {
706 InitializeVM(); 709 InitializeVM();
707 710
708 v8::HandleScope sc; 711 v8::HandleScope sc;
709 String* object_symbol = String::cast(HEAP->Object_symbol()); 712 String* object_symbol = String::cast(HEAP->Object_symbol());
710 Object* raw_object = Isolate::Current()->context()->global()-> 713 Object* raw_object = Isolate::Current()->context()->global_object()->
711 GetProperty(object_symbol)->ToObjectChecked(); 714 GetProperty(object_symbol)->ToObjectChecked();
712 JSFunction* object_function = JSFunction::cast(raw_object); 715 JSFunction* object_function = JSFunction::cast(raw_object);
713 Handle<JSFunction> constructor(object_function); 716 Handle<JSFunction> constructor(object_function);
714 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); 717 Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
715 Handle<String> first = FACTORY->LookupAsciiSymbol("first"); 718 Handle<String> first = FACTORY->LookupAsciiSymbol("first");
716 Handle<String> second = FACTORY->LookupAsciiSymbol("second"); 719 Handle<String> second = FACTORY->LookupAsciiSymbol("second");
717 720
718 obj->SetProperty( 721 obj->SetProperty(
719 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 722 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
720 obj->SetProperty( 723 obj->SetProperty(
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 "};" 952 "};"
950 "foo()"; 953 "foo()";
951 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo"); 954 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo");
952 955
953 // This compile will add the code to the compilation cache. 956 // This compile will add the code to the compilation cache.
954 { v8::HandleScope scope; 957 { v8::HandleScope scope;
955 CompileRun(source); 958 CompileRun(source);
956 } 959 }
957 960
958 // Check function is compiled. 961 // Check function is compiled.
959 Object* func_value = Isolate::Current()->context()->global()-> 962 Object* func_value = Isolate::Current()->context()->global_object()->
960 GetProperty(*foo_name)->ToObjectChecked(); 963 GetProperty(*foo_name)->ToObjectChecked();
961 CHECK(func_value->IsJSFunction()); 964 CHECK(func_value->IsJSFunction());
962 Handle<JSFunction> function(JSFunction::cast(func_value)); 965 Handle<JSFunction> function(JSFunction::cast(func_value));
963 CHECK(function->shared()->is_compiled()); 966 CHECK(function->shared()->is_compiled());
964 967
965 // TODO(1609) Currently incremental marker does not support code flushing. 968 // TODO(1609) Currently incremental marker does not support code flushing.
966 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 969 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
967 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 970 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
968 971
969 CHECK(function->shared()->is_compiled()); 972 CHECK(function->shared()->is_compiled());
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 CHECK(ic_before->ic_state() == MEGAMORPHIC); 2176 CHECK(ic_before->ic_state() == MEGAMORPHIC);
2174 2177
2175 // Fire context dispose notification. 2178 // Fire context dispose notification.
2176 v8::V8::ContextDisposedNotification(); 2179 v8::V8::ContextDisposedNotification();
2177 SimulateIncrementalMarking(); 2180 SimulateIncrementalMarking();
2178 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2181 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2179 2182
2180 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 2183 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
2181 CHECK(ic_after->ic_state() == UNINITIALIZED); 2184 CHECK(ic_after->ic_state() == UNINITIALIZED);
2182 } 2185 }
OLDNEW
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698