Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Meta Attributes

K. Gadd edited this page Apr 25, 2014 · 13 revisions

The assembly JSIL.Meta contains various attributes you can use to control the behavior of JSILc when it translates your managed code to JavaScript. These attributes can either be applied directly, or applied indirectly using Proxies.

Universal Attributes

JSIgnore

Ignore any references to the attributed type or member. Attempts to use it will produce errors at runtime. Anything defined by the ignored type or member will be ignored automatically (i.e. ignoring a class ignores its methods).

JSChangeName

Renames the type or member at runtime. This allows you to work around members having a reserved name in JavaScript, and similar problems (for example, we use this to rename .NET's ToString to match JS's toString.)

JSReplacement

Replaces references to the attributed type or member with a JavaScript Expression. Replacement expressions support special variable tokens:

lorem ipsum dolor amet

JSExternal

For methods and properties, only generate method information, not a method body. This lets you implement them in JS. For types, this applies the same behavior to all their methods and properties. I'm not really sure what this does for fields. (:

JSImmutable

For fields, tells JSILc to treat the field as if it is immutable - you're promising that it won't get modified, and the optimizer assumes as much. For types, all the type's fields (and instances of the type itself) are treated as immutable by the optimizer. This can have devastating code correctness consequences if used improperly.

Type Attributes

JSStubOnly

Only generate a stub for this type instead of a full definition. The stub will provide the shape of the type (as if the whole containing assembly were stubbed) so that you can provide implementations with externals. Similar to JSExternal, but easier to use for types.

Method or Constructor Attributes

JSRuntimeDispatch

Overload resolution and other invocation machinery is entirely deferred until runtime. Normally, JSILc does some work to figure out what method you're calling at compile time and generates JS accordingly. This attribute is designed for scenarios where you want to use a single JS function to implement many overloads (and check argument types at runtime).

Method Attributes

JSExtraStaticConstructor

This tags the attributed method as an 'extra' static constructor that JSIL will invoke at runtime (after the normal static constructor). You can use this for dark, terrible magic. Please don't.

Constructor Attributes

JSChangeToStaticMethod

Replaces invocations of this constructor with invocations of a static method. (You provide the name of the method.)

JSReplaceConstructor

Apply this to an individual constructor on a proxy to ensure that the constructor replaces that of the proxied type. (You have to do this because the .NET type system prevents us from automatically figuring out which constructors to replace).

Property Attributes

JSAlwaysAccessAsProperty

In many cases JSILc will attempt to invoke property accessors directly (instance.get_X()); this suppresses that optimization so that instance.X is always generated.