SlideShare a Scribd company logo
1 of 36
Download to read offline
TreatJS
Higher-Order Contracts for JavaScript
Matthias Keil, Peter Thiemann
Institute for Computer Science
University of Freiburg
Freiburg, Germany
June 30, 2014, Dagstuhl Seminar on Scripting Languages and Frameworks: Analysis and Verification
Introduction
TreatJS
Language embedded contract system for JavaScript
Enforced by run-time monitoring
Inspiration similar to Contracts.js [Disney]
Contract
Specifies the interface of a software component
Obligations - Benefits
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 2 / 14
Features
Standard abstractions for higher-order-contracts (base,
function, and object contracts) [Findler,Felleisen’02]
Support for boolean combinations (and, or, not contracts) as
building blocks for intersection, union, and implication
Contract constructors generalize dependent contracts
Non-interference for contract execution
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 3 / 14
Base Contract [Findler,Felleisen’02]
Base Contracts are built from predicates
Specified by a plain JavaScript function
1 function typeOfNumber (arg) {
2 return (typeof arg) === ’number’;
3 };
4 var IsNumber = BaseContract(typeOfNumber, ’IsNumber’);
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 4 / 14
Base Contract [Findler,Felleisen’02]
Base Contracts are built from predicates
Specified by a plain JavaScript function
1 function typeOfNumber (arg) {
2 return (typeof arg) === ’number’;
3 };
4 var IsNumber = BaseContract(typeOfNumber, ’IsNumber’);
5 assert(1, IsNumber); 
Value v fulfills BaseContract (B) iff: B(v) = true
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 4 / 14
Base Contract [Findler,Felleisen’02]
Base Contracts are predicates
Specified by a plain JavaScript function
1 function typeOfNumber (arg) {
2 return (typeof arg) === ’number’;
3 };
4 var IsNumber = BaseContract(typeOfNumber, ’IsNumber’);
5 assert(’a’, IsNumber);  Blame the Value
Value v gets blamed for contract B iff: B(v) = false
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 4 / 14
Function Contract [Findler,Felleisen’02]
1 // Number × Number → Number
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 5 / 14
Function Contract [Findler,Felleisen’02]
1 // Number × Number → Number
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 var addChecked = assert(addUnchecked,
6 FunctionContract([IsNumber, IsNumber], IsNumber));
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 5 / 14
Function Contract [Findler,Felleisen’02]
1 // Number × Number → Number
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(1, 1); 
x is an acceptable argument for contract C → C iff:
(x fulfills C)
Function f fulfills contract C → C at argument x iff:
(x fulfills C) → (f (x) fulfills C )
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 6 / 14
Function Contract [Findler,Felleisen’02]
1 // Number × Number → Number
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(’a’, ’a’);  Blame the Argument
Argument x gets blamed for C → C iff:
¬ (x is an acceptable argument for contract C → C ) iff:
¬ (x fulfills C)
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 6 / 14
Function Contract [Findler,Felleisen’02]
1 // Number × Number → Number
2 function addUnchecked(x, y) {
3 return (x0  y0) ? (x + y) : ’Error’;
4 }
5 addChecked(0, 1);  Blame the Fucntion
Function f gets blamed for C → C at argument x iff:
¬ (Function f fulfills contract C → C at argument x) iff:
(x fulfills C) ∧ ¬ (f (x) fulfills C )
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 6 / 14
TreatJS
New!
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 7 / 14
Intersection Contract
1 // Number × Number → Number
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(’a’, ’a’); 
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 var addChecked = assert(addUnchecked, Intersection(
6 FunctionContract([IsNumber, IsNumber], IsNumber)
7 FunctionContract([IsString, IsString], IsString));
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(’a’, ’a’); 
x is an acceptable argument for contract C ∩ C iff:
(x is acceptable arg. for C) ∨ (x is acceptable arg. for C )
Function f fulfills contract C ∩ C at argument x iff:
(f fulfills C at x) ∧ (f fulfills C at x)
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(true, true);  Blame the Argument
Argument x gets blamed for C ∩ C iff:
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(true, true);  Blame the Argument
Argument x gets blamed for C ∩ C iff:
¬ (x is an acceptable argument for contract C ∩ C )
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(true, true);  Blame the Argument
Argument x gets blamed for C ∩ C iff:
¬ (x is an acceptable argument for contract C ∩ C )
¬ ((x is acc. arg. for C) ∨ (x is acc. arg. for C ))
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(true, true);  Blame the Argument
Argument x gets blamed for C ∩ C iff:
¬ (x is an acceptable argument for contract C ∩ C )
¬ ((x is acc. arg. for C) ∨ (x is acc. arg. for C ))
¬(x is acc. arg. for C) ∧ ¬(x is acc. arg. for C )
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 addChecked(true, true);  Blame the Argument
Argument x gets blamed for C ∩ C iff:
¬ (x is an acceptable argument for contract C ∩ C )
¬ ((x is acc. arg. for C) ∨ (x is acc. arg. for C ))
¬(x is acc. arg. for C) ∧ ¬(x is acc. arg. for C )
(x gets blamed for C) ∧ (x gets blamed for C)
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Intersection Contract
1 // (Number × Number → Number) ∩ (String × String → String)
2 function addUnchecked(x, y) {
3 return (x0  y0) ? (x + y) : ’Error’;
4 }
5 addChecked(0, 1);  Blame the Function
Function f gets blamed for C ∩ C at argument x iff:
(f gets blamed for C at x) ∨ (f gets blamed for C at x)
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
Union Contract
1 // (Number × Number → Number) ∪ (Number × Number → String)
2 function addUnchecked(x, y) {
3 return (x0  y0) ? (x + y) : ’Error’;
4 }
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
Union Contract
1 // (Number × Number → Number) ∪ (Number × Number → String)
2 function addUnchecked(x, y) {
3 return (x0  y0) ? (x + y) : ’Error’;
4 }
5 var addChecked = assert(addUnchecked, Union(
6 FunctionContract([IsNumber, IsNumber], IsNumber)
7 FunctionContract([IsNumber, IsNumber], IsString));
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
Union Contract
1 // (Number × Number → Number) ∪ (Number × Number → String)
2 function addUnchecked(x, y) {
3 return (x0  y0) ? (x + y) : ’Error’;
4 }
5 addChecked(0, 1); 
Argument x is an acceptable argument for contract C ∪ C iff:
(x is acceptable arg. for C) ∧ (x is acceptable arg. for C )
Function f fulfills contract C ∪ C at argument x iff:
(f fulfills C at x) ∨ (f fulfills C at x)
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
Union Contract
1 // (Number × Number → Number) ∪ (Number × Number → String)
2 function addUnchecked(x, y) {
3 return (x0  y0) ? (x + y) : ’Error’;
4 }
5 addChecked(’a’, ’a’);  Blame the Argument
Argument x gets blamed for C ∪ C iff:
(x gets blamed for C) ∨ (x gets blamed for C)
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
Union Contract
1 // (Number × Number → Number) ∪ (Number × Number → String)
2 function addUnchecked(x, y) {
3 return (x0  y0) ? (x + y) : undefined;
4 }
5 addChecked(0, 1);  Blame the Fucntion
Function f gets blamed for C ∪ C at argument x iff:
(f gets blamed for C at x) ∧ (f gets blamed for C ) at x
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
Non-Interference
No syntactic restrictions on predicates
Problem: contract may interfere with program execution
Solution: Predicate evaluation takes place in a sandbox
1 function typeOfNumber (arg) {
2 type = (typeof arg);  Access forbidden
3 return type === ’number’;
4 };
5 var FaultyIsNumber =
6 BaseContract(typeOfNumber, ’FaultyIsNumber’);
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 10 / 14
Non-Interference
No syntactic restrictions on predicates
Problem: contract may interfere with program execution
Solution: Predicate evaluation takes place in a sandbox
1 var IsArray = BaseContract(function (arg) {
2 return (arg instanceof Array);  Access forbidden
3 });
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 10 / 14
Non-Interference
No syntactic restrictions on predicates
Problem: contract may interfere with program execution
Solution: Predicate evaluation takes place in a sandbox
1 var IsArray = BaseContract(function (arg) {
2 return (arg instanceof InsideArray); 
3 });
4 var IsArrayComplete = With({InsideArray:Array}, IsArray);
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 11 / 14
Contract Constructor
1 // T × T → T
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 12 / 14
Contract Constructor
1 // T × T → T
2 function addUnchecked(x, y) {
3 return (x + y);
4 }
5 var addChecked = assert(addUnchecked,
6 FunctionContract([CheckType, CheckType], CheckType)):
7 var CheckType = BaseContract(function (arg) {
8 // to be completed
9 });
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 12 / 14
Contract Constructor
Constructor gets evaluated in a sandbox, like a predicate
Returns a contract
No further sandboxing for predicates
1 var ctor = Constructor(function() {
2 var type = undefined;
3 var CheckType = BaseContract(function (arg) {
4 type = type || (typeof arg);
5 return type === (typeof arg);
6 });
7 return FunctionContract([CheckType, CheckType], CheckType):
8 }, ’SameType’);
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 12 / 14
Dependent Contract
1 var SameTypeCtor = Constructor(function(arg) {
2 var type = (typeof arg);
3 return BaseContract(function (arg) {
4 return (typeof arg) === type);
5 });
6 });
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 13 / 14
Dependent Contract
1 var SameTypeCtor = Constructor(function(arg) {
2 var type = (typeof arg);
3 return BaseContract(function (arg) {
4 return (typeof arg) === type);
5 });
6 });
7 var addChecked = assert(addUnchecked,
8 DependentContract(SameTypeCtor));
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 13 / 14
Conclusion
TreatJS: Language embedded, higher-order contract system
for JavaScript
Support for intersection and union contracts
Systematic blame calculation
Composable sandboxing that guarantees non-interference
Contract constructors with local scope
Matthias Keil, Peter Thiemann TreatJS June 30, 2014 14 / 14

More Related Content

What's hot

Recommendation System --Theory and Practice
Recommendation System --Theory and PracticeRecommendation System --Theory and Practice
Recommendation System --Theory and PracticeKimikazu Kato
 
prior selection for mixture estimation
prior selection for mixture estimationprior selection for mixture estimation
prior selection for mixture estimationChristian Robert
 
Tutorial on Belief Propagation in Bayesian Networks
Tutorial on Belief Propagation in Bayesian NetworksTutorial on Belief Propagation in Bayesian Networks
Tutorial on Belief Propagation in Bayesian NetworksAnmol Dwivedi
 
Bidimensionality
BidimensionalityBidimensionality
BidimensionalityASPAK2014
 
Neural Processes Family
Neural Processes FamilyNeural Processes Family
Neural Processes FamilyKota Matsui
 
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...dhruvgairola
 
Pattern Recognition
Pattern RecognitionPattern Recognition
Pattern RecognitionEunho Lee
 
Master thesis job shop generic time lag max plus
Master thesis job shop generic time lag max plusMaster thesis job shop generic time lag max plus
Master thesis job shop generic time lag max plusSiddhartha Verma
 
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...Dmitrii Ignatov
 
Digital system design
Digital system designDigital system design
Digital system designKuntala Das
 

What's hot (19)

Recommendation System --Theory and Practice
Recommendation System --Theory and PracticeRecommendation System --Theory and Practice
Recommendation System --Theory and Practice
 
Talk iccf 19_ben_hammouda
Talk iccf 19_ben_hammoudaTalk iccf 19_ben_hammouda
Talk iccf 19_ben_hammouda
 
Intro to ABC
Intro to ABCIntro to ABC
Intro to ABC
 
prior selection for mixture estimation
prior selection for mixture estimationprior selection for mixture estimation
prior selection for mixture estimation
 
Tutorial on Belief Propagation in Bayesian Networks
Tutorial on Belief Propagation in Bayesian NetworksTutorial on Belief Propagation in Bayesian Networks
Tutorial on Belief Propagation in Bayesian Networks
 
Bidimensionality
BidimensionalityBidimensionality
Bidimensionality
 
Ceske budevice
Ceske budeviceCeske budevice
Ceske budevice
 
Data Analysis Assignment Help
Data Analysis Assignment Help Data Analysis Assignment Help
Data Analysis Assignment Help
 
Neural Processes Family
Neural Processes FamilyNeural Processes Family
Neural Processes Family
 
Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
 
Side 2019 #12
Side 2019 #12Side 2019 #12
Side 2019 #12
 
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Pattern Recognition
Pattern RecognitionPattern Recognition
Pattern Recognition
 
report
reportreport
report
 
Master thesis job shop generic time lag max plus
Master thesis job shop generic time lag max plusMaster thesis job shop generic time lag max plus
Master thesis job shop generic time lag max plus
 
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
 
Digital system design
Digital system designDigital system design
Digital system design
 
statistics assignment help
statistics assignment helpstatistics assignment help
statistics assignment help
 

Viewers also liked

