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

Bidimensionality
BidimensionalityBidimensionality
Bidimensionality
ASPAK2014
 
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
 

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

Consumer making buying decison
Consumer making buying decisonConsumer making buying decison
Consumer making buying decison
Sameer 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 Removed
Hailey 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 samples
kingsmonkey15
 
Top 8 literacy teacher resume samples
Top 8 literacy teacher resume samplesTop 8 literacy teacher resume samples
Top 8 literacy teacher resume samples
kingsmonkey15
 
Top 8 accounting support resume samples
Top 8 accounting support resume samplesTop 8 accounting support resume samples
Top 8 accounting support resume samples
kingsmonkey15
 
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
kingsmonkey15
 
ESENCIALES PARA LA VIDA
ESENCIALES PARA LA VIDAESENCIALES PARA LA VIDA
ESENCIALES PARA LA VIDA
sandra Rincon
 

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

#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
Hadziq Fabroyir
 
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 (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

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
"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 ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

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