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 if (args.This()->InternalFieldCount() > 0) { |
727 if (!this_value->IsExternal()) { | 728 this_value = args.This()->GetInternalField(0); |
| 729 } |
| 730 if (this_value.IsEmpty()) { |
728 Throw(isolate, "this is not a Worker"); | 731 Throw(isolate, "this is not a Worker"); |
729 return; | 732 return; |
730 } | 733 } |
731 | 734 |
732 Worker* worker = | 735 Worker* worker = |
733 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); | 736 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); |
734 | 737 |
735 Handle<Value> message = args[0]; | 738 Handle<Value> message = args[0]; |
736 ObjectList to_transfer; | 739 ObjectList to_transfer; |
737 if (args.Length() >= 2) { | 740 if (args.Length() >= 2) { |
(...skipping 25 matching lines...) Expand all Loading... |
763 worker->PostMessage(data); | 766 worker->PostMessage(data); |
764 } else { | 767 } else { |
765 delete data; | 768 delete data; |
766 } | 769 } |
767 } | 770 } |
768 | 771 |
769 | 772 |
770 void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { | 773 void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { |
771 Isolate* isolate = args.GetIsolate(); | 774 Isolate* isolate = args.GetIsolate(); |
772 HandleScope handle_scope(isolate); | 775 HandleScope handle_scope(isolate); |
773 | 776 Local<Value> this_value; |
774 Local<Value> this_value = args.This()->GetInternalField(0); | 777 if (args.This()->InternalFieldCount() > 0) { |
775 if (!this_value->IsExternal()) { | 778 this_value = args.This()->GetInternalField(0); |
| 779 } |
| 780 if (this_value.IsEmpty()) { |
776 Throw(isolate, "this is not a Worker"); | 781 Throw(isolate, "this is not a Worker"); |
777 return; | 782 return; |
778 } | 783 } |
779 | 784 |
780 Worker* worker = | 785 Worker* worker = |
781 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); | 786 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); |
782 | 787 |
783 SerializationData* data = worker->GetMessage(); | 788 SerializationData* data = worker->GetMessage(); |
784 if (data) { | 789 if (data) { |
785 int offset = 0; | 790 int offset = 0; |
786 Local<Value> data_value; | 791 Local<Value> data_value; |
787 if (Shell::DeserializeValue(isolate, *data, &offset).ToLocal(&data_value)) { | 792 if (Shell::DeserializeValue(isolate, *data, &offset).ToLocal(&data_value)) { |
788 args.GetReturnValue().Set(data_value); | 793 args.GetReturnValue().Set(data_value); |
789 } | 794 } |
790 delete data; | 795 delete data; |
791 } | 796 } |
792 } | 797 } |
793 | 798 |
794 | 799 |
795 void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 800 void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
796 Isolate* isolate = args.GetIsolate(); | 801 Isolate* isolate = args.GetIsolate(); |
797 HandleScope handle_scope(isolate); | 802 HandleScope handle_scope(isolate); |
798 Local<Value> this_value = args.This()->GetInternalField(0); | 803 Local<Value> this_value; |
799 if (!this_value->IsExternal()) { | 804 if (args.This()->InternalFieldCount() > 0) { |
| 805 this_value = args.This()->GetInternalField(0); |
| 806 } |
| 807 if (this_value.IsEmpty()) { |
800 Throw(isolate, "this is not a Worker"); | 808 Throw(isolate, "this is not a Worker"); |
801 return; | 809 return; |
802 } | 810 } |
803 | 811 |
804 Worker* worker = | 812 Worker* worker = |
805 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); | 813 static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); |
806 worker->Terminate(); | 814 worker->Terminate(); |
807 } | 815 } |
808 #endif // !V8_SHARED | 816 #endif // !V8_SHARED |
809 | 817 |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2430 } | 2438 } |
2431 | 2439 |
2432 } // namespace v8 | 2440 } // namespace v8 |
2433 | 2441 |
2434 | 2442 |
2435 #ifndef GOOGLE3 | 2443 #ifndef GOOGLE3 |
2436 int main(int argc, char* argv[]) { | 2444 int main(int argc, char* argv[]) { |
2437 return v8::Shell::Main(argc, argv); | 2445 return v8::Shell::Main(argc, argv); |
2438 } | 2446 } |
2439 #endif | 2447 #endif |
OLD | NEW |