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

Side by Side Diff: src/messages.cc

Issue 2201823002: Make CallSite constructor inaccessible from JS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@get-stack-trace-line
Patch Set: Revert "CHECK invalid arguments to CallSite constructor" Created 4 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') | test/mjsunit/stack-traces.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 <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/execution.h" 10 #include "src/execution.h"
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 handle(FixedArray::cast(raw_stack_array->elements()), isolate); 502 handle(FixedArray::cast(raw_stack_array->elements()), isolate);
503 503
504 const int raw_stack_len = raw_stack_elements->length(); 504 const int raw_stack_len = raw_stack_elements->length();
505 DCHECK(raw_stack_len % 4 == 1); // Multiples of 4 plus sloppy frames count. 505 DCHECK(raw_stack_len % 4 == 1); // Multiples of 4 plus sloppy frames count.
506 const int frame_count = (raw_stack_len - 1) / 4; 506 const int frame_count = (raw_stack_len - 1) / 4;
507 507
508 Handle<Object> sloppy_frames_obj = 508 Handle<Object> sloppy_frames_obj =
509 FixedArray::get(*raw_stack_elements, 0, isolate); 509 FixedArray::get(*raw_stack_elements, 0, isolate);
510 int sloppy_frames = Handle<Smi>::cast(sloppy_frames_obj)->value(); 510 int sloppy_frames = Handle<Smi>::cast(sloppy_frames_obj)->value();
511 511
512 Handle<JSFunction> callsite_ctor =
513 handle(isolate->native_context()->callsite_function(), isolate);
514
515 int dst_ix = 0; 512 int dst_ix = 0;
516 Handle<FixedArray> frames = isolate->factory()->NewFixedArray(frame_count); 513 Handle<FixedArray> frames = isolate->factory()->NewFixedArray(frame_count);
517 for (int i = 1; i < raw_stack_len; i += 4) { 514 for (int i = 1; i < raw_stack_len; i += 4) {
518 Handle<Object> recv = FixedArray::get(*raw_stack_elements, i, isolate); 515 Handle<Object> recv = FixedArray::get(*raw_stack_elements, i, isolate);
519 Handle<Object> fun = FixedArray::get(*raw_stack_elements, i + 1, isolate); 516 Handle<Object> fun = FixedArray::get(*raw_stack_elements, i + 1, isolate);
520 Handle<AbstractCode> code = Handle<AbstractCode>::cast( 517 Handle<AbstractCode> code = Handle<AbstractCode>::cast(
521 FixedArray::get(*raw_stack_elements, i + 2, isolate)); 518 FixedArray::get(*raw_stack_elements, i + 2, isolate));
522 Handle<Smi> pc = 519 Handle<Smi> pc =
523 Handle<Smi>::cast(FixedArray::get(*raw_stack_elements, i + 3, isolate)); 520 Handle<Smi>::cast(FixedArray::get(*raw_stack_elements, i + 3, isolate));
524 521
525 Handle<Object> pos = 522 Handle<Object> pos =
526 (fun->IsSmi() && pc->value() < 0) 523 (fun->IsSmi() && pc->value() < 0)
527 ? handle(Smi::FromInt(-1 - pc->value()), isolate) 524 ? handle(Smi::FromInt(-1 - pc->value()), isolate)
528 : handle(Smi::FromInt(code->SourcePosition(pc->value())), isolate); 525 : handle(Smi::FromInt(code->SourcePosition(pc->value())), isolate);
529 526
530 sloppy_frames--; 527 sloppy_frames--;
531 Handle<Object> strict = isolate->factory()->ToBoolean(sloppy_frames < 0); 528 Handle<Object> strict = isolate->factory()->ToBoolean(sloppy_frames < 0);
532 529
533 Handle<Object> callsite; 530 Handle<Object> callsite;
534 ASSIGN_RETURN_ON_EXCEPTION( 531 ASSIGN_RETURN_ON_EXCEPTION(
535 isolate, callsite, 532 isolate, callsite,
536 CallSiteUtils::Construct(isolate, callsite_ctor, callsite_ctor, recv, 533 CallSiteUtils::Construct(isolate, recv, fun, pos, strict), FixedArray);
537 fun, pos, strict),
538 FixedArray);
539 534
540 frames->set(dst_ix++, *callsite); 535 frames->set(dst_ix++, *callsite);
541 } 536 }
542 537
543 DCHECK_EQ(frame_count, dst_ix); 538 DCHECK_EQ(frame_count, dst_ix);
544 return frames; 539 return frames;
545 } 540 }
546 541
547 MaybeHandle<Object> AppendErrorString(Isolate* isolate, Handle<Object> error, 542 MaybeHandle<Object> AppendErrorString(Isolate* isolate, Handle<Object> error,
548 IncrementalStringBuilder* builder) { 543 IncrementalStringBuilder* builder) {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, builder.Finish(), String); 877 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, builder.Finish(), String);
883 return result; 878 return result;
884 } 879 }
885 880
886 #define SET_CALLSITE_PROPERTY(target, key, value) \ 881 #define SET_CALLSITE_PROPERTY(target, key, value) \
887 RETURN_ON_EXCEPTION( \ 882 RETURN_ON_EXCEPTION( \
888 isolate, JSObject::SetOwnPropertyIgnoreAttributes( \ 883 isolate, JSObject::SetOwnPropertyIgnoreAttributes( \
889 target, isolate->factory()->key(), value, DONT_ENUM), \ 884 target, isolate->factory()->key(), value, DONT_ENUM), \
890 Object) 885 Object)
891 886
892 MaybeHandle<Object> CallSiteUtils::Construct( 887 MaybeHandle<Object> CallSiteUtils::Construct(Isolate* isolate,
893 Isolate* isolate, Handle<JSFunction> target, Handle<Object> new_target, 888 Handle<Object> receiver,
894 Handle<Object> receiver, Handle<Object> fun, Handle<Object> pos, 889 Handle<Object> fun,
895 Handle<Object> strict_mode) { 890 Handle<Object> pos,
891 Handle<Object> strict_mode) {
896 // Create the JS object. 892 // Create the JS object.
897 893
898 Handle<JSReceiver> new_target_recv = 894 Handle<JSFunction> target =
899 new_target->IsJSReceiver() ? Handle<JSReceiver>::cast(new_target) 895 handle(isolate->native_context()->callsite_function(), isolate);
900 : Handle<JSReceiver>::cast(target);
901 896
902 Handle<JSObject> obj; 897 Handle<JSObject> obj;
903 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, 898 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, JSObject::New(target, target),
904 JSObject::New(target, new_target_recv), Object); 899 Object);
905 900
906 // For wasm frames, receiver is the wasm object and fun is the function index 901 // For wasm frames, receiver is the wasm object and fun is the function index
907 // instead of an actual function. 902 // instead of an actual function.
908 const bool is_wasm_object = 903 const bool is_wasm_object =
909 receiver->IsJSObject() && wasm::IsWasmObject(JSObject::cast(*receiver)); 904 receiver->IsJSObject() && wasm::IsWasmObject(JSObject::cast(*receiver));
910 if (!fun->IsJSFunction() && !is_wasm_object) { 905 if (!fun->IsJSFunction() && !is_wasm_object) {
911 THROW_NEW_ERROR(isolate, 906 THROW_NEW_ERROR(isolate,
912 NewTypeError(MessageTemplate::kCallSiteExpectsFunction, 907 NewTypeError(MessageTemplate::kCallSiteExpectsFunction,
913 Object::TypeOf(isolate, receiver), 908 Object::TypeOf(isolate, receiver),
914 Object::TypeOf(isolate, fun)), 909 Object::TypeOf(isolate, fun)),
915 Object); 910 Object);
916 } 911 }
917 912
918 if (is_wasm_object) { 913 if (is_wasm_object) {
919 // TODO(jgruber): Convert back to DCHECK once the callsite constructor is 914 DCHECK(fun->IsSmi());
920 // inaccessible from JS. 915 DCHECK(wasm::GetNumberOfFunctions(JSObject::cast(*receiver)) >
921 CHECK(fun->IsSmi() && (wasm::GetNumberOfFunctions(JSObject::cast( 916 Smi::cast(*fun)->value());
922 *receiver)) > Smi::cast(*fun)->value()));
923 917
924 SET_CALLSITE_PROPERTY(obj, call_site_wasm_obj_symbol, receiver); 918 SET_CALLSITE_PROPERTY(obj, call_site_wasm_obj_symbol, receiver);
925 SET_CALLSITE_PROPERTY(obj, call_site_wasm_func_index_symbol, fun); 919 SET_CALLSITE_PROPERTY(obj, call_site_wasm_func_index_symbol, fun);
926 } else { 920 } else {
927 DCHECK(fun->IsJSFunction()); 921 DCHECK(fun->IsJSFunction());
928 SET_CALLSITE_PROPERTY(obj, call_site_receiver_symbol, receiver); 922 SET_CALLSITE_PROPERTY(obj, call_site_receiver_symbol, receiver);
929 SET_CALLSITE_PROPERTY(obj, call_site_function_symbol, fun); 923 SET_CALLSITE_PROPERTY(obj, call_site_function_symbol, fun);
930 } 924 }
931 925
932 // TODO(jgruber): Convert back to DCHECK once the callsite constructor is 926 DCHECK(pos->IsSmi());
933 // inaccessible from JS.
934 CHECK(pos->IsSmi());
935
936 SET_CALLSITE_PROPERTY(obj, call_site_position_symbol, pos); 927 SET_CALLSITE_PROPERTY(obj, call_site_position_symbol, pos);
937 SET_CALLSITE_PROPERTY( 928 SET_CALLSITE_PROPERTY(
938 obj, call_site_strict_symbol, 929 obj, call_site_strict_symbol,
939 isolate->factory()->ToBoolean(strict_mode->BooleanValue())); 930 isolate->factory()->ToBoolean(strict_mode->BooleanValue()));
940 931
941 return obj; 932 return obj;
942 } 933 }
943 934
944 #undef SET_CALLSITE_PROPERTY 935 #undef SET_CALLSITE_PROPERTY
945 936
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 builder.AppendCString(" ("); 1158 builder.AppendCString(" (");
1168 RETURN_ON_EXCEPTION( 1159 RETURN_ON_EXCEPTION(
1169 isolate, AppendFileLocation(isolate, recv, &call_site, &builder), String); 1160 isolate, AppendFileLocation(isolate, recv, &call_site, &builder), String);
1170 builder.AppendCString(")"); 1161 builder.AppendCString(")");
1171 1162
1172 RETURN_RESULT(isolate, builder.Finish(), String); 1163 RETURN_RESULT(isolate, builder.Finish(), String);
1173 } 1164 }
1174 1165
1175 } // namespace internal 1166 } // namespace internal
1176 } // namespace v8 1167 } // namespace v8
OLDNEW
« no previous file with comments | « src/messages.h ('k') | test/mjsunit/stack-traces.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698