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

Side by Side Diff: src/liveedit.cc

Issue 650127: Implement BlindReference object and provide couple of liveedit-specific structures (Closed)
Patch Set: follow codereview Created 10 years, 10 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/contexts.h ('k') | 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 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 void LiveEditFunctionTracker::RecordFunctionScope(Scope* scope) { 78 void LiveEditFunctionTracker::RecordFunctionScope(Scope* scope) {
79 if (active_function_info_listener != NULL) { 79 if (active_function_info_listener != NULL) {
80 active_function_info_listener->FunctionScope(scope); 80 active_function_info_listener->FunctionScope(scope);
81 } 81 }
82 } 82 }
83 bool LiveEditFunctionTracker::IsActive() { 83 bool LiveEditFunctionTracker::IsActive() {
84 return active_function_info_listener != NULL; 84 return active_function_info_listener != NULL;
85 } 85 }
86 86
87 // Unwraps JSValue object, returning its field "value"
88 static Handle<Object> UnwrapJSValue(Handle<JSValue> jsValue) {
89 return Handle<Object>(jsValue->value());
90 }
91
92 // Wraps any object into a OpaqueReference, that will hide the object
93 // from JavaScript.
94 static Handle<JSValue> WrapInJSValue(Object* object) {
95 Handle<JSFunction> constructor = Top::opaque_reference_function();
96 Handle<JSValue> result =
97 Handle<JSValue>::cast(Factory::NewJSObject(constructor));
98 result->set_value(object);
99 return result;
100 }
101
102 // Simple helper class that creates more or less typed structures over
103 // JSArray object. This is an adhoc method of passing structures from C++
104 // to JavaScript.
105 template<typename S>
106 class JSArrayBasedStruct {
107 public:
108 static S Create() {
109 Handle<JSArray> array = Factory::NewJSArray(S::kSize_);
110 return S(array);
111 }
112 static S cast(Object* object) {
113 JSArray* array = JSArray::cast(object);
114 Handle<JSArray> array_handle(array);
115 return S(array_handle);
116 }
117 explicit JSArrayBasedStruct(Handle<JSArray> array) : array_(array) {
118 }
119 Handle<JSArray> GetJSArray() {
120 return array_;
121 }
122 protected:
123 void SetField(int field_position, Handle<Object> value) {
124 SetElement(array_, field_position, value);
125 }
126 void SetSmiValueField(int field_position, int value) {
127 SetElement(array_, field_position, Handle<Smi>(Smi::FromInt(value)));
128 }
129 Object* GetField(int field_position) {
130 return array_->GetElement(field_position);
131 }
132 int GetSmiValueField(int field_position) {
133 Object* res = GetField(field_position);
134 return Smi::cast(res)->value();
135 }
136 private:
137 Handle<JSArray> array_;
138 };
139
140
141 // Represents some function compilation details. This structure will be used
142 // from JavaScript. It contains Code object, which is kept wrapped
143 // into a BlindReference for sanitizing reasons.
144 class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> {
145 public:
146 explicit FunctionInfoWrapper(Handle<JSArray> array)
147 : JSArrayBasedStruct<FunctionInfoWrapper>(array) {
148 }
149 void SetInitialProperties(Handle<String> name, int start_position,
150 int end_position, int param_num, int parent_index) {
151 HandleScope scope;
152 this->SetField(kFunctionNameOffset_, name);
153 this->SetSmiValueField(kStartPositionOffset_, start_position);
154 this->SetSmiValueField(kEndPositionOffset_, end_position);
155 this->SetSmiValueField(kParamNumOffset_, param_num);
156 this->SetSmiValueField(kParentIndexOffset_, parent_index);
157 }
158 void SetFunctionCode(Handle<Code> function_code) {
159 Handle<JSValue> wrapper = WrapInJSValue(*function_code);
160 this->SetField(kCodeOffset_, wrapper);
161 }
162 void SetScopeInfo(Handle<JSArray> scope_info_array) {
163 this->SetField(kScopeInfoOffset_, scope_info_array);
164 }
165 int GetParentIndex() {
166 return this->GetSmiValueField(kParentIndexOffset_);
167 }
168 Handle<Code> GetFunctionCode() {
169 Handle<Object> raw_result = UnwrapJSValue(Handle<JSValue>(
170 JSValue::cast(this->GetField(kCodeOffset_))));
171 return Handle<Code>::cast(raw_result);
172 }
173 int GetStartPosition() {
174 return this->GetSmiValueField(kStartPositionOffset_);
175 }
176 int GetEndPosition() {
177 return this->GetSmiValueField(kEndPositionOffset_);
178 }
179
180 private:
181 static const int kFunctionNameOffset_ = 0;
182 static const int kStartPositionOffset_ = 1;
183 static const int kEndPositionOffset_ = 2;
184 static const int kParamNumOffset_ = 3;
185 static const int kCodeOffset_ = 4;
186 static const int kScopeInfoOffset_ = 5;
187 static const int kParentIndexOffset_ = 6;
188 static const int kSize_ = 7;
189 };
190
191 // Wraps SharedFunctionInfo along with some of its fields for passing it
192 // back to JavaScript. SharedFunctionInfo object itself is additionally
193 // wrapped into BlindReference for sanitizing reasons.
194 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> {
195 public:
196 explicit SharedInfoWrapper(Handle<JSArray> array)
197 : JSArrayBasedStruct<SharedInfoWrapper>(array) {
198 }
199
200 void SetProperties(Handle<String> name, int start_position, int end_position,
201 Handle<SharedFunctionInfo> info) {
202 HandleScope scope;
203 this->SetField(kFunctionNameOffset_, name);
204 Handle<JSValue> info_holder = WrapInJSValue(*info);
205 this->SetField(kSharedInfoOffset_, info_holder);
206 this->SetSmiValueField(kStartPositionOffset_, start_position);
207 this->SetSmiValueField(kEndPositionOffset_, end_position);
208 }
209 Handle<SharedFunctionInfo> GetInfo() {
210 Object* element = this->GetField(kSharedInfoOffset_);
211 Handle<JSValue> value_wrapper(JSValue::cast(element));
212 Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
213 return Handle<SharedFunctionInfo>::cast(raw_result);
214 }
215
216 private:
217 static const int kFunctionNameOffset_ = 0;
218 static const int kStartPositionOffset_ = 1;
219 static const int kEndPositionOffset_ = 2;
220 static const int kSharedInfoOffset_ = 3;
221 static const int kSize_ = 4;
222 };
223
224
225
87 } } // namespace v8::internal 226 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698