# US 2016/0259633 A1 · Safely consuming dynamically-typed code from a statically-typed programming language

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2016/0259633 A1
- Document ID: US20160259633A1
- Status: Published application
- Kind: A1
- Application number: 14/944,855
- Filed: 2015-11-18
- Published: 2016-09-08
- Earliest claimed: 2014-11-18
- Inventors: Roger James Poon
- Web page: https://patentgrep.com/patent/US20160259633A1

## CPC

- G06F 8/437: {Type checking}
- G06F 8/51: Source to source
- G06F 9/45529: {Embedded in an application, e.g. JavaScript in a Web browser}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A computerized method is provided to consume a dynamically-typed language in a compatible language, and to compile source code in a compatible language into a target language to add “eventual type safety” and static type checking to a superset of a dynamically-typed language, irrespective of whether the dynamically-typed language is dynamically type-checked or not. The computing environment is a development environment comprising a compiler to compile statically-typed code to a dynamically-typed target language (or any other target language), a user interface for rendering visual interface for editing code and managing code, an editor for allowing programmers to edit source code, an execution engine for runtime execution of compiled code, a source code manager to enable programmers to manage source code files, and a source files module to store and retrieve source files.

## Claims

### Claim 1

A method of safely consuming dynamically-typed code from a statically-typed programming language, said method comprising:
consuming code of said dynamically-typed language in a compatible statically-typed language;
compiling said compatible language with consumed dynamically-typed language to a target language, said compiling further comprising
importing external definitions;
merging one or more external types into a unified external type;
performing type checking with the unified external type as one of the types used by the type checker;
performing implementation-defined conversions;
performing user-defined conversions; and
generating code in said target language.

### Claim 2 (depends on 1)

The method in claim 1, wherein said dynamically-typed language is JavaScript.

### Claim 3 (depends on 1)

The method in claim 1, wherein said compatible language is a language compatible with JavaScript.

### Claim 4 (depends on 3)

The method in claim 3, wherein an external type from said one or more external types is declared using keyword “var”.

### Claim 5 (depends on 3)

The method in claim 3, wherein an external type from said one or more external types is declared using keyword “let”.

### Claim 6 (depends on 3)

The method in claim 3, wherein an external type from said one or more external types is a return type of a function declared using keyword “function”.

### Claim 7 (depends on 3)

The method in claim 3, wherein an external type from said one or more external types is declared using keyword “class”.

### Claim 8 (depends on 3)

The method in claim 3, said method further comprising implicitly converting an array to unified external type.

### Claim 9 (depends on 3)

The method in claim 3, said method further comprising explicitly converting an array to unified external type.

### Claim 10 (depends on 3)

The method in claim 3, said method further comprising merging an array type to the unified external type for compile-time type checking.

### Claim 11 (depends on 3)

The method in claim 3, said method further comprising implicitly converting a reference type to unified external type.

### Claim 12 (depends on 3)

The method in claim 3, said method further comprising explicitly converting a reference type to unified external type.

### Claim 13 (depends on 3)

The method in claim 3, said method further comprising merging a reference type to a unified external type for compile-time type checking.

### Claim 14 (depends on 3)

The method in claim 3, wherein a JavaScript object type is merged into a unified external type for compile-time type checking.

### Claim 15 (depends on 14)

The method in claim 14, said method further comprising merging types of all properties of said JavaScript object to a unified external type for compile-time type checking.

### Claim 16 (depends on 3)

The method in claim 3, where a “typeof” keyword returns at runtime the type of types belonging to both compatible language and JavaScript language.

### Claim 17 (depends on 3)

The method in claim 3, where a “typeof” keyword supports custom implementation to return at runtime the type of types belonging to both compatible language and JavaScript language.

### Claim 18 (depends on 1)

The method in claim 1, said method further comprising converting a unified external type to another unified external type during compile-time type checking.

### Claim 19 (depends on 1)

The method in claim 1, said method further comprising bypassing properties, elements, fields, methods, and children for data of unified external type.

