8000 Protocols no longer extend built-ins. · repos-javascript-compilers/wisp@b9505cd · GitHub
[go: up one dir, main page]

Skip to content

Commit b9505cd

Browse files
committed
Protocols no longer extend built-ins.
1 parent fe83edd commit b9505cd

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

src/backend/escodegen/writer.wisp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,10 @@
10711071
(.-nil ~id)
10721072

10731073
:else (or (aget self '~id)
1074+
(aget ~id
1075+
(.replace (.replace (.call Object.prototype.toString self)
1076+
"[object " "")
1077+
#"\]$" ""))
10741078
(.-_ ~id))))
10751079
(.apply f self arguments))})))
10761080

@@ -1139,30 +1143,35 @@
11391143
[type & forms]
11401144
(let [default-type? (= type 'default)
11411145
nil-type? (nil? type)
1142-
satisfy (fn [protocol]
1143-
(cond default-type?
1144-
`(set! (.-wisp_core$IProtocol$_ ~protocol) true)
11451146

1146-
nil-type?
1147-
`(set! (.-wisp_core$IProtocol$nil ~protocol) true)
1147+
type-name (cond (= type 'default) '_
1148+
(nil? type) (symbol "nil")
1149+
(= type 'number) 'Number
1150+
(= type 'string) 'String
1151+
(= type 'boolean) 'Boolean
1152+
(= type 'vector) 'Array
1153+
(= type 'function) 'Function
1154+
(= (namespace type) "js") type
1155+
:else nil)
1156+
1157+
satisfy (fn [protocol]
1158+
(if type-name
1159+
`(set! (aget ~protocol
1160+
'~(symbol (str "wisp_core$IProtocol$"
1161+
(name type-name))))
1162+
true)
1163+
`(set! (aget (.-prototype ~type)
1164+
(.-wisp_core$IProtocol$id ~protocol))
1165+
true)))
11481166

1149-
:else
1150-
`(set! (aget (.-prototype ~type)
1151-
(.-wisp_core$IProtocol$id ~protocol))
1152-
true)))
11531167
make-method (fn [protocol form]
11541168
(let [method-name (first form)
11551169
params (second form)
11561170
body (rest (rest form))
1157-
target (cond default-type?
1158-
`(.-_ (aget ~protocol '~method-name))
1159-
1160-
nil-type?
1161-
`(.-nil (aget ~protocol '~method-name))
1162-
1163-
:else
1164-
`(aget (.-prototype ~type)
1165-
(.-name (aget ~protocol '~method-name))))]
1171+
target (if type-name
1172+
`(aget (aget ~protocol '~method-name) '~type-name)
1173+
`(aget (.-prototype ~type)
1174+
(.-name (aget ~protocol '~method-name))))]
11661175
`(set! ~target (fn ~params ~@body))))
11671176

11681177
body (reduce (fn [body form]

test/escodegen.wisp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,11 +1395,11 @@
13951395
var ISeq = exports.ISeq = {
13961396
wisp_core$IProtocol$id: 'user.wisp/ISeq',
13971397
_first: function user_wisp$ISeq$First(self) {
1398-
var f = self === null ? user_wisp$ISeq$First.nil : self === void 0 ? user_wisp$ISeq$First.nil : 'else' ? self.user_wisp$ISeq$First || user_wisp$ISeq$First._ : void 0;
1398+
var f = self === null ? user_wisp$ISeq$First.nil : self === void 0 ? user_wisp$ISeq$First.nil : 'else' ? self.user_wisp$ISeq$First || user_wisp$ISeq$First[Object.prototype.toString.call(self).replace('[object ', '').replace(/\\]$/, '')] || user_wisp$ISeq$First._ : void 0;
13991399
return f.apply(self, arguments);
14001400
},
14011401
_rest: function user_wisp$ISeq$Rest(self) {
1402-
var f = self === null ? user_wisp$ISeq$Rest.nil : self === void 0 ? user_wisp$ISeq$Rest.nil : 'else' ? self.user_wisp$ISeq$Rest || user_wisp$ISeq$Rest._ : void 0;
1402+
var f = self === null ? user_wisp$ISeq$Rest.nil : self === void 0 ? user_wisp$ISeq$Rest.nil : 'else' ? self.user_wisp$ISeq$Rest || user_wisp$ISeq$Rest[Object.prototype.toString.call(self).replace('[object ', '').replace(/\\]$/, '')] || user_wisp$ISeq$Rest._ : void 0;
14031403
return f.apply(self, arguments);
14041404
}
14051405
};
@@ -1424,11 +1424,11 @@
14241424
var ISeq = exports.ISeq = {
14251425
wisp_core$IProtocol$id: 'wisp.core/ISeq',
14261426
_first: function wisp_core$ISeq$First(self) {
1427-
var f = self === null ? wisp_core$ISeq$First.nil : self === void 0 ? wisp_core$ISeq$First.nil : 'else' ? self.wisp_core$ISeq$First || wisp_core$ISeq$First._ : void 0;
1427+
var f = self === null ? wisp_core$ISeq$First.nil : self === void 0 ? wisp_core$ISeq$First.nil : 'else' ? self.wisp_core$ISeq$First || wisp_core$ISeq$First[Object.prototype.toString.call(self).replace('[object ', '').replace(/\\]$/, '')] || wisp_core$ISeq$First._ : void 0;
14281428
return f.apply(self, arguments);
14291429
},
14301430
_rest: function wisp_core$ISeq$Rest(self) {
1431-
var f = self === null ? wisp_core$ISeq$Rest.nil : self === void 0 ? wisp_core$ISeq$Rest.nil : 'else' ? self.wisp_core$ISeq$Rest || wisp_core$ISeq$Rest._ : void 0;
1431+
var f = self === null ? wisp_core$ISeq$Rest.nil : self === void 0 ? wisp_core$ISeq$Rest.nil : 'else' ? self.wisp_core$ISeq$Rest || wisp_core$ISeq$Rest[Object.prototype.toString.call(self).replace('[object ', '').replace(/\\]$/, '')] || wisp_core$ISeq$Rest._ : void 0;
14321432
return f.apply(self, arguments);
14331433
}
14341434
};
@@ -1454,11 +1454,11 @@
14541454
var IFooBar = {
14551455
wisp_core$IProtocol$id: 'user.wisp/IFooBar',
14561456
foo: function user_wisp$IFooBar$foo(self) {
1457-
var f = self === null ? user_wisp$IFooBar$foo.nil : self === void 0 ? user_wisp$IFooBar$foo.nil : 'else' ? self.user_wisp$IFooBar$foo || user_wisp$IFooBar$foo._ : void 0;
1457+
var f = self === null ? user_wisp$IFooBar$foo.nil : self === void 0 ? user_wisp$IFooBar$foo.nil : 'else' ? self.user_wisp$IFooBar$foo || user_wisp$IFooBar$foo[Object.prototype.toString.call(self).replace('[object ', '').replace(/\\]$/, '')] || user_wisp$IFooBar$foo._ : void 0;
14581458
return f.apply(self, arguments);
14591459
},
14601460
bar: function user_wisp$IFooBar$bar(self) {
1461-
var f = self === null ? user_wisp$IFooBar$bar.nil : self === void 0 ? user_wisp$IFooBar$bar.nil : 'else' ? self.user_wisp$IFooBar$bar || user_wisp$IFooBar$bar._ : void 0;
1461+
var f = self === null ? user_wisp$IFooBar$bar.nil : self === void 0 ? user_wisp$IFooBar$bar.nil : 'else' ? self.user_wisp$IFooBar$bar || user_wisp$IFooBar$bar[Object.prototype.toString.call(self).replace('[object ', '').replace(/\\]$/, '')] || user_wisp$IFooBar$bar._ : void 0;
14621462
return f.apply(self, arguments);
14631463
}
14641464
};
@@ -1474,7 +1474,7 @@
14741474
var ICounted = exports.ICounted = {
14751475
wisp_core$IProtocol$id: 'user.wisp/ICounted',
14761476
_count: function user_wisp$ICounted$Count(self) {
1477-
var f = self === null ? user_wisp$ICounted$Count.nil : self === void 0 ? user_wisp$ICounted$Count.nil : 'else' ? self.user_wisp$ICounted$Count || user_wisp$ICounted$Count._ : void 0;
1477+
var f = self === null ? user_wisp$ICounted$Count.nil : self === void 0 ? user_wisp$ICounted$Count.nil : 'else' ? self.user_wisp$ICounted$Count || user_wisp$ICounted$Count[Object.prototype.toString.call(self).replace('[object ', '').replace(/\\]$/, '')] || user_wisp$ICounted$Count._ : void 0;
14781478
return f.apply(self, arguments);
14791479
}
14801480
};
@@ -1596,8 +1596,8 @@
15961596
IEquiv
15971597
(-equiv [x o] (identical? x o)))")
15981598
"(function () {
1599-
number.prototype[IEquiv.wisp_core$IProtocol$id] = true;
1600-
number.prototype[IEquiv._equiv.name] = function (x, o) {
1599+
IEquiv.wisp_core$IProtocol$Number = true;
1600+
IEquiv._equiv.Number = function (x, o) {
16011601
return x === o;
16021602
};
16031603
return void 0;

0 commit comments

Comments
 (0)
0