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

Side by Side Diff: src/liveedit.cc

Issue 3586006: Begin a more aggressive refactoring of the Compiler interface. (Closed)
Patch Set: Always return false on a parse failure. Created 10 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
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | src/parser.h » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 LineArrayCompareInput input(s1, s2, line_ends1, line_ends2); 391 LineArrayCompareInput input(s1, s2, line_ends1, line_ends2);
392 LineArrayCompareOutput output(line_ends1, line_ends2); 392 LineArrayCompareOutput output(line_ends1, line_ends2);
393 393
394 Comparator::CalculateDifference(&input, &output); 394 Comparator::CalculateDifference(&input, &output);
395 395
396 return output.GetResult(); 396 return output.GetResult();
397 } 397 }
398 398
399 399
400 static void CompileScriptForTracker(Handle<Script> script) { 400 static void CompileScriptForTracker(Handle<Script> script) {
401 const bool is_eval = false;
402 const bool is_global = true;
403 // TODO(635): support extensions. 401 // TODO(635): support extensions.
404 Extension* extension = NULL;
405
406 PostponeInterruptsScope postpone; 402 PostponeInterruptsScope postpone;
407 403
408 // Only allow non-global compiles for eval.
409 ASSERT(is_eval || is_global);
410
411 // Build AST. 404 // Build AST.
412 ScriptDataImpl* pre_data = NULL; 405 CompilationInfo info(script);
413 EagerCompilationInfo info(script, is_eval); 406 info.MarkAsGlobal();
414 FunctionLiteral* lit = 407 if (!Parser::Parse(&info)) return;
415 Parser::MakeAST(is_global, script, extension, pre_data);
416
417 // Check for parse errors.
418 if (lit == NULL) {
419 ASSERT(Top::has_pending_exception());
420 return;
421 }
422 info.set_function(lit);
423 408
424 // Compile the code. 409 // Compile the code.
425 LiveEditFunctionTracker tracker(lit); 410 LiveEditFunctionTracker tracker(info.function());
426 Handle<Code> code = MakeCodeForLiveEdit(&info); 411 Handle<Code> code = MakeCodeForLiveEdit(&info);
427 412
428 // Check for stack-overflow exceptions. 413 // Check for stack-overflow exceptions.
429 if (code.is_null()) { 414 if (code.is_null()) {
430 Top::StackOverflow(); 415 Top::StackOverflow();
431 return; 416 return;
432 } 417 }
433 tracker.RecordRootFunctionInfo(code); 418 tracker.RecordRootFunctionInfo(code);
434 } 419 }
435 420
421
436 // Unwraps JSValue object, returning its field "value" 422 // Unwraps JSValue object, returning its field "value"
437 static Handle<Object> UnwrapJSValue(Handle<JSValue> jsValue) { 423 static Handle<Object> UnwrapJSValue(Handle<JSValue> jsValue) {
438 return Handle<Object>(jsValue->value()); 424 return Handle<Object>(jsValue->value());
439 } 425 }
440 426
427
441 // Wraps any object into a OpaqueReference, that will hide the object 428 // Wraps any object into a OpaqueReference, that will hide the object
442 // from JavaScript. 429 // from JavaScript.
443 static Handle<JSValue> WrapInJSValue(Object* object) { 430 static Handle<JSValue> WrapInJSValue(Object* object) {
444 Handle<JSFunction> constructor = Top::opaque_reference_function(); 431 Handle<JSFunction> constructor = Top::opaque_reference_function();
445 Handle<JSValue> result = 432 Handle<JSValue> result =
446 Handle<JSValue>::cast(Factory::NewJSObject(constructor)); 433 Handle<JSValue>::cast(Factory::NewJSObject(constructor));
447 result->set_value(object); 434 result->set_value(object);
448 return result; 435 return result;
449 } 436 }
450 437
438
451 // Simple helper class that creates more or less typed structures over 439 // Simple helper class that creates more or less typed structures over
452 // JSArray object. This is an adhoc method of passing structures from C++ 440 // JSArray object. This is an adhoc method of passing structures from C++
453 // to JavaScript. 441 // to JavaScript.
454 template<typename S> 442 template<typename S>
455 class JSArrayBasedStruct { 443 class JSArrayBasedStruct {
456 public: 444 public:
457 static S Create() { 445 static S Create() {
458 Handle<JSArray> array = Factory::NewJSArray(S::kSize_); 446 Handle<JSArray> array = Factory::NewJSArray(S::kSize_);
459 return S(array); 447 return S(array);
460 } 448 }
461 static S cast(Object* object) { 449 static S cast(Object* object) {
462 JSArray* array = JSArray::cast(object); 450 JSArray* array = JSArray::cast(object);
463 Handle<JSArray> array_handle(array); 451 Handle<JSArray> array_handle(array);
464 return S(array_handle); 452 return S(array_handle);
465 } 453 }
466 explicit JSArrayBasedStruct(Handle<JSArray> array) : array_(array) { 454 explicit JSArrayBasedStruct(Handle<JSArray> array) : array_(array) {
467 } 455 }
468 Handle<JSArray> GetJSArray() { 456 Handle<JSArray> GetJSArray() {
469 return array_; 457 return array_;
470 } 458 }
459
471 protected: 460 protected:
472 void SetField(int field_position, Handle<Object> value) { 461 void SetField(int field_position, Handle<Object> value) {
473 SetElement(array_, field_position, value); 462 SetElement(array_, field_position, value);
474 } 463 }
475 void SetSmiValueField(int field_position, int value) { 464 void SetSmiValueField(int field_position, int value) {
476 SetElement(array_, field_position, Handle<Smi>(Smi::FromInt(value))); 465 SetElement(array_, field_position, Handle<Smi>(Smi::FromInt(value)));
477 } 466 }
478 Object* GetField(int field_position) { 467 Object* GetField(int field_position) {
479 return array_->GetElement(field_position); 468 return array_->GetElement(field_position);
480 } 469 }
481 int GetSmiValueField(int field_position) { 470 int GetSmiValueField(int field_position) {
482 Object* res = GetField(field_position); 471 Object* res = GetField(field_position);
483 return Smi::cast(res)->value(); 472 return Smi::cast(res)->value();
484 } 473 }
474
485 private: 475 private:
486 Handle<JSArray> array_; 476 Handle<JSArray> array_;
487 }; 477 };
488 478
489 479
490 // Represents some function compilation details. This structure will be used 480 // Represents some function compilation details. This structure will be used
491 // from JavaScript. It contains Code object, which is kept wrapped 481 // from JavaScript. It contains Code object, which is kept wrapped
492 // into a BlindReference for sanitizing reasons. 482 // into a BlindReference for sanitizing reasons.
493 class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> { 483 class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> {
494 public: 484 public:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 static const int kCodeOffset_ = 4; 537 static const int kCodeOffset_ = 4;
548 static const int kCodeScopeInfoOffset_ = 5; 538 static const int kCodeScopeInfoOffset_ = 5;
549 static const int kOuterScopeInfoOffset_ = 6; 539 static const int kOuterScopeInfoOffset_ = 6;
550 static const int kParentIndexOffset_ = 7; 540 static const int kParentIndexOffset_ = 7;
551 static const int kSharedFunctionInfoOffset_ = 8; 541 static const int kSharedFunctionInfoOffset_ = 8;
552 static const int kSize_ = 9; 542 static const int kSize_ = 9;
553 543
554 friend class JSArrayBasedStruct<FunctionInfoWrapper>; 544 friend class JSArrayBasedStruct<FunctionInfoWrapper>;
555 }; 545 };
556 546
547
557 // Wraps SharedFunctionInfo along with some of its fields for passing it 548 // Wraps SharedFunctionInfo along with some of its fields for passing it
558 // back to JavaScript. SharedFunctionInfo object itself is additionally 549 // back to JavaScript. SharedFunctionInfo object itself is additionally
559 // wrapped into BlindReference for sanitizing reasons. 550 // wrapped into BlindReference for sanitizing reasons.
560 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> { 551 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> {
561 public: 552 public:
562 static bool IsInstance(Handle<JSArray> array) { 553 static bool IsInstance(Handle<JSArray> array) {
563 return array->length() == Smi::FromInt(kSize_) && 554 return array->length() == Smi::FromInt(kSize_) &&
564 array->GetElement(kSharedInfoOffset_)->IsJSValue(); 555 array->GetElement(kSharedInfoOffset_)->IsJSValue();
565 } 556 }
566 557
(...skipping 20 matching lines...) Expand all
587 private: 578 private:
588 static const int kFunctionNameOffset_ = 0; 579 static const int kFunctionNameOffset_ = 0;
589 static const int kStartPositionOffset_ = 1; 580 static const int kStartPositionOffset_ = 1;
590 static const int kEndPositionOffset_ = 2; 581 static const int kEndPositionOffset_ = 2;
591 static const int kSharedInfoOffset_ = 3; 582 static const int kSharedInfoOffset_ = 3;
592 static const int kSize_ = 4; 583 static const int kSize_ = 4;
593 584
594 friend class JSArrayBasedStruct<SharedInfoWrapper>; 585 friend class JSArrayBasedStruct<SharedInfoWrapper>;
595 }; 586 };
596 587
588
597 class FunctionInfoListener { 589 class FunctionInfoListener {
598 public: 590 public:
599 FunctionInfoListener() { 591 FunctionInfoListener() {
600 current_parent_index_ = -1; 592 current_parent_index_ = -1;
601 len_ = 0; 593 len_ = 0;
602 result_ = Factory::NewJSArray(10); 594 result_ = Factory::NewJSArray(10);
603 } 595 }
604 596
605 void FunctionStarted(FunctionLiteral* fun) { 597 void FunctionStarted(FunctionLiteral* fun) {
606 HandleScope scope; 598 HandleScope scope;
607 FunctionInfoWrapper info = FunctionInfoWrapper::Create(); 599 FunctionInfoWrapper info = FunctionInfoWrapper::Create();
608 info.SetInitialProperties(fun->name(), fun->start_position(), 600 info.SetInitialProperties(fun->name(), fun->start_position(),
609 fun->end_position(), fun->num_parameters(), 601 fun->end_position(), fun->num_parameters(),
610 current_parent_index_); 602 current_parent_index_);
611 current_parent_index_ = len_; 603 current_parent_index_ = len_;
612 SetElement(result_, len_, info.GetJSArray()); 604 SetElement(result_, len_, info.GetJSArray());
613 len_++; 605 len_++;
614 } 606 }
615 607
616 void FunctionDone() { 608 void FunctionDone() {
617 HandleScope scope; 609 HandleScope scope;
618 FunctionInfoWrapper info = 610 FunctionInfoWrapper info =
619 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_)); 611 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_));
620 current_parent_index_ = info.GetParentIndex(); 612 current_parent_index_ = info.GetParentIndex();
621 } 613 }
622 614
623 public:
624 // Saves only function code, because for a script function we 615 // Saves only function code, because for a script function we
625 // may never create a SharedFunctionInfo object. 616 // may never create a SharedFunctionInfo object.
626 void FunctionCode(Handle<Code> function_code) { 617 void FunctionCode(Handle<Code> function_code) {
627 FunctionInfoWrapper info = 618 FunctionInfoWrapper info =
628 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_)); 619 FunctionInfoWrapper::cast(result_->GetElement(current_parent_index_));
629 info.SetFunctionCode(function_code, Handle<Object>(Heap::null_value())); 620 info.SetFunctionCode(function_code, Handle<Object>(Heap::null_value()));
630 } 621 }
631 622
632 // Saves full information about a function: its code, its scope info 623 // Saves full information about a function: its code, its scope info
633 // and a SharedFunctionInfo object. 624 // and a SharedFunctionInfo object.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } while (outer_scope != NULL); 692 } while (outer_scope != NULL);
702 693
703 return *scope_info_list; 694 return *scope_info_list;
704 } 695 }
705 696
706 Handle<JSArray> result_; 697 Handle<JSArray> result_;
707 int len_; 698 int len_;
708 int current_parent_index_; 699 int current_parent_index_;
709 }; 700 };
710 701
702
711 static FunctionInfoListener* active_function_info_listener = NULL; 703 static FunctionInfoListener* active_function_info_listener = NULL;
712 704
713 JSArray* LiveEdit::GatherCompileInfo(Handle<Script> script, 705 JSArray* LiveEdit::GatherCompileInfo(Handle<Script> script,
714 Handle<String> source) { 706 Handle<String> source) {
715 CompilationZoneScope zone_scope(DELETE_ON_EXIT); 707 CompilationZoneScope zone_scope(DELETE_ON_EXIT);
716 708
717 FunctionInfoListener listener; 709 FunctionInfoListener listener;
718 Handle<Object> original_source = Handle<Object>(script->source()); 710 Handle<Object> original_source = Handle<Object>(script->source());
719 script->set_source(*source); 711 script->set_source(*source);
720 active_function_info_listener = &listener; 712 active_function_info_listener = &listener;
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 1471
1480 bool LiveEditFunctionTracker::IsActive() { 1472 bool LiveEditFunctionTracker::IsActive() {
1481 return false; 1473 return false;
1482 } 1474 }
1483 1475
1484 #endif // ENABLE_DEBUGGER_SUPPORT 1476 #endif // ENABLE_DEBUGGER_SUPPORT
1485 1477
1486 1478
1487 1479
1488 } } // namespace v8::internal 1480 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698