### Claim 20 (depends on 1)

The method in claim 1, said method further comprising providing a matching wrapper for a primitive unified external type.

### Claim 21 (depends on 1)

The method in claim 1, said method further comprising converting a primitive type to unified external type using conversion mechanism associated with a corresponding reference type.

### Claim 22 (depends on 1)

The method in claim 1, said method further comprising converting a unified external type to a primitive type using conversion mechanism associated with a corresponding reference type.

### Claim 23 (depends on 1)

The method in claim 1, said method further comprising bypassing name mangling for identifiers for symbols of unified external type.

### Claim 24

The method in 23, wherein a keyword is provided for identifying one or more identifiers and symbols to be bypassed for name mangling.

### Claim 25

The method in 23, wherein a symbol from said symbols has an assigned value through an expression from among an initialization expression or an assignment expression.

### Claim 26

The method in 25, wherein said expression evaluating to an internal type having associated conversion mechanism to a unified external type.

### Claim 27

The method in 25, wherein said expression evaluates to a unified external type.

### Claim 28 (depends on 1)

The method in claim 1, said method further comprising inserting cached result into generated code.

### Claim 29 (depends on 28)

The method in claim 28, wherein said cached result is a result of a property access of a unified external type.

### Claim 30 (depends on 1)

The method in claim 1, said method further comprising rejecting usages of dynamic code evaluation.

### Claim 31 (depends on 30)

The method in claim 30, wherein said rejection is a compiler error.

### Claim 32 (depends on 30)

The method in claim 30, wherein said rejection is a compiler warning.

### Claim 33 (depends on 30)

The method in claim 30, wherein said rejection is disabling of dynamic code evaluation for external declarations.

### Claim 34 (depends on 30)

The method in claim 30, wherein said rejection includes referencing the dynamic code evaluation mechanism.

### Claim 35 (depends on 30)

The method in claim 30, wherein said rejection is a runtime error inserted into generated code.

### Claim 36 (depends on 30)

The method in claim 30, wherein said rejection is a modification inserted into generated code.

### Claim 37 (depends on 1)

The method in claim 1, inserting runtime mechanisms into generated code.

### Claim 38 (depends on 37)

The method in claim 37, wherein said runtime mechanism is a runtime conversion.

### Claim 39 (depends on 38)

The method in claim 38, wherein said runtime conversion has lower priority compared to a compile-time check.

### Claim 40 (depends on 37)

The method in claim 37, wherein said runtime mechanism is a runtime check.

### Claim 41 (depends on 40)

The method in claim 40, wherein said runtime check has lower priority compared a compile-time check.

### Claim 42 (depends on 40)

The method in claim 40, wherein said runtime check is a backup operation performed only when no corresponding conversion mechanism exists.

### Claim 43 (depends on 40)

The method in claim 40, wherein said runtime check has higher priority over a runtime conversion if said runtime check is to check if said conversion is available.

### Claim 44 (depends on 1)

The method in claim 1, said method further comprising merging return type of a function call expression to a unified external type for compile-time type checking, when said function is one among:
a function declared with a unified external type; and
a function having a return type being a unified external type.

### Claim 45 (depends on 44)

The method in claim 44, wherein said function is called with fewer arguments than defined parameters.

### Claim 46 (depends on 44)

The method in claim 44, wherein said function is called with more arguments than defined parameters.

### Claim 47 (depends on 1)

The method in claim 1, said method further comprising merging ‘this’ keyword to an object for compile-time type checking.

### Claim 48 (depends on 1)

The method in claim 1, said method further comprising merging ‘this’ keyword to a unified external type for compile-time type checking.

### Claim 49 (depends on 44)

The method in claim 44, said method further comprising merging type of ‘arguments’ object to one among an array, an object, and a unified external type for compile-time type checking.

### Claim 50 (depends on 1)

The method in claim 1, said method further comprising inserting at least one among a runtime check and a runtime error into generated code when an operation is detected involving a unified external type.