Les joies de la prière nocturne
Les joies de la prière nocturneLes joies de la prière nocturne
Les joies de la prière nocturneSaïd Bouzidi
 
Inspirational powerpoint
Inspirational powerpointInspirational powerpoint
Inspirational powerpointjar91
 
Consumer making buying decison
Consumer making buying decisonConsumer making buying decison
Consumer making buying decisonSameer Agarwal
 
Evaluation for Ku-ring-gai Council Appendices Removed
Evaluation for Ku-ring-gai Council Appendices RemovedEvaluation for Ku-ring-gai Council Appendices Removed
Evaluation for Ku-ring-gai Council Appendices RemovedHailey Ward
 
Top 8 infant toddler teacher resume samples
Top 8 infant toddler teacher resume samplesTop 8 infant toddler teacher resume samples
Top 8 infant toddler teacher resume sampleskingsmonkey15
 
Germer isoladores valores e benificios
Germer isoladores valores e benificiosGermer isoladores valores e benificios
Germer isoladores valores e benificiosJonas Meynaczyk
 
On Contracts, Sandboxes, and Proxies for JavaScript
On Contracts, Sandboxes, and Proxies for JavaScriptOn Contracts, Sandboxes, and Proxies for JavaScript
On Contracts, Sandboxes, and Proxies for JavaScriptMatthias Keil
 
Top 8 literacy teacher resume samples
Top 8 literacy teacher resume samplesTop 8 literacy teacher resume samples
Top 8 literacy teacher resume sampleskingsmonkey15
 
Ярмарка вакансий
Ярмарка вакансийЯрмарка вакансий
Ярмарка вакансийvikaevp
 
Top 8 accounting support resume samples
Top 8 accounting support resume samplesTop 8 accounting support resume samples
Top 8 accounting support resume sampleskingsmonkey15
 
Проектирование классификаторов технико экономической информации
Проектирование классификаторов технико экономической информацииПроектирование классификаторов технико экономической информации
Проектирование классификаторов технико экономической информацииadam93
 
Top 8 computer technical support resume samples
Top 8 computer technical support resume samplesTop 8 computer technical support resume samples
Top 8 computer technical support resume sampleskingsmonkey15
 
Типовое проектирование эис
Типовое проектирование эисТиповое проектирование эис
Типовое проектирование эисadam93
 
ESENCIALES PARA LA VIDA
ESENCIALES PARA LA VIDAESENCIALES PARA LA VIDA
ESENCIALES PARA LA VIDAsandra Rincon
 
Международное разделение труда и его основные принципы
Международное разделение труда и его основные принципыМеждународное разделение труда и его основные принципы
Международное разделение труда и его основные принципыadam93
 

Viewers also liked (20)

Les joies de la prière nocturne
Les joies de la prière nocturneLes joies de la prière nocturne
Les joies de la prière nocturne
 
Inspirational powerpoint
Inspirational powerpointInspirational powerpoint
Inspirational powerpoint
 
dipankar cdc-new
dipankar cdc-newdipankar cdc-new
dipankar cdc-new
 
Consumer making buying decison
Consumer making buying decisonConsumer making buying decison
Consumer making buying decison
 
Evaluation for Ku-ring-gai Council Appendices Removed
Evaluation for Ku-ring-gai Council Appendices RemovedEvaluation for Ku-ring-gai Council Appendices Removed
Evaluation for Ku-ring-gai Council Appendices Removed
 
Charles Dickens
Charles DickensCharles Dickens
Charles Dickens
 
Top 8 infant toddler teacher resume samples
Top 8 infant toddler teacher resume samplesTop 8 infant toddler teacher resume samples
Top 8 infant toddler teacher resume samples
 
Transcript-ComSc
Transcript-ComScTranscript-ComSc
Transcript-ComSc
 
Germer isoladores valores e benificios
Germer isoladores valores e benificiosGermer isoladores valores e benificios
Germer isoladores valores e benificios
 
On Contracts, Sandboxes, and Proxies for JavaScript
On Contracts, Sandboxes, and Proxies for JavaScriptOn Contracts, Sandboxes, and Proxies for JavaScript
On Contracts, Sandboxes, and Proxies for JavaScript
 
El poder-y-sus-conflictos
El poder-y-sus-conflictosEl poder-y-sus-conflictos
El poder-y-sus-conflictos
 
