namin / lms-sandbox Goto Github PK
View Code? Open in Web Editor NEWGraduated to js.scala: JavaScript as an embedded DSL in Scala
Home Page: http://github.com/js-scala/js-scala
Graduated to js.scala: JavaScript as an embedded DSL in Scala
Home Page: http://github.com/js-scala/js-scala
In particular having an incremental mode which compiles js or scala or both would rock.
So it'd have default imports of some package objects/Predef type constructs.
e.g.
// Foo.scalajs
package foo
def blah(x: Int) = x * 2
class Whatnot(val y: String) {
def thingy = "Hello " + y
}
which then pseudo-generates something like this from the perspective of Scala IDE / sbt...
// Foo.scala
package foo
import scalajs._
def blah(x: Int) = x * 2
class Whatnot(val y: String) {
def thingy = "Hello " + y
}
which then aliases things like scalajs.Int => scala.js.Rep[Int] etc
It happened only once with the class proxy, but I thought I'd record it anyways, lest I forget. In one run of the tests, testReifiedExtendedClass had calls to finalize() like this:
...
x7 = new x6()
var x8 = this.finalize()
var x9 = this.finalize()
...
I am not sure if any other calls falls into this category, but for these, it seems we can just skip handling them in the JS invocation handler. (For the class proxy based on javassist, we can just use the filter for that, so the super 'real' class will handle these calls.)
This example returns "1abc" instead of 2, because the private fields x overwrite each other dynamically, instead of being resolved statically.
@gkossakowski suggests just renaming private fields to avoid conflict.
diff --git a/src/test/scala/scala/js/TestClasses.scala b/src/test/scala/scala/js/TestClasses.scala
index 60713c2..072cfed 100644
--- a/src/test/scala/scala/js/TestClasses.scala
+++ b/src/test/scala/scala/js/TestClasses.scala
@@ -60,6 +60,19 @@ trait ClassesProg { this: JS with JSClasses =>
}
implicit def proxyRepFooFun(x: Rep[FooFun]) = repClassProxy[FooFun](x, this)
+ class PrivateA {
+ private val x = unit(1)
+ def get() = x
+ }
+ implicit def proxyRepPrivateA(x: Rep[PrivateA]) = repClassProxy[PrivateA](x, this)
+
+ class PrivateB extends PrivateA {
+ private val x = unit("abc")
+ def get2() = x
+ def get3() = unit(2)
+ }
+ implicit def proxyRepPrivateB(x: Rep[PrivateB]) = repClassProxy[PrivateB](x, this)
+
def testClassProxy(foo: Rep[Foo]): Rep[Int] = {
foo.f()
}
@@ -147,6 +160,14 @@ trait ClassesProg { this: JS with JSClasses =>
val outProducer = fun { () => 1 }
(outProducer() + (fooFun.producer())()) // x+1
}
+
+ def testPrivateConflictingVals(x: Rep[Int]): Rep[Int] = {
+ val newA = registerClass[PrivateA](this)
+ val newB = registerClass[PrivateB](this)
+ val a = newA()
+ val b = newB()
+ a.get() + b.get()
+ }
}
class TestClasses extends FileDiffSuite {
@@ -292,6 +313,16 @@ class TestClasses extends FileDiffSuite {
assertFileEqualsCheck(prefix+"reified-class-fun-in-and-out")
}
+ def testPrivateConflictingVals = {
+ withOutFile(prefix+"reified-class-private-conflicting-vals") {
+ new ClassesProg with JSExp with JSClassesExp { self =>
+ val codegen = new JSGen with JSGenClasses { val IR: self.type = self }
+ codegen.emitSource(testPrivateConflictingVals _, "main", new PrintWriter(System.out))
+ }
+ }
+ assertFileEqualsCheck(prefix+"reified-class-private-conflicting-vals")
+ }
+
def testMixInClassesAndTraitsProxy = {
trait ClassesAndTraitsProxyProg { this: JS with JSClassProxyBase with JSProxyBase =>
}
@@ -307,4 +338,5 @@ class TestClasses extends FileDiffSuite {
val codegen = new JSGen with JSGenClasses with JSGenTraits { val IR: self.type = self }
}
}
+
}
Hopefully the same hook could be reused to support build.sbt files as for supporting Foo.scalajs
In reified traits, we only support single inheritance. Right now, we resolve super calls dynamically, having set this.$super$ to the parent. But this means that in a method inherited twice, where each calls its super, we would have an infinite loop.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.