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

Side by Side Diff: src/liveedit.cc

Issue 1687022: Make LiveEdit natives fuzzy (Closed)
Patch Set: uncomment code Created 10 years, 7 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/liveedit.h ('k') | src/runtime.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 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 static const int kSize_ = 8; 538 static const int kSize_ = 8;
539 539
540 friend class JSArrayBasedStruct<FunctionInfoWrapper>; 540 friend class JSArrayBasedStruct<FunctionInfoWrapper>;
541 }; 541 };
542 542
543 // Wraps SharedFunctionInfo along with some of its fields for passing it 543 // Wraps SharedFunctionInfo along with some of its fields for passing it
544 // back to JavaScript. SharedFunctionInfo object itself is additionally 544 // back to JavaScript. SharedFunctionInfo object itself is additionally
545 // wrapped into BlindReference for sanitizing reasons. 545 // wrapped into BlindReference for sanitizing reasons.
546 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> { 546 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> {
547 public: 547 public:
548 static bool IsInstance(Handle<JSArray> array) {
549 return array->length() == Smi::FromInt(kSize_) &&
550 array->GetElement(kSharedInfoOffset_)->IsJSValue();
551 }
552
548 explicit SharedInfoWrapper(Handle<JSArray> array) 553 explicit SharedInfoWrapper(Handle<JSArray> array)
549 : JSArrayBasedStruct<SharedInfoWrapper>(array) { 554 : JSArrayBasedStruct<SharedInfoWrapper>(array) {
550 } 555 }
551 556
552 void SetProperties(Handle<String> name, int start_position, int end_position, 557 void SetProperties(Handle<String> name, int start_position, int end_position,
553 Handle<SharedFunctionInfo> info) { 558 Handle<SharedFunctionInfo> info) {
554 HandleScope scope; 559 HandleScope scope;
555 this->SetField(kFunctionNameOffset_, name); 560 this->SetField(kFunctionNameOffset_, name);
556 Handle<JSValue> info_holder = WrapInJSValue(*info); 561 Handle<JSValue> info_holder = WrapInJSValue(*info);
557 this->SetField(kSharedInfoOffset_, info_holder); 562 this->SetField(kSharedInfoOffset_, info_holder);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 } 832 }
828 833
829 834
830 // Check whether the code is natural function code (not a lazy-compile stub 835 // Check whether the code is natural function code (not a lazy-compile stub
831 // code). 836 // code).
832 static bool IsJSFunctionCode(Code* code) { 837 static bool IsJSFunctionCode(Code* code) {
833 return code->kind() == Code::FUNCTION; 838 return code->kind() == Code::FUNCTION;
834 } 839 }
835 840
836 841
837 void LiveEdit::ReplaceFunctionCode(Handle<JSArray> new_compile_info_array, 842 Object* LiveEdit::ReplaceFunctionCode(Handle<JSArray> new_compile_info_array,
838 Handle<JSArray> shared_info_array) { 843 Handle<JSArray> shared_info_array) {
839 HandleScope scope; 844 HandleScope scope;
840 845
846 if (!SharedInfoWrapper::IsInstance(shared_info_array)) {
847 return Top::ThrowIllegalOperation();
848 }
849
841 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); 850 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array);
842 SharedInfoWrapper shared_info_wrapper(shared_info_array); 851 SharedInfoWrapper shared_info_wrapper(shared_info_array);
843 852
844 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); 853 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
845 854
846 if (IsJSFunctionCode(shared_info->code())) { 855 if (IsJSFunctionCode(shared_info->code())) {
847 ReplaceCodeObject(shared_info->code(), 856 ReplaceCodeObject(shared_info->code(),
848 *(compile_info_wrapper.GetFunctionCode())); 857 *(compile_info_wrapper.GetFunctionCode()));
849 } 858 }
850 859
851 if (shared_info->debug_info()->IsDebugInfo()) { 860 if (shared_info->debug_info()->IsDebugInfo()) {
852 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); 861 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info()));
853 Handle<Code> new_original_code = 862 Handle<Code> new_original_code =
854 Factory::CopyCode(compile_info_wrapper.GetFunctionCode()); 863 Factory::CopyCode(compile_info_wrapper.GetFunctionCode());
855 debug_info->set_original_code(*new_original_code); 864 debug_info->set_original_code(*new_original_code);
856 } 865 }
857 866
858 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); 867 shared_info->set_start_position(compile_info_wrapper.GetStartPosition());
859 shared_info->set_end_position(compile_info_wrapper.GetEndPosition()); 868 shared_info->set_end_position(compile_info_wrapper.GetEndPosition());
860 869
861 shared_info->set_construct_stub( 870 shared_info->set_construct_stub(
862 Builtins::builtin(Builtins::JSConstructStubGeneric)); 871 Builtins::builtin(Builtins::JSConstructStubGeneric));
863 // update breakpoints 872
873 return Heap::undefined_value();
864 } 874 }
865 875
866 876
867 // TODO(635): Eval caches its scripts (same text -- same compiled info). 877 // TODO(635): Eval caches its scripts (same text -- same compiled info).
868 // Make sure we clear such caches. 878 // Make sure we clear such caches.
869 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, 879 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper,
870 Handle<Object> script_handle) { 880 Handle<Object> script_handle) {
871 Handle<SharedFunctionInfo> shared_info = 881 Handle<SharedFunctionInfo> shared_info =
872 Handle<SharedFunctionInfo>::cast(UnwrapJSValue(function_wrapper)); 882 Handle<SharedFunctionInfo>::cast(UnwrapJSValue(function_wrapper));
873 shared_info->set_script(*script_handle); 883 shared_info->set_script(*script_handle);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 } else { 1027 } else {
1018 // Relocation info section now has different size. We cannot simply 1028 // Relocation info section now has different size. We cannot simply
1019 // rewrite it inside code object. Instead we have to create a new 1029 // rewrite it inside code object. Instead we have to create a new
1020 // code object. 1030 // code object.
1021 Handle<Code> result(Factory::CopyCode(code, buffer)); 1031 Handle<Code> result(Factory::CopyCode(code, buffer));
1022 return result; 1032 return result;
1023 } 1033 }
1024 } 1034 }
1025 1035
1026 1036
1027 void LiveEdit::PatchFunctionPositions( 1037 Object* LiveEdit::PatchFunctionPositions(
1028 Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array) { 1038 Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array) {
1039
1040 if (!SharedInfoWrapper::IsInstance(shared_info_array)) {
1041 return Top::ThrowIllegalOperation();
1042 }
1043
1029 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1044 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1030 Handle<SharedFunctionInfo> info = shared_info_wrapper.GetInfo(); 1045 Handle<SharedFunctionInfo> info = shared_info_wrapper.GetInfo();
1031 1046
1032 int old_function_start = info->start_position(); 1047 int old_function_start = info->start_position();
1033 int new_function_start = TranslatePosition(old_function_start, 1048 int new_function_start = TranslatePosition(old_function_start,
1034 position_change_array); 1049 position_change_array);
1035 info->set_start_position(new_function_start); 1050 info->set_start_position(new_function_start);
1036 info->set_end_position(TranslatePosition(info->end_position(), 1051 info->set_end_position(TranslatePosition(info->end_position(),
1037 position_change_array)); 1052 position_change_array));
1038 1053
1039 info->set_function_token_position( 1054 info->set_function_token_position(
1040 TranslatePosition(info->function_token_position(), 1055 TranslatePosition(info->function_token_position(),
1041 position_change_array)); 1056 position_change_array));
1042 1057
1043 if (IsJSFunctionCode(info->code())) { 1058 if (IsJSFunctionCode(info->code())) {
1044 // Patch relocation info section of the code. 1059 // Patch relocation info section of the code.
1045 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()), 1060 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()),
1046 position_change_array); 1061 position_change_array);
1047 if (*patched_code != info->code()) { 1062 if (*patched_code != info->code()) {
1048 // Replace all references to the code across the heap. In particular, 1063 // Replace all references to the code across the heap. In particular,
1049 // some stubs may refer to this code and this code may be being executed 1064 // some stubs may refer to this code and this code may be being executed
1050 // on stack (it is safe to substitute the code object on stack, because 1065 // on stack (it is safe to substitute the code object on stack, because
1051 // we only change the structure of rinfo and leave instructions 1066 // we only change the structure of rinfo and leave instructions
1052 // untouched). 1067 // untouched).
1053 ReplaceCodeObject(info->code(), *patched_code); 1068 ReplaceCodeObject(info->code(), *patched_code);
1054 } 1069 }
1055 } 1070 }
1071
1072 return Heap::undefined_value();
1056 } 1073 }
1057 1074
1058 1075
1059 static Handle<Script> CreateScriptCopy(Handle<Script> original) { 1076 static Handle<Script> CreateScriptCopy(Handle<Script> original) {
1060 Handle<String> original_source(String::cast(original->source())); 1077 Handle<String> original_source(String::cast(original->source()));
1061 1078
1062 Handle<Script> copy = Factory::NewScript(original_source); 1079 Handle<Script> copy = Factory::NewScript(original_source);
1063 1080
1064 copy->set_name(original->name()); 1081 copy->set_name(original->name());
1065 copy->set_line_offset(original->line_offset()); 1082 copy->set_line_offset(original->line_offset());
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 1459
1443 bool LiveEditFunctionTracker::IsActive() { 1460 bool LiveEditFunctionTracker::IsActive() {
1444 return false; 1461 return false;
1445 } 1462 }
1446 1463
1447 #endif // ENABLE_DEBUGGER_SUPPORT 1464 #endif // ENABLE_DEBUGGER_SUPPORT
1448 1465
1449 1466
1450 1467
1451 } } // namespace v8::internal 1468 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/liveedit.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698