### Claim 51 (depends on 50)

The method in claim 50, wherein a runtime error is raised when corresponding runtime check fails.

### Claim 52 (depends on 50)

The method in claim 50, wherein an operation is cached before performing a runtime check on said operation.

### Claim 53 (depends on 50)

The method in claim 50, wherein a runtime check on an operation is asserting that a callee is a function type at runtime, when said operation is a function call expression with the callee being unified external type at compile time.

### Claim 54 (depends on 53)

The method in claim 53, wherein said function call is cached before performing runtime checks on said operation.

### Claim 55 (depends on 50)

The method in claim 50, wherein said runtime check is asserting if instantiated subject is instantiable at runtime, when said operation is an instantiation operation.

### Claim 56 (depends on 55)

The method in claim 55, wherein said instantiation operation is cached before performing runtime checks.

### Claim 57 (depends on 50)

The method in claim 50, wherein said runtime check is asserting runtime type of one or more parents of an object property, when said operation is accessing said object property.

### Claim 58 (depends on 57)

The method in claim 57, wherein said object property is cached before performing runtime checks.

### Claim 59 (depends on 57)

The method in claim 57, wherein said one or more parents of said object property is cached before performing runtime checks.

### Claim 60 (depends on 57)

The method in claim 57, wherein said runtime check includes checking if object property's parent is among JavaScript object, JavaScript function, JavaScript class, and JavaScript array.

### Claim 61 (depends on 50)

The method in claim 50, said method further comprising a runtime check asserting if a throw statement results in a valid exception, when said operation is a throw statement and when the thrown subject is a unified external type at compile time.

### Claim 62 (depends on 50)

The method in claim 50, said method further comprising a runtime check asserting if an iteration is possible, when said operation is an iteration operation.

### Claim 63 (depends on 50)

The method in claim 50, wherein a runtime error includes at least original source line number, column number, and file path from source file.

### Claim 64 (depends on 1)

The method in claim 1, said method further comprising rejecting an operation when a unified external type occurs within said operation.

### Claim 65 (depends on 64)

The method in claim 64, wherein said rejection is one among a compile-time error, and compile-time warning.

### Claim 66 (depends on 64)

The method in claim 64, wherein said rejection is one among a runtime error, a runtime warning, and a runtime exception.

### Claim 67 (depends on 1)

The method in claim 1, said method further comprising aborting checking properties of a reference type at compile time when a unified external type is encountered and when at least one of the following conditions are satisfied:
said reference type is a unified external type; and
a property of data of said reference type is a unified external type.

### Claim 68 (depends on 67)

The method in claim 67, wherein access operation of data of said reference type occurs with a dot accessor.

### Claim 69 (depends on 67)

The method in claim 67, wherein access operation of data of said reference type occurs with an index accessor.

### Claim 70

A method of compiling a statically-typed compatible language with consumed dynamically-typed external language to a target language, said compiling further comprising
merging one or more external types to a unified external type during compile-time type checking;
generating code in said target language.

### Claim 71 (depends on 70)

The method in claim 70, wherein a keyword is used to declare said one or more external types as unified external type, when the statically-typed programming language is a nominally-typed programming language.

### Claim 72 (depends on 70)

The method in claim 70, wherein an “external” keyword modifier is used to modify at least one among variable declarations, function declarations, function expressions, method declarations, and classes to the unified external type.

### Claim 73 (depends on 70)

The method in claim 70, wherein an “external” keyword modifier is used to convert at least one among variable declarations, function declarations, function expressions, method declarations, and classes to the unified external type.

### Claim 74 (depends on 70)

The method in claim 70, wherein a variable that can hold more than one type of data at runtime is merged to a unified external type at compile time.

### Claim 75 (depends on 70)

The method in claim 70, wherein the types from the dynamically-typed programming language that are unified to the unified external type include at least one among string, number, boolean, object, function, and undefined, when said dynamically typed external language is JavaScript.

### Claim 76 (depends on 70)

