In JSLint 2, unparam is gone. Insteady, you may name a function parameter 'ignore' and the linter will ignore its unused state.
The problem I can't solve: How do I ignore multiple function parameters? Here's what I'm looking to replace:
$rootScope.$on('$routeChangeError', function (ignore_ev, ignore_current, ignore_previous, rejection) {
if (rejection === 'route value is not an integer') {
useTheUnloved(ignore_ev);
useTheUnloved(ignore_current);
useTheUnloved(ignore_previous);
$location.path(ENV.uiRouteBase + '/');
}
});
useTheUnloved = function (ignore) {
return 'JSLint 2 - how can I ignore multiple function args';
};
Related
I have following .ts files
core.ts
interface Signature {
args: string[];
ret?: string;
}
const subject = 'hook'
const now = () => (new Date()).getTime()
const readable = (type: string, arg: NativePointer) => (type === 'char *' ? arg.readUtf8String() : arg)
export function hook(mod: string | null, symbol: string, signature: Signature) {
const p = Module.findExportByName(mod, symbol)
if (!p) throw new Error(`Function ${mod || 'global'}!${symbol} not found`)
const range = Process.findRangeByAddress(p)
if (!range?.protection.includes('x')) throw new Error('Invalid symbol, expected a function but received a data pointer')
const id = p.toString()
const lib = mod || Process.getModuleByAddress(p)!.name
const listener = Interceptor.attach(p, {
onEnter(args) {
const time = now()
const pretty = signature.args.map((type, i) => readable(type, args[i]))
const backtrace = Thread.backtrace(this.context, Backtracer.ACCURATE)
.map(DebugSymbol.fromAddress).filter(e => e.name)
this.backtrace = backtrace
send({
subject,
event: 'call',
args: pretty,
lib,
symbol,
backtrace,
time
})
},
onLeave(retVal) {
if (!signature.ret) return
const time = now()
const ret = readable(signature.ret, retVal)
send({
subject,
event: 'return',
lib,
symbol,
time,
backtrace: this.backtrace,
ret
})
}
})
return listener
}
sql-hooks.ts
// import { hook } from './core'
const { hook } = require('./core.ts')
ObjC.schedule(ObjC.mainQueue, function () {
enable()
});
function enable() {
console.log('enabled')
hook('libsqlite3.dylib', 'sqlite3_open', { args: ['char *', 'int'], ret: 'int' })
hook('libsqlite3.dylib', 'sqlite3_prepare_v2', { args: ['pointer', 'char *', 'int', 'pointer', 'pointer'] })
hook('libsqlite3.dylib', 'sqlite3_bind_int', { args: ['pointer', 'int', 'int'] })
hook('libsqlite3.dylib', 'sqlite3_bind_null', { args: ['pointer', 'int'] })
hook('libsqlite3.dylib', 'sqlite3_bind_text', { args: ['pointer', 'int', 'char *', 'int', 'pointer'] })
}
Then I used following command to connect these two files
frida-compile '/path/to/sql-hooks.ts' -o out.ts
Finally I used following command to actually use out.ts
frida -U -F -l '/path/to/out.ts'
But unfortunately I get this error
out.ts:1:1 - error TS1127: Invalid character.
out.ts:2:6 - error TS2304: Cannot find name 'sql'.
out.ts:2:10 - error TS2552: Cannot find name 'hooks'. Did you mean 'hook'?
out.ts:3:6 - error TS2304: Cannot find name 'sql'.
out.ts:3:10 - error TS2552: Cannot find name 'hooks'. Did you mean 'hook'?
out.ts:4:1 - error TS1127: Invalid character.
out.ts:5:11 - error TS1005: ';' expected.
out.ts:5:12 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:20 - error TS1005: ';' expected.
out.ts:5:21 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:48 - error TS1005: ';' expected.
out.ts:5:49 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:105 - error TS1005: ';' expected.
out.ts:5:106 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:130 - error TS1005: ';' expected.
out.ts:5:131 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:144 - error TS1005: ';' expected.
out.ts:6:1 - error TS1127: Invalid character.
What am I doing wrong?
I bumped into a frida-compile example (from oleavr) and I found out I was doing a couple of things wrong. In particular I took a look at the agent folder and at the package.json scripts region.
I'm going to mention two files: sql-hooks.ts (which is my main.ts) and core.ts (which is my module.ts); both of them are inside the same folder.
I changed first line of sql-hooks.ts from
const { hook } = require('./core.ts')
to
import { hook } from './core.js'
Notice I imported core.ts as a .js
Then I used following command to connect sql-hooks.ts and core.ts
frida-compile '/path/to/sql-hooks.ts' -o out.js
Notice output extension is .js
And that's it, everything's gonna work fine.
I'm using highcharts 4.0.4 and trying to catch any error that occurs during rendering.
I was able to catch the error#19, but when error#12 occurs the control doesn't go to the catch block. Does anyone know what could be the reason ?
Function call for the error #12 is done without second function argument error(12);. The second function argument is responsible for stopping the code execution, so the code is not stopped.
Code from Highcharts 4.0.4:
/**
* Provide error messages for debugging, with links to online explanation
*/
error = function (code, stop) {
var msg = 'Highcharts error #' + code + ': www.highcharts.com/errors/' + code;
if (stop) {
throw msg;
}
// else ...
if (win.console) {
console.log(msg);
}
};
In Highcharts 5.0.0+ it is possible to override/extend/wrap the error function with you own code.
I have updated the yeoman generator dependency from 0.18.10 to 0.20.3.
I have updated the deprecated this.dest to this.destinationRoot()
I am now having issues with the generator when it comes to getting the base path of the project, so that I can copy files from one location to another.
I have created a function to put the paths together, this then passes to another function which excludes some files from being copied over.
Here is the function I getting the error with
// Copy Bower files to another directory
var copyBowerFiles = function (component, to, exclude) {
var base = this.destinationRoot(),
publicDir = base + '/' + this.publicDir,
publicAssetsDir = publicDir + '/assets',
bowerComponentsDir = publicAssetsDir + '/bower_components',
bower,
from;
to = (base + '/' + to || publicAssetsDir);
from = bowerComponentsDir + '/' + component;
//this.dest.copy(from, to);
this.bulkDirectory(from, copyDestPathPartial.call(this, to, exclude));
};
This is being called in the end function:
end: function () {
this.installDependencies({
callback: function () {
copyBowerFiles.call('jam', this.publicDir, excludeJamFiles);
}.bind(this)
});
}
I get the error message:
var base = this.destinationRoot(),
^
TypeError: undefined is not a function
I have also tried sourceRoot()
I would like to update my generator to work with the latest version of the generator. Any help getting this working would be great.
Also do you still have to pass this as the first parameter when calling a function?
EDIT:
Here is the copyDestPathPartial function
// Copy destination path partial
var copyDestPathPartial = function (to, exclude) {
exclude = exclude || [];
return function (abs, root, sub, file) {
if (!_.contains(exclude, file) && ! _.contains(exclude, sub)) {
this.copy(abs, to + '/' + (sub || '') + '/' + file);
}
}.bind(this.destinationRoot());
};
When I use this in the copyBowerFiles function I get another error message which says when I call this function:
throw new TypeError('Arguments to path.resolve must be strings');
Is the copyDestPathPartial function not outputting a string?
This is only a JavaScript error, this inside copyBowerFiles is not what you think it is.
With the code you wrote, this is equal to jam.
So here you'd want: copyBowerFiles.call(this, 'jam', this.publicDir, excludeJamFiles);. As the first argument to call is the this value. See documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
That being said, assigning random this value is very dirty and super hard to maintain. Why not making copyBowerFiles a prototype method?
I´v got a "detail" view and a controller that initilizes data with an id.
My view:
<div ng-app="AFApp" ng-controller="AgentCtrl" ng-init="init('#Model.Id')">
My controller:
$scope.id;
$scope.agent = {};
$scope.init = function (id) {
$scope.id = id;
getAgent();
getAgentStatus();
getSystemInfo();
getActions();
};
The problem is that the method "getAgentStatus();" gets executed before "getAgent();". The "getAgentStatus" needs the $scope.agent data that "getAgent" provides. The function getAgentStatus has an attached timer, and it gets the value as the timer elepses but not in the init function. Can someone please help me out with the method execution sequence in angular controllers and how the id parameter is provided the best possible way.
See methods below:
function getAgent() {
agentDataFactory.getAgent($scope.id)
.success(function (data) {
$scope.agent = data;
})
.error(function (error) {
console.log('Unable to load data: ' + error.message);
});
};
function getAgentStatus() {
if (typeof ($scope.agent.ServiceUrl) == 'undefined' || $scope.agent.ServiceUrl == null) {
console.log('getAgentStatus: ServiceUrl is undefined ' + JSON.stringify($scope.agent));
}
agentDataFactory.getAgentStatus($scope.agent.ServiceUrl)
.success(function (data) {
$scope.agent.CurrentStatus = data.Status;
$scope.agent.CurrentInterval = data.Interval;
})
.error(function (error) {
console.log('Unable to load data: ' + error);
});
$timeout(getAgentStatus, 3000);
};
You can pass getAgentStatus() as a callback parameter to getAgent() and have it executed in the success callback (at which point agent will be defined):
function getAgent(callback) {
agentDataFactory.getAgent($scope.id)
.success(function (data) {
$scope.agent = data;
callback && callback();
})
.error(function (error) {
console.log('Unable to load data: ' + error.message);
});
};
$scope.init = function (id) {
$scope.id = id;
getAgent(getAgentStatus);
getSystemInfo();
getActions();
};
Short explanation:
Some highlights first:
agentDataFactory.getAgent($scope.id).success(...).error(...);:
Creates a promise (which will be resolved) asynchronously and registers two callbacks, one if the promise is successfully resolved and one for the case of an error.
.success(function (data) { $scope.agent = data; }):
Registers a callbackfor when the promise is successfully resolved. When (and if) that happens, $scope.agent will be set.
function getAgentStatus() { if (typeof ($scope.agent.ServiceUrl...:
Tries to access some properties of $scope.agent and thus requires the object to be defined.
So, what happens with your code:
getAgent() is gets called.
[$scope.agent is undefined]
A promise is created that when resolved will set $scope.agent.
[$scope.agent is undefined]
getAgent() returns and getAgentStatus() is called.
[$scope.agent is undefined]
getAgentStatus() tries to access $scope.agent's properties and fails.
[$scope.agent is undefined]
The promise created in step 2 is resolved and its success callback get executed.
[$scope.agent is finally defined]
My version of the code ensures that getAgentStatus() is not executed before the promise is resolved and thus $scope.agent is defined:
getAgent() is gets called.
[$scope.agent is undefined]
A promise is created that when resolved will set $scope.agent.
[$scope.agent is undefined]
getAgent() returns and other functions get called (e.g. getSystemInfo(), getActions(), etc.).
[$scope.agent is undefined]
The promise created in step 2 is resolved and its success callback get executed.
[$scope.agent is finally defined]
Only now does getAgentStatus() get called and it works as expected since...
[$scope.agent is defined]
Take a look at the $q service for more info on Angular promises.
I have been building a SPA with breeze and WebAPI (starting with John Papa's sample) for a couple of months. A couple of days ago on my Windows 8 VS2012 internal IE browser started giving me javascript errors in breeze.debug.js.
JavaScript critical error at line 4663, column 13 in //http://localhost:50033/Script/breeze.debug.js
SCRIPT1028: Expected identifier, string or number
I went back to my other development machine, Windows 7 with VS2012 and it does not give the error. The code between the two machines is identical. I use Azure TFS to sync the code.
The error occurs at the closing });
function convertFromODataEntityType(odataEntityType, schema, metadataStore, serviceName) {
var shortName = odataEntityType.name;
var namespace = translateNamespace(schema, schema.namespace);
var entityType = new EntityType({
shortName: shortName,
namespace: namespace,
}); <==== line 4663
When I remove the comma after namespace, the error goes away but errors out again in another spot on line 6911.
day: { fn: function(source) { return source.day;}, dataType: "Number" },
month: { fn: function(source) { return source.month; }, dataType: "Number" },
year: { fn: function(source) { return source.year; }, dataType: "Number"},
}; <========= line 6911
Remove the comma on the line above and it errors out on line 1271
Unhandled exception at line 1271, column 17 in http://localhost:50033/Scripts/breeze.debug.js
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'some'
at this code:
function compile(self) {
if (!self._compiledFn) {
// clear off last one if null
if (self._fns[self._fns.length - 1] == null) {
self._fns.pop();
}
if (self._fns.length === 0) {
return undefined;
}
self._compiledFn = function (that, v) {
return that._fns.some(function (fn) {
return fn(that, v);
});
};
};
return self._compiledFn;
}
Has anyone else seen this behavior?
Just a guess, but check that you are not running IE in 'compatability' mode. The 'some' method is part of the ES5 standard and is not available in 'compatability' mode.
To avoid compatability mode issues with IE browsers, we highly recommend adding the following to your HTML header:
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
I've run into it too. In fact, I often do this to myself, especially when deleting or reordering the last k/v pair during development.
While IE10 and other browsers are more forgiving, we should eliminate trailing commas on our hashmap object key/value lists ... and will do so.
FWIW, the following regex expression finds them all
,(\s*)\}\)
and the following regex substitution pattern fixes them (preserving whitespace):
$1\}\)