Top 8 literacy teacher resume samples
Top 8 literacy teacher resume samplesTop 8 literacy teacher resume samples
Top 8 literacy teacher resume samples
 
Ярмарка вакансий
Ярмарка вакансийЯрмарка вакансий
Ярмарка вакансий
 
Top 8 accounting support resume samples
Top 8 accounting support resume samplesTop 8 accounting support resume samples
Top 8 accounting support resume samples
 
El Poder y sus Conflictos
El Poder y sus ConflictosEl Poder y sus Conflictos
El Poder y sus Conflictos
 
Проектирование классификаторов технико экономической информации
Проектирование классификаторов технико экономической информацииПроектирование классификаторов технико экономической информации
Проектирование классификаторов технико экономической информации
 
Top 8 computer technical support resume samples
Top 8 computer technical support resume samplesTop 8 computer technical support resume samples
Top 8 computer technical support resume samples
 
Типовое проектирование эис
Типовое проектирование эисТиповое проектирование эис
Типовое проектирование эис
 
ESENCIALES PARA LA VIDA
ESENCIALES PARA LA VIDAESENCIALES PARA LA VIDA
ESENCIALES PARA LA VIDA
 
Международное разделение труда и его основные принципы
Международное разделение труда и его основные принципыМеждународное разделение труда и его основные принципы
Международное разделение труда и его основные принципы
 

Similar to TreatJS: Higher-Order Contracts for JavaScript

TreatJS: Higher-Order Contracts for JavaScripts
TreatJS: Higher-Order Contracts for JavaScriptsTreatJS: Higher-Order Contracts for JavaScripts
TreatJS: Higher-Order Contracts for JavaScriptsMatthias Keil
 
Blame Assignment for Higher-Order Contracts with Intersection and Union
Blame Assignment for Higher-Order Contracts with Intersection and UnionBlame Assignment for Higher-Order Contracts with Intersection and Union
Blame Assignment for Higher-Order Contracts with Intersection and UnionMatthias Keil
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And ReferencesHadziq Fabroyir
 
Actors for Behavioural Simulation
Actors for Behavioural SimulationActors for Behavioural Simulation
Actors for Behavioural SimulationClarkTony
 
Connection between inverse problems and uncertainty quantification problems
Connection between inverse problems and uncertainty quantification problemsConnection between inverse problems and uncertainty quantification problems
Connection between inverse problems and uncertainty quantification problemsAlexander Litvinenko
 
Reject Inference in Credit Scoring
Reject Inference in Credit ScoringReject Inference in Credit Scoring
Reject Inference in Credit ScoringAdrien Ehrhardt
 
SANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkNikolaos Tsantalis
 
Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals sakhi pathak
 

Similar to TreatJS: Higher-Order Contracts for JavaScript (10)

TreatJS: Higher-Order Contracts for JavaScripts
TreatJS: Higher-Order Contracts for JavaScriptsTreatJS: Higher-Order Contracts for JavaScripts
TreatJS: Higher-Order Contracts for JavaScripts
 
Blame Assignment for Higher-Order Contracts with Intersection and Union
Blame Assignment for Higher-Order Contracts with Intersection and UnionBlame Assignment for Higher-Order Contracts with Intersection and Union
Blame Assignment for Higher-Order Contracts with Intersection and Union
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References
 
Actors for Behavioural Simulation
Actors for Behavioural SimulationActors for Behavioural Simulation
Actors for Behavioural Simulation
 
Decision tree learning
Decision tree learningDecision tree learning
Decision tree learning
 
Connection between inverse problems and uncertainty quantification problems
Connection between inverse problems and uncertainty quantification problemsConnection between inverse problems and uncertainty quantification problems
Connection between inverse problems and uncertainty quantification problems
 
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
 
Reject Inference in Credit Scoring
Reject Inference in Credit ScoringReject Inference in Credit Scoring
Reject Inference in Credit Scoring
 
SANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper Talk
 
Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals
 

More from Matthias Keil

Transparent Object Proxies for JavaScript
Transparent Object Proxies for JavaScriptTransparent Object Proxies for JavaScript
Transparent Object Proxies for JavaScriptMatthias Keil
 
On Contracts and Sandboxes for JavaScript
On Contracts and Sandboxes for JavaScriptOn Contracts and Sandboxes for JavaScript
On Contracts and Sandboxes for JavaScriptMatthias Keil
 