The method in claim 70, wherein the types that are dynamically-typed and unified to the unified external type include Document Object Model (DOM) API (Application Programming Interface) types.

### Claim 77 (depends on 70)

The method in claim 70, wherein the types that are dynamically-typed and unified to the unified external type at compile time are ECMAScript host object types.

### Claim 78 (depends on 70)

The method in claim 70, wherein the consumed dynamically-typed external language is restricted from accessing types of the statically-typed compatible language.

### Claim 79 (depends on 70)

The method in claim 70, wherein said one or more external types include types that are type casted to the unified external type.

### Claim 80 (depends on 70)

The method in claim 70, said method further comprising discarding unified external types at runtime, where symbols having type of the unified external type assume any one of possible runtime types.

### Claim 81 (depends on 70)

The method in claim 70, wherein a unified external type unifies primitive types.

### Claim 82 (depends on 70)

The method in claim 70, wherein a unified external type unifies reference types.

### Claim 83 (depends on 70)

The method in claim 70, wherein a unified external type unifies void types.

### Claim 84 (depends on 70)

The method in claim 70, wherein a unified external type unifies JavaScript Object types.

### Claim 85 (depends on 70)

The method in claim 70, wherein a unified external type unifies numeric types.

### Claim 86 (depends on 70)

The method in claim 70, wherein a unified external type unifies class types.

### Claim 87 (depends on 70)

The method in claim 70, wherein a unified external type unifies function types.

### Claim 88 (depends on 70)

The method in claim 70, wherein a unified external type unifies textual types.

### Claim 89

A method of compiling a statically-typed compatible language with consumed dynamically-typed external language to a target language, said compiling further comprising
inserting implementation-defined conversions;
generating code in said target language.

### Claim 90 (depends on 89)

The method in claim 89, wherein said implementation-defined conversion is to convert an internal type to a unified external type.

### Claim 91 (depends on 90)

The method in claim 90, wherein said conversion is an implicit conversion.

### Claim 92 (depends on 90)

The method in claim 90, wherein said conversion is an explicit conversion.

### Claim 93 (depends on 90)

The method in claim 90, wherein said conversion is to convert a type-checked array to a non-type checked array.

### Claim 94 (depends on 93)

The method in claim 93, wherein said type-checked array is a type of said statically-typed compatible language.

### Claim 95 (depends on 93)

The method in claim 93, wherein said non-type checked array is a type of said dynamically-typed programming language.

### Claim 96 (depends on 90)

The method in claim 90, wherein said conversion is to convert a type-checked array to a runtime type-checked array.

### Claim 97 (depends on 96)

The method in claim 96, wherein said conversion is an implicit conversion.

### Claim 98 (depends on 96)

The method in claim 96, wherein said conversion is an explicit conversion.

### Claim 99 (depends on 96)

The method in claim 96, wherein said type-checked array is a type of said statically-typed compatible language.

### Claim 100 (depends on 96)

The method in claim 96, wherein said type-checked array is a type of said dynamically-typed programming language.

### Claim 101 (depends on 90)

The method in claim 90, wherein said conversion is to convert a type-checked array to a JavaScript array, when said dynamically-typed external language is JavaScript.

### Claim 102 (depends on 101)

The method in claim 101, wherein said type-checked array is a type of said statically-typed compatible language.

### Claim 103 (depends on 101)

The method in claim 101, wherein said JavaScript array is a type of said dynamically-typed programming language.

### Claim 104 (depends on 90)

The method in claim 90, wherein said conversion is to convert a type-checked key-value pair to a non-type-checked key-value pair.

### Claim 105 (depends on 104)

The method in claim 104, wherein said conversion is an implicit conversion.

### Claim 106 (depends on 104)

The method in claim 104, wherein said conversion is an explicit conversion.

### Claim 107 (depends on 104)

The method in claim 104, wherein said type-checked key-value pair is a type of said statically-typed compatible language.

### Claim 108 (depends on 104)

