Skip to content

Commit

Permalink
Mojo: Reimplement unicode.js in JavaScript, remove native implementat…
Browse files Browse the repository at this point in the history
…ion.

This version is likely less efficient, but doesn't require gin.

BUG=372065

Review URL: https://codereview.chromium.org/294123008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275342 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mpcomplete@chromium.org committed Jun 6, 2014
1 parent fb1464a commit cd45f02
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 129 deletions.
1 change: 1 addition & 0 deletions content/browser/webui/web_ui_data_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ WebUIDataSource* WebUIDataSource::AddMojoDataSource(
{ mojo::kConnectionModuleName, IDR_MOJO_CONNECTION_JS },
{ mojo::kConnectorModuleName, IDR_MOJO_CONNECTOR_JS },
{ mojo::kRouterModuleName, IDR_MOJO_ROUTER_JS },
{ mojo::kUnicodeModuleName, IDR_MOJO_UNICODE_JS },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i)
mojo_source->AddResourcePath(resources[i].path, resources[i].id);
Expand Down
1 change: 1 addition & 0 deletions content/browser/webui/web_ui_mojo_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool GetResource(const std::string& id,
if (id == mojo::kCodecModuleName ||
id == mojo::kConnectionModuleName ||
id == mojo::kConnectorModuleName ||
id == mojo::kUnicodeModuleName ||
id == mojo::kRouterModuleName)
return false;

Expand Down
1 change: 1 addition & 0 deletions content/content_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<include name="IDR_MOJO_CONNECTION_JS" file="../mojo/public/js/bindings/connection.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_MOJO_CONNECTOR_JS" file="../mojo/public/js/bindings/connector.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_MOJO_ROUTER_JS" file="../mojo/public/js/bindings/router.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_MOJO_UNICODE_JS" file="../mojo/public/js/bindings/unicode.js" flattenhtml="true" type="BINDATA" />
</if>
</includes>
</release>
Expand Down
5 changes: 0 additions & 5 deletions content/renderer/web_ui_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "gin/public/context_holder.h"
#include "mojo/bindings/js/core.h"
#include "mojo/bindings/js/support.h"
#include "mojo/bindings/js/unicode.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"

Expand Down Expand Up @@ -48,10 +47,6 @@ void WebUIRunner::RegisterBuiltinModules() {
mojo::js::Support::kModuleName,
mojo::js::Support::GetModule(
context_holder_->isolate()));
registry->AddBuiltinModule(context_holder_->isolate(),
mojo::js::Unicode::kModuleName,
mojo::js::Unicode::GetModule(
context_holder_->isolate()));
}

void WebUIRunner::Run(const std::string& source,
Expand Down
2 changes: 0 additions & 2 deletions mojo/apps/js/mojo_runner_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "mojo/bindings/js/core.h"
#include "mojo/bindings/js/handle.h"
#include "mojo/bindings/js/support.h"
#include "mojo/bindings/js/unicode.h"

namespace mojo {
namespace apps {
Expand Down Expand Up @@ -54,7 +53,6 @@ MojoRunnerDelegate::MojoRunnerDelegate()
AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
AddBuiltinModule(js::Core::kModuleName, js::Core::GetModule);
AddBuiltinModule(js::Support::kModuleName, js::Support::GetModule);
AddBuiltinModule(js::Unicode::kModuleName, js::Unicode::GetModule);
AddBuiltinModule(js::gl::kModuleName, js::gl::GetModule);
AddBuiltinModule(MonotonicClock::kModuleName, MonotonicClock::GetModule);
AddBuiltinModule(Threading::kModuleName, Threading::GetModule);
Expand Down
2 changes: 0 additions & 2 deletions mojo/apps/js/test/run_apps_js_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "mojo/apps/js/bindings/monotonic_clock.h"
#include "mojo/apps/js/bindings/threading.h"
#include "mojo/bindings/js/core.h"
#include "mojo/bindings/js/unicode.h"
#include "mojo/common/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -26,7 +25,6 @@ class TestRunnerDelegate : public gin::FileRunnerDelegate {
TestRunnerDelegate() {
AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
AddBuiltinModule(Core::kModuleName, Core::GetModule);
AddBuiltinModule(Unicode::kModuleName, Unicode::GetModule);
AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
AddBuiltinModule(apps::MonotonicClock::kModuleName,
apps::MonotonicClock::GetModule);
Expand Down
2 changes: 0 additions & 2 deletions mojo/bindings/js/run_js_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "gin/test/file_runner.h"
#include "gin/test/gtest.h"
#include "mojo/bindings/js/core.h"
#include "mojo/bindings/js/unicode.h"
#include "mojo/common/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -24,7 +23,6 @@ class TestRunnerDelegate : public gin::FileRunnerDelegate {
TestRunnerDelegate() {
AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
AddBuiltinModule(Core::kModuleName, Core::GetModule);
AddBuiltinModule(Unicode::kModuleName, Unicode::GetModule);
}

private:
Expand Down
69 changes: 0 additions & 69 deletions mojo/bindings/js/unicode.cc

This file was deleted.

22 changes: 0 additions & 22 deletions mojo/bindings/js/unicode.h

This file was deleted.

2 changes: 0 additions & 2 deletions mojo/mojo.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,6 @@
'bindings/js/handle.h',
'bindings/js/support.cc',
'bindings/js/support.h',
'bindings/js/unicode.cc',
'bindings/js/unicode.h',
'bindings/js/waiting_callback.cc',
'bindings/js/waiting_callback.h',
],
Expand Down
1 change: 1 addition & 0 deletions mojo/public/js/bindings/constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace mojo {
const char kCodecModuleName[] = "mojo/public/js/bindings/codec";
const char kConnectionModuleName[] = "mojo/public/js/bindings/connection";
const char kConnectorModuleName[] = "mojo/public/js/bindings/connector";
const char kUnicodeModuleName[] = "mojo/public/js/bindings/unicode";
const char kRouterModuleName[] = "mojo/public/js/bindings/router";

} // namespace mojo
1 change: 1 addition & 0 deletions mojo/public/js/bindings/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace mojo {
extern const char kCodecModuleName[];
extern const char kConnectionModuleName[];
extern const char kConnectorModuleName[];
extern const char kUnicodeModuleName[];
extern const char kRouterModuleName[];

} // namespace mojo
Expand Down
68 changes: 43 additions & 25 deletions mojo/public/js/bindings/unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Module "mojo/public/js/bindings/unicode"
//
// Note: This file is for documentation purposes only. The code here is not
// actually executed. The real module is implemented natively in Mojo.

while (1);

/**
* Decodes the UTF8 string from the given buffer.
* @param {ArrayBufferView} buffer The buffer containing UTF8 string data.
* @return {string} The corresponding JavaScript string.
* Defines functions for translating between JavaScript strings and UTF8 strings
* stored in ArrayBuffers. There is much room for optimization in this code if
* it proves necessary.
*/
function decodeUtf8String(buffer) { [native code] }
define("mojo/public/js/bindings/unicode", function() {
/**
* Decodes the UTF8 string from the given buffer.
* @param {ArrayBufferView} buffer The buffer containing UTF8 string data.
* @return {string} The corresponding JavaScript string.
*/
function decodeUtf8String(buffer) {
return decodeURIComponent(escape(String.fromCharCode.apply(null, buffer)));
}

/**
* Encodes the given JavaScript string into UTF8.
* @param {string} str The string to encode.
* @param {ArrayBufferView} outputBuffer The buffer to contain the result.
* Should be pre-allocated to hold enough space. Use |utf8Length| to determine
* how much space is required.
* @return {number} The number of bytes written to |outputBuffer|.
*/
function encodeUtf8String(str, outputBuffer) { [native code] }
/**
* Encodes the given JavaScript string into UTF8.
* @param {string} str The string to encode.
* @param {ArrayBufferView} outputBuffer The buffer to contain the result.
* Should be pre-allocated to hold enough space. Use |utf8Length| to determine
* how much space is required.
* @return {number} The number of bytes written to |outputBuffer|.
*/
function encodeUtf8String(str, outputBuffer) {
var utf8String = unescape(encodeURIComponent(str));
if (outputBuffer.length < utf8String.length)
throw new Error("Buffer too small for encodeUtf8String");
for (var i = 0; i < outputBuffer.length && i < utf8String.length; i++)
outputBuffer[i] = utf8String.charCodeAt(i);
return i;
}

/**
* Returns the number of bytes that a UTF8 encoding of the JavaScript string
* |str| would occupy.
*/
function utf8Length(str) { [native code] }
/**
* Returns the number of bytes that a UTF8 encoding of the JavaScript string
* |str| would occupy.
*/
function utf8Length(str) {
var utf8String = unescape(encodeURIComponent(str));
return utf8String.length;
}

var exports = {};
exports.decodeUtf8String = decodeUtf8String;
exports.encodeUtf8String = encodeUtf8String;
exports.utf8Length = utf8Length;
return exports;
});

0 comments on commit cd45f02

Please sign in to comment.