Skip to content

Commit 0422083

Browse files
authored
Merge pull request #2959 from gzm0/no-js-use-as
Fix #2948: Remove js.use(x).as[T]
2 parents f21e7f5 + 9fec009 commit 0422083

File tree

8 files changed

+0
-1325
lines changed

8 files changed

+0
-1325
lines changed

library/src/main/scala/scala/scalajs/js/Using.scala

Lines changed: 0 additions & 19 deletions
This file was deleted.

library/src/main/scala/scala/scalajs/js/package.scala

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -130,107 +130,4 @@ package object js {
130130
"because you tried to run Scala.js binaries on the JVM. Make sure you " +
131131
"are using the JVM version of the libraries.")
132132

133-
/** Allows to cast a value to a facade trait in a type-safe way.
134-
*
135-
* Use as follows:
136-
* {{{
137-
* js.use(x).as[MyFacade]
138-
* }}}
139-
*
140-
* Note that the method calls are only syntactic sugar. There is no overhead
141-
* at runtime for such an operation. Using `use(x).as[T]` is strictly
142-
* equivalent to `x.asInstanceOf[T]` if the compile time check does not fail.
143-
*
144-
* This method supports both Scala classes with exports and facade types
145-
* which are structurally equivalent.
146-
*
147-
* == Examples ==
148-
* Given the following facade type:
149-
* {{{
150-
* trait MyFacade extends js.Object {
151-
* def foo(x: Int): String = js.native
152-
* val bar: Int = js.native
153-
* }
154-
* }}}
155-
*
156-
* We show a couple of examples:
157-
* {{{
158-
* class MyClass1 {
159-
* @JSExport
160-
* def foo(x: Int): String = x.toString
161-
*
162-
* @JSExport
163-
* val bar: Int = 1
164-
* }
165-
*
166-
* val x1 = new MyClass1
167-
* js.use(x1).as[MyFacade] // OK
168-
* }}}
169-
*
170-
* Note that JS conventions apply: The `val bar` can be implemented with a
171-
* `def`.
172-
*
173-
* {{{
174-
* class MyClass2 {
175-
* @JSExport
176-
* def foo(x: Int): String = x.toString
177-
*
178-
* @JSExport
179-
* def bar: Int = 1 // def instead of val
180-
* }
181-
*
182-
* val x2 = new MyClass2
183-
* js.use(x2).as[MyFacade] // OK
184-
* }}}
185-
*
186-
* Missing methods or methods with wrong types will cause a compile-time
187-
* failure.
188-
*
189-
* {{{
190-
* class MyClass3 {
191-
* @JSExport
192-
* def foo(x: String): String = x.toString // wrong type signature
193-
*
194-
* // bar is missing
195-
* }
196-
*
197-
* val x3 = new MyClass3
198-
* js.use(x2).as[MyFacade] // Fails: bar is missing and foo has wrong type
199-
* }}}
200-
*
201-
* Methods must be exported, otherwise they are not taken into consideration.
202-
*
203-
* {{{
204-
* class MyClass4 {
205-
* def foo(x: Int): String = x.toString
206-
*
207-
* @JSExport
208-
* def bar: Int = 1 // def instead of val
209-
* }
210-
*
211-
* val x4 = new MyClass4
212-
* js.use(x4).as[MyFacade] // Fails, foo is missing
213-
* }}}
214-
*
215-
* Other facade types can also be used
216-
*
217-
* {{{
218-
* trait MyOtherFacade extends js.Object {
219-
* def foo(x: Any): String = js.native
220-
* val bar: Int = js.native
221-
* def otherMethod(): Unit = js.native
222-
* }
223-
*
224-
* val x5: MyOtherFacade = // ...
225-
* js.use(x5).as[MyFacade] // OK
226-
* }}}
227-
*
228-
* == Restrictions ==
229-
* - Facade types may only be traits and not have any class ancestors
230-
* - Polymorphic methods are currently not supported
231-
* - Facade types defining an apply method cannot used (this is a JavaScript
232-
* restriction).
233-
*/
234-
def use[A](x: A): Using[A] = new Using[A](x)
235-
236133
}

library/src/main/scala/scala/scalajs/macroimpls/Compat210.scala

Lines changed: 0 additions & 53 deletions
This file was deleted.

library/src/main/scala/scala/scalajs/macroimpls/JSMemberSelection.scala

Lines changed: 0 additions & 26 deletions
This file was deleted.

library/src/main/scala/scala/scalajs/macroimpls/JSMembers.scala

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)