Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android/jni/JniJsValue.cpp

Issue 29437563: Issue 5239 - JsValue access crash (Closed)
Patch Set: Created May 12, 2017, 11:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 CATCH_THROW_AND_RETURN(env, 0) 161 CATCH_THROW_AND_RETURN(env, 0)
162 } 162 }
163 163
164 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 164 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
165 { 165 {
166 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 166 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
167 } 167 }
168 168
169 jobject NewJniJsValue(JNIEnv* env, AdblockPlus::JsValue&& jsValue, jclass jsValu eClassArg) 169 jobject NewJniJsValue(JNIEnv* env, AdblockPlus::JsValue&& jsValue, jclass jsValu eClassArg)
170 { 170 {
sergei 2017/05/12 15:38:07 I thought about adding some static_assert like bel
171 return env->NewObject(jsValueClass->Get(), jsValueCtor, new AdblockPlus::JsVal ue(std::move(jsValue))); 171 auto pJsValue = reinterpret_cast<uintptr_t>(new AdblockPlus::JsValue(std::move (jsValue)));
172 return env->NewObject(jsValueClass->Get(), jsValueCtor, static_cast<jlong>(pJs Value));
172 } 173 }
173 174
174 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr) 175 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr)
175 { 176 {
176 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 177 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
177 } 178 }
178 179
179 AdblockPlus::JsValue& JniGetJsValue(jlong ptr) 180 AdblockPlus::JsValue& JniGetJsValue(jlong ptr)
180 { 181 {
181 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 182 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, 220 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean },
220 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, 221 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList },
221 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*) JniGetProperty }, 222 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*) JniGetProperty },
222 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 223 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
223 }; 224 };
224 225
225 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re gisterNatives(JNIEnv *env, jclass clazz) 226 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re gisterNatives(JNIEnv *env, jclass clazz)
226 { 227 {
227 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 228 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
228 } 229 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld