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

Side by Side Diff: src/runtime.cc

Issue 6531: - Added %IsArrayClass, %IsDateClass, and %IsStringClass.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 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 | « src/runtime.h ('k') | src/runtime.js » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 215
216 static Object* Runtime_ClassOf(Arguments args) { 216 static Object* Runtime_ClassOf(Arguments args) {
217 NoHandleAllocation ha; 217 NoHandleAllocation ha;
218 ASSERT(args.length() == 1); 218 ASSERT(args.length() == 1);
219 Object* obj = args[0]; 219 Object* obj = args[0];
220 if (!obj->IsJSObject()) return Heap::null_value(); 220 if (!obj->IsJSObject()) return Heap::null_value();
221 return JSObject::cast(obj)->class_name(); 221 return JSObject::cast(obj)->class_name();
222 } 222 }
223 223
224 inline static Object* IsSpecificClassOf(Arguments args, String* name) {
225 NoHandleAllocation ha;
226 ASSERT(args.length() == 1);
227 Object* obj = args[0];
228 if (obj->IsJSObject() && (JSObject::cast(obj)->class_name() == name)) {
229 return Heap::true_value();
230 }
231 return Heap::false_value();
232 }
233
234 static Object* Runtime_IsStringClass(Arguments args) {
235 return IsSpecificClassOf(args, Heap::String_symbol());
236 }
237
238
239 static Object* Runtime_IsDateClass(Arguments args) {
240 return IsSpecificClassOf(args, Heap::Date_symbol());
241 }
242
243
244 static Object* Runtime_IsArrayClass(Arguments args) {
245 return IsSpecificClassOf(args, Heap::Array_symbol());
246 }
247
224 248
225 static Object* Runtime_IsInPrototypeChain(Arguments args) { 249 static Object* Runtime_IsInPrototypeChain(Arguments args) {
226 NoHandleAllocation ha; 250 NoHandleAllocation ha;
227 ASSERT(args.length() == 2); 251 ASSERT(args.length() == 2);
228 // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8). 252 // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8).
229 Object* O = args[0]; 253 Object* O = args[0];
230 Object* V = args[1]; 254 Object* V = args[1];
231 while (true) { 255 while (true) {
232 Object* prototype = V->GetPrototype(); 256 Object* prototype = V->GetPrototype();
233 if (prototype->IsNull()) return Heap::false_value(); 257 if (prototype->IsNull()) return Heap::false_value();
(...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2501 // requires flattened strings as input, whereas we flatten the 2525 // requires flattened strings as input, whereas we flatten the
2502 // strings only if the fast cases fail. Note that this may fail, 2526 // strings only if the fast cases fail. Note that this may fail,
2503 // requiring a GC. String::Equals(String*) returns a bool and has 2527 // requiring a GC. String::Equals(String*) returns a bool and has
2504 // no way to signal a failure. 2528 // no way to signal a failure.
2505 if (y == x) return Smi::FromInt(EQUAL); 2529 if (y == x) return Smi::FromInt(EQUAL);
2506 if (x->IsSymbol() && y->IsSymbol()) return Smi::FromInt(NOT_EQUAL); 2530 if (x->IsSymbol() && y->IsSymbol()) return Smi::FromInt(NOT_EQUAL);
2507 // Compare contents 2531 // Compare contents
2508 int len = x->length(); 2532 int len = x->length();
2509 if (len != y->length()) return Smi::FromInt(NOT_EQUAL); 2533 if (len != y->length()) return Smi::FromInt(NOT_EQUAL);
2510 if (len == 0) return Smi::FromInt(EQUAL); 2534 if (len == 0) return Smi::FromInt(EQUAL);
2535
2536 // Handle one elment strings.
2537 if (x->Get(0) != y->Get(0)) return Smi::FromInt(NOT_EQUAL);
2538 if (len == 1) return Smi::FromInt(EQUAL);
2539
2511 // Fast case: First, middle and last characters. 2540 // Fast case: First, middle and last characters.
2512 if (x->Get(0) != y->Get(0)) return Smi::FromInt(NOT_EQUAL);
2513 if (x->Get(len>>1) != y->Get(len>>1)) return Smi::FromInt(NOT_EQUAL); 2541 if (x->Get(len>>1) != y->Get(len>>1)) return Smi::FromInt(NOT_EQUAL);
2514 if (x->Get(len - 1) != y->Get(len - 1)) return Smi::FromInt(NOT_EQUAL); 2542 if (x->Get(len - 1) != y->Get(len - 1)) return Smi::FromInt(NOT_EQUAL);
2515 2543
2516 x->TryFlatten(); 2544 x->TryFlatten();
2517 y->TryFlatten(); 2545 y->TryFlatten();
2518 2546
2519 static StringInputBuffer buf1; 2547 static StringInputBuffer buf1;
2520 static StringInputBuffer buf2; 2548 static StringInputBuffer buf2;
2521 buf1.Reset(x); 2549 buf1.Reset(x);
2522 buf2.Reset(y); 2550 buf2.Reset(y);
(...skipping 2646 matching lines...) Expand 10 before | Expand all | Expand 10 after
5169 5197
5170 void Runtime::PerformGC(Object* result) { 5198 void Runtime::PerformGC(Object* result) {
5171 Failure* failure = Failure::cast(result); 5199 Failure* failure = Failure::cast(result);
5172 // Try to do a garbage collection; ignore it if it fails. The C 5200 // Try to do a garbage collection; ignore it if it fails. The C
5173 // entry stub will throw an out-of-memory exception in that case. 5201 // entry stub will throw an out-of-memory exception in that case.
5174 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); 5202 Heap::CollectGarbage(failure->requested(), failure->allocation_space());
5175 } 5203 }
5176 5204
5177 5205
5178 } } // namespace v8::internal 5206 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698