OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 } | 710 } |
711 worker->StartExecuteInThread(isolate, *script); | 711 worker->StartExecuteInThread(isolate, *script); |
712 } | 712 } |
713 } | 713 } |
714 | 714 |
715 | 715 |
716 void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { | 716 void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { |
717 Isolate* isolate = args.GetIsolate(); | 717 Isolate* isolate = args.GetIsolate(); |
718 HandleScope handle_scope(isolate); | 718 HandleScope handle_scope(isolate); |
719 Local<Context> context = isolate->GetCurrentContext(); | 719 Local<Context> context = isolate->GetCurrentContext(); |
720 Local<Value> this_value; | |
720 | 721 |
721 if (args.Length() < 1) { | 722 if (args.Length() < 1) { |
722 Throw(isolate, "Invalid argument"); | 723 Throw(isolate, "Invalid argument"); |
723 return; | 724 return; |
724 } | 725 } |
725 | 726 |
726 Local<Value> this_value = args.This()->GetInternalField(0); | 727 // Bounds-check to avoid fatal error in debug mode |
adamk
2015/07/07 18:48:26
I'd just remove this comment: it's not a "bounds-c
caitp (gmail)
2015/07/07 19:00:17
Acknowledged.
| |
727 if (!this_value->IsExternal()) { | 728 if (args.This()->InternalFieldCount() > 0) { |
729 this_value = args.This()->GetInternalField(0); | |
730 } | |
731 if (this_value.IsEmpty() || !this_value->IsExternal()) { | |
adamk
2015/07/07 18:48:26
Can the second part of this conditional ever fail?
caitp (gmail)
2015/07/07 19:00:17
right now, I don't think so
| |
728 Throw(isolate, "this is not a Worker"); | 732 Throw(isolate, "this is not a Worker"); |
729 return; | 733 return; |
730 } | 734 } |
731 | 735 |
732 Worker* worker = | 736 Worker* worker = |
733 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); | 737 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); |
734 | 738 |
735 Handle<Value> message = args[0]; | 739 Handle<Value> message = args[0]; |
736 ObjectList to_transfer; | 740 ObjectList to_transfer; |
737 if (args.Length() >= 2) { | 741 if (args.Length() >= 2) { |
(...skipping 25 matching lines...) Expand all Loading... | |
763 worker->PostMessage(data); | 767 worker->PostMessage(data); |
764 } else { | 768 } else { |
765 delete data; | 769 delete data; |
766 } | 770 } |
767 } | 771 } |
768 | 772 |
769 | 773 |
770 void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { | 774 void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { |
771 Isolate* isolate = args.GetIsolate(); | 775 Isolate* isolate = args.GetIsolate(); |
772 HandleScope handle_scope(isolate); | 776 HandleScope handle_scope(isolate); |
773 | 777 Local<Value> this_value; |
774 Local<Value> this_value = args.This()->GetInternalField(0); | 778 // Bounds-check to avoid fatal error in debug mode |
adamk
2015/07/07 18:48:26
Ditto, comment seems off.
| |
775 if (!this_value->IsExternal()) { | 779 if (args.This()->InternalFieldCount() > 0) { |
780 this_value = args.This()->GetInternalField(0); | |
781 } | |
782 if (this_value.IsEmpty() || !this_value->IsExternal()) { | |
adamk
2015/07/07 18:48:26
Ditto, I don't think IsExternal can fail now
| |
776 Throw(isolate, "this is not a Worker"); | 783 Throw(isolate, "this is not a Worker"); |
777 return; | 784 return; |
778 } | 785 } |
779 | 786 |
780 Worker* worker = | 787 Worker* worker = |
781 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); | 788 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); |
782 | 789 |
783 SerializationData* data = worker->GetMessage(); | 790 SerializationData* data = worker->GetMessage(); |
784 if (data) { | 791 if (data) { |
785 int offset = 0; | 792 int offset = 0; |
786 Local<Value> data_value; | 793 Local<Value> data_value; |
787 if (Shell::DeserializeValue(isolate, *data, &offset).ToLocal(&data_value)) { | 794 if (Shell::DeserializeValue(isolate, *data, &offset).ToLocal(&data_value)) { |
788 args.GetReturnValue().Set(data_value); | 795 args.GetReturnValue().Set(data_value); |
789 } | 796 } |
790 delete data; | 797 delete data; |
791 } | 798 } |
792 } | 799 } |
793 | 800 |
794 | 801 |
795 void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 802 void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
796 Isolate* isolate = args.GetIsolate(); | 803 Isolate* isolate = args.GetIsolate(); |
797 HandleScope handle_scope(isolate); | 804 HandleScope handle_scope(isolate); |
798 Local<Value> this_value = args.This()->GetInternalField(0); | 805 Local<Value> this_value; |
799 if (!this_value->IsExternal()) { | 806 // Bounds-check to avoid fatal error in debug mode |
adamk
2015/07/07 18:48:26
And here...
| |
807 if (args.This()->InternalFieldCount() > 0) { | |
808 this_value = args.This()->GetInternalField(0); | |
809 } | |
810 if (this_value.IsEmpty() || !this_value->IsExternal()) { | |
adamk
2015/07/07 18:48:26
And here
| |
800 Throw(isolate, "this is not a Worker"); | 811 Throw(isolate, "this is not a Worker"); |
801 return; | 812 return; |
802 } | 813 } |
803 | 814 |
804 Worker* worker = | 815 Worker* worker = |
805 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); | 816 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); |
806 worker->Terminate(); | 817 worker->Terminate(); |
807 } | 818 } |
808 #endif // !V8_SHARED | 819 #endif // !V8_SHARED |
809 | 820 |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2430 } | 2441 } |
2431 | 2442 |
2432 } // namespace v8 | 2443 } // namespace v8 |
2433 | 2444 |
2434 | 2445 |
2435 #ifndef GOOGLE3 | 2446 #ifndef GOOGLE3 |
2436 int main(int argc, char* argv[]) { | 2447 int main(int argc, char* argv[]) { |
2437 return v8::Shell::Main(argc, argv); | 2448 return v8::Shell::Main(argc, argv); |
2438 } | 2449 } |
2439 #endif | 2450 #endif |
OLD | NEW |