forked from nuprl/augur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
native.ts
773 lines (699 loc) · 32.8 KB
/
native.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
import JSMachine from "../abstractMachine/JSMachine";
import {
DynamicDescription,
StaticDescription,
} from "../types";
import Analysis from "../analysis/analysis";
// TODO: document pre and post implementations
/**
* A mechanism for a native model to record runtime information. This
* information can then be used when the abstract machine executes a
* NativeModelImplementation. NativeModelRecorders are useful when a
* NativeModelImplementation needs a *concrete* value from the program,
* as opposed to a taint value.
*
* For example, let's assume you want to write a native model of
* Object.defineProperty. You would want to translate a call like:
*
* Object.defineProperty(obj, "prop", {value: true})
*
* to set the property "prop" on "obj" to the value "true". When your NativeModel
*
* Since native models are executed inside the AbstractMachine, this means
* the program has already finished running and you only have access to
* abstract values.
*
* Native models are implemented inside the
* AbstractMachine, so the model will observe a call to Object.defineProperty
*/
type NativeModelRecorder<R> =
(analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
isMethod: boolean,
description: StaticDescription) => R;
type NativeModelImplementationPre<R, S> =
<V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
extraRecords: R,
isMethod: boolean,
description: StaticDescription) => S;
type NativeModelImplementationPost<S> =
<V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
returnValueName: DynamicDescription | undefined,
saved: S,
description: StaticDescription) => void;
type NativeModel<R, S> = {
// record step @ instrumentation time
recorder?: NativeModelRecorder<R>;
// actual model @ abstract machine time
implementationPre: NativeModelImplementationPre<R, S>;
// TODO: document
implementationPost?: NativeModelImplementationPost<S>;
};
type NativeModelMap<S> = {
[K in keyof S]: S[K];
}
let asNativeModel = <R, S>(x: NativeModel<R, S>) => x;
let asNativeModelMap = <S>(x: NativeModelMap<S>): NativeModelMap<S> => x;
class NativeModelError extends Error {
constructor(message: string) {
super(message);
this.name = "NativeModelError";
}
}
// prepares the stack for an upcoming functionEnter by pushing the arguments
// in reverse order.
let prepareFunctionCall = <V, F>(machine: JSMachine<V, F>,
functionTaintValue: V,
argTaintValues: V[],
builtinDescription: StaticDescription): void => {
// prepare the stack for an upcoming functionEnter
machine.push([functionTaintValue, builtinDescription]);
// push the arguments in reverse order
for (let i = argTaintValues.length - 1; i >= 0; i--) {
machine.push([argTaintValues[i], builtinDescription]);
}
// inform the stack machine how many args are coming in
machine.argsLeftToProcess = argTaintValues.length;
};
// Pops the values associated with this builtin call from the stack.
// Returns them in the form [builtin taint value, args' taint values []]
let popArgs = <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
actualArgs: number,
isMethod: boolean,
description: StaticDescription): [V, V, V[]] => {
let args: V[] = [];
// if this is a method call, the taint value for the base object will
// also be on the stack. pop this if necessary
let receiverTaint;
if (isMethod) {
// receiverTaint = machine.taintStack.pop();
receiverTaint = machine.taintTree.get(machine.ROOTID).pop();
} else {
// if this isn't a method call, the base object is untainted
receiverTaint = machine.getUntaintedValue();
}
// pop taint value of args
for (let i = 0; i < actualArgs; i++) {
// args[actualArgs - i - 1] = (machine.taintStack.pop());
args[actualArgs - i - 1] = (machine.taintTree.get(machine.ROOTID).pop());
}
// pop value of builtin
// let builtinTaint = machine.taintStack.pop();
let builtinTaint = machine.taintTree.get(machine.ROOTID).pop();
return [builtinTaint, receiverTaint, args];
};
let popArgsAndReportFlowsIntoBuiltin =
<V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
isMethod: boolean,
description: StaticDescription): [V, V, V[]] => {
let [builtinTaint, receiverTaint, argsTaint] =
popArgs(machine, name, actualArgs, isMethod, description);
argsTaint.forEach((v: V) =>
machine.reportPossibleFlow(description, v));
return [builtinTaint, receiverTaint, argsTaint];
};
let returnTaints = <V, F>(machine: JSMachine<V, F>,
taint: V) => {
// machine.taintStack.push(taint);
machine.taintTree.get(machine.ROOTID).push(taint);
};
let defaultImplementationPre: NativeModelImplementationPre<void, void> =
(machine, name, receiverName, actualArgs, extraRecords, isMethod, description): void => {
let [_, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// combine args taint with `this` object taint
let returnTaint = machine.join(receiverTaint,
argsTaint.reduce(machine.join, machine.getUntaintedValue()));
// return that taint
returnTaints(machine, returnTaint);
};
let defaultModel: NativeModel<void, void> = {
// no recorder required, see top of file
implementationPre: defaultImplementationPre
// no post implementation required, see top of file
};
let models = asNativeModelMap({
"augur_testFunSkip": asNativeModel({
recorder: function(analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription): boolean {
return false;
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
isArray: boolean,
isMethod: boolean,
description: StaticDescription): void {
},
}),
// "findOne": asNativeModel({
// recorder: function(analysis: Analysis,
// name: DynamicDescription,
// receiverName: DynamicDescription,
// receiver: any,
// args: any[],
// description: StaticDescription): boolean {
// console.log('[!!!!] in recorder...');
// return false;
// },
// implementationPre: function <V, F>(machine: JSMachine<V, F>,
// name: DynamicDescription,
// receiverName: DynamicDescription,
// actualArgs: number,
// isArray: boolean,
// isMethod: boolean,
// description: StaticDescription): number {
// console.log('[!!!!] in implementationPre...');
// return 2;
// },
// implementationPost: function<V, F>(machine: JSMachine<V, F>,
// name: DynamicDescription,
// returnValueName: DynamicDescription,
// saved: number,
// description: StaticDescription): void {
// console.log('[!!!!] in implementationPost...');
// console.log('[!!!!] returnValueName:', returnValueName);
// // let [numSplits, stringTaint] = saved;
// // let returnValueShadowObject = machine.getShadowObject(returnValueName);
// // // propagate the taint value of the string (`saved`) to each
// // // string in the split array
// // for (let i = 0; i < numSplits; i++) {
// // returnValueShadowObject[i] = stringTaint;
// // }
// }
// }),
"toString": asNativeModel({
recorder: function(analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription): boolean {
// We need to know if we're calling toString on an Array vs.
// something else, because Array.prototype.toString is special.
return Array.isArray(receiver);
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
isArray: boolean,
isMethod: boolean,
description: StaticDescription): void {
// before popping the arguments or doing anything else,
// immediately dispatch on whether or not we're calling toString
// on an array
if (!isArray) {
// if this isn't an array, the default native model will work
defaultImplementationPre(machine,
name,
receiverName,
actualArgs,
null,
isMethod,
description);
} else {
// if this is an array, we have one extra step: join the
// taint values of each element of the array
let [builtinTaint, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// eventually we're going to return this taint value.
// we want it to reflect the combination of the array's
// taint, AND the taint of all its elements.
let returnTaint = receiverTaint;
// loop through elements of the shadow array and read their
// taint values
let shadowArray = machine.getShadowObject(receiverName);
for (let prop in shadowArray) {
// can't call hasOwnProperty directly because shadow
// objects don't have the Object prototype
if (Object.hasOwnProperty.call(shadowArray, prop)) {
returnTaint =
machine.join(returnTaint, shadowArray[prop]);
}
}
// return the combined taint value
returnTaints(machine, returnTaint);
}
},
}),
"split": asNativeModel({
recorder: function(analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription): number {
// record length of split string array. we need to do this
// because the abstract machine will have no idea how many
// splits occurred at runtime, and therefore won't know which
// properties in the split array to propagate the taint to.
return String.prototype.split.apply(receiver).length;
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
numSplits: number,
isMethod: boolean,
description: StaticDescription): [number, V] {
let [builtinTaint, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// save the taint value of the string we're splitting
return [numSplits, receiverTaint];
},
implementationPost: function<V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
returnValueName: DynamicDescription,
saved: [number, V],
description: StaticDescription): void {
let [numSplits, stringTaint] = saved;
let returnValueShadowObject = machine.getShadowObject(returnValueName);
// propagate the taint value of the string (`saved`) to each
// string in the split array
for (let i = 0; i < numSplits; i++) {
returnValueShadowObject[i] = stringTaint;
}
}
}),
"push": asNativeModel({
recorder: (analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription) => {
// return receiver's length if it exists, otherwise 0
return receiver.length || 0;
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
previousLength: number,
isMethod: boolean,
description: StaticDescription): void {
let [builtinTaint, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// find the shadow object corresponding to this array
let shadowArray = machine.getShadowObject(receiverName);
// copy taint values of args into the shadow array. we start
// copying into the array at the end, as specified by its length
// property BEFORE we executed this function.
for (let i = 0; i < actualArgs; i++) {
shadowArray[previousLength + i] = argsTaint[i];
}
// Array.prototype.push returns the new length of the array. we
// haven't tainted the length field, so we'll just return its
// old taint value. if this object didn't have a length field
// yet, we'll return the untainted value.
returnTaints(machine, shadowArray.length || machine.getUntaintedValue());
}
}),
"join": asNativeModel({
recorder: (analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription) => {
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
recorded: null,
isMethod: boolean,
description: StaticDescription): void {
let [builtinTaint, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// find the shadow object corresponding to this array
let shadowArray = machine.getShadowObject(receiverName);
// join all the taints in this array. this computes the *result*
// of this builtin, a.k.a. whether or not the result of this
// function should be tainted.
let arrayValuesTaint = Object.values(shadowArray).reduce(machine.join, machine.getUntaintedValue());
// get the taint of the separator string used to join all the
// values of this array together. if no separator was specified,
// use the untainted value.
let separatorTaint;
if (argsTaint.length > 0) {
// user specified a separator
separatorTaint = argsTaint[0];
} else {
// user didn't specify a separator, use the untainted value
separatorTaint = machine.getUntaintedValue();
}
// compute the taint value that should be output by this
// function, consisting of joining the taint values of the array
// values and the separator string.
let returnTaint = machine.join(arrayValuesTaint, separatorTaint);
// return this taint value
returnTaints(machine, returnTaint);
}
}),
/**
* TODO: actually inspect the "descriptor" object and only perform
* the change if it's possible/allowed by the semantics defined in
* the API
*/
"defineProperty": asNativeModel({
recorder: (analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription) => {
let [obj, prop, descriptor] = args;
return {obj: analysis.shadowMemory.getShadowID(obj),
prop: prop,
descriptor: analysis.shadowMemory.getShadowID(descriptor)
};
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
recorded: {obj: DynamicDescription, prop: string, descriptor: DynamicDescription},
isMethod: boolean,
description: StaticDescription): void {
let [builtinTaint, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// deconstruct recorded information
let {obj, prop, descriptor} = recorded;
// emulate a regular writeProperty event in the abstract machine
let abstractPropertyValue = machine.getShadowObject(descriptor).value;
machine.push([abstractPropertyValue, description]);
machine.writeProperty([obj, prop, description]);
returnTaints(machine, receiverTaint);
}
}),
"call": asNativeModel({
recorder: (analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription) => {
/*
// Record two things:
// 1. the shadow id of the function the user wants to call
// 2. the number of arguments that function is expecting
return [name, args[1].length];
*/
return [receiver.length, description];
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
extraRecords: [number, StaticDescription],
isMethod: boolean,
description: StaticDescription): void {
// let expectedArgs
// ([name, expectedArgs, actualArgs, description])
let [builtinTaint, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// create an entry on the callstack for this builtin
machine.callstackPush(description);
// TODO: currently we're passing in the description of the builtin.
// this is not really correct. but it appears that
// functionEnter isn't even using this value. so really
// both of these issues need to be fixed.
prepareFunctionCall(machine, builtinTaint, argsTaint.slice(1), description);
machine.installAdvice(machine.functionExitAdvice,
() => {
// machine.callstackPop();
returnTaints(machine, machine.returnValue);
machine.callstackPop();
machine.callstackPop();
});
}
}),
"max": asNativeModel({recorder:
(analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription) => {
// our goal in this recorder is to determine *which*
// argument is the maximum. we can use this information at
// abstract machine time to correctly determine which taint
// value should be returned from this builtin.
// we will return a number n (>0) to represent that the
// argument at args[n] was the maximum.
// we will return -1 to represent that Math.max returned
// NaN, and thus, none of the arguments are related to the
// return value.
// TODO: we shouldn't make a duplicate call to Math.max here.
// first, get the actual maximum of the arguments
let max = Math.max(...args);
// there are two cases for the return value of Math.max:
// 1. NaN, when one or more of the arguments could not be
// converted to a number.
// (to deal with this case, we check if the return value of
// Math.max is NaN. if it is, we return the untainted value.)
if (isNaN(max)) {
// record that none of the arguments are related to this
// function's output
return -1;
}
// 2. a number >0, representing the maximum of the given
// arguments.
// (to deal with this case, we figure out *which* argument ended
// up being the result of the function.)
for (let i = 0; i < args.length; i++) {
if (args[i] == max) {
return i;
}
}
// if we execute this, this means that Math.max returned a value
// that wasn't any of our arguments or NaN. this should
// never happen.
throw new NativeModelError("Math.max didn't return a value" +
" equal to any of its arguments");
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
extraRecords: number,
isMethod: boolean,
description: StaticDescription): void {
let [builtinTaint, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
// the return value of this native function should be equal to
// the taint value of whichever argument was the maximum
returnTaints(machine, argsTaint[extraRecords]);
}
}),
/*
* Promises
*/
"then": asNativeModel({
recorder: (analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
description: StaticDescription) => {
// This refers to .then called on the returns of async functions.
// Get the asyncID of the promise, and return it.
return analysis.getAsyncPromiseId(receiver);
},
implementationPre: function <V, F>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiverName: DynamicDescription,
actualArgs: number,
idOfReactedUponPromise: DynamicDescription,
isMethod: boolean,
description: StaticDescription): void {
let [_, receiverTaint, argsTaint] =
popArgsAndReportFlowsIntoBuiltin(machine,
name,
receiverName,
actualArgs,
isMethod,
description);
let promise = machine.getPromise(idOfReactedUponPromise);
let promiseTaint = machine.getUntaintedValue();
if (promise != undefined)
promiseTaint = machine.getPromise(idOfReactedUponPromise).resolve;
// install advice for initVar
// the next initVar will be for the argument to the callback passed to .then,
// so we should taint it according to the promise's resolve value taintedness
machine.installAdvice(machine.initVarAdvice,
(s : any, description : StaticDescription) => {
let v = machine.join(promiseTaint, machine.produceMark(description));
if (machine.argsLeftToProcess > 0) {
machine.taintTree.get(machine.ROOTID).pop();
machine.argsLeftToProcess--;
}
// actually set the taint value of the variable
machine.varTaintMap.set(s, v);
});
}
}),
// "catch": asNativeModel({
// recorder: (analysis: Analysis,
// name: DynamicDescription,
// receiverName: DynamicDescription,
// receiver: any,
// args: any[],
// description: StaticDescription) => {
// // This refers to .then called on the returns of async functions.
// // Get the asyncID of the promise, and return it.
// return analysis.getAsyncPromiseId(receiver);
// },
// implementationPre: function <V, F>(machine: JSMachine<V, F>,
// name: DynamicDescription,
// receiverName: DynamicDescription,
// actualArgs: number,
// idOfReactedUponPromise: DynamicDescription,
// isMethod: boolean,
// description: StaticDescription): void {
// let [_, receiverTaint, argsTaint] =
// popArgsAndReportFlowsIntoBuiltin(machine,
// name,
// receiverName,
// actualArgs,
// isMethod,
// description);
// let promise = machine.getPromise(idOfReactedUponPromise);
// let promiseTaint = machine.getUntaintedValue();
// if (promise != undefined)
// promiseTaint = machine.getPromise(idOfReactedUponPromise).reject;
// // install advice for initVar
// // the next initVar will be for the argument to the callback passed to .then,
// // so we should taint it according to the promise's resolve value taintedness
// machine.installAdvice(machine.initVarAdvice,
// (s : any, description : StaticDescription) => {
// let v = machine.join(promiseTaint, machine.produceMark(description));
// if (machine.argsLeftToProcess > 0) {
// machine.taintTree.get(machine.ROOTID).pop();
// machine.argsLeftToProcess--;
// }
// // actually set the taint value of the variable
// machine.varTaintMap.set(s, v);
// });
// }
// }),
});
// TODO: don't use string here; create a type for builtin names
export function getNativeModel<V, F>(name: string): NativeModel<any, any> {
if (models.hasOwnProperty(name)) {
// @ts-ignore
return models[name] as NativeModel<any>;
} else {
return defaultModel;
}
}
export function useNativeRecorder<R>(analysis: Analysis,
name: DynamicDescription,
receiverName: DynamicDescription,
receiver: any,
args: any[],
isMethod: boolean,
description: StaticDescription): R {
let nativeModel = getNativeModel(description.name);
if (nativeModel.recorder) {
return nativeModel.recorder(analysis, name, receiverName, receiver, args, isMethod, description);
} else {
// if there isn't a recorder, return null. this is ok because a lack
// of a recorder only makes sense when we aren't expecting any
// recorded information.
return null;
}
}
export function useNativeImplementationPre<V, F, R, S>(machine: JSMachine<V, F>,
name: DynamicDescription,
receiver: DynamicDescription,
actualArgs: number,
extraRecords: R,
isMethod: boolean,
description: StaticDescription): S {
return getNativeModel(description.name)
.implementationPre(machine,
name,
receiver,
actualArgs,
extraRecords,
isMethod,
description);
}
export function useNativeImplementationPost<V, F, S>(machine: JSMachine<V, F>,
name: DynamicDescription,
returnValueName: DynamicDescription,
saved: S,
description: StaticDescription): void {
let model = getNativeModel(description.name);
if (model.implementationPost) {
model.implementationPost(machine,
name,
returnValueName,
saved,
description);
}
// if there isn't an implementationPost, don't do anything. this is ok
// because we don't need to return anything.
}
export function getModelledFunctionNames() : string[] {
return Object.keys(models);
}