The method in claim 104, wherein said non-type checked key-value pair is a type of said dynamically-typed programming language.

### Claim 109 (depends on 90)

The method in claim 90, wherein said conversion is to convert a type-checked key-value pair to a runtime type-checked key-value pair.

### Claim 110 (depends on 109)

The method in claim 109, wherein said conversion is an implicit conversion.

### Claim 111 (depends on 109)

The method in claim 109, wherein said conversion is an explicit conversion.

### Claim 112 (depends on 109)

The method in claim 109, wherein said type-checked key-value pair is a type of said statically-typed compatible language.

### Claim 113 (depends on 109)

The method in claim 109, wherein said runtime type-checked key-value pair is a type of said dynamically-typed programming language.

### Claim 114 (depends on 90)

The method in claim 90, wherein said conversion is to convert a type-checked key-value pair to a JavaScript object, when said dynamically typed external language is JavaScript.

### Claim 115 (depends on 114)

The method in claim 114, wherein said conversion an implicit conversion.

### Claim 116 (depends on 114)

The method in claim 114, wherein said conversion an explicit conversion.

### Claim 117 (depends on 114)

The method in claim 114, wherein said type-checked key-value pair is a type of said statically-typed compatible language.

### Claim 118 (depends on 114)

The method in claim 114, wherein said JavaScript object is a type of said dynamically-typed programming language.

### Claim 119 (depends on 90)

The method in claim 90, said method further comprising raising a warning at compile time if there is a loss of precision during said conversion.

### Claim 120 (depends on 90)

The method in claim 90, said method further comprising raising an error at compile time if there is a loss of precision during said conversion.

### Claim 121 (depends on 90)

The method in claim 90, said conversion is to convert literals to non-type checked values implicitly.

### Claim 122 (depends on 90)

The method in claim 90, said conversion is to convert literals converted to runtime type-checked values implicitly.

### Claim 123 (depends on 90)

The method in claim 90, said conversion is to convert literals to equivalent JavaScript values implicitly.

### Claim 124 (depends on 90)

The method in claim 90, said method further comprising providing a matching reference type for said conversion, when said unified external type is a primitive type with a matching reference type.

### Claim 125 (depends on 90)

The method in claim 90, said method further comprising applying a conversion defined for a reference type to a corresponding primitive type.

### Claim 126 (depends on 89)

The method in claim 89, wherein said implementation-defined conversion is to convert a unified external type to an internal type.

### Claim 127 (depends on 126)

The method in claim 126, wherein said conversion is an implicit conversion.

### Claim 128 (depends on 126)

The method in claim 126, wherein said conversion is an explicit conversion.

### Claim 129 (depends on 126)

The method in claim 126, wherein said conversion occurs through auto-boxing.

### Claim 130 (depends on 126)

The method in claim 126, said method further comprising converting an internal integer type symbol value to zero (0), when said symbol with unified external type at compile time has a textual type at runtime with text data that is not a textual representation of a real number or IEEE 754 single/double floating-point value.

### Claim 131 (depends on 126)

The method in claim 126, said method further comprising converting symbol with unified external type to zero (0), when said symbol with the unified external type at compile time has a reference type at runtime, the value is converted to zero (0).

### Claim 132 (depends on 126)

The method in claim 126, said method further comprising inserting wrapping instructions into generated code to wrap integers.

### Claim 133 (depends on 89)

The method in claim 89, wherein a conversion is from a primitive type to a unified external type.

### Claim 134 (depends on 89)

The method in claim 89, wherein a conversion is from a unified external type to a primitive type.

### Claim 135 (depends on 89)

The method in claim 89, wherein a conversion is from a reference type to a unified external type.

### Claim 136 (depends on 89)

The method in claim 89, wherein a conversion is from a unified external type to a reference type.

### Claim 137

A method of compiling a compatible language with consumed dynamically typed language to a target language, said compiling further comprising:
inserting user-defined conversions;
generating code in said target language.

### Claim 138 (depends on 137)