Symbolic Solving of Extended Regular Expression Inequalities
Symbolic Solving of Extended Regular Expression InequalitiesSymbolic Solving of Extended Regular Expression Inequalities
Symbolic Solving of Extended Regular Expression InequalitiesMatthias Keil
 
Efficient Dynamic Access Analysis Using JavaScript Proxies
Efficient Dynamic Access Analysis Using JavaScript ProxiesEfficient Dynamic Access Analysis Using JavaScript Proxies
Efficient Dynamic Access Analysis Using JavaScript ProxiesMatthias Keil
 
Type-based Dependency Analysis for JavaScript
Type-based Dependency Analysis for JavaScriptType-based Dependency Analysis for JavaScript
Type-based Dependency Analysis for JavaScriptMatthias Keil
 
Type-based Dependency Analysis
Type-based Dependency AnalysisType-based Dependency Analysis
Type-based Dependency AnalysisMatthias Keil
 

More from Matthias Keil (6)

Transparent Object Proxies for JavaScript
Transparent Object Proxies for JavaScriptTransparent Object Proxies for JavaScript
Transparent Object Proxies for JavaScript
 
On Contracts and Sandboxes for JavaScript
On Contracts and Sandboxes for JavaScriptOn Contracts and Sandboxes for JavaScript
On Contracts and Sandboxes for JavaScript
 
Symbolic Solving of Extended Regular Expression Inequalities
Symbolic Solving of Extended Regular Expression InequalitiesSymbolic Solving of Extended Regular Expression Inequalities
Symbolic Solving of Extended Regular Expression Inequalities
 
Efficient Dynamic Access Analysis Using JavaScript Proxies
Efficient Dynamic Access Analysis Using JavaScript ProxiesEfficient Dynamic Access Analysis Using JavaScript Proxies
Efficient Dynamic Access Analysis Using JavaScript Proxies
 
Type-based Dependency Analysis for JavaScript
Type-based Dependency Analysis for JavaScriptType-based Dependency Analysis for JavaScript
Type-based Dependency Analysis for JavaScript
 
Type-based Dependency Analysis
Type-based Dependency AnalysisType-based Dependency Analysis
Type-based Dependency Analysis
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

