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

Side by Side Diff: src/execution.cc

Issue 6759029: Cleanup of Isolate::Current() and FACTORY macro usage in execution.cc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 8 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 | « no previous file | no next file » | 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 193
194 ASSERT(!Isolate::Current()->has_pending_exception()); 194 ASSERT(!Isolate::Current()->has_pending_exception());
195 ASSERT(!Isolate::Current()->external_caught_exception()); 195 ASSERT(!Isolate::Current()->external_caught_exception());
196 return result; 196 return result;
197 } 197 }
198 198
199 199
200 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { 200 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
201 ASSERT(!object->IsJSFunction()); 201 ASSERT(!object->IsJSFunction());
202 Isolate* isolate = Isolate::Current();
203 Factory* factory = isolate->factory();
202 204
203 // If you return a function from here, it will be called when an 205 // If you return a function from here, it will be called when an
204 // attempt is made to call the given object as a function. 206 // attempt is made to call the given object as a function.
205 207
206 // Regular expressions can be called as functions in both Firefox 208 // Regular expressions can be called as functions in both Firefox
207 // and Safari so we allow it too. 209 // and Safari so we allow it too.
208 if (object->IsJSRegExp()) { 210 if (object->IsJSRegExp()) {
209 Handle<String> exec = FACTORY->exec_symbol(); 211 Handle<String> exec = factory->exec_symbol();
210 // TODO(lrn): Bug 617. We should use the default function here, not the 212 // TODO(lrn): Bug 617. We should use the default function here, not the
211 // one on the RegExp object. 213 // one on the RegExp object.
212 Object* exec_function; 214 Object* exec_function;
213 { MaybeObject* maybe_exec_function = object->GetProperty(*exec); 215 { MaybeObject* maybe_exec_function = object->GetProperty(*exec);
214 // This can lose an exception, but the alternative is to put a failure 216 // This can lose an exception, but the alternative is to put a failure
215 // object in a handle, which is not GC safe. 217 // object in a handle, which is not GC safe.
216 if (!maybe_exec_function->ToObject(&exec_function)) { 218 if (!maybe_exec_function->ToObject(&exec_function)) {
217 return FACTORY->undefined_value(); 219 return factory->undefined_value();
218 } 220 }
219 } 221 }
220 return Handle<Object>(exec_function); 222 return Handle<Object>(exec_function);
221 } 223 }
222 224
223 // Objects created through the API can have an instance-call handler 225 // Objects created through the API can have an instance-call handler
224 // that should be used when calling the object as a function. 226 // that should be used when calling the object as a function.
225 if (object->IsHeapObject() && 227 if (object->IsHeapObject() &&
226 HeapObject::cast(*object)->map()->has_instance_call_handler()) { 228 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
227 return Handle<JSFunction>( 229 return Handle<JSFunction>(
228 Isolate::Current()->global_context()->call_as_function_delegate()); 230 isolate->global_context()->call_as_function_delegate());
229 } 231 }
230 232
231 return FACTORY->undefined_value(); 233 return factory->undefined_value();
232 } 234 }
233 235
234 236
235 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { 237 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) {
236 ASSERT(!object->IsJSFunction()); 238 ASSERT(!object->IsJSFunction());
239 Isolate* isolate = Isolate::Current();
237 240
238 // If you return a function from here, it will be called when an 241 // If you return a function from here, it will be called when an
239 // attempt is made to call the given object as a constructor. 242 // attempt is made to call the given object as a constructor.
240 243
241 // Objects created through the API can have an instance-call handler 244 // Objects created through the API can have an instance-call handler
242 // that should be used when calling the object as a function. 245 // that should be used when calling the object as a function.
243 if (object->IsHeapObject() && 246 if (object->IsHeapObject() &&
244 HeapObject::cast(*object)->map()->has_instance_call_handler()) { 247 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
245 return Handle<JSFunction>( 248 return Handle<JSFunction>(
246 Isolate::Current()->global_context()->call_as_constructor_delegate()); 249 isolate->global_context()->call_as_constructor_delegate());
247 } 250 }
248 251
249 return FACTORY->undefined_value(); 252 return isolate->factory()->undefined_value();
250 } 253 }
251 254
252 255
253 bool StackGuard::IsStackOverflow() { 256 bool StackGuard::IsStackOverflow() {
254 ExecutionAccess access(isolate_); 257 ExecutionAccess access(isolate_);
255 return (thread_local_.jslimit_ != kInterruptLimit && 258 return (thread_local_.jslimit_ != kInterruptLimit &&
256 thread_local_.climit_ != kInterruptLimit); 259 thread_local_.climit_ != kInterruptLimit);
257 } 260 }
258 261
259 262
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 if (stored_limit != 0) { 463 if (stored_limit != 0) {
461 StackGuard::SetStackLimit(stored_limit); 464 StackGuard::SetStackLimit(stored_limit);
462 } 465 }
463 } 466 }
464 467
465 468
466 // --- C a l l s t o n a t i v e s --- 469 // --- C a l l s t o n a t i v e s ---
467 470
468 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \ 471 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \
469 do { \ 472 do { \
473 Isolate* isolate = Isolate::Current(); \
470 Object** args[argc] = argv; \ 474 Object** args[argc] = argv; \
471 ASSERT(has_pending_exception != NULL); \ 475 ASSERT(has_pending_exception != NULL); \
472 return Call(Isolate::Current()->name##_fun(), \ 476 return Call(isolate->name##_fun(), \
473 Isolate::Current()->js_builtins_object(), argc, args, \ 477 isolate->js_builtins_object(), argc, args, \
474 has_pending_exception); \ 478 has_pending_exception); \
475 } while (false) 479 } while (false)
476 480
477 481
478 Handle<Object> Execution::ToBoolean(Handle<Object> obj) { 482 Handle<Object> Execution::ToBoolean(Handle<Object> obj) {
479 // See the similar code in runtime.js:ToBoolean. 483 // See the similar code in runtime.js:ToBoolean.
480 if (obj->IsBoolean()) return obj; 484 if (obj->IsBoolean()) return obj;
481 bool result = true; 485 bool result = true;
482 if (obj->IsString()) { 486 if (obj->IsString()) {
483 result = Handle<String>::cast(obj)->length() != 0; 487 result = Handle<String>::cast(obj)->length() != 0;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 Handle<JSFunction> function = Handle<JSFunction>( 546 Handle<JSFunction> function = Handle<JSFunction>(
543 pattern->GetIsolate()->global_context()->regexp_function()); 547 pattern->GetIsolate()->global_context()->regexp_function());
544 Handle<Object> re_obj = RegExpImpl::CreateRegExpLiteral( 548 Handle<Object> re_obj = RegExpImpl::CreateRegExpLiteral(
545 function, pattern, flags, exc); 549 function, pattern, flags, exc);
546 if (*exc) return Handle<JSRegExp>(); 550 if (*exc) return Handle<JSRegExp>();
547 return Handle<JSRegExp>::cast(re_obj); 551 return Handle<JSRegExp>::cast(re_obj);
548 } 552 }
549 553
550 554
551 Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { 555 Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
556 Isolate* isolate = Isolate::Current();
Mads Ager (chromium) 2011/04/01 07:56:19 Get the isolate from the string instead of going t
557 Factory* factory = isolate->factory();
558
552 int int_index = static_cast<int>(index); 559 int int_index = static_cast<int>(index);
553 if (int_index < 0 || int_index >= string->length()) { 560 if (int_index < 0 || int_index >= string->length()) {
554 return FACTORY->undefined_value(); 561 return factory->undefined_value();
555 } 562 }
556 563
557 Handle<Object> char_at = 564 Handle<Object> char_at =
558 GetProperty(Isolate::Current()->js_builtins_object(), 565 GetProperty(isolate->js_builtins_object(),
559 FACTORY->char_at_symbol()); 566 factory->char_at_symbol());
560 if (!char_at->IsJSFunction()) { 567 if (!char_at->IsJSFunction()) {
561 return FACTORY->undefined_value(); 568 return factory->undefined_value();
562 } 569 }
563 570
564 bool caught_exception; 571 bool caught_exception;
565 Handle<Object> index_object = FACTORY->NewNumberFromInt(int_index); 572 Handle<Object> index_object = factory->NewNumberFromInt(int_index);
566 Object** index_arg[] = { index_object.location() }; 573 Object** index_arg[] = { index_object.location() };
567 Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at), 574 Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at),
568 string, 575 string,
569 ARRAY_SIZE(index_arg), 576 ARRAY_SIZE(index_arg),
570 index_arg, 577 index_arg,
571 &caught_exception); 578 &caught_exception);
572 if (caught_exception) { 579 if (caught_exception) {
573 return FACTORY->undefined_value(); 580 return factory->undefined_value();
574 } 581 }
575 return result; 582 return result;
576 } 583 }
577 584
578 585
579 Handle<JSFunction> Execution::InstantiateFunction( 586 Handle<JSFunction> Execution::InstantiateFunction(
580 Handle<FunctionTemplateInfo> data, bool* exc) { 587 Handle<FunctionTemplateInfo> data, bool* exc) {
588 Isolate* isolate = Isolate::Current();
Mads Ager (chromium) 2011/04/01 07:56:19 Get the isolate from the data instead of going thr
581 // Fast case: see if the function has already been instantiated 589 // Fast case: see if the function has already been instantiated
582 int serial_number = Smi::cast(data->serial_number())->value(); 590 int serial_number = Smi::cast(data->serial_number())->value();
583 Object* elm = 591 Object* elm =
584 Isolate::Current()->global_context()->function_cache()-> 592 isolate->global_context()->function_cache()->
585 GetElementNoExceptionThrown(serial_number); 593 GetElementNoExceptionThrown(serial_number);
586 if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); 594 if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm));
587 // The function has not yet been instantiated in this context; do it. 595 // The function has not yet been instantiated in this context; do it.
588 Object** args[1] = { Handle<Object>::cast(data).location() }; 596 Object** args[1] = { Handle<Object>::cast(data).location() };
589 Handle<Object> result = 597 Handle<Object> result =
590 Call(Isolate::Current()->instantiate_fun(), 598 Call(isolate->instantiate_fun(),
591 Isolate::Current()->js_builtins_object(), 1, args, exc); 599 isolate->js_builtins_object(), 1, args, exc);
592 if (*exc) return Handle<JSFunction>::null(); 600 if (*exc) return Handle<JSFunction>::null();
593 return Handle<JSFunction>::cast(result); 601 return Handle<JSFunction>::cast(result);
594 } 602 }
595 603
596 604
597 Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, 605 Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data,
598 bool* exc) { 606 bool* exc) {
607 Isolate* isolate = Isolate::Current();
Mads Ager (chromium) 2011/04/01 07:56:19 Ditto.
599 if (data->property_list()->IsUndefined() && 608 if (data->property_list()->IsUndefined() &&
600 !data->constructor()->IsUndefined()) { 609 !data->constructor()->IsUndefined()) {
601 // Initialization to make gcc happy. 610 // Initialization to make gcc happy.
602 Object* result = NULL; 611 Object* result = NULL;
603 { 612 {
604 HandleScope scope; 613 HandleScope scope(isolate);
605 Handle<FunctionTemplateInfo> cons_template = 614 Handle<FunctionTemplateInfo> cons_template =
606 Handle<FunctionTemplateInfo>( 615 Handle<FunctionTemplateInfo>(
607 FunctionTemplateInfo::cast(data->constructor())); 616 FunctionTemplateInfo::cast(data->constructor()));
608 Handle<JSFunction> cons = InstantiateFunction(cons_template, exc); 617 Handle<JSFunction> cons = InstantiateFunction(cons_template, exc);
609 if (*exc) return Handle<JSObject>::null(); 618 if (*exc) return Handle<JSObject>::null();
610 Handle<Object> value = New(cons, 0, NULL, exc); 619 Handle<Object> value = New(cons, 0, NULL, exc);
611 if (*exc) return Handle<JSObject>::null(); 620 if (*exc) return Handle<JSObject>::null();
612 result = *value; 621 result = *value;
613 } 622 }
614 ASSERT(!*exc); 623 ASSERT(!*exc);
615 return Handle<JSObject>(JSObject::cast(result)); 624 return Handle<JSObject>(JSObject::cast(result));
616 } else { 625 } else {
617 Object** args[1] = { Handle<Object>::cast(data).location() }; 626 Object** args[1] = { Handle<Object>::cast(data).location() };
618 Handle<Object> result = 627 Handle<Object> result =
619 Call(Isolate::Current()->instantiate_fun(), 628 Call(isolate->instantiate_fun(),
620 Isolate::Current()->js_builtins_object(), 1, args, exc); 629 isolate->js_builtins_object(), 1, args, exc);
621 if (*exc) return Handle<JSObject>::null(); 630 if (*exc) return Handle<JSObject>::null();
622 return Handle<JSObject>::cast(result); 631 return Handle<JSObject>::cast(result);
623 } 632 }
624 } 633 }
625 634
626 635
627 void Execution::ConfigureInstance(Handle<Object> instance, 636 void Execution::ConfigureInstance(Handle<Object> instance,
628 Handle<Object> instance_template, 637 Handle<Object> instance_template,
629 bool* exc) { 638 bool* exc) {
639 Isolate* isolate = Isolate::Current();
630 Object** args[2] = { instance.location(), instance_template.location() }; 640 Object** args[2] = { instance.location(), instance_template.location() };
631 Execution::Call(Isolate::Current()->configure_instance_fun(), 641 Execution::Call(isolate->configure_instance_fun(),
632 Isolate::Current()->js_builtins_object(), 2, args, exc); 642 isolate->js_builtins_object(), 2, args, exc);
633 } 643 }
634 644
635 645
636 Handle<String> Execution::GetStackTraceLine(Handle<Object> recv, 646 Handle<String> Execution::GetStackTraceLine(Handle<Object> recv,
637 Handle<JSFunction> fun, 647 Handle<JSFunction> fun,
638 Handle<Object> pos, 648 Handle<Object> pos,
639 Handle<Object> is_global) { 649 Handle<Object> is_global) {
650 Isolate* isolate = Isolate::Current();
640 const int argc = 4; 651 const int argc = 4;
641 Object** args[argc] = { recv.location(), 652 Object** args[argc] = { recv.location(),
642 Handle<Object>::cast(fun).location(), 653 Handle<Object>::cast(fun).location(),
643 pos.location(), 654 pos.location(),
644 is_global.location() }; 655 is_global.location() };
645 bool caught_exception = false; 656 bool caught_exception = false;
646 Handle<Object> result = 657 Handle<Object> result =
647 TryCall(Isolate::Current()->get_stack_trace_line_fun(), 658 TryCall(isolate->get_stack_trace_line_fun(),
648 Isolate::Current()->js_builtins_object(), argc, args, 659 isolate->js_builtins_object(), argc, args,
649 &caught_exception); 660 &caught_exception);
650 if (caught_exception || !result->IsString()) return FACTORY->empty_symbol(); 661 if (caught_exception || !result->IsString()) {
662 return isolate->factory()->empty_symbol();
663 }
664
651 return Handle<String>::cast(result); 665 return Handle<String>::cast(result);
652 } 666 }
653 667
654 668
655 static Object* RuntimePreempt() { 669 static Object* RuntimePreempt() {
656 Isolate* isolate = Isolate::Current(); 670 Isolate* isolate = Isolate::Current();
657 671
658 // Clear the preempt request flag. 672 // Clear the preempt request flag.
659 isolate->stack_guard()->Continue(PREEMPT); 673 isolate->stack_guard()->Continue(PREEMPT);
660 674
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 // Clear the debug break request flag. 735 // Clear the debug break request flag.
722 isolate->stack_guard()->Continue(DEBUGBREAK); 736 isolate->stack_guard()->Continue(DEBUGBREAK);
723 737
724 ProcessDebugMesssages(debug_command_only); 738 ProcessDebugMesssages(debug_command_only);
725 739
726 // Return to continue execution. 740 // Return to continue execution.
727 return isolate->heap()->undefined_value(); 741 return isolate->heap()->undefined_value();
728 } 742 }
729 743
730 void Execution::ProcessDebugMesssages(bool debug_command_only) { 744 void Execution::ProcessDebugMesssages(bool debug_command_only) {
745 Isolate* isolate = Isolate::Current();
731 // Clear the debug command request flag. 746 // Clear the debug command request flag.
732 Isolate::Current()->stack_guard()->Continue(DEBUGCOMMAND); 747 isolate->stack_guard()->Continue(DEBUGCOMMAND);
733 748
734 HandleScope scope; 749 HandleScope scope(isolate);
735 // Enter the debugger. Just continue if we fail to enter the debugger. 750 // Enter the debugger. Just continue if we fail to enter the debugger.
736 EnterDebugger debugger; 751 EnterDebugger debugger;
737 if (debugger.FailedToEnter()) { 752 if (debugger.FailedToEnter()) {
738 return; 753 return;
739 } 754 }
740 755
741 // Notify the debug event listeners. Indicate auto continue if the break was 756 // Notify the debug event listeners. Indicate auto continue if the break was
742 // a debug command break. 757 // a debug command break.
743 Isolate::Current()->debugger()->OnDebugBreak(FACTORY->undefined_value(), 758 isolate->debugger()->OnDebugBreak(isolate->factory()->undefined_value(),
744 debug_command_only); 759 debug_command_only);
Mads Ager (chromium) 2011/04/01 07:56:19 Indentation is off.
745 } 760 }
746 761
747 762
748 #endif 763 #endif
749 764
750 MaybeObject* Execution::HandleStackGuardInterrupt() { 765 MaybeObject* Execution::HandleStackGuardInterrupt() {
751 Isolate* isolate = Isolate::Current(); 766 Isolate* isolate = Isolate::Current();
752 StackGuard* stack_guard = isolate->stack_guard(); 767 StackGuard* stack_guard = isolate->stack_guard();
753 isolate->counters()->stack_interrupts()->Increment(); 768 isolate->counters()->stack_interrupts()->Increment();
754 if (stack_guard->IsRuntimeProfilerTick()) { 769 if (stack_guard->IsRuntimeProfilerTick()) {
(...skipping 12 matching lines...) Expand all
767 return isolate->TerminateExecution(); 782 return isolate->TerminateExecution();
768 } 783 }
769 if (stack_guard->IsInterrupted()) { 784 if (stack_guard->IsInterrupted()) {
770 stack_guard->Continue(INTERRUPT); 785 stack_guard->Continue(INTERRUPT);
771 return isolate->StackOverflow(); 786 return isolate->StackOverflow();
772 } 787 }
773 return isolate->heap()->undefined_value(); 788 return isolate->heap()->undefined_value();
774 } 789 }
775 790
776 } } // namespace v8::internal 791 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698