Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/WebRequestJsObject.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
Patch Set: address comments Created Nov. 25, 2016, 12:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 } 52 }
53 53
54 callback = arguments[2]; 54 callback = arguments[2];
55 if (!callback->IsFunction()) 55 if (!callback->IsFunction())
56 throw std::runtime_error("Third argument to GET must be a function"); 56 throw std::runtime_error("Third argument to GET must be a function");
57 } 57 }
58 58
59 void Run() 59 void Run()
60 { 60 {
61 AdblockPlus::ServerResponse result = jsEngine->GetWebRequest()->GET(url, h eaders); 61 // Don't keep a strong reference to JsEngine while request is being execut ed.
62 62 auto webRequest = AdblockPlus::Utils::lockJsEngine(jsEngine)->GetWebReques t();
63 auto result = webRequest->GET(url, headers);
63 AdblockPlus::JsContext context(jsEngine); 64 AdblockPlus::JsContext context(jsEngine);
64 65 AdblockPlus::JsValuePtr resultObject = context.GetJsEngine().NewObject();
65 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject();
66 resultObject->SetProperty("status", result.status); 66 resultObject->SetProperty("status", result.status);
67 resultObject->SetProperty("responseStatus", result.responseStatus); 67 resultObject->SetProperty("responseStatus", result.responseStatus);
68 resultObject->SetProperty("responseText", result.responseText); 68 resultObject->SetProperty("responseText", result.responseText);
69 69
70 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); 70 AdblockPlus::JsValuePtr headersObject = context.GetJsEngine().NewObject();
71 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin() ; 71 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin() ;
72 it != result.responseHeaders.end(); ++it) 72 it != result.responseHeaders.end(); ++it)
73 { 73 {
74 headersObject->SetProperty(it->first, it->second); 74 headersObject->SetProperty(it->first, it->second);
75 } 75 }
76 resultObject->SetProperty("responseHeaders", headersObject); 76 resultObject->SetProperty("responseHeaders", headersObject);
77 77
78 AdblockPlus::JsValueList params; 78 AdblockPlus::JsValueList params;
79 params.push_back(resultObject); 79 params.push_back(resultObject);
80 callback->Call(params); 80 callback->Call(params);
81 } 81 }
82 82
83 private: 83 private:
84 AdblockPlus::JsEnginePtr jsEngine; 84 std::weak_ptr<AdblockPlus::JsEngine> jsEngine;
85 std::string url; 85 std::string url;
86 AdblockPlus::HeaderList headers; 86 AdblockPlus::HeaderList headers;
87 AdblockPlus::JsValuePtr callback; 87 AdblockPlus::JsValuePtr callback;
88 }; 88 };
89 89
90 v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments) 90 v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments)
91 { 91 {
92 WebRequestThread* thread; 92 WebRequestThread* thread;
93 try 93 try
94 { 94 {
(...skipping 13 matching lines...) Expand all
108 return v8::Undefined(); 108 return v8::Undefined();
109 } 109 }
110 } 110 }
111 111
112 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( 112 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup(
113 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) 113 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj)
114 { 114 {
115 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); 115 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback));
116 return obj; 116 return obj;
117 } 117 }
OLDNEW
« src/Utils.cpp ('K') | « src/Utils.cpp ('k') | test/BaseJsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld