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

[js] move standard library types to js.lib #7390

Merged
merged 7 commits into from
Apr 17, 2019
Merged
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
4 changes: 2 additions & 2 deletions src/filters/jsExceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let follow = Abstract.follow_with_abstracts

let rec is_js_error c =
match c with
| { cl_path = ["js"],"Error" } -> true
| { cl_path = ["js";"lib"],"Error" } -> true
| { cl_super = Some (csup,_) } -> is_js_error csup
| _ -> false

Expand All @@ -69,7 +69,7 @@ let find_cl com path =
) com.types

let init ctx =
let cJsError = find_cl ctx.com (["js"],"Error") in
let cJsError = find_cl ctx.com (["js";"lib"],"Error") in
let cHaxeError = find_cl ctx.com (["js";"_Boot"],"HaxeError") in
let cStd = find_cl ctx.com ([],"Std") in
let cBoot = find_cl ctx.com (["js"],"Boot") in
Expand Down
6 changes: 3 additions & 3 deletions std/haxe/CallStack.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ enum StackItem {
**/
class CallStack {
#if js
static var lastException:js.Error;
static var lastException:js.lib.Error;

static function getStack(e:js.Error):Array<StackItem> {
static function getStack(e:js.lib.Error):Array<StackItem> {
if (e == null) return [];
// https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
var oldValue = (untyped Error).prepareStackTrace;
Expand Down Expand Up @@ -97,7 +97,7 @@ class CallStack {
return makeStack(s);
#elseif js
try {
throw new js.Error();
throw new js.lib.Error();
} catch( e : Dynamic ) {
var a = getStack(js.Lib.getOriginalException());
a.shift(); // remove Stack.callStack()
Expand Down
2 changes: 1 addition & 1 deletion std/haxe/Timer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Timer {
#elseif (neko || php)
return Sys.time();
#elseif js
return js.Date.now() / 1000;
return js.lib.Date.now() / 1000;
#elseif cpp
return untyped __global__.__time_stamp();
#elseif python
Expand Down
14 changes: 7 additions & 7 deletions std/js/Boot.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ package js;

import js.Syntax; // import it here so it's always available in the compiler

private class HaxeError extends js.Error {
private class HaxeError extends js.lib.Error {
var val:Dynamic;

@:pure
public function new(val:Dynamic) {
super();
this.val = val;
if ((cast js.Error).captureStackTrace) (cast js.Error).captureStackTrace(this, HaxeError);
if ((cast js.lib.Error).captureStackTrace) (cast js.lib.Error).captureStackTrace(this, HaxeError);
}

public static function wrap(val:Dynamic):js.Error {
return if (js.Syntax.instanceof(val, js.Error)) val else new HaxeError(val);
public static function wrap(val:Dynamic):js.lib.Error {
return if (js.Syntax.instanceof(val, js.lib.Error)) val else new HaxeError(val);
}

static function __init__() {
js.Object.defineProperty((cast HaxeError).prototype, "message", {get: () -> (cast String)(js.Lib.nativeThis.val)});
js.lib.Object.defineProperty((cast HaxeError).prototype, "message", {get: () -> (cast String)(js.Lib.nativeThis.val)});
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ class Boot {
return false;
if( cc == cl )
return true;
if( js.Object.prototype.hasOwnProperty.call(cc, "__interfaces__") ) {
if( js.lib.Object.prototype.hasOwnProperty.call(cc, "__interfaces__") ) {
var intf : Dynamic = cc.__interfaces__;
for( i in 0...intf.length ) {
var i : Dynamic = intf[i];
Expand Down Expand Up @@ -220,7 +220,7 @@ class Boot {
else throw "Cannot cast " +Std.string(o) + " to " +Std.string(t);
}

static var __toStr:js.Function;
static var __toStr:js.lib.Function;
static function __init__() {
Boot.__toStr = (cast {}).toString;
}
Expand Down
52 changes: 7 additions & 45 deletions std/js/Error.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,10 @@
*/
package js;

@:native("Error")
extern class Error
{
var message : String;
var name : String;
var stack(default,null) : String;

function new(?message : String) : Void;
}

@:native("EvalError")
extern class EvalError extends Error
{
function new(?message : String) : Void;
}

@:native("RangeError")
extern class RangeError extends Error
{
function new(?message : String) : Void;
}

@:native("ReferenceError")
extern class ReferenceError extends Error
{
function new(?message : String) : Void;
}

@:native("SyntaxError")
extern class SyntaxError extends Error
{
function new(?message : String) : Void;
}

@:native("TypeError")
extern class TypeError extends Error
{
function new(?message : String) : Void;
}

@:native("URIError")
extern class URIError extends Error
{
function new(?message : String) : Void;
}
@:deprecated typedef Error = js.lib.Error;
@:deprecated typedef EvalError = js.lib.Error.EvalError;
@:deprecated typedef RangeError = js.lib.Error.RangeError;
@:deprecated typedef ReferenceError = js.lib.Error.ReferenceError;
@:deprecated typedef SyntaxError = js.lib.Error.SyntaxError;
@:deprecated typedef TypeError = js.lib.Error.TypeError;
@:deprecated typedef URIError = js.lib.Error.URIError;
29 changes: 1 addition & 28 deletions std/js/Function.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,4 @@
*/
package js;

import haxe.extern.Rest;

@:native("Function")
extern class Function {
/** Specifies the number of arguments expected by the function. **/
var length(default,never):Int;

/** The name of the function. **/
var name:String;

/** Creates a new Function object. **/
function new(arg:String, rest:Rest<String>);

/** Calls a function and sets its this to the provided value, arguments can be passed as an Array object. **/
function apply(thisArg:Dynamic, argsArray:Array<Dynamic>):Dynamic;

/** Calls (executes) a function and sets its this to the provided value, arguments can be passed as they are. **/
function call(thisArg:Dynamic, args:Rest<Dynamic>):Dynamic;

/**
Creates a new function which, when called, has its this set to the provided value,
with a given sequence of arguments preceding any provided when the new function was called.
**/
@:pure function bind(thisArg:Dynamic, args:Rest<Dynamic>):Function;

/** Returns a string representing the source code of the function. **/
@:pure function toString():String;
}
@:deprecated typedef Function = js.lib.Function;
17 changes: 2 additions & 15 deletions std/js/JsIterator.hx
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
package js;

/**
JsIterator is prefixed with Js to avoid name clashes with standard
Iterator structure.
**/
typedef JsIterator<T> = {
function next():JsIteratorStep<T>;
}

/**
Object returned by `JsIterator.next`.
**/
typedef JsIteratorStep<T> = {
done:Bool,
?value:T
}
@:deprecated typedef JsIterator<T> = js.lib.Iterator<T>;
@:deprecated typedef JsIteratorStep<T> = js.lib.Iterator.JsIteratorStep<T>;
Loading