TreatJS: Higher-Order Contracts for JavaScript

  • 1. TreatJS Higher-Order Contracts for JavaScript Matthias Keil, Peter Thiemann Institute for Computer Science University of Freiburg Freiburg, Germany June 30, 2014, Dagstuhl Seminar on Scripting Languages and Frameworks: Analysis and Verification
  • 2. Introduction TreatJS Language embedded contract system for JavaScript Enforced by run-time monitoring Inspiration similar to Contracts.js [Disney] Contract Specifies the interface of a software component Obligations - Benefits Matthias Keil, Peter Thiemann TreatJS June 30, 2014 2 / 14
  • 3. Features Standard abstractions for higher-order-contracts (base, function, and object contracts) [Findler,Felleisen’02] Support for boolean combinations (and, or, not contracts) as building blocks for intersection, union, and implication Contract constructors generalize dependent contracts Non-interference for contract execution Matthias Keil, Peter Thiemann TreatJS June 30, 2014 3 / 14
  • 4. Base Contract [Findler,Felleisen’02] Base Contracts are built from predicates Specified by a plain JavaScript function 1 function typeOfNumber (arg) { 2 return (typeof arg) === ’number’; 3 }; 4 var IsNumber = BaseContract(typeOfNumber, ’IsNumber’); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 4 / 14
  • 5. Base Contract [Findler,Felleisen’02] Base Contracts are built from predicates Specified by a plain JavaScript function 1 function typeOfNumber (arg) { 2 return (typeof arg) === ’number’; 3 }; 4 var IsNumber = BaseContract(typeOfNumber, ’IsNumber’); 5 assert(1, IsNumber); Value v fulfills BaseContract (B) iff: B(v) = true Matthias Keil, Peter Thiemann TreatJS June 30, 2014 4 / 14
  • 6. Base Contract [Findler,Felleisen’02] Base Contracts are predicates Specified by a plain JavaScript function 1 function typeOfNumber (arg) { 2 return (typeof arg) === ’number’; 3 }; 4 var IsNumber = BaseContract(typeOfNumber, ’IsNumber’); 5 assert(’a’, IsNumber); Blame the Value Value v gets blamed for contract B iff: B(v) = false Matthias Keil, Peter Thiemann TreatJS June 30, 2014 4 / 14
  • 7. Function Contract [Findler,Felleisen’02] 1 // Number × Number → Number 2 function addUnchecked(x, y) { 3 return (x + y); 4 } Matthias Keil, Peter Thiemann TreatJS June 30, 2014 5 / 14
  • 8. Function Contract [Findler,Felleisen’02] 1 // Number × Number → Number 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 var addChecked = assert(addUnchecked, 6 FunctionContract([IsNumber, IsNumber], IsNumber)); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 5 / 14
  • 9. Function Contract [Findler,Felleisen’02] 1 // Number × Number → Number 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(1, 1); x is an acceptable argument for contract C → C iff: (x fulfills C) Function f fulfills contract C → C at argument x iff: (x fulfills C) → (f (x) fulfills C ) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 6 / 14
  • 10. Function Contract [Findler,Felleisen’02] 1 // Number × Number → Number 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(’a’, ’a’); Blame the Argument Argument x gets blamed for C → C iff: ¬ (x is an acceptable argument for contract C → C ) iff: ¬ (x fulfills C) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 6 / 14
  • 11. Function Contract [Findler,Felleisen’02] 1 // Number × Number → Number 2 function addUnchecked(x, y) { 3 return (x0 y0) ? (x + y) : ’Error’; 4 } 5 addChecked(0, 1); Blame the Fucntion Function f gets blamed for C → C at argument x iff: ¬ (Function f fulfills contract C → C at argument x) iff: (x fulfills C) ∧ ¬ (f (x) fulfills C ) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 6 / 14
  • 12. TreatJS New! Matthias Keil, Peter Thiemann TreatJS June 30, 2014 7 / 14
  • 13. Intersection Contract 1 // Number × Number → Number 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(’a’, ’a’); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 14. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 15. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 var addChecked = assert(addUnchecked, Intersection( 6 FunctionContract([IsNumber, IsNumber], IsNumber) 7 FunctionContract([IsString, IsString], IsString)); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 16. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(’a’, ’a’); x is an acceptable argument for contract C ∩ C iff: (x is acceptable arg. for C) ∨ (x is acceptable arg. for C ) Function f fulfills contract C ∩ C at argument x iff: (f fulfills C at x) ∧ (f fulfills C at x) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 17. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(true, true); Blame the Argument Argument x gets blamed for C ∩ C iff: Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 18. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(true, true); Blame the Argument Argument x gets blamed for C ∩ C iff: ¬ (x is an acceptable argument for contract C ∩ C ) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 19. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(true, true); Blame the Argument Argument x gets blamed for C ∩ C iff: ¬ (x is an acceptable argument for contract C ∩ C ) ¬ ((x is acc. arg. for C) ∨ (x is acc. arg. for C )) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 20. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(true, true); Blame the Argument Argument x gets blamed for C ∩ C iff: ¬ (x is an acceptable argument for contract C ∩ C ) ¬ ((x is acc. arg. for C) ∨ (x is acc. arg. for C )) ¬(x is acc. arg. for C) ∧ ¬(x is acc. arg. for C ) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 21. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 addChecked(true, true); Blame the Argument Argument x gets blamed for C ∩ C iff: ¬ (x is an acceptable argument for contract C ∩ C ) ¬ ((x is acc. arg. for C) ∨ (x is acc. arg. for C )) ¬(x is acc. arg. for C) ∧ ¬(x is acc. arg. for C ) (x gets blamed for C) ∧ (x gets blamed for C) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 22. Intersection Contract 1 // (Number × Number → Number) ∩ (String × String → String) 2 function addUnchecked(x, y) { 3 return (x0 y0) ? (x + y) : ’Error’; 4 } 5 addChecked(0, 1); Blame the Function Function f gets blamed for C ∩ C at argument x iff: (f gets blamed for C at x) ∨ (f gets blamed for C at x) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 8 / 14
  • 23. Union Contract 1 // (Number × Number → Number) ∪ (Number × Number → String) 2 function addUnchecked(x, y) { 3 return (x0 y0) ? (x + y) : ’Error’; 4 } Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
  • 24. Union Contract 1 // (Number × Number → Number) ∪ (Number × Number → String) 2 function addUnchecked(x, y) { 3 return (x0 y0) ? (x + y) : ’Error’; 4 } 5 var addChecked = assert(addUnchecked, Union( 6 FunctionContract([IsNumber, IsNumber], IsNumber) 7 FunctionContract([IsNumber, IsNumber], IsString)); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
  • 25. Union Contract 1 // (Number × Number → Number) ∪ (Number × Number → String) 2 function addUnchecked(x, y) { 3 return (x0 y0) ? (x + y) : ’Error’; 4 } 5 addChecked(0, 1); Argument x is an acceptable argument for contract C ∪ C iff: (x is acceptable arg. for C) ∧ (x is acceptable arg. for C ) Function f fulfills contract C ∪ C at argument x iff: (f fulfills C at x) ∨ (f fulfills C at x) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
  • 26. Union Contract 1 // (Number × Number → Number) ∪ (Number × Number → String) 2 function addUnchecked(x, y) { 3 return (x0 y0) ? (x + y) : ’Error’; 4 } 5 addChecked(’a’, ’a’); Blame the Argument Argument x gets blamed for C ∪ C iff: (x gets blamed for C) ∨ (x gets blamed for C) Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
  • 27. Union Contract 1 // (Number × Number → Number) ∪ (Number × Number → String) 2 function addUnchecked(x, y) { 3 return (x0 y0) ? (x + y) : undefined; 4 } 5 addChecked(0, 1); Blame the Fucntion Function f gets blamed for C ∪ C at argument x iff: (f gets blamed for C at x) ∧ (f gets blamed for C ) at x Matthias Keil, Peter Thiemann TreatJS June 30, 2014 9 / 14
  • 28. Non-Interference No syntactic restrictions on predicates Problem: contract may interfere with program execution Solution: Predicate evaluation takes place in a sandbox 1 function typeOfNumber (arg) { 2 type = (typeof arg); Access forbidden 3 return type === ’number’; 4 }; 5 var FaultyIsNumber = 6 BaseContract(typeOfNumber, ’FaultyIsNumber’); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 10 / 14
  • 29. Non-Interference No syntactic restrictions on predicates Problem: contract may interfere with program execution Solution: Predicate evaluation takes place in a sandbox 1 var IsArray = BaseContract(function (arg) { 2 return (arg instanceof Array); Access forbidden 3 }); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 10 / 14
  • 30. Non-Interference No syntactic restrictions on predicates Problem: contract may interfere with program execution Solution: Predicate evaluation takes place in a sandbox 1 var IsArray = BaseContract(function (arg) { 2 return (arg instanceof InsideArray); 3 }); 4 var IsArrayComplete = With({InsideArray:Array}, IsArray); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 11 / 14
  • 31. Contract Constructor 1 // T × T → T 2 function addUnchecked(x, y) { 3 return (x + y); 4 } Matthias Keil, Peter Thiemann TreatJS June 30, 2014 12 / 14
  • 32. Contract Constructor 1 // T × T → T 2 function addUnchecked(x, y) { 3 return (x + y); 4 } 5 var addChecked = assert(addUnchecked, 6 FunctionContract([CheckType, CheckType], CheckType)): 7 var CheckType = BaseContract(function (arg) { 8 // to be completed 9 }); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 12 / 14
  • 33. Contract Constructor Constructor gets evaluated in a sandbox, like a predicate Returns a contract No further sandboxing for predicates 1 var ctor = Constructor(function() { 2 var type = undefined; 3 var CheckType = BaseContract(function (arg) { 4 type = type || (typeof arg); 5 return type === (typeof arg); 6 }); 7 return FunctionContract([CheckType, CheckType], CheckType): 8 }, ’SameType’); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 12 / 14
  • 34. Dependent Contract 1 var SameTypeCtor = Constructor(function(arg) { 2 var type = (typeof arg); 3 return BaseContract(function (arg) { 4 return (typeof arg) === type); 5 }); 6 }); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 13 / 14
  • 35. Dependent Contract 1 var SameTypeCtor = Constructor(function(arg) { 2 var type = (typeof arg); 3 return BaseContract(function (arg) { 4 return (typeof arg) === type); 5 }); 6 }); 7 var addChecked = assert(addUnchecked, 8 DependentContract(SameTypeCtor)); Matthias Keil, Peter Thiemann TreatJS June 30, 2014 13 / 14
  • 36. Conclusion TreatJS: Language embedded, higher-order contract system for JavaScript Support for intersection and union contracts Systematic blame calculation Composable sandboxing that guarantees non-interference Contract constructors with local scope Matthias Keil, Peter Thiemann TreatJS June 30, 2014 14 / 14