Skip to content

Commit a0f7ea9

Browse files
committed
refactor for instanceof
1 parent 38f35c0 commit a0f7ea9

File tree

9 files changed

+27
-69
lines changed

9 files changed

+27
-69
lines changed

Source/Ejecta/EJAudio/EJBindingAudio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This provides an <audio> element to JavaScript. Each instance has its own
2+
// AudioSource - either backed by AVAudio or OpenAL.
3+
14
#import <Foundation/Foundation.h>
25
#import "EJBindingEventedBase.h"
36

Source/Ejecta/EJAudio/EJBindingAudio.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ - (id)initWithContext:(JSContextRef)ctx argc:(size_t)argc argv:(const JSValueRef
2525
return self;
2626
}
2727

28-
- (void)createWithJSObject:(JSObjectRef)obj scriptView:(EJJavaScriptView *)view {
29-
[super createWithJSObject:obj scriptView:view];
30-
31-
JSStringRef protoName = JSStringCreateWithUTF8CString("__proto__");
32-
JSObjectSetProperty(scriptView.jsGlobalContext, jsObject, protoName,
33-
scriptView->jsHTMLAudioElementProto, kJSPropertyAttributeReadOnly, NULL);
34-
}
35-
3628
- (void)dealloc {
3729
[loadCallback cancel];
3830
[loadCallback release];

Source/Ejecta/EJBindingGlobalUtils.m

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,4 @@ - (void)setAudioSession:(EJCoreAudioSession)session {
289289
}
290290
}
291291

292-
EJ_BIND_GET(__image__proto__, ctx ) {
293-
return scriptView->jsHTMLImageElementProto;
294-
}
295-
EJ_BIND_GET(__canvas__proto__, ctx ) {
296-
return scriptView->jsHTMLCanvasElementProto;
297-
}
298-
EJ_BIND_GET(__video__proto__, ctx ) {
299-
return scriptView->jsHTMLVideoElementProto;
300-
}
301-
EJ_BIND_GET(__audio__proto__, ctx ) {
302-
return scriptView->jsHTMLAudioElementProto;
303-
}
304-
305292
@end

Source/Ejecta/EJBindingVideo.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ - (id)initWithContext:(JSContextRef)ctx argc:(size_t)argc argv:(const JSValueRef
1212
return self;
1313
}
1414

15-
- (void)createWithJSObject:(JSObjectRef)obj scriptView:(EJJavaScriptView *)view {
16-
[super createWithJSObject:obj scriptView:view];
17-
18-
JSStringRef protoName = JSStringCreateWithUTF8CString("__proto__");
19-
JSObjectSetProperty(scriptView.jsGlobalContext, jsObject, protoName,
20-
scriptView->jsHTMLVideoElementProto, kJSPropertyAttributeReadOnly, NULL);
21-
}
22-
2315
- (void)prepareGarbageCollection {
2416
[NSNotificationCenter.defaultCenter removeObserver:self];
2517
}

