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

Delta Between Two Patch Sets: src/FileSystemJsObject.cpp

Issue 29531696: Issue 5568 - Improve string handling by splitting read strings into only ASCII and non-ASCII strings (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Left Patch Set: Created Aug. 30, 2017, 4:55 p.m.
Right Patch Set: address comments Created Aug. 31, 2017, 1:20 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/io.js ('k') | src/JsError.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 const JsContext context(*jsEngine); 58 const JsContext context(*jsEngine);
59 auto result = jsEngine->NewObject(); 59 auto result = jsEngine->NewObject();
60 result.SetStringBufferProperty("content", std::move(content)); 60 result.SetStringBufferProperty("content", std::move(content));
61 if (!error.empty()) 61 if (!error.empty())
62 result.SetProperty("error", error); 62 result.SetProperty("error", error);
63 jsEngine->TakeJsValues(weakCallback)[0].Call(result); 63 jsEngine->TakeJsValues(weakCallback)[0].Call(result);
64 }); 64 });
65 } 65 }
66 66
67 inline bool CReturnOrLineFeed(char c) 67 inline bool IsEndOfLine(char c)
hub 2017/08/30 21:13:31 nit': I would name this function "IsEndOfLine()"
sergei 2017/08/31 10:45:26 I am actually also not glad with the name of this
hub 2017/08/31 12:59:43 "End of line" or EOL is often used through the UNI
sergei 2017/08/31 13:21:44 agree.
68 { 68 {
69 return c == 10 || c == 13; 69 return c == 10 || c == 13;
70 } 70 }
71 71
72 inline StringBuffer::const_iterator SkipCReturnAndLineFeed(StringBuffer::const _iterator ii, StringBuffer::const_iterator end) 72 inline StringBuffer::const_iterator SkipEndOfLine(StringBuffer::const_iterator ii, StringBuffer::const_iterator end)
hub 2017/08/30 21:13:30 and this one SkipEndOfLine()
73 { 73 {
74 while (ii != end && CReturnOrLineFeed(*ii)) 74 while (ii != end && IsEndOfLine(*ii))
75 ++ii; 75 ++ii;
76 return ii; 76 return ii;
77 } 77 }
78 78
79 inline StringBuffer::const_iterator AdvanceUntilCReturnOrLineFeed(StringBuffer ::const_iterator ii, StringBuffer::const_iterator end) 79 inline StringBuffer::const_iterator AdvanceToEndOfLine(StringBuffer::const_ite rator ii, StringBuffer::const_iterator end)
hub 2017/08/30 21:13:31 And this one AdvanceToEndOfLine() But this is not
80 { 80 {
81 while (ii != end && !CReturnOrLineFeed(*ii)) 81 while (ii != end && !IsEndOfLine(*ii))
82 ++ii; 82 ++ii;
83 return ii; 83 return ii;
84 } 84 }
85 85
86 void ReadFromFileCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments ) 86 void ReadFromFileCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments )
87 { 87 {
88 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 88 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
89 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 89 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
90 90
91 v8::Isolate* isolate = arguments.GetIsolate(); 91 v8::Isolate* isolate = arguments.GetIsolate();
(...skipping 28 matching lines...) Expand all
120 120
121 auto processFunc = jsValues[0].UnwrapValue().As<v8::Function>(); 121 auto processFunc = jsValues[0].UnwrapValue().As<v8::Function>();
122 122
123 auto globalContext = context.GetV8Context()->Global(); 123 auto globalContext = context.GetV8Context()->Global();
124 if (!globalContext->IsObject()) 124 if (!globalContext->IsObject())
125 throw std::runtime_error("`this` pointer has to be an object"); 125 throw std::runtime_error("`this` pointer has to be an object");
126 126
127 const v8::TryCatch tryCatch; 127 const v8::TryCatch tryCatch;
128 128
129 const auto contentEnd = content.cend(); 129 const auto contentEnd = content.cend();
130 auto stringBegin = SkipCReturnAndLineFeed(content.begin(), contentEnd); 130 auto stringBegin = SkipEndOfLine(content.begin(), contentEnd);
131 do 131 do
132 { 132 {
133 auto stringEnd = AdvanceUntilCReturnOrLineFeed(stringBegin, contentEnd); 133 auto stringEnd = AdvanceToEndOfLine(stringBegin, contentEnd);
134 auto jsLine = Utils::StringBufferToV8String(jsEngine->GetIsolate(), Stri ngBuffer(stringBegin, stringEnd)).As<v8::Value>(); 134 auto jsLine = Utils::StringBufferToV8String(jsEngine->GetIsolate(), Stri ngBuffer(stringBegin, stringEnd)).As<v8::Value>();
135 processFunc->Call(globalContext, 1, &jsLine); 135 processFunc->Call(globalContext, 1, &jsLine);
136 if (tryCatch.HasCaught()) 136 if (tryCatch.HasCaught())
137 { 137 {
138 jsValues[1].Call(jsEngine->NewValue(JsError::ExceptionToString(tryCatc h.Exception(), tryCatch.Message()))); 138 jsValues[1].Call(jsEngine->NewValue(JsError::ExceptionToString(tryCatc h.Exception(), tryCatch.Message())));
139 return; 139 return;
140 } 140 }
141 stringBegin = SkipCReturnAndLineFeed(stringEnd, contentEnd); 141 stringBegin = SkipEndOfLine(stringEnd, contentEnd);
142 } while (stringBegin != contentEnd); 142 } while (stringBegin != contentEnd);
143 jsValues[1].Call(); 143 jsValues[1].Call();
144 }); 144 });
145 } 145 }
146 146
147 void WriteCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 147 void WriteCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
148 { 148 {
149 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 149 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
150 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 150 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
151 151
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj) 279 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj)
280 { 280 {
281 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback)); 281 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback));
282 obj.SetProperty("readFromFile", jsEngine.NewCallback(::ReadFromFileCallback)); 282 obj.SetProperty("readFromFile", jsEngine.NewCallback(::ReadFromFileCallback));
283 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback)); 283 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback));
284 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback)); 284 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback));
285 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback)); 285 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback));
286 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback)); 286 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback));
287 return obj; 287 return obj;
288 } 288 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld