Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of updated JsAPI #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Builtins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public sealed class JSGlobal {
/// Retrieves a name from the global namespace (note that this is the global namespace at the time that the JSIL runtime was loaded).
/// </summary>
/// <param name="name">The name to retrieve. This may be a literal, or a string-producing expression.</param>
public dynamic this[string name] {
public JsObject this[string name] {
get {
return null;
throw new NotSupportedException("Not available outside JS");
}
}
}
Expand All @@ -23,9 +23,9 @@ public sealed class JSLocal {
/// Retrieves a name from the local namespace.
/// </summary>
/// <param name="name">The name to retrieve. This must be a string literal!</param>
public dynamic this[string name] {
public JsObject this[string name] {
get {
return null;
throw new NotSupportedException("Not available outside JS");
}
}
}
Expand All @@ -35,16 +35,16 @@ public static class Builtins {
public static readonly JSLocal Local = new JSLocal();

/// <summary>
/// When running as C#, this method does nothing and returns null.
/// When running as C#, this method throws NotSupportedException.
/// When running as JavaScript, this method call is replaced with an invocation of the builtin javascript eval function.
/// </summary>
/// <param name="expression">The expression to evaluate.</param>
public static dynamic Eval (string expression) {
return null;
public static JsObject Eval (string expression) {
throw new NotSupportedException("Not available outside JS");
}

/// <summary>
/// When running as C#, this method does nothing and returns null.
/// When running as C#, this method throws NotSupportedException.
/// When running as JavaScript, this method call is replaced with an invocation of the builtin JSIL CreateNamedFunction utility.
/// </summary>
public static T CreateNamedFunction<T> (
Expand All @@ -53,7 +53,7 @@ public static T CreateNamedFunction<T> (
string body,
object closure = null
) {
throw new NotImplementedException("Not available outside JS");
throw new NotSupportedException("Not available outside JS");
}

public static bool IsTruthy (dynamic value) {
Expand All @@ -67,9 +67,9 @@ public static bool IsFalsy (dynamic value) {
/// <summary>
/// When running as javascript, this property evaluates to the current scope's this-reference.
/// </summary>
public static dynamic This {
public static JsObject This {
get {
return null;
throw new NotSupportedException("Not available outside JS");
}
}

Expand All @@ -89,7 +89,7 @@ public static class Services {
/// When running as JavaScript this method returns a reference to the named runtime service.
/// </summary>
/// <param name="serviceName">The name of the runtime service.</param>
public static dynamic Get (string serviceName, bool throwIfMissing = true) {
public static JsObject Get (string serviceName, bool throwIfMissing = true) {
if (throwIfMissing)
throw new NotImplementedException("Services.get is only available at runtime and you passed true for throwIfMissing.");
else
Expand Down
247 changes: 247 additions & 0 deletions JSObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
#pragma warning disable 1591
namespace JSIL {
using System;

using JSIL.Meta;

public class JsObject
{
private JsObject()
{
}

//Should work same as Builtins.Global[key]
public static JsObject Global(string key)
{
throw new NotSupportedException("Not available outside JS");
}

public sealed class JsFunction : JsObject
{
private JsFunction() : base()
{
}
}
}

public static class JsObjectHelpers
{
[JSReplacement("$target[$key]")]
public static JsObject Get(this JsObject target, string key)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("($target[$key] = $value)")]
public static void Set<TValue>(this JsObject target, string key, TValue value)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("($key in $target)")]
public static bool In(this JsObject target, string key)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("(delete $target[$key])")]
public static void Delete(this JsObject target, string key)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]()")]
public static JsObject Call(this JsObject.JsFunction target, string key)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1)")]
public static JsObject Call<TArg1>(this JsObject.JsFunction target, string key, TArg1 arg1)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1, $arg2)")]
public static JsObject Call<TArg1, TArg2>(this JsObject.JsFunction target, string key, TArg1 arg1, TArg2 arg2)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1, $arg2, $arg3)")]
public static JsObject Call<TArg1, TArg2, TArg3>(this JsObject.JsFunction target, string key, TArg1 arg1, TArg2 arg2, TArg3 arg3)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1, $arg2, $arg3, $arg4)")]
public static JsObject Call<TArg1, TArg2, TArg3, TArg4>(this JsObject.JsFunction target, string key, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1, $arg2, $arg3, $arg4, $arg5)")]
public static JsObject Call<TArg1, TArg2, TArg3, TArg4, TArg5>(this JsObject.JsFunction target, string key, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1, $arg2, $arg3, $arg4, $arg5, $arg6)")]
public static JsObject Call<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(this JsObject.JsFunction target, string key, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7)")]
public static JsObject Call<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(this JsObject.JsFunction target, string key, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target[$key]($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8)")]
public static JsObject Call<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(this JsObject.JsFunction target, string key, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null)")]
public static JsObject Invoke(this JsObject.JsFunction target)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1)")]
public static JsObject Invoke<TArg1>(this JsObject.JsFunction target, TArg1 arg1)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1, $arg2)")]
public static JsObject Invoke<TArg1, TArg2>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1, $arg2, $arg3)")]
public static JsObject Invoke<TArg1, TArg2, TArg3>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1, $arg2, $arg3, $arg4)")]
public static JsObject Invoke<TArg1, TArg2, TArg3, TArg4>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1, $arg2, $arg3, $arg4, $arg5)")]
public static JsObject Invoke<TArg1, TArg2, TArg3, TArg4, TArg5>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6)")]
public static JsObject Invoke<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7)")]
public static JsObject Invoke<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$target.call(null, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8)")]
public static JsObject Invoke<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target()")]
public static JsObject New(this JsObject.JsFunction target)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1)")]
public static JsObject New<TArg1>(this JsObject.JsFunction target, TArg1 arg1)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1, $arg2)")]
public static JsObject New<TArg1, TArg2>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1, $arg2, $arg3)")]
public static JsObject New<TArg1, TArg2, TArg3>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1, $arg2, $arg3, $arg4)")]
public static JsObject New<TArg1, TArg2, TArg3, TArg4>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1, $arg2, $arg3, $arg4, $arg5)")]
public static JsObject New<TArg1, TArg2, TArg3, TArg4, TArg5>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1, $arg2, $arg3, $arg4, $arg5, $arg6)")]
public static JsObject New<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7)")]
public static JsObject New<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("new $target($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8)")]
public static JsObject New<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(this JsObject.JsFunction target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8)
{
throw new NotSupportedException("Not available outside JS");
}


[JSReplacement("$obj")]
public static T AssumeType<T>(this JsObject obj)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$T.$$As($obj)")]
public static T As<T>(this JsObject obj) where T : class
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$T.$$Cast($obj)")]
public static T Cast<T>(this JsObject obj)
{
throw new NotSupportedException("Not available outside JS");
}

[JSReplacement("$T.$$Is($obj)")]
public static bool Is<T>(this JsObject obj)
{
throw new NotSupportedException("Not available outside JS");
}

// Will wrap JS object in adapter, that implement interface T
// If T is not interface, than work same as Cast
//public static T Adapt<T>(this JsObject obj)
//{
// throw new NotSupportedException("Not available outside JS");
//}
}
}
1 change: 1 addition & 0 deletions Meta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<ItemGroup>
<Compile Include="Attributes.cs" />
<Compile Include="Builtins.cs" />
<Compile Include="JSObject.cs" />
<Compile Include="PackedArray.cs" />
<Compile Include="StaticAnalysis.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Loading