Source/Ejecta/EJCanvas/EJBindingCanvas.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ @implementation EJBindingCanvas
1818
- (void)createWithJSObject:(JSObjectRef)obj scriptView:(EJJavaScriptView *)view {
1919
[super createWithJSObject:obj scriptView:view];
2020

21-
JSStringRef protoName = JSStringCreateWithUTF8CString("__proto__");
22-
JSObjectSetProperty(scriptView.jsGlobalContext, jsObject, protoName,
23-
scriptView->jsHTMLCanvasElementProto, kJSPropertyAttributeReadOnly, NULL);
24-
2521
// If we don't have a screen canvas yet, make it this one
2622
if( !scriptView.hasScreenCanvas ) {
2723
isScreenCanvas = YES;

Source/Ejecta/EJCanvas/EJBindingImage.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66
@implementation EJBindingImage
77
@synthesize texture;
88

9-
- (void)createWithJSObject:(JSObjectRef)obj scriptView:(EJJavaScriptView *)view {
10-
[super createWithJSObject:obj scriptView:view];
11-
12-
JSStringRef protoName = JSStringCreateWithUTF8CString("__proto__");
13-
JSObjectSetProperty(scriptView.jsGlobalContext, jsObject, protoName,
14-
scriptView->jsHTMLImageElementProto, kJSPropertyAttributeReadOnly, NULL);
15-
}
16-
179
- (void)beginLoad {
1810
// This will begin loading the texture in a background thread and will call the
1911
// JavaScript onload callback when done

Source/Ejecta/EJJavaScriptView.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@
9292
@public JSValueRef jsNull;
9393
@public JSValueRef jsTrue;
9494
@public JSValueRef jsFalse;
95-
96-
@public JSValueRef jsHTMLImageElementProto;
97-
@public JSValueRef jsHTMLCanvasElementProto;
98-
@public JSValueRef jsHTMLVideoElementProto;
99-
@public JSValueRef jsHTMLAudioElementProto;
95+
10096
}
10197

10298
@property (nonatomic, copy) NSString *appFolder;

Source/Ejecta/EJJavaScriptView.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ -(void)setupWithAppFolder:(NSString*)folder {
113113
JSValueProtect(jsGlobalContext, jsTrue);
114114
jsFalse = JSValueMakeBoolean(jsGlobalContext, false);
115115
JSValueProtect(jsGlobalContext, jsFalse);
116-
117-
118-
jsHTMLImageElementProto = NSObjectToJSValue(jsGlobalContext, @{ @"_type" : @"HTMLImageElement" });
119-
JSValueProtect(jsGlobalContext, jsHTMLImageElementProto);
120-
jsHTMLCanvasElementProto = NSObjectToJSValue(jsGlobalContext, @{ @"_type" : @"HTMLCanvasElement" });
121-
JSValueProtect(jsGlobalContext, jsHTMLCanvasElementProto);
122-
jsHTMLVideoElementProto = NSObjectToJSValue(jsGlobalContext, @{ @"_type" : @"HTMLVideoElement" });
123-
JSValueProtect(jsGlobalContext, jsHTMLVideoElementProto);
124-
jsHTMLAudioElementProto = NSObjectToJSValue(jsGlobalContext, @{ @"_type" : @"HTMLAudioElement" });
125-
JSValueProtect(jsGlobalContext, jsHTMLAudioElementProto);
126116

127117
// Attach all native class constructors to 'Ejecta'
128118
classLoader = [[EJClassLoader alloc] initWithScriptView:self name:@"Ejecta"];

Source/Ejecta/Ejecta.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,6 @@ HTMLElement.prototype.removeEventListener = function(event, method){
267267
}
268268
};
269269

270-
HTMLImageElement = function(){};
271-
HTMLImageElement.prototype = ejecta.__image__proto__;
272-
273-
HTMLCanvasElement = function(){};
274-
HTMLCanvasElement.prototype = ejecta.__canvas__proto__;
275-
276-
HTMLVideoElement = function(){};
277-
HTMLVideoElement.prototype = ejecta.__video__proto__;
278-
279-
HTMLAudioElement = function(){};
280-
HTMLAudioElement.prototype = ejecta.__audio__proto__;
281-
282-
283270
// The document object
284271
window.document = {
285272
readyState: 'complete',
@@ -388,6 +375,29 @@ window.document = {
388375
}
389376
};
390377

378+
379+
(function(){
380+
381+
var element = document.createElement("img");
382+
HTMLImageElement = function(){};
383+
HTMLImageElement.prototype = element.__proto__;
384+
385+
var element = document.createElement("canvas");
386+
HTMLCanvasElement = function(){};
387+
HTMLCanvasElement.prototype = element.__proto__;
388+
389+
var element = document.createElement("video");
390+
HTMLVideoElement = function(){};
391+
HTMLVideoElement.prototype = element.__proto__;
392+
393+
var element = document.createElement("audio");
394+
HTMLAudioElement = function(){};
395+
HTMLAudioElement.prototype = element.__proto__;
396+
397+
})();
398+
399+
400+
391401
window.canvas.addEventListener = window.addEventListener = function( type, callback ) {
392402
window.document.addEventListener(type,callback);
393403
};

0 commit comments

Comments
 (0)