OLD | NEW |
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/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "src/keys.h" | 10 #include "src/keys.h" |
11 #include "src/string-builder.h" | 11 #include "src/string-builder.h" |
| 12 #include "src/wasm/wasm-module.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, | 17 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, |
17 int end_pos) | 18 int end_pos) |
18 : script_(script), start_pos_(start_pos), end_pos_(end_pos) {} | 19 : script_(script), start_pos_(start_pos), end_pos_(end_pos) {} |
19 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, | 20 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, |
20 int end_pos, Handle<JSFunction> function) | 21 int end_pos, Handle<JSFunction> function) |
21 : script_(script), | 22 : script_(script), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 Isolate* isolate, Handle<Object> data) { | 163 Isolate* isolate, Handle<Object> data) { |
163 HandleScope scope(isolate); | 164 HandleScope scope(isolate); |
164 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); | 165 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); |
165 } | 166 } |
166 | 167 |
167 | 168 |
168 CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj) | 169 CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj) |
169 : isolate_(isolate) { | 170 : isolate_(isolate) { |
170 Handle<Object> maybe_function = JSObject::GetDataProperty( | 171 Handle<Object> maybe_function = JSObject::GetDataProperty( |
171 call_site_obj, isolate->factory()->call_site_function_symbol()); | 172 call_site_obj, isolate->factory()->call_site_function_symbol()); |
172 if (!maybe_function->IsJSFunction()) return; | 173 if (maybe_function->IsJSFunction()) { |
| 174 // javascript |
| 175 fun_ = Handle<JSFunction>::cast(maybe_function); |
| 176 receiver_ = JSObject::GetDataProperty( |
| 177 call_site_obj, isolate->factory()->call_site_receiver_symbol()); |
| 178 } else { |
| 179 Handle<Object> maybe_wasm_func_index = JSObject::GetDataProperty( |
| 180 call_site_obj, isolate->factory()->call_site_wasm_func_index_symbol()); |
| 181 if (!maybe_wasm_func_index->IsSmi()) { |
| 182 // invalid: neither javascript nor wasm |
| 183 return; |
| 184 } |
| 185 // wasm |
| 186 wasm_obj_ = Handle<JSObject>::cast(JSObject::GetDataProperty( |
| 187 call_site_obj, isolate->factory()->call_site_wasm_obj_symbol())); |
| 188 wasm_func_index_ = Smi::cast(*maybe_wasm_func_index)->value(); |
| 189 DCHECK(static_cast<int>(wasm_func_index_) >= 0); |
| 190 } |
173 | 191 |
174 fun_ = Handle<JSFunction>::cast(maybe_function); | |
175 receiver_ = JSObject::GetDataProperty( | |
176 call_site_obj, isolate->factory()->call_site_receiver_symbol()); | |
177 CHECK(JSObject::GetDataProperty( | 192 CHECK(JSObject::GetDataProperty( |
178 call_site_obj, isolate->factory()->call_site_position_symbol()) | 193 call_site_obj, isolate->factory()->call_site_position_symbol()) |
179 ->ToInt32(&pos_)); | 194 ->ToInt32(&pos_)); |
180 } | 195 } |
181 | 196 |
182 | 197 |
183 Handle<Object> CallSite::GetFileName() { | 198 Handle<Object> CallSite::GetFileName() { |
184 Handle<Object> script(fun_->shared()->script(), isolate_); | 199 if (!IsJavaScript()) return isolate_->factory()->null_value(); |
185 if (script->IsScript()) { | 200 Object* script = fun_->shared()->script(); |
186 return Handle<Object>(Handle<Script>::cast(script)->name(), isolate_); | 201 if (!script->IsScript()) return isolate_->factory()->null_value(); |
187 } | 202 return Handle<Object>(Script::cast(script)->name(), isolate_); |
188 return isolate_->factory()->null_value(); | |
189 } | 203 } |
190 | 204 |
191 | 205 |
192 Handle<Object> CallSite::GetFunctionName() { | 206 Handle<Object> CallSite::GetFunctionName() { |
| 207 if (IsWasm()) { |
| 208 if (wasm_obj_->IsUndefined()) return isolate_->factory()->null_value(); |
| 209 // wasm_obj_ can be a String if we generate WASM code directly in a test |
| 210 // case. |
| 211 if (wasm_obj_->IsString()) return wasm_obj_; |
| 212 return wasm::GetWasmFunctionName(Handle<JSObject>::cast(wasm_obj_), |
| 213 wasm_func_index_); |
| 214 } |
193 Handle<String> result = JSFunction::GetName(fun_); | 215 Handle<String> result = JSFunction::GetName(fun_); |
194 if (result->length() != 0) return result; | 216 if (result->length() != 0) return result; |
195 | 217 |
196 Handle<Object> script(fun_->shared()->script(), isolate_); | 218 Handle<Object> script(fun_->shared()->script(), isolate_); |
197 if (script->IsScript() && | 219 if (script->IsScript() && |
198 Handle<Script>::cast(script)->compilation_type() == | 220 Handle<Script>::cast(script)->compilation_type() == |
199 Script::COMPILATION_TYPE_EVAL) { | 221 Script::COMPILATION_TYPE_EVAL) { |
200 return isolate_->factory()->eval_string(); | 222 return isolate_->factory()->eval_string(); |
201 } | 223 } |
202 return isolate_->factory()->null_value(); | 224 return isolate_->factory()->null_value(); |
203 } | 225 } |
204 | 226 |
205 | |
206 Handle<Object> CallSite::GetScriptNameOrSourceUrl() { | 227 Handle<Object> CallSite::GetScriptNameOrSourceUrl() { |
207 Handle<Object> script_obj(fun_->shared()->script(), isolate_); | 228 if (!IsJavaScript()) return isolate_->factory()->null_value(); |
208 if (script_obj->IsScript()) { | 229 Object* script_obj = fun_->shared()->script(); |
209 Handle<Script> script = Handle<Script>::cast(script_obj); | 230 if (!script_obj->IsScript()) return isolate_->factory()->null_value(); |
210 Object* source_url = script->source_url(); | 231 Handle<Script> script(Script::cast(script_obj), isolate_); |
211 if (source_url->IsString()) return Handle<Object>(source_url, isolate_); | 232 Object* source_url = script->source_url(); |
212 return Handle<Object>(script->name(), isolate_); | 233 if (source_url->IsString()) return Handle<Object>(source_url, isolate_); |
213 } | 234 return Handle<Object>(script->name(), isolate_); |
214 return isolate_->factory()->null_value(); | |
215 } | 235 } |
216 | 236 |
217 | |
218 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, | 237 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, |
219 Handle<JSFunction> fun, | 238 Handle<JSFunction> fun, |
220 LookupIterator::Configuration config) { | 239 LookupIterator::Configuration config) { |
221 LookupIterator iter = | 240 LookupIterator iter = |
222 LookupIterator::PropertyOrElement(isolate, obj, name, config); | 241 LookupIterator::PropertyOrElement(isolate, obj, name, config); |
223 if (iter.state() == LookupIterator::DATA) { | 242 if (iter.state() == LookupIterator::DATA) { |
224 return iter.GetDataValue().is_identical_to(fun); | 243 return iter.GetDataValue().is_identical_to(fun); |
225 } else if (iter.state() == LookupIterator::ACCESSOR) { | 244 } else if (iter.state() == LookupIterator::ACCESSOR) { |
226 Handle<Object> accessors = iter.GetAccessors(); | 245 Handle<Object> accessors = iter.GetAccessors(); |
227 if (accessors->IsAccessorPair()) { | 246 if (accessors->IsAccessorPair()) { |
228 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); | 247 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); |
229 return pair->getter() == *fun || pair->setter() == *fun; | 248 return pair->getter() == *fun || pair->setter() == *fun; |
230 } | 249 } |
231 } | 250 } |
232 return false; | 251 return false; |
233 } | 252 } |
234 | 253 |
235 | 254 |
236 Handle<Object> CallSite::GetMethodName() { | 255 Handle<Object> CallSite::GetMethodName() { |
237 if (receiver_->IsNull() || receiver_->IsUndefined()) { | 256 if (!IsJavaScript() || receiver_->IsNull() || receiver_->IsUndefined()) { |
238 return isolate_->factory()->null_value(); | 257 return isolate_->factory()->null_value(); |
239 } | 258 } |
240 Handle<JSReceiver> receiver = | 259 Handle<JSReceiver> receiver = |
241 Object::ToObject(isolate_, receiver_).ToHandleChecked(); | 260 Object::ToObject(isolate_, receiver_).ToHandleChecked(); |
242 if (!receiver->IsJSObject()) { | 261 if (!receiver->IsJSObject()) { |
243 return isolate_->factory()->null_value(); | 262 return isolate_->factory()->null_value(); |
244 } | 263 } |
245 | 264 |
246 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); | 265 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); |
247 Handle<Object> function_name(fun_->shared()->name(), isolate_); | 266 Handle<Object> function_name(fun_->shared()->name(), isolate_); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 result = inner_scope.CloseAndEscape(name_key); | 305 result = inner_scope.CloseAndEscape(name_key); |
287 } | 306 } |
288 } | 307 } |
289 | 308 |
290 if (!result.is_null()) return outer_scope.CloseAndEscape(result); | 309 if (!result.is_null()) return outer_scope.CloseAndEscape(result); |
291 return isolate_->factory()->null_value(); | 310 return isolate_->factory()->null_value(); |
292 } | 311 } |
293 | 312 |
294 | 313 |
295 int CallSite::GetLineNumber() { | 314 int CallSite::GetLineNumber() { |
296 if (pos_ >= 0) { | 315 if (pos_ >= 0 && IsJavaScript()) { |
297 Handle<Object> script_obj(fun_->shared()->script(), isolate_); | 316 Handle<Object> script_obj(fun_->shared()->script(), isolate_); |
298 if (script_obj->IsScript()) { | 317 if (script_obj->IsScript()) { |
299 Handle<Script> script = Handle<Script>::cast(script_obj); | 318 Handle<Script> script = Handle<Script>::cast(script_obj); |
300 return Script::GetLineNumber(script, pos_) + 1; | 319 return Script::GetLineNumber(script, pos_) + 1; |
301 } | 320 } |
302 } | 321 } |
303 return -1; | 322 return -1; |
304 } | 323 } |
305 | 324 |
306 | 325 |
307 int CallSite::GetColumnNumber() { | 326 int CallSite::GetColumnNumber() { |
308 if (pos_ >= 0) { | 327 if (pos_ >= 0 && IsJavaScript()) { |
309 Handle<Object> script_obj(fun_->shared()->script(), isolate_); | 328 Handle<Object> script_obj(fun_->shared()->script(), isolate_); |
310 if (script_obj->IsScript()) { | 329 if (script_obj->IsScript()) { |
311 Handle<Script> script = Handle<Script>::cast(script_obj); | 330 Handle<Script> script = Handle<Script>::cast(script_obj); |
312 return Script::GetColumnNumber(script, pos_) + 1; | 331 return Script::GetColumnNumber(script, pos_) + 1; |
313 } | 332 } |
314 } | 333 } |
315 return -1; | 334 return -1; |
316 } | 335 } |
317 | 336 |
318 | 337 |
319 bool CallSite::IsNative() { | 338 bool CallSite::IsNative() { |
| 339 if (!IsJavaScript()) return false; |
320 Handle<Object> script(fun_->shared()->script(), isolate_); | 340 Handle<Object> script(fun_->shared()->script(), isolate_); |
321 return script->IsScript() && | 341 return script->IsScript() && |
322 Handle<Script>::cast(script)->type() == Script::TYPE_NATIVE; | 342 Handle<Script>::cast(script)->type() == Script::TYPE_NATIVE; |
323 } | 343 } |
324 | 344 |
325 | 345 |
326 bool CallSite::IsToplevel() { | 346 bool CallSite::IsToplevel() { |
| 347 if (IsWasm()) return false; |
327 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || | 348 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || |
328 receiver_->IsUndefined(); | 349 receiver_->IsUndefined(); |
329 } | 350 } |
330 | 351 |
331 | 352 |
332 bool CallSite::IsEval() { | 353 bool CallSite::IsEval() { |
| 354 if (!IsJavaScript()) return false; |
333 Handle<Object> script(fun_->shared()->script(), isolate_); | 355 Handle<Object> script(fun_->shared()->script(), isolate_); |
334 return script->IsScript() && | 356 return script->IsScript() && |
335 Handle<Script>::cast(script)->compilation_type() == | 357 Handle<Script>::cast(script)->compilation_type() == |
336 Script::COMPILATION_TYPE_EVAL; | 358 Script::COMPILATION_TYPE_EVAL; |
337 } | 359 } |
338 | 360 |
339 | 361 |
340 bool CallSite::IsConstructor() { | 362 bool CallSite::IsConstructor() { |
341 if (!receiver_->IsJSObject()) return false; | 363 if (!IsJavaScript() || !receiver_->IsJSObject()) return false; |
342 Handle<Object> constructor = | 364 Handle<Object> constructor = |
343 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), | 365 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), |
344 isolate_->factory()->constructor_string()); | 366 isolate_->factory()->constructor_string()); |
345 return constructor.is_identical_to(fun_); | 367 return constructor.is_identical_to(fun_); |
346 } | 368 } |
347 | 369 |
348 | 370 |
349 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, | 371 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, |
350 int template_index, | 372 int template_index, |
351 Handle<Object> arg) { | 373 Handle<Object> arg) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 builder.AppendCharacter(*c); | 445 builder.AppendCharacter(*c); |
424 } | 446 } |
425 } | 447 } |
426 | 448 |
427 return builder.Finish(); | 449 return builder.Finish(); |
428 } | 450 } |
429 | 451 |
430 | 452 |
431 } // namespace internal | 453 } // namespace internal |
432 } // namespace v8 | 454 } // namespace v8 |
OLD | NEW |