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