History

significant cleanup of ScriptEngineQtScript (which isn't exposed to the scripting engine and shouldn't be @jsdoc'ed)

Heather Anderson committed 5 years ago

Commit bd4a0351 parent ef16b835 files · +17 −288Browse files

Showing the changes to libraries/script-engine/src/qtscript/ScriptEngineQtScript.h (1 of 5 files). Show all

Unified · Split

libraries/script-engine/src/qtscript/ScriptEngineQtScript.h+4−242
@@ -25,7 +25,6 @@ · 24 unmodified lines
25#include <QtCore/QString>25#include <QtCore/QString>
26 26
27#include <QtScript/QScriptEngine>27#include <QtScript/QScriptEngine>
28#include <QtScriptTools/QScriptEngineDebugger>
29 28
30#include "../ScriptEngine.h"29#include "../ScriptEngine.h"
31#include "../ScriptManager.h"30#include "../ScriptManager.h"
@@ -97,19 +96,14 @@ public: // ScriptEngine implementation · 65 unmodified lines
97 virtual ScriptValue uncaughtException() const override;96 virtual ScriptValue uncaughtException() const override;
98 virtual QStringList uncaughtExceptionBacktrace() const override;97 virtual QStringList uncaughtExceptionBacktrace() const override;
99 virtual int uncaughtExceptionLineNumber() const override;98 virtual int uncaughtExceptionLineNumber() const override;
99 virtual void updateMemoryCost(const qint64& deltaSize) override;
100 virtual void requestCollectGarbage() override { collectGarbage(); }
100 101
101 // helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways102 // helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways
102 inline bool IS_THREADSAFE_INVOCATION(const QString& method) { return ScriptEngine::IS_THREADSAFE_INVOCATION(method); }103 inline bool IS_THREADSAFE_INVOCATION(const QString& method) { return ScriptEngine::IS_THREADSAFE_INVOCATION(method); }
103 104
104protected: // brought over from BaseScriptEngine105protected: // brought over from BaseScriptEngine
105 /**jsdoc106 QScriptValue makeError(const QScriptValue& other = QScriptValue(), const QString& type = "Error");
106 * @function Script.makeError
107 * @param {object} [other] - Other.
108 * @param {string} [type="Error"] - Error.
109 * @returns {object} Object.
110 * @deprecated This function is deprecated and will be removed.
111 */
112 Q_INVOKABLE QScriptValue makeError(const QScriptValue& other = QScriptValue(), const QString& type = "Error");
113 107
114 // if the currentContext() is valid then throw the passed exception; otherwise, immediately emit it.108 // if the currentContext() is valid then throw the passed exception; otherwise, immediately emit it.
115 // note: this is used in cases where C++ code might call into JS API methods directly109 // note: this is used in cases where C++ code might call into JS API methods directly
@@ -126,23 +120,9 @@ public: · 10 unmodified lines
126 // NOTE - these are NOT intended to be public interfaces available to scripts, the are only Q_INVOKABLE so we can120 // NOTE - these are NOT intended to be public interfaces available to scripts, the are only Q_INVOKABLE so we can
127 // properly ensure they are only called on the correct thread121 // properly ensure they are only called on the correct thread
128 122
129 /**jsdoc
130 * @function Script.registerGlobalObject
131 * @param {string} name - Name.
132 * @param {object} object - Object.
133 * @deprecated This function is deprecated and will be removed.
134 */
135 /// registers a global object by name123 /// registers a global object by name
136 Q_INVOKABLE virtual void registerGlobalObject(const QString& name, QObject* object) override;124 Q_INVOKABLE virtual void registerGlobalObject(const QString& name, QObject* object) override;
137 125
138 /**jsdoc
139 * @function Script.registerGetterSetter
140 * @param {string} name - Name.
141 * @param {function} getter - Getter.
142 * @param {function} setter - Setter.
143 * @param {string} [parent=""] - Parent.
144 * @deprecated This function is deprecated and will be removed.
145 */
146 /// registers a global getter/setter126 /// registers a global getter/setter
147 Q_INVOKABLE void registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter,127 Q_INVOKABLE void registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter,
148 QScriptEngine::FunctionSignature setter, const QString& parent = QString(""));128 QScriptEngine::FunctionSignature setter, const QString& parent = QString(""));
@@ -152,13 +132,6 @@ public: · 3 unmodified lines
152 ScriptEngine::FunctionSignature setter,132 ScriptEngine::FunctionSignature setter,
153 const QString& parent = QString("")) override;133 const QString& parent = QString("")) override;
154 134
155 /**jsdoc
156 * @function Script.registerFunction
157 * @param {string} name - Name.
158 * @param {function} function - Function.
159 * @param {number} [numArguments=-1] - Number of arguments.
160 * @deprecated This function is deprecated and will be removed.
161 */
162 /// register a global function135 /// register a global function
163 Q_INVOKABLE void registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments = -1);136 Q_INVOKABLE void registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments = -1);
164 137
@@ -167,14 +140,6 @@ public: · 2 unmodified lines
167 ScriptEngine::FunctionSignature fun,140 ScriptEngine::FunctionSignature fun,
168 int numArguments = -1) override;141 int numArguments = -1) override;
169 142
170 /**jsdoc
171 * @function Script.registerFunction
172 * @param {string} parent - Parent.
173 * @param {string} name - Name.
174 * @param {function} function - Function.
175 * @param {number} [numArguments=-1] - Number of arguments.
176 * @deprecated This function is deprecated and will be removed.
177 */
178 /// register a function as a method on a previously registered global object143 /// register a function as a method on a previously registered global object
179 Q_INVOKABLE void registerFunction(const QString& parent, const QString& name, QScriptEngine::FunctionSignature fun,144 Q_INVOKABLE void registerFunction(const QString& parent, const QString& name, QScriptEngine::FunctionSignature fun,
180 int numArguments = -1);145 int numArguments = -1);
@@ -185,34 +150,14 @@ public: · 4 unmodified lines
185 ScriptEngine::FunctionSignature fun,150 ScriptEngine::FunctionSignature fun,
186 int numArguments = -1) override;151 int numArguments = -1) override;
187 152
188 /**jsdoc
189 * @function Script.registerEnum
190 * @param {string} name - Name.
191 * @param {object} enum - Enum.
192 * @deprecated This function is deprecated and will be removed.
193 */
194 // WARNING: This function must be called after a registerGlobalObject that creates the namespace this enum is located in, or153 // WARNING: This function must be called after a registerGlobalObject that creates the namespace this enum is located in, or
195 // the globalObject won't function. E.g., if you have a Foo object and a Foo.FooType enum, Foo must be registered first.154 // the globalObject won't function. E.g., if you have a Foo object and a Foo.FooType enum, Foo must be registered first.
196 /// registers a global enum155 /// registers a global enum
197 Q_INVOKABLE virtual void registerEnum(const QString& enumName, QMetaEnum newEnum) override;156 Q_INVOKABLE virtual void registerEnum(const QString& enumName, QMetaEnum newEnum) override;
198 157
199 /**jsdoc
200 * @function Script.registerValue
201 * @param {string} name - Name.
202 * @param {object} value - Value.
203 * @deprecated This function is deprecated and will be removed.
204 */
205 /// registers a global object by name158 /// registers a global object by name
206 Q_INVOKABLE void registerValue(const QString& valueName, QScriptValue value);159 Q_INVOKABLE void registerValue(const QString& valueName, QScriptValue value);
207 160
208 /**jsdoc
209 * @function Script.evaluate
210 * @param {string} program - Program.
211 * @param {string} filename - File name.
212 * @param {number} [lineNumber=-1] - Line number.
213 * @returns {object} Object.
214 * @deprecated This function is deprecated and will be removed.
215 */
216 /// evaluate some code in the context of the ScriptEngineQtScript and return the result161 /// evaluate some code in the context of the ScriptEngineQtScript and return the result
217 Q_INVOKABLE virtual ScriptValue evaluate(const QString& program,162 Q_INVOKABLE virtual ScriptValue evaluate(const QString& program,
218 const QString& fileName) override; // this is also used by the script tool widget163 const QString& fileName) override; // this is also used by the script tool widget
@@ -220,177 +165,10 @@ public: · 1 unmodified line
220 165
221 Q_INVOKABLE virtual ScriptValue evaluate(const ScriptProgramPointer& program) override;166 Q_INVOKABLE virtual ScriptValue evaluate(const ScriptProgramPointer& program) override;
222 167
223 /**jsdoc
224 * @function Script.evaluateInClosure
225 * @param {object} locals - Locals.
226 * @param {object} program - Program.
227 * @returns {object} Object.
228 * @deprecated This function is deprecated and will be removed.
229 */
230 Q_INVOKABLE virtual ScriptValue evaluateInClosure(const ScriptValue& locals, const ScriptProgramPointer& program) override;168 Q_INVOKABLE virtual ScriptValue evaluateInClosure(const ScriptValue& locals, const ScriptProgramPointer& program) override;
231 169
232 /**jsdoc
233 * Checks whether the application was compiled as a debug build.
234 * @function Script.isDebugMode
235 * @returns {boolean} <code>true</code> if the application was compiled as a debug build, <code>false</code> if it was
236 * compiled as a release build.
237 */
238 Q_INVOKABLE bool isDebugMode() const;
239
240 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
241 // MODULE related methods
242
243 /**jsdoc
244 * Prints a message to the program log and emits {@link Script.printedMessage}.
245 * <p>Alternatively, you can use {@link print} or one of the {@link console} API methods.</p>
246 * @function Script.print
247 * @param {string} message - The message to print.
248 */
249 Q_INVOKABLE void print(const QString& message);
250
251 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
252 // Entity Script Related methods
253
254 /**jsdoc
255 * Manually runs the JavaScript garbage collector which reclaims memory by disposing of objects that are no longer
256 * reachable.
257 * @function Script.requestGarbageCollection
258 */
259 Q_INVOKABLE void requestGarbageCollection() { collectGarbage(); }
260
261 bool isRunning() const { return _isRunning; } // used by ScriptWidget
262
263 bool isDebuggable() const { return _debuggable; }
264
265 void disconnectNonEssentialSignals();
266
267 // NOTE - this is used by the TypedArray implementation. we need to review this for thread safety170 // NOTE - this is used by the TypedArray implementation. we need to review this for thread safety
268 ArrayBufferClass* getArrayBufferClass() { return _arrayBufferClass; }171 inline ArrayBufferClass* getArrayBufferClass() { return _arrayBufferClass; }
269
270 /**jsdoc
271 * @function Script.updateMemoryCost
272 * @param {number} deltaSize - Delta size.
273 * @deprecated This function is deprecated and will be removed.
274 */
275 virtual void updateMemoryCost(const qint64& deltaSize) override;
276
277signals:
278
279 /**jsdoc
280 * Triggered frequently at a system-determined interval.
281 * @function Script.update
282 * @param {number} deltaTime - The time since the last update, in s.
283 * @returns {Signal}
284 * @example <caption>Report script update intervals.</caption>
285 * Script.update.connect(function (deltaTime) {
286 * print("Update: " + deltaTime);
287 * });
288 */
289 void update(float deltaTime);
290
291 /**jsdoc
292 * @function Script.finished
293 * @param {string} filename - File name.
294 * @param {object} engine - Engine.
295 * @returns {Signal}
296 * @deprecated This signal is deprecated and will be removed.
297 */
298 void finished(const QString& fileNameString, ScriptEngineQtScriptPointer);
299
300 /**jsdoc
301 * @function Script.cleanupMenuItem
302 * @param {string} menuItem - Menu item.
303 * @returns {Signal}
304 * @deprecated This signal is deprecated and will be removed.
305 */
306 void cleanupMenuItem(const QString& menuItemString);
307
308 /**jsdoc
309 * Triggered when the script prints a message to the program log via {@link print}, {@link Script.print},
310 * {@link console.log}, {@link console.debug}, {@link console.group}, {@link console.groupEnd}, {@link console.time}, or
311 * {@link console.timeEnd}.
312 * @function Script.printedMessage
313 * @param {string} message - The message.
314 * @param {string} scriptName - The name of the script that generated the message.
315 * @returns {Signal}
316 */
317 void printedMessage(const QString& message, const QString& scriptName);
318
319 /**jsdoc
320 * Triggered when the script generates an error, {@link console.error} or {@link console.exception} is called, or
321 * {@link console.assert} is called and fails.
322 * @function Script.errorMessage
323 * @param {string} message - The error message.
324 * @param {string} scriptName - The name of the script that generated the error message.
325 * @returns {Signal}
326 */
327 void errorMessage(const QString& message, const QString& scriptName);
328
329 /**jsdoc
330 * Triggered when the script generates a warning or {@link console.warn} is called.
331 * @function Script.warningMessage
332 * @param {string} message - The warning message.
333 * @param {string} scriptName - The name of the script that generated the warning message.
334 * @returns {Signal}
335 */
336 void warningMessage(const QString& message, const QString& scriptName);
337
338 /**jsdoc
339 * Triggered when the script generates an information message or {@link console.info} is called.
340 * @function Script.infoMessage
341 * @param {string} message - The information message.
342 * @param {string} scriptName - The name of the script that generated the information message.
343 * @returns {Signal}
344 */
345 void infoMessage(const QString& message, const QString& scriptName);
346
347 /**jsdoc
348 * Triggered when the running state of the script changes, e.g., from running to stopping.
349 * @function Script.runningStateChanged
350 * @returns {Signal}
351 */
352 void runningStateChanged();
353
354 /**jsdoc
355 * @function Script.clearDebugWindow
356 * @returns {Signal}
357 * @deprecated This signal is deprecated and will be removed.
358 */
359 void clearDebugWindow();
360
361 /**jsdoc
362 * @function Script.loadScript
363 * @param {string} scriptName - Script name.
364 * @param {boolean} isUserLoaded - Is user loaded.
365 * @returns {Signal}
366 * @deprecated This signal is deprecated and will be removed.
367 */
368 void loadScript(const QString& scriptName, bool isUserLoaded);
369
370 /**jsdoc
371 * @function Script.reloadScript
372 * @param {string} scriptName - Script name.
373 * @param {boolean} isUserLoaded - Is user loaded.
374 * @returns {Signal}
375 * @deprecated This signal is deprecated and will be removed.
376 */
377 void reloadScript(const QString& scriptName, bool isUserLoaded);
378
379 /**jsdoc
380 * Triggered when the script has stopped.
381 * @function Script.doneRunning
382 * @returns {Signal}
383 */
384 void doneRunning();
385
386 /**jsdoc
387 * @function Script.entityScriptDetailsUpdated
388 * @returns {Signal}
389 * @deprecated This signal is deprecated and will be removed.
390 */
391 // Emitted when an entity script is added or removed, or when the status of an entity
392 // script is updated (goes from RUNNING to ERROR_RUNNING_SCRIPT, for example)
393 void entityScriptDetailsUpdated();
394 172
395public: // not for public use, but I don't like how Qt strings this along with private friend functions173public: // not for public use, but I don't like how Qt strings this along with private friend functions
396 virtual ScriptValue create(int type, const void* ptr) override;174 virtual ScriptValue create(int type, const void* ptr) override;
@@ -409,15 +187,6 @@ protected: · 12 unmodified lines
409 const QScriptEngine::ValueOwnership& ownership = QScriptEngine::AutoOwnership);187 const QScriptEngine::ValueOwnership& ownership = QScriptEngine::AutoOwnership);
410 188
411protected:189protected:
412
413 /**jsdoc
414 * @function Script.executeOnScriptThread
415 * @param {function} function - Function.
416 * @param {ConnectionType} [type=2] - Connection type.
417 * @deprecated This function is deprecated and will be removed.
418 */
419 Q_INVOKABLE void executeOnScriptThread(std::function<void()> function, const Qt::ConnectionType& type = Qt::QueuedConnection );
420
421 QPointer<ScriptManager> _manager;190 QPointer<ScriptManager> _manager;
422 191
423 int _nextCustomType = 0;192 int _nextCustomType = 0;
@@ -425,13 +194,6 @@ protected: · 1 unmodified line
425 ScriptValue _undefinedValue;194 ScriptValue _undefinedValue;
426 mutable ScriptContextQtPointer _currContext;195 mutable ScriptContextQtPointer _currContext;
427 196
428 std::atomic<bool> _isRunning { false };
429
430 bool _isThreaded { false };
431 QScriptEngineDebugger* _debugger { nullptr };
432 bool _debuggable { false };
433 qint64 _lastUpdate;
434
435 ArrayBufferClass* _arrayBufferClass;197 ArrayBufferClass* _arrayBufferClass;
436 198
437 ScriptContextQtAgent* _contextAgent{ nullptr };199 ScriptContextQtAgent* _contextAgent{ nullptr };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t