Can I update the extern for AbortController in the Google closure compiler? - google-closure-compiler

I'm working on an application that uses Fetch in the browser. The compiler (v20221102) complains:
.../src/main/js/src/Fetch.js:766:29: WARNING - [JSC_WRONG_ARGUMENT_COUNT] Function AbortController.prototype.abort: called with 1 argument(s). Function requires at least 0 argument(s) and no more than 0 argument(s).
766| setTimeout(() => controller.abort(reason), wait);`
AFAICT, this is because the extern for AbortController in externs/browser/w3c_abort.js (in the Closure compiler source) defines:
AbortController.prototype.abort = function() {};
Is there any way I can override or extend this prototype to avoid the warnings? AFAICT, the browser implementation of AbortController now allows a reason to be passed to the abort method.

Related

How to Fetch a JSON file in Webassembly

I'm currently experimenting with Webassembly, and one thing I'm trying to do here is with a Webassembly to Fetch data from a JSON file, compile that into a .wasm module, and use that module in Javascript to read the result of the fetch.
I've tried following the code on https://kripken.github.io/emscripten-site/docs/api_reference/fetch.html but the resulting .wasm code is confusing to me because I can't find how to properly load that .wasm module in Javascript.
In case I'm going about this the wrong way, I really need some help with this.
started with this fetch.c file that is supposed to fetch JSON data from a file.
#include <stdio.h>
#include <string.h>
#include <emscripten/fetch.h>
/*////////////////////////
// This file contains the code for fetching
// -> Compiled to .wasm file with emscripten <-
*////////////////////////
void downloadSucceeded(emscripten_fetch_t *fetch) {
printf("Finished downloading %llu bytes from URL %s.\n", fetch->numBytes, fetch->url);
// The data is now available at fetch->data[0] through fetch->data[fetch->numBytes-1];
emscripten_fetch_close(fetch); // Free data associated with the fetch.
}
void downloadFailed(emscripten_fetch_t *fetch) {
printf("Downloading %s failed, HTTP failure status code: %d.\n", fetch->url, fetch->status);
emscripten_fetch_close(fetch); // Also free data on failure.
}
int main() {
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_PERSIST_FILE;
attr.onsuccess = downloadSucceeded;
attr.onerror = downloadFailed;
emscripten_fetch(&attr, "./json/bol_list1.json");
}
I compiled this with : emcc wasm/fetch.c -Os -s WASM=1 -s FETCH=1 -s SIDE_MODULE=1 -s BINARYEN_ASYNC_COMPILATION=0 -o wasm/fetch.wasm
fetch.wasm: https://pastebin.com/cHYpgazy
So, now with that module I'm supposed to read it in Javascript and get the result, but this is where I'm stuck, because as opposed to other examples this .wasm module doesn't have an obvious export/import thing and my previous methods of trying to load it failed.
wasmbyfile.js:
Method 1:
let obj;
loadWebAssembly('./wasm/fetch.wasm') //Testing function
.then(instance => {
obj = instance.exports._main;
console.log(obj);
});
function loadWebAssembly(fileName) {
return fetch(fileName)
.then(response => response.arrayBuffer())
.then(bits => WebAssembly.compile(bits))
.then(module => { return new WebAssembly.Instance(module) });
};
error result: wasmbyfile.js:64 Uncaught (in promise) TypeError: WebAssembly Instantiation: Imports argument must be present and must be an object
at fetch.then.then.then.module (wasmbyfile.js:64)
Method 2:
(async () => {
const fetchPromise = fetch('./wasm/fetch.wasm');
const { instance } = await WebAssembly.instantiateStreaming(fetchPromise);
const result = instance.exports._main;
console.log(result);
})();
error result: Uncaught (in promise) TypeError: WebAssembly Instantiation: Imports argument must be present and must be an object
So I'm stuck at this point, and not really sure how to load the module correctly in JS. I need some help for this, or am I doing this the wrong way from the beginning and is there a better way for me to do this?
You are getting an error because your WASM has import statements, while your call to instantiateStreaming does not send an importObject.
But the basic way to use WASM from Javascript is much simpler than: Just define a function in WASM that you can call from JS, and then you do the "fetch" from JS, for instance ("add.wasm"):
(module
(type $t0 (func (param i32 i32) (result i32)))
(func $add (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
get_local $p0
get_local $p1
i32.add)
(export "add" (func $add)))
And then call it from Javascript:
const wasmInstanceFromFile = await WebAssembly.instantiateStreaming(await fetch('add.wasm'));
let sum = wasmInstanceFromFile.instance.exports.add(1,2);

WCSessionDelegate: sessionDidBecomeInactive and sessionDidDeactivate have been marked unavailable, but are required

I just converted a Swift 2 app to Swift 3, using the convert function of Xcode 8.
My code has a class marked as WCSessionDelegate.
In Swift 2 it compiled without the methods sessionDidBecomeInactive and sessionDidDeactivate.
If I compile the Swift 3 version, the compiler complains that my class does not conform to protocol WCSessionDelegate, which is apparently correct.
It then offers to insert stubs for both functions:
public func sessionDidBecomeInactive(_ session: WCSession) { }
public func sessionDidDeactivate(_ session: WCSession) { }
After these stubs are inserted, these errors are reported:
Cannot override 'sessionDidBecomeInactive' which has been marked unavailable
Cannot override 'sessionDidDeactivate' which has been marked unavailable
How can I fix this problem?
Because the delegate methods sessionDidDeactivate and sessionDidBecomeInactive are marked as unavailable on watchOS you will have to make the compiler ignore those pieces of code in the shared class. You can do so using the following preprocessor macro:
#if os(iOS)
public func sessionDidBecomeInactive(_ session: WCSession) { }
public func sessionDidDeactivate(_ session: WCSession) {
session.activate()
}
#endif
Please also note I added the activate call in the sessionDidDeactivate call. This is to re-activate the session on the phone when the user has switched from one paired watch to second paired one. Calling it like this assumes that you have no other threads/part of your code that needs to be given time before the switch occurs. For more information on supporting the quick watch switching you should take a look at the Apple sample code

"strict" mode for QML?

Does Qt's QML language provide any kind of "strict" mode? In particular, there are two features I'd like:
Application crash on reference to undefined or null (e.g. foo = bar when foo is an existing property but bar is not defined, and foo.bar when foo is null)
"hard" asserts (the console.assert feature does not crash the application).
1. Use qml lint
Run qmllint on all .qml and .js files in your build setup
find ./myproject -type f -regex ".*\.\(qml\|js\)" -exec "$QT_DIR/bin/qmllint" \{\} +
2. Crash app on QML error/warning
Write a custom QDebug message handler function static void handler(QtMsgType type, const QMessageLogContext& context, const QString &message); you register via qInstallMessageHandler(&MyQDebugMessageHandler::handler); that turns QML warnings into fatal logs:
if (type == QtWarningMsg)
{
auto fatalWarnings = std::vector<QString>{
QStringLiteral("ReferenceError:"),
QStringLiteral("is not a type"),
QStringLiteral("File not found"),
};
for (const auto &s : fatalWarnings)
{
if (message.contains(s))
{
type = QtFatalMsg;
break;
}
}
}
Then make sure that QDebug messages of type QtFatalMsg crash the app.
3. Crash on console.assert()
console.assert() creates errors but nothing specific to detect them. So adapt point 2. to crash the app on errors as well.

Specification of Access Functions in ACSL

I have a problem specifiying the access to internal state variables, i.e. those local to a module that are accessed by getters and setters only. I have tried to use the getter function in the specification of the function contract of the setter function, but frama-c returns an error:
> frama-c -wp -wp-rte -verbose 0 intstate.c intstate.h
...
intstate.h:4:[kernel] user error: unexpected token ')'
[kernel] user error: skipping file "intstate.c" that has errors.
[kernel] Frama-C aborted: invalid user input.
Here is the header:
int get_state(void);
/*#
# ensures val == get_state();
#*/
void set_state(int val);
and here the source:
#include "intstate.h"
static int the_state = 0;
int get_state(void) {
return the_state;
}
void set_state(int val) {
the_state = val;
}
I think it is a common problem. How is it done in ACSL? Does anyone have an example of a similar problem?
I use Frama-C Fluorine-20130601.
Thanks in advance
Frank
Edit:
Re-reading the ACSL spec more closely revealed to me that C-functions are not possible in specifications, only logic functions. I tried to wrap the C-function in a logic function but that wasn't accepted too, same error message. I finally modelled the interanl state variable by a ghost variable, but I am not sure if this is the decent approach.

Photon Networking Instantiate Error (Unity3d)

Ok, so I'm making an online FPS in Unity and I was scripting that Photon Networking Script to connect and spawn the player and I keep getting these two errors:
Assets/Resources/GameManager.cs(64,23): error CS1502: The best overloaded method match for `PhotonNetwork.Instantiate(string, UnityEngine.Vector3, UnityEngine.Quaternion, int)' has some invalid arguments
Assets/Resources/GameManager.cs(64,23): error CS1503: Argument `#1' cannot convert `UnityEngine.Transform' expression to type `string'
Here is where the error is in my code:
// When Connected [Photon Callback]
void OnJoinedRoom()
{
PhotonNetwork.Instantiate(playerPrefab, transform.position, Quaternion.identity, 0);
}
//In Game: Disconnect from room.
void InGameGUI()
{
if (GUILayout.Button("Leave Game"))
PhotonNetwork.LeaveRoom();
}
}
And I did reference the Transform at the top:
public Transform playerPrefab;
Any ideas on what I did wrong and how I could fix it. Please help!
PhotonNetwork.Instantiate requires a string, not a Transform object as it's first parameter. (I do believe this was changed from a Transform object a while ago). Simply name the prefab that you want to instantiate (which must be in the Resources folder).

Resources