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

Side by Side Diff: src/messages.cc

Issue 1293493004: Unify symbols sharing across native scripts and runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 4 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/messages.h ('k') | src/messages.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/messages.h" 5 #include "src/messages.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/execution.h" 8 #include "src/execution.h"
9 #include "src/string-builder.h" 9 #include "src/string-builder.h"
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 133
134 base::SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( 134 base::SmartArrayPointer<char> MessageHandler::GetLocalizedMessage(
135 Isolate* isolate, Handle<Object> data) { 135 Isolate* isolate, Handle<Object> data) {
136 HandleScope scope(isolate); 136 HandleScope scope(isolate);
137 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); 137 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS);
138 } 138 }
139 139
140 140
141 Handle<Object> CallSite::GetFileName(Isolate* isolate) { 141 CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj)
142 Handle<Object> script(fun_->shared()->script(), isolate); 142 : isolate_(isolate) {
143 if (script->IsScript()) { 143 receiver_ = JSObject::GetDataProperty(
144 return Handle<Object>(Handle<Script>::cast(script)->name(), isolate); 144 call_site_obj, isolate->factory()->call_site_receiver_symbol());
145 } 145 fun_ = Handle<JSFunction>::cast(JSObject::GetDataProperty(
146 return isolate->factory()->null_value(); 146 call_site_obj, isolate->factory()->call_site_function_symbol()));
147 pos_ = Handle<Smi>::cast(JSObject::GetDataProperty(
148 call_site_obj,
149 isolate->factory()->call_site_position_symbol()))
150 ->value();
147 } 151 }
148 152
149 153
150 Handle<Object> CallSite::GetFunctionName(Isolate* isolate) { 154 Handle<Object> CallSite::GetFileName() {
155 Handle<Object> script(fun_->shared()->script(), isolate_);
156 if (script->IsScript()) {
157 return Handle<Object>(Handle<Script>::cast(script)->name(), isolate_);
158 }
159 return isolate_->factory()->null_value();
160 }
161
162
163 Handle<Object> CallSite::GetFunctionName() {
151 Handle<String> result = JSFunction::GetDebugName(fun_); 164 Handle<String> result = JSFunction::GetDebugName(fun_);
152 if (result->length() != 0) return result; 165 if (result->length() != 0) return result;
153 Handle<Object> script(fun_->shared()->script(), isolate); 166 Handle<Object> script(fun_->shared()->script(), isolate_);
154 if (script->IsScript() && 167 if (script->IsScript() &&
155 Handle<Script>::cast(script)->compilation_type() == 168 Handle<Script>::cast(script)->compilation_type() ==
156 Script::COMPILATION_TYPE_EVAL) { 169 Script::COMPILATION_TYPE_EVAL) {
157 return isolate->factory()->eval_string(); 170 return isolate_->factory()->eval_string();
158 } 171 }
159 return isolate->factory()->null_value(); 172 return isolate_->factory()->null_value();
160 } 173 }
161 174
162 175
163 Handle<Object> CallSite::GetScriptNameOrSourceUrl(Isolate* isolate) { 176 Handle<Object> CallSite::GetScriptNameOrSourceUrl() {
164 Handle<Object> script_obj(fun_->shared()->script(), isolate); 177 Handle<Object> script_obj(fun_->shared()->script(), isolate_);
165 if (script_obj->IsScript()) { 178 if (script_obj->IsScript()) {
166 Handle<Script> script = Handle<Script>::cast(script_obj); 179 Handle<Script> script = Handle<Script>::cast(script_obj);
167 Object* source_url = script->source_url(); 180 Object* source_url = script->source_url();
168 if (source_url->IsString()) return Handle<Object>(source_url, isolate); 181 if (source_url->IsString()) return Handle<Object>(source_url, isolate_);
169 return Handle<Object>(script->name(), isolate); 182 return Handle<Object>(script->name(), isolate_);
170 } 183 }
171 return isolate->factory()->null_value(); 184 return isolate_->factory()->null_value();
172 } 185 }
173 186
174 187
175 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, 188 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name,
176 Handle<JSFunction> fun, 189 Handle<JSFunction> fun,
177 LookupIterator::Configuration config) { 190 LookupIterator::Configuration config) {
178 LookupIterator iter = 191 LookupIterator iter =
179 LookupIterator::PropertyOrElement(isolate, obj, name, config); 192 LookupIterator::PropertyOrElement(isolate, obj, name, config);
180 if (iter.state() == LookupIterator::DATA) { 193 if (iter.state() == LookupIterator::DATA) {
181 return iter.GetDataValue().is_identical_to(fun); 194 return iter.GetDataValue().is_identical_to(fun);
182 } else if (iter.state() == LookupIterator::ACCESSOR) { 195 } else if (iter.state() == LookupIterator::ACCESSOR) {
183 Handle<Object> accessors = iter.GetAccessors(); 196 Handle<Object> accessors = iter.GetAccessors();
184 if (accessors->IsAccessorPair()) { 197 if (accessors->IsAccessorPair()) {
185 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); 198 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors);
186 return pair->getter() == *fun || pair->setter() == *fun; 199 return pair->getter() == *fun || pair->setter() == *fun;
187 } 200 }
188 } 201 }
189 return false; 202 return false;
190 } 203 }
191 204
192 205
193 Handle<Object> CallSite::GetMethodName(Isolate* isolate) { 206 Handle<Object> CallSite::GetMethodName() {
194 MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate, receiver_); 207 MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate_, receiver_);
195 Handle<JSReceiver> receiver; 208 Handle<JSReceiver> receiver;
196 if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) { 209 if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) {
197 return isolate->factory()->null_value(); 210 return isolate_->factory()->null_value();
198 } 211 }
199 212
200 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); 213 Handle<JSObject> obj = Handle<JSObject>::cast(receiver);
201 Handle<Object> function_name(fun_->shared()->name(), isolate); 214 Handle<Object> function_name(fun_->shared()->name(), isolate_);
202 if (function_name->IsName()) { 215 if (function_name->IsName()) {
203 Handle<Name> name = Handle<Name>::cast(function_name); 216 Handle<Name> name = Handle<Name>::cast(function_name);
204 if (CheckMethodName(isolate, obj, name, fun_, 217 if (CheckMethodName(isolate_, obj, name, fun_,
205 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR)) 218 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR))
206 return name; 219 return name;
207 } 220 }
208 221
209 HandleScope outer_scope(isolate); 222 HandleScope outer_scope(isolate_);
210 Handle<Object> result; 223 Handle<Object> result;
211 for (PrototypeIterator iter(isolate, obj, 224 for (PrototypeIterator iter(isolate_, obj,
212 PrototypeIterator::START_AT_RECEIVER); 225 PrototypeIterator::START_AT_RECEIVER);
213 !iter.IsAtEnd(); iter.Advance()) { 226 !iter.IsAtEnd(); iter.Advance()) {
214 Handle<Object> current = PrototypeIterator::GetCurrent(iter); 227 Handle<Object> current = PrototypeIterator::GetCurrent(iter);
215 if (!current->IsJSObject()) break; 228 if (!current->IsJSObject()) break;
216 Handle<JSObject> current_obj = Handle<JSObject>::cast(current); 229 Handle<JSObject> current_obj = Handle<JSObject>::cast(current);
217 if (current_obj->IsAccessCheckNeeded()) break; 230 if (current_obj->IsAccessCheckNeeded()) break;
218 Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false); 231 Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false);
219 for (int i = 0; i < keys->length(); i++) { 232 for (int i = 0; i < keys->length(); i++) {
220 HandleScope inner_scope(isolate); 233 HandleScope inner_scope(isolate_);
221 if (!keys->get(i)->IsName()) continue; 234 if (!keys->get(i)->IsName()) continue;
222 Handle<Name> name_key(Name::cast(keys->get(i)), isolate); 235 Handle<Name> name_key(Name::cast(keys->get(i)), isolate_);
223 if (!CheckMethodName(isolate, current_obj, name_key, fun_, 236 if (!CheckMethodName(isolate_, current_obj, name_key, fun_,
224 LookupIterator::OWN_SKIP_INTERCEPTOR)) 237 LookupIterator::OWN_SKIP_INTERCEPTOR))
225 continue; 238 continue;
226 // Return null in case of duplicates to avoid confusion. 239 // Return null in case of duplicates to avoid confusion.
227 if (!result.is_null()) return isolate->factory()->null_value(); 240 if (!result.is_null()) return isolate_->factory()->null_value();
228 result = inner_scope.CloseAndEscape(name_key); 241 result = inner_scope.CloseAndEscape(name_key);
229 } 242 }
230 } 243 }
231 244
232 if (!result.is_null()) return outer_scope.CloseAndEscape(result); 245 if (!result.is_null()) return outer_scope.CloseAndEscape(result);
233 return isolate->factory()->null_value(); 246 return isolate_->factory()->null_value();
234 } 247 }
235 248
236 249
237 int CallSite::GetLineNumber(Isolate* isolate) { 250 int CallSite::GetLineNumber() {
238 if (pos_ >= 0) { 251 if (pos_ >= 0) {
239 Handle<Object> script_obj(fun_->shared()->script(), isolate); 252 Handle<Object> script_obj(fun_->shared()->script(), isolate_);
240 if (script_obj->IsScript()) { 253 if (script_obj->IsScript()) {
241 Handle<Script> script = Handle<Script>::cast(script_obj); 254 Handle<Script> script = Handle<Script>::cast(script_obj);
242 return Script::GetLineNumber(script, pos_) + 1; 255 return Script::GetLineNumber(script, pos_) + 1;
243 } 256 }
244 } 257 }
245 return -1; 258 return -1;
246 } 259 }
247 260
248 261
249 int CallSite::GetColumnNumber(Isolate* isolate) { 262 int CallSite::GetColumnNumber() {
250 if (pos_ >= 0) { 263 if (pos_ >= 0) {
251 Handle<Object> script_obj(fun_->shared()->script(), isolate); 264 Handle<Object> script_obj(fun_->shared()->script(), isolate_);
252 if (script_obj->IsScript()) { 265 if (script_obj->IsScript()) {
253 Handle<Script> script = Handle<Script>::cast(script_obj); 266 Handle<Script> script = Handle<Script>::cast(script_obj);
254 return Script::GetColumnNumber(script, pos_) + 1; 267 return Script::GetColumnNumber(script, pos_) + 1;
255 } 268 }
256 } 269 }
257 return -1; 270 return -1;
258 } 271 }
259 272
260 273
261 bool CallSite::IsNative(Isolate* isolate) { 274 bool CallSite::IsNative() {
262 Handle<Object> script(fun_->shared()->script(), isolate); 275 Handle<Object> script(fun_->shared()->script(), isolate_);
263 return script->IsScript() && 276 return script->IsScript() &&
264 Handle<Script>::cast(script)->type()->value() == Script::TYPE_NATIVE; 277 Handle<Script>::cast(script)->type()->value() == Script::TYPE_NATIVE;
265 } 278 }
266 279
267 280
268 bool CallSite::IsToplevel(Isolate* isolate) { 281 bool CallSite::IsToplevel() {
269 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || 282 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() ||
270 receiver_->IsUndefined(); 283 receiver_->IsUndefined();
271 } 284 }
272 285
273 286
274 bool CallSite::IsEval(Isolate* isolate) { 287 bool CallSite::IsEval() {
275 Handle<Object> script(fun_->shared()->script(), isolate); 288 Handle<Object> script(fun_->shared()->script(), isolate_);
276 return script->IsScript() && 289 return script->IsScript() &&
277 Handle<Script>::cast(script)->compilation_type() == 290 Handle<Script>::cast(script)->compilation_type() ==
278 Script::COMPILATION_TYPE_EVAL; 291 Script::COMPILATION_TYPE_EVAL;
279 } 292 }
280 293
281 294
282 bool CallSite::IsConstructor(Isolate* isolate) { 295 bool CallSite::IsConstructor() {
283 if (!receiver_->IsJSObject()) return false; 296 if (!receiver_->IsJSObject()) return false;
284 Handle<Object> constructor = 297 Handle<Object> constructor =
285 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), 298 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_),
286 isolate->factory()->constructor_string()); 299 isolate_->factory()->constructor_string());
287 return constructor.is_identical_to(fun_); 300 return constructor.is_identical_to(fun_);
288 } 301 }
289 302
290 303
291 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, 304 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate,
292 int template_index, 305 int template_index,
293 Handle<Object> arg) { 306 Handle<Object> arg) {
294 Factory* factory = isolate->factory(); 307 Factory* factory = isolate->factory();
295 Handle<String> result_string; 308 Handle<String> result_string;
296 if (arg->IsString()) { 309 if (arg->IsString()) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (obj->IsUndefined()) return default_value; 468 if (obj->IsUndefined()) return default_value;
456 if (!obj->IsString()) { 469 if (!obj->IsString()) {
457 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Execution::ToString(isolate, obj), 470 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Execution::ToString(isolate, obj),
458 String); 471 String);
459 } 472 }
460 return Handle<String>::cast(obj); 473 return Handle<String>::cast(obj);
461 } 474 }
462 475
463 } // namespace internal 476 } // namespace internal
464 } // namespace v8 477 } // namespace v8
OLDNEW
« no previous file with comments | « src/messages.h ('k') | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698