The method in claim 137, wherein said user-defined conversion is to convert an internal type to a unified external type.

### Claim 139 (depends on 138)

The method in claim 138, wherein said user-defined conversion is for a user-defined type.

### Claim 140 (depends on 139)

The method in claim 139, wherein subtypes of said user-defined type do not inherit said user-defined conversion.

### Claim 141 (depends on 139)

The method in claim 139, wherein runtime reflection or mirrors are used for conversion, when said user-defined type is generic.

### Claim 142 (depends on 138)

The method in claim 138, wherein said user-defined conversion is an implicit conversion.

### Claim 143 (depends on 138)

The method in claim 138, wherein said user-defined conversion is an explicit conversion.

### Claim 144 (depends on 138)

The method in claim 138, said method further comprising making an internal type safe for conversion before converting to a unified external type, when said internal type is a reference type.

### Claim 145 (depends on 144)

The method in claim 144, wherein said internal type is made safe by inserting one or more deep cloning instructions into generated code.

### Claim 146 (depends on 144)

The method in claim 144, wherein said internal type is made safe by inserting a conversion to a compatible type in generated code.

### Claim 147 (depends on 144)

The method in claim 144, wherein said internal type is made safe by providing a compile-time notification.

### Claim 148 (depends on 144)

The method in claim 144, wherein said internal type is made safe by inserting runtime checks into generated code.

### Claim 149 (depends on 137)

The method in claim 137, wherein said user-defined conversion is to convert a unified external type to an internal type.

### Claim 150 (depends on 149)

The method in claim 149, wherein said user-defined conversion is for a user-defined type.

### Claim 151 (depends on 149)

The method in claim 149, wherein subtypes of said user-defined type do not inherit said user-defined conversion.

### Claim 152 (depends on 149)

The method in claim 149, wherein said user-defined conversion is an implicit conversion.

### Claim 153 (depends on 149)

The method in claim 149, wherein said user-defined conversion is an explicit conversion.

### Claim 154 (depends on 149)

The method in claim 149, said method further comprising making a unified external type safe for conversion before converting to a corresponding internal type, when said unified external type is a reference type.

### Claim 155 (depends on 154)

The method in claim 154, wherein said unified external type is made safe by inserting one or more deep cloning instructions into generated code.

### Claim 156 (depends on 154)

The method in claim 154, wherein said unified external type is made safe by inserting a conversion to a compatible type in generated code.

### Claim 157 (depends on 154)

The method in claim 154, wherein said unified external type is made safe by providing a compile-time notification.

### Claim 158 (depends on 154)

The method in claim 154, wherein said unified external type is made safe by inserting runtime checks into generated code.

### Claim 159

A method of compiling a compatible language with consumed dynamically-typed language to a target language, said compiling further comprising:
importing external definitions;
generating code in said target language.

### Claim 160 (depends on 159)

The method in claim 159, wherein said importing is done using one or more importables.

### Claim 161 (depends on 160)

The method in claim 160, wherein said importing of external definitions using an importable consists of at least 50% declarations having unified external type.

### Claim 162 (depends on 160)

The method in claim 160, wherein an importable from said one or more importables is for JavaScript.

### Claim 163 (depends on 160)

The method in claim 160, wherein an importable from said one or more importables is for ECMAScript.

### Claim 164 (depends on 160)

The method in claim 160, wherein an importable from said one or more importables is for web browser DOM (Document Object Model) API (Application Programming Interface).

### Claim 165 (depends on 160)

The method in claim 160, wherein an importable from said one or more importables is for jQuery.

### Claim 166 (depends on 160)

The method in claim 160, wherein an importable from said one or more importables is for Node.js API.

### Claim 167 (depends on 160)

The method in claim 160, wherein an importable from said one or more importables is for the combination of JavaScript language, ECMAScript language, and web browser DOM API.

### Claim 168 (depends on 160)

The method in claim 160, wherein importables are implementation-defined.

### Claim 169 (depends on 160)

The method in claim 160, wherein importables are user-defined.
