[node] switch to NodeRequest member fn callback
For (hopefully) better performance than creating a new v8::Context to wrap each callback while still avoiding leaking memory with v8::FunctionTemplate. Adds a JavaScript shim in front of module.exports.Map to wrap the req.respond API internally and preserve the public callback-passing API, while still exporting the correct prototype.
This commit is contained in:
committed by
Mike Morris
parent
d6f667a5e7
commit
edec56e6c5
@@ -1,13 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var mbgl = require('../../../../lib/mapbox-gl-native');
|
||||
var mbgl = require('../../index');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var style = require('../fixtures/style.json');
|
||||
|
||||
test('Map', function(t) {
|
||||
t.test('must be constructed with new', function(t) {
|
||||
// This test is skipped because of the req.respond shim in index.js
|
||||
// which will always call new mbgl.Map()
|
||||
t.skip('must be constructed with new', function(t) {
|
||||
t.throws(function() {
|
||||
mbgl.Map();
|
||||
}, /Use the new operator to create new Map objects/);
|
||||
@@ -87,6 +89,42 @@ test('Map', function(t) {
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('instanceof mbgl.Map', function(t) {
|
||||
var options = {
|
||||
request: function() {},
|
||||
ratio: 1
|
||||
};
|
||||
|
||||
var map = new mbgl.Map(options);
|
||||
|
||||
t.ok(map instanceof mbgl.Map);
|
||||
t.equal(map.__proto__, mbgl.Map.prototype);
|
||||
|
||||
var keys = Object.keys(mbgl.Map.prototype);
|
||||
|
||||
t.deepEqual(keys, [
|
||||
'load',
|
||||
'loaded',
|
||||
'render',
|
||||
'release',
|
||||
'addClass',
|
||||
'addSource',
|
||||
'addLayer',
|
||||
'removeLayer',
|
||||
'setLayoutProperty',
|
||||
'setPaintProperty',
|
||||
'setFilter',
|
||||
'dumpDebugLogs',
|
||||
'queryRenderedFeatures'
|
||||
]);
|
||||
|
||||
for (var key in keys) {
|
||||
t.equal(map[key], mbgl.Map.prototype[key]);
|
||||
}
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('.load', function(t) {
|
||||
var options = {
|
||||
request: function() {},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var mbgl = require('../../../lib/mapbox-gl-native');
|
||||
var mbgl = require('../index');
|
||||
var path = require('path');
|
||||
var test = require('tape');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var mbgl = require('../../../lib/mapbox-gl-native');
|
||||
var mbgl = require('../index');
|
||||
var request = require('request');
|
||||
|
||||
mbgl.on('message', function(msg) {
|
||||
|
||||
Reference in New Issue
Block a user