JS backend: switched to use native Function.bind(from ES5) instead library function b0-b4.
Removed unnecessary functions from jslib. (cherry picked from commit f6550e9)
This commit is contained in:
+1
-5
@@ -69,7 +69,7 @@ abstract class InnerDeclarationTranslator {
|
||||
return;
|
||||
}
|
||||
|
||||
List<JsExpression> expressions = getCapturedValueParametersList(bind);
|
||||
List<JsExpression> expressions = bind.getArguments();
|
||||
for (CallableDescriptor descriptor : closureContext.getDescriptors()) {
|
||||
JsName name;
|
||||
if (descriptor instanceof VariableDescriptor) {
|
||||
@@ -83,8 +83,4 @@ abstract class InnerDeclarationTranslator {
|
||||
expressions.add(name.makeRef());
|
||||
}
|
||||
}
|
||||
|
||||
protected List<JsExpression> getCapturedValueParametersList(JsInvocation invocation) {
|
||||
return invocation.getArguments();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-29
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.k2js.translate.expression;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
@@ -56,10 +57,7 @@ class InnerFunctionTranslator extends InnerDeclarationTranslator {
|
||||
|
||||
@Override
|
||||
protected JsInvocation createInvocation(@NotNull JsNameRef nameRef, @Nullable JsExpression self) {
|
||||
JsInvocation bind = new JsInvocation(context.namer().kotlin(getBindMethodName()));
|
||||
bind.getArguments().add(nameRef);
|
||||
bind.getArguments().add(self);
|
||||
return bind;
|
||||
return new JsInvocation(new JsNameRef("bind", nameRef), new SmartList<JsExpression>(self));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -71,29 +69,4 @@ class InnerFunctionTranslator extends InnerDeclarationTranslator {
|
||||
|
||||
return JsLiteral.NULL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getBindMethodName() {
|
||||
if (closureContext.getDescriptors().isEmpty()) {
|
||||
return !hasArguments() ? "b3" : "b4";
|
||||
}
|
||||
else {
|
||||
return !hasArguments() ? (closureContext.getDescriptors().size() == 1 ? "b0" : "b1") : "b2";
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasArguments() {
|
||||
return !getValueParameters().isEmpty() || descriptor.getReceiverParameter() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<JsExpression> getCapturedValueParametersList(JsInvocation invocation) {
|
||||
if (closureContext.getDescriptors().size() > 1 || hasArguments()) {
|
||||
JsArrayLiteral values = new JsArrayLiteral();
|
||||
invocation.getArguments().add(values);
|
||||
return values.getExpressions();
|
||||
}
|
||||
|
||||
return super.getCapturedValueParametersList(invocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,52 +569,9 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
Kotlin.sure = function (obj) {
|
||||
return obj;
|
||||
};
|
||||
|
||||
// native concat doesn't work for arguments
|
||||
Kotlin.concat = function (a, b) {
|
||||
var r = new Array(a.length + b.length);
|
||||
var i = 0;
|
||||
var n = a.length;
|
||||
for (; i < n; i++) {
|
||||
r[i] = a[i];
|
||||
}
|
||||
n = b.length;
|
||||
for (var j = 0; j < n;) {
|
||||
r[i++] = b[j++];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
})();
|
||||
|
||||
Kotlin.assignOwner = function(f, o) {
|
||||
f.o = o;
|
||||
return f;
|
||||
};
|
||||
|
||||
// we cannot use Function.bind, because if we bind with null self, but call with not null — fun must receive passed not null self
|
||||
// test case: WebDemoExamples2Test.testBuilder
|
||||
Kotlin.b0 = function (f, self, value) {
|
||||
return function () {
|
||||
return f.call(self !== null ? self : this, value);
|
||||
}
|
||||
};
|
||||
Kotlin.b1 = function (f, self, values) {
|
||||
return function () {
|
||||
return f.apply(self !== null ? self : this, values);
|
||||
}
|
||||
};
|
||||
Kotlin.b2 = function (f, self, values) {
|
||||
return function () {
|
||||
return f.apply(self !== null ? self : this, Kotlin.concat(values, arguments));
|
||||
}
|
||||
};
|
||||
Kotlin.b3 = function (f, self) {
|
||||
return function () {
|
||||
return f.call(self)
|
||||
}
|
||||
};
|
||||
Kotlin.b4 = function (f, self) {
|
||||
return function () {
|
||||
return f.apply(self, Kotlin.argumentsToArrayLike(arguments));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -48,15 +48,6 @@ var Kotlin = {};
|
||||
return result;
|
||||
};
|
||||
|
||||
Kotlin.argumentsToArrayLike = function (args) {
|
||||
var n = args.length;
|
||||
var result = new Array(n);
|
||||
while (n--) {
|
||||
result[n] = args[n];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
function copyProperties(to, from) {
|
||||
for (var p in from) {
|
||||
if (from.hasOwnProperty(p)) {
|
||||
|
||||
@@ -5,11 +5,6 @@ var Kotlin = Object.create(null);
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
// ecma5 is still sucks — concat doesn't accept arguments, but apply does, so, we just return arguments
|
||||
Kotlin.argumentsToArrayLike = function (args) {
|
||||
return args;
|
||||
};
|
||||
|
||||
Kotlin.keys = Object.keys;
|
||||
|
||||
Kotlin.isType = function (object, type) {
|
||||
|
||||
Reference in New Issue
Block a user